• 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/grid/init.lua
UNCOV
1
local base = require("packages.base")
×
2

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

6
local oldPagebuilderType, oldTypesetterType
7

8
local function startGridInFrame (typesetter)
UNCOV
9
   if not SILE.typesetter.state.grid then
×
10
      return
×
11
   end -- Ensure the frame hook isn't effective when grid is off
UNCOV
12
   local queue = typesetter.state.outputQueue
×
UNCOV
13
   typesetter.frame.state.totals.gridCursor = SILE.types.measurement(0)
×
UNCOV
14
   if #queue == 0 then
×
UNCOV
15
      typesetter.state.previousVbox = typesetter:pushVbox()
×
UNCOV
16
      return
×
17
   end
UNCOV
18
   while queue[1] and (queue[1].discardable or queue[1].gridleading) do
×
UNCOV
19
      table.remove(queue, 1)
×
20
   end
UNCOV
21
   if queue[1] then
×
UNCOV
22
      table.insert(queue, 1, SILE.types.node.vbox())
×
UNCOV
23
      table.insert(queue, 2, SILE.typesetter:leadingFor(queue[2], queue[1]))
×
24
   end
25
end
26

UNCOV
27
function package:_init (options)
×
UNCOV
28
   self.spacing = SU.cast("measurement", options.spacing or "1bs"):absolute()
×
UNCOV
29
   base._init(self)
×
30
end
31

UNCOV
32
function package:registerCommands ()
×
UNCOV
33
   self:registerCommand("grid:debug", function (options, _)
×
UNCOV
34
      local spacing = SU.cast("measurement", options.spacing or self.spacing):absolute()
×
35
      local debugGrid = function ()
UNCOV
36
         local frame = SILE.typesetter.frame
×
UNCOV
37
         local gridCursor = spacing
×
UNCOV
38
         while gridCursor < frame:height() do
×
UNCOV
39
            SILE.outputter:drawRule(frame:left(), frame:top() + gridCursor, frame:width(), 0.1)
×
UNCOV
40
            gridCursor = gridCursor + spacing
×
41
         end
42
      end
UNCOV
43
      debugGrid()
×
UNCOV
44
      SILE.typesetter:registerNewFrameHook(debugGrid)
×
45
   end)
46

UNCOV
47
   self:registerCommand("grid", function (options, _)
×
UNCOV
48
      if options.spacing then
×
UNCOV
49
         self.spacing = SU.cast("measurement", options.spacing):absolute()
×
50
      end
UNCOV
51
      SILE.typesetter.state.grid = true
×
UNCOV
52
      oldPagebuilderType = SILE.pagebuilder._name
×
UNCOV
53
      oldTypesetterType = SILE.typesetter._name
×
UNCOV
54
      SILE.pagebuilders.grid:cast(SILE.pagebuilder)
×
UNCOV
55
      SILE.typesetters.grid:cast(SILE.typesetter)
×
UNCOV
56
      SILE.typesetter.options = { spacing = self.spacing }
×
UNCOV
57
      if SILE.typesetter.frame then
×
UNCOV
58
         startGridInFrame(SILE.typesetter)
×
59
      end
UNCOV
60
      SILE.typesetter:registerNewFrameHook(startGridInFrame)
×
UNCOV
61
   end, "Begins typesetting on a grid spaced at <spacing> intervals.")
×
62

UNCOV
63
   self:registerCommand("no-grid", function (_, _)
×
64
      SILE.typesetter.state.grid = false
×
65
      SILE.typesetters[oldTypesetterType]:cast(SILE.typesetter)
×
66
      SILE.pagebuilders[oldPagebuilderType]:cast(SILE.pagebuilder)
×
UNCOV
67
   end, "Stops grid typesetting.")
×
68
end
69

70
package.documentation = [[
71
\begin{document}
72
\use[module=packages.grid]
73
\grid[spacing=15pt]
74
In normal typesetting, SILE determines the spacing between lines of type according to the following two rules:
75

76
\begin{itemize}
77
\item{SILE tries to insert space between two successive lines so that their baselines are separated by a fixed distance called the \code{baselineskip}.}
78
\item{If this first rule would mean that the bottom and the top of the lines are less than two points apart, then they are forced to be two points apart.
79
      (This distance is configurable, and called the \code{lineskip}.)}
80
\end{itemize}
81

82
The second rule is designed to avoid the situation where the first line has a long descender (letters such as g, q, j, p, etc.) which abuts a high ascender on the second line (k, l, capitals, etc.).
83

84
In addition, the \code{baselineskip} contains a certain amount of “stretch,” so that the lines can expand if this would help with producing a page break at an optimal location, and similarly spacing between paragraphs can stretch or shrink.
85

86
The combination of all of these rules means that a line may begin at practically any point on the page.
87

88
An alternative way of typesetting is to require that lines begin at fixed points on a regular grid.
89
Some people prefer the “color” of pages produced by grid typesetting, and the method is often used when typesetting on very thin paper, as lining up the lines of type on both sides of a page ensures that ink does not bleed through from the back to the front.
90
Compare the following examples: on the left, the lines are guaranteed to fall in the same places on the recto (front) and the verso (back) of the paper; on the right, no such guarantee is made.
91

92
\img[src=documentation/grid-1.png,height=130]
93
\img[src=documentation/grid-2.png,height=130]
94

95
The \autodoc:package{grid} package alters the operation of SILE’s typesetter so that the two rules above do not apply; lines are always aligned on a fixed grid, and spaces between paragraphs, etc., are adjusted to conform to the grid.
96
Loading the package adds two new commands to SILE: \autodoc:command{\grid[spacing=<dimension>]} and \autodoc:command{\no-grid}.
97
The first turns on grid typesetting for the remainder of the document; the second turns it off again.
98

99
At the start of this section, we issued the command \autodoc:command{\grid[spacing=15pt]} to set up a regular 15-point grid.
100
Here is some text typeset with the grid set up:
101

102
\smallskip
103
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
104
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
105
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
106
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
107
\smallskip
108

109
And here is the same text after we issue \autodoc:command{\no-grid}:
110

111
\no-grid\smallskip
112
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
113
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
114
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
115
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
116
\end{document}
UNCOV
117
]]
×
118

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