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

sile-typesetter / sile / 6713098919

31 Oct 2023 10:21PM UTC coverage: 52.831% (-21.8%) from 74.636%
6713098919

push

github

web-flow
Merge d0a2a1ee9 into b185d4972

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

8173 of 15470 relevant lines covered (52.83%)

6562.28 hits per line

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

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

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

6
local oldPagebuilderType, oldTypesetterType
7

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

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

30
function package:registerCommands ()
×
31

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

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

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)
×
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}
117
]]
×
118

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

© 2025 Coveralls, Inc