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

sile-typesetter / sile / 11770252752

11 Nov 2024 01:09AM UTC coverage: 32.853% (-27.5%) from 60.402%
11770252752

Pull #2164

github

web-flow
chore(deps): Bump DeterminateSystems/nix-installer-action from 14 to 15

Bumps [DeterminateSystems/nix-installer-action](https://github.com/determinatesystems/nix-installer-action) from 14 to 15.
- [Release notes](https://github.com/determinatesystems/nix-installer-action/releases)
- [Commits](https://github.com/determinatesystems/nix-installer-action/compare/v14...v15)

---
updated-dependencies:
- dependency-name: DeterminateSystems/nix-installer-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #2164: chore(deps): Bump DeterminateSystems/nix-installer-action from 14 to 15

5855 of 17822 relevant lines covered (32.85%)

2493.73 hits per line

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

70.69
/types/unit.lua
1
--- SILE unit type.
2
-- @types unit
3

4
local bits = require("core.parserbits")
5✔
5

6
local unittypes = {
5✔
7
   pt = {
5✔
8
      relative = false,
9
      value = 1,
10
   },
5✔
11
}
12

13
setmetatable(unittypes, {
10✔
14
   __newindex = function (self, unit, spec)
15
      local def = SU.required(spec, "definition", "registering unit " .. unit)
125✔
16
      local relative = SU.boolean(spec.relative, false)
125✔
17
      if type(def) == "string" then
125✔
18
         local parsed = bits.measurement:match(def)
50✔
19
         if not parsed then
50✔
20
            SU.error("Could not parse unit definition '" .. def .. "'")
×
21
         end
22
         if not self[parsed.unit] then
50✔
23
            SU.error("Unit " .. unit .. " defined in terms of unknown unit " .. parsed.unit)
×
24
         elseif self[parsed.unit].relative then
50✔
25
            rawset(self, unit, {
10✔
26
               relative = true,
27
               converter = function (value)
28
                  return value * self[parsed.unit].converter(parsed.amount)
×
29
               end,
30
            })
5✔
31
         else
32
            rawset(self, unit, {
90✔
33
               relative = false,
34
               value = parsed.amount * self[parsed.unit].value,
45✔
35
            })
36
         end
37
      elseif type(def) == "function" then
75✔
38
         rawset(self, unit, {
150✔
39
            relative = relative,
75✔
40
            converter = def,
75✔
41
         })
42
      end
43
   end,
44
})
45

46
unittypes["twip"] = {
5✔
47
   definition = "0.05pt",
48
}
5✔
49

50
unittypes["mm"] = {
5✔
51
   definition = "2.8346457pt",
52
}
5✔
53

54
unittypes["cm"] = {
5✔
55
   definition = "10mm",
56
}
5✔
57

58
unittypes["m"] = {
5✔
59
   definition = "100cm",
60
}
5✔
61

62
unittypes["hm"] = {
5✔
63
   definition = "0.01mm",
64
}
5✔
65

66
unittypes["in"] = {
5✔
67
   definition = "72pt",
68
}
5✔
69

70
unittypes["ft"] = {
5✔
71
   definition = "12in",
72
}
5✔
73

74
-- Picas are 1/6 inch, used in Docbook images
75
unittypes["pc"] = {
5✔
76
   definition = "0.166666667in",
77
}
5✔
78

79
-- Pixel, by convention 1px = 1/96in = 0.75pt
80
-- (CSS Values and Units Module Level 3, §5.2)
81
-- Used in MathML, etc.
82
unittypes["px"] = {
5✔
83
   definition = "0.75pt",
84
}
5✔
85

86
local checkPaperDefined = function ()
87
   if not SILE.documentState or not SILE.documentState.orgPaperSize then
342✔
88
      SU.error("A measurement tried to measure the paper size before the paper was defined", true)
×
89
   end
90
end
91

92
local checkFrameDefined = function ()
93
   if not SILE.typesetter.frame then
×
94
      SU.error("A measurement tried to measure the frame before the frame was defined", true)
×
95
   end
96
end
97

98
unittypes["%pw"] = {
5✔
99
   relative = true,
100
   definition = function (value)
101
      checkPaperDefined()
116✔
102
      return value / 100 * SILE.documentState.orgPaperSize[1]
116✔
103
   end,
104
}
5✔
105

106
unittypes["%ph"] = {
5✔
107
   relative = true,
108
   definition = function (value)
109
      checkPaperDefined()
226✔
110
      return value / 100 * SILE.documentState.orgPaperSize[2]
226✔
111
   end,
112
}
5✔
113

114
unittypes["%pmin"] = {
5✔
115
   relative = true,
116
   definition = function (value)
117
      checkPaperDefined()
×
118
      return value / 100 * SU.min(SILE.documentState.orgPaperSize[1], SILE.documentState.orgPaperSize[2])
×
119
   end,
120
}
5✔
121

122
unittypes["%pmax"] = {
5✔
123
   relative = true,
124
   definition = function (value)
125
      checkPaperDefined()
×
126
      return value / 100 * SU.max(SILE.documentState.orgPaperSize[1], SILE.documentState.orgPaperSize[2])
×
127
   end,
128
}
5✔
129

130
unittypes["%fw"] = {
5✔
131
   relative = true,
132
   definition = function (value)
133
      checkFrameDefined()
×
134
      return value / 100 * SILE.typesetter.frame:width():tonumber()
×
135
   end,
136
}
5✔
137

138
unittypes["%fh"] = {
5✔
139
   relative = true,
140
   definition = function (value)
141
      checkFrameDefined()
×
142
      return value / 100 * SILE.typesetter.frame:height():tonumber()
×
143
   end,
144
}
5✔
145

146
unittypes["%fmin"] = {
5✔
147
   relative = true,
148
   definition = function (value)
149
      checkFrameDefined()
×
150
      return value / 100 * SU.min(SILE.typesetter.frame:width():tonumber(), SILE.typesetter.frame:height():tonumber())
×
151
   end,
152
}
5✔
153

154
unittypes["%fmax"] = {
5✔
155
   relative = true,
156
   definition = function (value)
157
      checkFrameDefined()
×
158
      return value / 100 * SU.max(SILE.typesetter.frame:width():tonumber(), SILE.typesetter.frame:height():tonumber())
×
159
   end,
160
}
5✔
161

162
unittypes["%lw"] = {
5✔
163
   relative = true,
164
   definition = function (value)
165
      local lskip = SILE.settings:get("document.lskip")
×
166
      local rskip = SILE.settings:get("document.rskip")
×
167
      local left = lskip and lskip.width:tonumber() or 0
×
168
      local right = rskip and rskip.width:tonumber() or 0
×
169
      checkFrameDefined()
×
170
      return value / 100 * SILE.typesetter.frame:getLineWidth():tonumber() - left - right
×
171
   end,
172
}
5✔
173

174
unittypes["ps"] = {
5✔
175
   relative = true,
176
   definition = function (value)
177
      local ps = SILE.settings:get("document.parskip")
×
178
      ps = ps.height:tonumber() or 0
×
179
      return value * ps
×
180
   end,
181
}
5✔
182

183
unittypes["bs"] = {
5✔
184
   relative = true,
185
   definition = function (value)
186
      local bs = SILE.settings:get("document.baselineskip")
3✔
187
      bs = bs.height:tonumber() or 0
6✔
188
      return value * bs
3✔
189
   end,
190
}
5✔
191

192
unittypes["em"] = {
5✔
193
   relative = true,
194
   definition = function (value)
195
      return value * SILE.settings:get("font.size")
144✔
196
   end,
197
}
5✔
198

199
unittypes["ex"] = {
5✔
200
   relative = true,
201
   definition = function (value)
202
      return value * SILE.shaper:measureChar("x").height
10✔
203
   end,
204
}
5✔
205

206
unittypes["spc"] = {
5✔
207
   relative = true,
208
   definition = function (value)
209
      return value * SILE.shaper:measureChar(" ").width
20✔
210
   end,
211
}
5✔
212

213
unittypes["en"] = {
5✔
214
   relative = true,
215
   definition = "0.5em",
216
}
5✔
217

218
-- jlreq measures distances in units of 1em, but also assumes that an em is the
219
-- width of a full-width character. In SILE terms it isn't: measuring an "m" in
220
-- a 10pt Japanese font gets you 5 points. So we measure a full-width character
221
-- and use that as a unit. We call it zw following ptex (zenkaku width)
222
unittypes["zw"] = {
5✔
223
   relative = true,
224
   definition = function (v)
225
      local zenkakuchar = SILE.settings:get("document.zenkakuchar")
×
226
      local measurable, zenkaku = pcall(SILE.shaper.measureChar, SILE.shaper, zenkakuchar)
×
227
      if not measurable then
×
228
         SU.warn(([[
×
229
            Zenkaku width (全角幅) unit zw is falling back to 1em == 1zw as we cannot measure %s
230

231
            Either change this char to one suitable for your language, or load a font that
232
            has it.
233
         ]]):format(zenkakuchar))
×
234
      end
235
      local width = measurable and zenkaku.width or SILE.settings:get("font.size")
×
236
      return v * width
×
237
   end,
238
}
5✔
239

240
return unittypes
5✔
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