• 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

87.76
/pagebuilders/base.lua
1
local pagebuilder = pl.class()
181✔
2
pagebuilder.type = "pagebuilder"
181✔
3
pagebuilder._name = "base"
181✔
4

5
function pagebuilder:_init ()
181✔
6
   self.awful_bad = 1073741823
182✔
7
   self.inf_bad = 10000
182✔
8
   self.eject_penalty = -self.inf_bad
182✔
9
   self.deplorable = 100000
182✔
10
end
11

12
function pagebuilder.collateVboxes (_, vboxlist)
181✔
13
   local output = SILE.nodefactory.vbox()
48✔
14
   output:append(vboxlist)
48✔
15
   return output
48✔
16
end
17

18
-- Note: Almost 1/3 of the time in a typical SILE in taken iterating through
19
-- this function. As a result there are some micro-optimizations here that
20
-- make it a-typical of preferred coding styles. In particular note that
21
-- we absolutize heavily iterated lengths as early as possible and make
22
-- make direct calls to their integer amounts, assumed to be in points by
23
-- the point they are called **without actually checking**!
24
function pagebuilder:findBestBreak (options)
181✔
25
   local vboxlist = SU.required(options, "vboxlist", "in findBestBreak")
1,683✔
26
   local target = SU.required(options, "target", "in findBestBreak", "length")
1,683✔
27
   local restart = options.restart or false
1,683✔
28
   local force = options.force or false
1,683✔
29
   local i = 0
1,683✔
30
   local totalHeight = SILE.length()
1,683✔
31
   local bestBreak = nil
1,683✔
32
   local started = false
1,683✔
33
   if restart and restart.target == target then
1,683✔
NEW
34
      totalHeight = restart.totalHeight
×
NEW
35
      i = restart.i
×
NEW
36
      started = restart.started
×
37
   end
38
   local leastC = self.inf_bad
1,683✔
39
   SU.debug("pagebuilder", function ()
3,366✔
NEW
40
      return "Page builder for frame "
×
NEW
41
         .. SILE.typesetter.frame.id
×
NEW
42
         .. " called with "
×
NEW
43
         .. #vboxlist
×
NEW
44
         .. " nodes, "
×
NEW
45
         .. tostring(target)
×
46
   end)
47
   if SU.debugging("vboxes") then
3,366✔
NEW
48
      for j, box in ipairs(vboxlist) do
×
NEW
49
         SU.debug("vboxes", function ()
×
NEW
50
            return (j == i and " >" or "  ") .. j .. ": " .. box
×
51
         end)
52
      end
53
   end
54
   while not started and i < #vboxlist do
4,051✔
55
      i = i + 1
4,019✔
56
      if not vboxlist[i].is_vglue then
4,019✔
57
         started = true
1,651✔
58
         i = i - 1
1,651✔
59
         break
1,651✔
60
      end
61
   end
62
   local pi
63
   while i < #vboxlist do
25,773✔
64
      i = i + 1
24,348✔
65
      local vbox = vboxlist[i]
24,348✔
66
      SU.debug("pagebuilder", "Dealing with VBox", vbox)
24,348✔
67
      if vbox.is_vbox then
24,348✔
68
         totalHeight:___add(vbox.height)
8,059✔
69
         totalHeight:___add(vbox.depth)
16,118✔
70
      elseif vbox.is_vglue then
16,289✔
71
         totalHeight:___add(vbox.height)
28,686✔
72
      elseif vbox.is_insertion then
1,946✔
73
         -- TODO: refactor as hook and without side effects!
74
         target = SILE.insertions.processInsertion(vboxlist, i, totalHeight, target)
296✔
75
         vbox = vboxlist[i]
148✔
76
      end
77
      local left = target - totalHeight
24,348✔
78
      SU.debug("pagebuilder", "I have", left, "left")
24,348✔
79
      -- if left < -20 then SU.error("\nCatastrophic page breaking failure!"); end
80
      pi = 0
24,348✔
81
      if vbox.is_penalty then
24,348✔
82
         pi = vbox.penalty
1,803✔
83
      end
84
      if
85
         vbox.is_penalty and vbox.penalty < self.inf_bad
24,348✔
86
         or (vbox.is_vglue and i > 1 and not vboxlist[i - 1].discardable)
22,593✔
87
      then
88
         local badness
89
         SU.debug("pagebuilder", "totalHeight", totalHeight, "with target", target)
9,199✔
90
         if totalHeight.length.amount < target.length.amount then -- TeX #1039
9,199✔
91
            -- Account for infinite stretch?
92
            badness = SU.rateBadness(self.inf_bad, left.length.amount, totalHeight.stretch.amount)
18,310✔
93
         elseif left.length.amount < totalHeight.shrink.amount then
44✔
94
            badness = self.awful_bad
43✔
95
         else
96
            badness = SU.rateBadness(self.inf_bad, -left.length.amount, totalHeight.shrink.amount)
2✔
97
         end
98

99
         local c
100
         if badness < self.awful_bad then
9,199✔
101
            if pi <= self.eject_penalty then
9,156✔
102
               c = pi
215✔
103
            elseif badness < self.inf_bad then
8,941✔
104
               c = badness + pi -- plus insert
789✔
105
            else
106
               c = self.deplorable
8,152✔
107
            end
108
         else
109
            c = badness
43✔
110
         end
111
         if c < leastC then
9,199✔
112
            leastC = c
862✔
113
            bestBreak = i
862✔
114
         else
115
            restart = { totalHeight = totalHeight, i = i, started = started, target = target }
8,337✔
116
         end
117

118
         SU.debug("pagebuilder", "Badness:", c)
9,199✔
119
         if c == self.awful_bad or pi <= self.eject_penalty then
9,199✔
120
            SU.debug("pagebuilder", "outputting")
258✔
121
            local onepage = {}
258✔
122
            if not bestBreak then
258✔
123
               bestBreak = i
26✔
124
            end
125
            for j = 1, bestBreak do
4,648✔
126
               onepage[j] = table.remove(vboxlist, 1)
8,780✔
127
            end
128
            while #onepage > 1 and onepage[#onepage].discardable do
553✔
129
               onepage[#onepage] = nil
295✔
130
            end
131
            return onepage, pi
258✔
132
         end
133
      end
134
   end
135
   SU.debug("pagebuilder", "No page break here")
1,425✔
136
   if force and bestBreak then
1,425✔
137
      local onepage = {}
1✔
138
      for j = 1, bestBreak do
9✔
139
         onepage[j] = table.remove(vboxlist, 1)
16✔
140
      end
141
      return onepage, pi
1✔
142
   end
143
   return false, restart
1,424✔
144
end
145

146
return pagebuilder
181✔
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