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

sile-typesetter / sile / 9304049654

30 May 2024 02:12PM UTC coverage: 60.021% (-14.7%) from 74.707%
9304049654

push

github

web-flow
Merge 1a26b4f22 into a1fd105f8

6743 of 12900 new or added lines in 186 files covered. (52.27%)

347 existing lines in 49 files now uncovered.

10311 of 17179 relevant lines covered (60.02%)

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

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

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

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

NEW
63
   self:registerCommand("no-grid", function (_, _)
×
NEW
64
      SILE.typesetter.state.grid = false
×
NEW
65
      SILE.typesetters[oldTypesetterType]:cast(SILE.typesetter)
×
NEW
66
      SILE.pagebuilders[oldPagebuilderType]:cast(SILE.pagebuilder)
×
NEW
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