• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sile-typesetter / sile / 9304060604

30 May 2024 02:07PM UTC coverage: 74.124% (-0.6%) from 74.707%
9304060604

push

github

alerque
style: Reformat Lua with stylua

8104 of 11995 new or added lines in 184 files covered. (67.56%)

15 existing lines in 11 files now uncovered.

12444 of 16788 relevant lines covered (74.12%)

7175.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.32
/packages/tate/init.lua
1
local base = require("packages.base")
9✔
2

3
local package = pl.class(base)
9✔
4
package._name = "tate"
9✔
5

6
SILE.tateFramePrototype = pl.class(SILE.framePrototype)
18✔
7
SILE.tateFramePrototype.direction = "TTB-RTL"
9✔
8

9
SILE.tateFramePrototype.enterHooks = {
9✔
10
   function (_, typesetter)
11
      SILE.typesetters.tate:cast(typesetter)
9✔
12
   end,
13
}
9✔
14

15
SILE.tateFramePrototype.leaveHooks = {
9✔
16
   function (_, typesetter)
17
      SILE.typesetters.base:cast(typesetter)
5✔
18
   end,
19
}
9✔
20

21
SILE.newTateFrame = function (spec)
9✔
NEW
22
   return SILE.newFrame(spec, SILE.tateFramePrototype)
×
23
end
24

25
local outputLatinInTate = function (self, typesetter, line)
26
   -- My baseline moved
27
   typesetter.frame:advanceWritingDirection(SILE.measurement("-0.5zw"))
10✔
28
   typesetter.frame:advancePageDirection(SILE.measurement("0.25zw"))
10✔
29

30
   local vorigin = -typesetter.frame.state.cursorY
5✔
31
   self:oldOutputYourself(typesetter, line)
5✔
32
   typesetter.frame.state.cursorY = -vorigin
10✔
33
   typesetter.frame:advanceWritingDirection(self:lineContribution())
10✔
34
   -- My baseline moved
35
   typesetter.frame:advanceWritingDirection(SILE.measurement("0.5zw"))
10✔
36
   typesetter.frame:advancePageDirection(-SILE.measurement("0.25zw"))
15✔
37
end
38

39
local outputTateChuYoko = function (self, typesetter, line)
40
   -- My baseline moved
NEW
41
   local em = SILE.measurement("1zw")
×
NEW
42
   typesetter.frame:advanceWritingDirection(-em + em / 4 - self:lineContribution() / 2)
×
NEW
43
   typesetter.frame:advancePageDirection(2 * self.height - self.width / 2)
×
NEW
44
   self:oldOutputYourself(typesetter, line)
×
NEW
45
   typesetter.frame:advanceWritingDirection(-self:lineContribution() * 1.5 + self.height * 3 / 4)
×
46
end
47

48
function package:registerCommands ()
9✔
49
   self:registerCommand("tate-frame", function (options, _)
26✔
NEW
50
      SILE.documentState.thisPageTemplate.frames[options.id] = SILE.newTateFrame(options)
×
51
   end, "Declares (or re-declares) a frame on this page.")
13✔
52

53
   -- Eventually will be automatically called by script detection, but for now
54
   -- called manually
55
   self:registerCommand("latin-in-tate", function (_, content)
26✔
56
      if SILE.typesetter.frame:writingDirection() ~= "TTB" then
6✔
NEW
57
         return SILE.process(content)
×
58
      end
59
      local nodes
60
      local oldT = SILE.typesetter
3✔
61
      local prevDirection = oldT.frame.direction
3✔
62
      self:loadPackage("rotate")
3✔
63
      SILE.settings:temporarily(function ()
6✔
64
         local latinTypesetter = pl.class(SILE.typesetters.base)
3✔
65
         local dummyFrame = pl.class(SILE.framePrototype)
3✔
66
         dummyFrame.init = function (f)
NEW
67
            f.state = {}
×
68
         end
69
         latinTypesetter.initFrame = function (typesetter, frame)
70
            typesetter.frame = frame
3✔
71
         end
72
         local frame = dummyFrame({}, true)
3✔
73
         SILE.typesetter = latinTypesetter(frame)
6✔
74
         SILE.settings:set("document.language", "und")
3✔
75
         SILE.settings:set("font.direction", "LTR")
3✔
76
         SILE.process(content)
3✔
77
         nodes = SILE.typesetter.state.nodes
3✔
78
         SILE.typesetter:shapeAllNodes(nodes)
3✔
79
         SILE.typesetter.frame.direction = prevDirection
3✔
80
      end)
81
      SILE.typesetter = oldT
3✔
82
      SILE.typesetter:pushGlue({
6✔
83
         width = SILE.length("0.5zw", "0.25zw", "0.25zw"):absolute(),
9✔
84
      })
85
      for i = 1, #nodes do
15✔
86
         if SILE.typesetter.frame:writingDirection() ~= "TTB" or nodes[i].is_glue then
24✔
87
            SILE.typesetter:pushHorizontal(nodes[i])
8✔
88
         elseif nodes[i]:lineContribution():tonumber() > 0 then
24✔
89
            local hbox = SILE.call("hbox", {}, function ()
10✔
90
               SILE.typesetter:pushHorizontal(nodes[i])
5✔
91
            end)
92
            -- Turn off all complex flags.
93
            for j = 1, #hbox.value do
10✔
94
               for k = 1, #hbox.value[j].nodes do
10✔
95
                  hbox.value[j].nodes[k].value.complex = false
5✔
96
               end
97
            end
98
            hbox.oldOutputYourself = hbox.outputYourself
5✔
99
            hbox.outputYourself = outputLatinInTate
5✔
100
         end
101
      end
102
   end, "Typeset rotated Western text in vertical Japanese")
16✔
103

104
   self:registerCommand("tate-chu-yoko", function (_, content)
26✔
NEW
105
      if SILE.typesetter.frame:writingDirection() ~= "TTB" then
×
NEW
106
         return SILE.process(content)
×
107
      end
108
      -- SILE.typesetter:pushGlue({
109
      --   width = SILE.length.new({length = SILE.toPoints("0.5zw"),
110
      --                            stretch = SILE.toPoints("0.25zw"),
111
      --                             shrink = SILE.toPoints("0.25zw")
112
      --                           })
113
      -- })
NEW
114
      SILE.settings:temporarily(function ()
×
NEW
115
         SILE.settings:set("document.language", "und")
×
NEW
116
         SILE.settings:set("font.direction", "LTR")
×
NEW
117
         SILE.call("rotate", { angle = -90 }, function ()
×
NEW
118
            local hbox = SILE.call("hbox", {}, content)
×
NEW
119
            hbox.misfit = true
×
NEW
120
            hbox.oldOutputYourself = hbox.outputYourself
×
NEW
121
            hbox.outputYourself = outputTateChuYoko
×
122
         end)
123
      end)
124
      -- SILE.typesetter:pushGlue({
125
      --   width = SILE.length.new({length = SILE.toPoints("0.5zw"),
126
      --                            stretch = SILE.toPoints("0.25zw"),
127
      --                             shrink = SILE.toPoints("0.25zw")
128
      --                           })
129
      -- })
130
   end)
131
end
132

133
package.documentation = [[
134
\begin{document}
135
The \autodoc:package{tate} package provides support for Japanese vertical typesetting.
136
It allows for the definition of vertical-oriented frames, as well as for two specific typesetting techniques required in vertical documents: \autodoc:command{\latin-in-tate} typesets its content as Latin text rotated 90 degrees, and \autodoc:command{\tate-chu-yoko} places (Latin) text horizontally within a single grid-square of the vertical \em{hanmen}.
137
\end{document}
138
]]
9✔
139

140
return package
9✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc