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

sile-typesetter / sile / 8288578143

14 Mar 2024 09:39PM UTC coverage: 64.155% (-10.6%) from 74.718%
8288578143

Pull #1904

github

alerque
chore(core): Fixup ec6ed657 which didn't shim old pack styles properly
Pull Request #1904: Merge develop into master (commit to next release being breaking)

1648 of 2421 new or added lines in 107 files covered. (68.07%)

1843 existing lines in 77 files now uncovered.

10515 of 16390 relevant lines covered (64.15%)

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

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

UNCOV
30
function package:registerCommands ()
×
31

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

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

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

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