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

sile-typesetter / sile / 14361761590

09 Apr 2025 03:53PM UTC coverage: 29.317% (-31.1%) from 60.462%
14361761590

push

github

alerque
chore(deps): Bump LuaRocks dependencies to latest versions

5876 of 20043 relevant lines covered (29.32%)

4237.53 hits per line

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

0.0
/packages/tate/init.lua
1
local base = require("packages.base")
×
2

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

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

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

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

21
SILE.newTateFrame = function (spec)
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.types.measurement("-0.5zw"))
×
28
   typesetter.frame:advancePageDirection(SILE.types.measurement("0.25zw"))
×
29

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

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

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

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

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

129
package.documentation = [[
130
\begin{document}
131
The \autodoc:package{tate} package provides support for Japanese vertical typesetting.
132
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}.
133
\end{document}
134
]]
×
135

136
return package
×
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