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

sile-typesetter / sile / 6713098919

31 Oct 2023 10:21PM UTC coverage: 52.831% (-21.8%) from 74.636%
6713098919

push

github

web-flow
Merge d0a2a1ee9 into b185d4972

45 of 45 new or added lines in 3 files covered. (100.0%)

8173 of 15470 relevant lines covered (52.83%)

6562.28 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

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

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

22
SILE.newTateFrame = function (spec)
23
  return SILE.newFrame(spec, SILE.tateFramePrototype)
×
24
end
25

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

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

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

48
end
49

50
function package:registerCommands ()
×
51

52
  self:registerCommand("tate-frame", function (options, _)
×
53
    SILE.documentState.thisPageTemplate.frames[options.id] = SILE.newTateFrame(options)
×
54
  end, "Declares (or re-declares) a frame on this page.")
×
55

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

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

125
    end)
126
    -- SILE.typesetter:pushGlue({
127
    --   width = SILE.length.new({length = SILE.toPoints("0.5zw"),
128
    --                            stretch = SILE.toPoints("0.25zw"),
129
    --                             shrink = SILE.toPoints("0.25zw")
130
    --                           })
131
    -- })
132

133
  end)
134

135
end
136

137
package.documentation = [[
138
\begin{document}
139
The \autodoc:package{tate} package provides support for Japanese vertical typesetting.
140
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}.
141
\end{document}
142
]]
×
143

144
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

© 2025 Coveralls, Inc