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

sile-typesetter / sile / 9507147410

13 Jun 2024 09:40PM UTC coverage: 50.521% (-18.7%) from 69.177%
9507147410

push

github

web-flow
Merge pull request #2062 from alerque/plug-fluent-leak

Link document.language setting more closely with Fluent locale

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

3244 existing lines in 65 files now uncovered.

8586 of 16995 relevant lines covered (50.52%)

4659.09 hits per line

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

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

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

UNCOV
6
local typesetterPool = {}
×
UNCOV
7
local calculations = {}
×
UNCOV
8
local folioOrder = {}
×
9

10
local allTypesetters = function (callback)
UNCOV
11
   local oldtypesetter = SILE.typesetter
×
UNCOV
12
   for frame, typesetter in pairs(typesetterPool) do
×
UNCOV
13
      SILE.typesetter = typesetter
×
UNCOV
14
      callback(frame, typesetter)
×
15
   end
UNCOV
16
   SILE.typesetter = oldtypesetter
×
17
end
18

UNCOV
19
local nulTypesetter = pl.class(SILE.typesetters.base) -- we ignore this
×
UNCOV
20
nulTypesetter.outputLinesToPage = function () end
×
21

22
local parallelPagebreak = function ()
UNCOV
23
   for i = 1, #folioOrder do
×
UNCOV
24
      local thisPageFrames = folioOrder[i]
×
UNCOV
25
      for j = 1, #thisPageFrames do
×
UNCOV
26
         local frame = thisPageFrames[j]
×
UNCOV
27
         local typesetter = typesetterPool[frame]
×
UNCOV
28
         local thispage = {}
×
UNCOV
29
         SU.debug("parallel", "Dumping lines for page on typesetter", typesetter.id)
×
UNCOV
30
         if #typesetter.state.outputQueue > 0 and calculations[frame].mark == 0 then
×
31
            -- More than one page worth of stuff here.
32
            -- Just ship out one page and hope for the best.
33
            SILE.typesetters.base.buildPage(typesetter)
×
34
         else
UNCOV
35
            for l = 1, calculations[frame].mark do
×
UNCOV
36
               thispage[l] = table.remove(typesetter.state.outputQueue, 1)
×
UNCOV
37
               SU.debug("parallel", thispage[l])
×
38
            end
UNCOV
39
            typesetter:outputLinesToPage(thispage)
×
40
         end
41
      end
UNCOV
42
      SILE.documentState.documentClass:endPage()
×
UNCOV
43
      for l = 1, #thisPageFrames do
×
UNCOV
44
         local frame = thisPageFrames[l]
×
UNCOV
45
         local typesetter = typesetterPool[frame]
×
UNCOV
46
         typesetter:initFrame(typesetter.frame)
×
47
      end
UNCOV
48
      SILE.documentState.documentClass:newPage()
×
49
   end
50
end
51

52
local addBalancingGlue = function (height)
UNCOV
53
   allTypesetters(function (frame, typesetter)
×
UNCOV
54
      local glue = height - calculations[frame].heightOfNewMaterial
×
UNCOV
55
      if glue.length:tonumber() > 0 then
×
UNCOV
56
         SU.debug("parallel", "Adding", glue, "to", frame)
×
UNCOV
57
         typesetter:pushVglue({ height = glue })
×
58
      end
UNCOV
59
      calculations[frame].mark = #typesetter.state.outputQueue
×
60
   end)
61
end
62

UNCOV
63
function package:_init (options)
×
UNCOV
64
   base._init(self, options)
×
UNCOV
65
   SILE.typesetter = nulTypesetter(SILE.getFrame("page"))
×
UNCOV
66
   if type(options.frames) ~= "table" then
×
67
      SU.error([[Package parallel must be initialized with a set of appropriately named frames.
×
68
This package is usually intended to be loaded from some supporting class or
69
from another package, responsible for correct initialization.]])
×
70
   end
UNCOV
71
   for frame, typesetter in pairs(options.frames) do
×
UNCOV
72
      typesetterPool[frame] = SILE.typesetters.base(SILE.getFrame(typesetter))
×
UNCOV
73
      typesetterPool[frame].id = typesetter
×
UNCOV
74
      typesetterPool[frame].buildPage = function ()
×
75
         -- No thank you, I will do that.
76
      end
77
      -- Fixed leading here is obviously a bug, but n-way leading calculations
78
      -- get very complicated...
79
      -- typesetterPool[frame].leadingFor = function() return SILE.types.node.vglue(SILE.settings:get("document.lineskip")) end
UNCOV
80
      local fontcommand = frame .. ":font"
×
UNCOV
81
      self:registerCommand(frame, function (_, _) -- \left ...
×
UNCOV
82
         SILE.typesetter = typesetterPool[frame]
×
UNCOV
83
         SILE.call(fontcommand)
×
84
      end)
UNCOV
85
      if not SILE.Commands[fontcommand] then
×
UNCOV
86
         self:registerCommand(fontcommand, function (_, _) end) -- to be overridden
×
87
      end
88
   end
UNCOV
89
   if not options.folios then
×
UNCOV
90
      folioOrder = { {} }
×
91
      -- Note output order doesn't matter for PDF, but for our test suite it is
92
      -- essential that the output order is deterministic, hence this sort()
UNCOV
93
      for frame, _ in pl.tablex.sort(options.frames) do
×
UNCOV
94
         table.insert(folioOrder[1], frame)
×
95
      end
96
   else
97
      folioOrder = options.folios -- As usual we trust the user knows what they're doing
×
98
   end
UNCOV
99
   self.class.newPage = function (self_)
×
UNCOV
100
      allTypesetters(function (frame, _)
×
UNCOV
101
         calculations[frame] = { mark = 0 }
×
102
      end)
UNCOV
103
      self.class._base.newPage(self_)
×
UNCOV
104
      SILE.call("sync")
×
105
   end
UNCOV
106
   allTypesetters(function (frame, _)
×
UNCOV
107
      calculations[frame] = { mark = 0 }
×
108
   end)
UNCOV
109
   local oldfinish = self.class.finish
×
UNCOV
110
   self.class.finish = function (self_)
×
UNCOV
111
      parallelPagebreak()
×
UNCOV
112
      oldfinish(self_)
×
113
   end
114
end
115

UNCOV
116
function package:registerCommands ()
×
UNCOV
117
   self:registerCommand("sync", function (_, _)
×
UNCOV
118
      local anybreak = false
×
UNCOV
119
      local maxheight = SILE.types.length()
×
UNCOV
120
      SU.debug("parallel", "Trying a sync")
×
UNCOV
121
      allTypesetters(function (_, typesetter)
×
UNCOV
122
         SU.debug("parallel", "Leaving hmode on", typesetter.id)
×
UNCOV
123
         typesetter:leaveHmode(true)
×
124
         -- Now we have each typesetter's content boxed up onto the output stream
125
         -- but page breaking has not been run. See if page breaking would cause a
126
         -- break
UNCOV
127
         local lines = pl.tablex.copy(typesetter.state.outputQueue)
×
UNCOV
128
         if SILE.pagebuilder:findBestBreak({ vboxlist = lines, target = typesetter:getTargetLength() }) then
×
129
            anybreak = true
×
130
         end
131
      end)
132

UNCOV
133
      if anybreak then
×
134
         parallelPagebreak()
×
135
         return
×
136
      end
137

UNCOV
138
      allTypesetters(function (frame, typesetter)
×
UNCOV
139
         calculations[frame].heightOfNewMaterial = SILE.types.length()
×
UNCOV
140
         for i = calculations[frame].mark + 1, #typesetter.state.outputQueue do
×
UNCOV
141
            local thisHeight = typesetter.state.outputQueue[i].height + typesetter.state.outputQueue[i].depth
×
UNCOV
142
            calculations[frame].heightOfNewMaterial = calculations[frame].heightOfNewMaterial + thisHeight
×
143
         end
UNCOV
144
         if maxheight < calculations[frame].heightOfNewMaterial then
×
UNCOV
145
            maxheight = calculations[frame].heightOfNewMaterial
×
146
         end
UNCOV
147
         SU.debug(
×
148
            "parallel",
149
            frame,
150
            ": pre-sync content=",
UNCOV
151
            calculations[frame].mark,
×
152
            ", now",
UNCOV
153
            #typesetter.state.outputQueue,
×
154
            ", height of material:",
UNCOV
155
            calculations[frame].heightOfNewMaterial
×
156
         )
157
      end)
UNCOV
158
      addBalancingGlue(maxheight)
×
159
   end)
160
end
161

162
package.documentation = [[
163
\begin{document}
164
The \autodoc:package{parallel} package provides the mechanism for typesetting diglot or other parallel documents.
165
When used by a class such as \code{classes/diglot.lua}, it registers a command for each parallel frame, to allow you to select which frame you’re typesetting into.
166
It also defines the \autodoc:command{\sync} command, which adds vertical spacing to each frame such that the \em{next} set of text is vertically aligned.
167
See \url{https://sile-typesetter.org/examples/parallel.sil} and the source of \code{classes/diglot.lua} for examples which make the operation clear.
168
\end{document}
UNCOV
169
]]
×
170

UNCOV
171
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