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

sile-typesetter / sile / 7246678005

18 Dec 2023 10:19AM UTC coverage: 67.096% (-7.5%) from 74.62%
7246678005

push

github

web-flow
chore(deps): Bump actions/upload-artifact from 3 to 4 (#1940)

Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

10583 of 15773 relevant lines covered (67.1%)

3150.6 hits per line

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

84.21
/shapers/base.lua
1
-- local smallTokenSize = 20 -- Small words will be cached
2
-- local shapeCache = {}
3
-- local _key = function (options)
4
--   return table.concat({ options.family;options.language;options.script;options.size;("%d"):format(options.weight);options.style;options.variant;options.features;options.variations;options.direction;options.filename }, ";")
5
-- end
6

7
SILE.settings:declare({ parameter = "shaper.variablespaces", type = "boolean", default = true })
64✔
8
SILE.settings:declare({ parameter = "shaper.spaceenlargementfactor", type = "number or integer", default = 1.2 })
64✔
9
SILE.settings:declare({ parameter = "shaper.spacestretchfactor", type = "number or integer", default = 1/2 })
64✔
10
SILE.settings:declare({ parameter = "shaper.spaceshrinkfactor", type = "number or integer", default = 1/3 })
64✔
11

12
SILE.settings:declare({
64✔
13
    parameter = "shaper.tracking",
14
    type = "number or nil",
15
    default = nil
×
16
  })
17

18
-- Function for testing shaping in the repl
19
-- luacheck: ignore makenodes
20
-- TODO, figure out a way to explicitly register things in the repl env
21
makenodes = function (token, options)
22
  return SILE.shaper:createNnodes(token, SILE.font.loadDefaults(options or {}))
×
23
end
24

25
local function shapespace (spacewidth)
26
  spacewidth = SU.cast("measurement", spacewidth)
5,846✔
27
  -- In some scripts with word-level kerning, glue can be negative.
28
  -- Use absolute value to ensure stretch and shrink work as expected.
29
  local absoluteSpaceWidth = math.abs(spacewidth:tonumber())
5,846✔
30
  local length = spacewidth * SILE.settings:get("shaper.spaceenlargementfactor")
5,846✔
31
  local stretch = absoluteSpaceWidth * SILE.settings:get("shaper.spacestretchfactor")
5,846✔
32
  local shrink = absoluteSpaceWidth * SILE.settings:get("shaper.spaceshrinkfactor")
5,846✔
33
  return SILE.length(length, stretch, shrink)
2,923✔
34
end
35

36
local shaper = pl.class()
64✔
37
shaper.type = "shaper"
64✔
38
shaper._name = "base"
64✔
39

40
-- Return the length of a space character
41
-- with a particular set of font options,
42
-- giving preference to document.spaceskip
43
-- Caching this has no significant speedup
44
function shaper:measureSpace (options)
64✔
45
  local ss = SILE.settings:get("document.spaceskip")
31✔
46
  if ss then
31✔
47
    SILE.settings:temporarily(function ()
×
48
      SILE.settings:set("font.size", options.size)
×
49
      SILE.settings:set("font.family", options.family)
×
50
      SILE.settings:set("font.filename", options.filename)
×
51
      ss = ss:absolute()
×
52
    end)
53
    return ss
×
54
  end
55
  local items, width = self:shapeToken(" ", options)
31✔
56
  if not width and not items[1] then
31✔
57
    SU.warn("Could not measure the width of a space")
×
58
    return SILE.length()
×
59
  end
60
  return shapespace(width and width.length or items[1].width)
31✔
61
end
62

63
function shaper:measureChar (char)
64✔
64
  local options = SILE.font.loadDefaults({})
1,469✔
65
  options.tracking = SILE.settings:get("shaper.tracking")
2,938✔
66
  local items = self:shapeToken(char, options)
1,469✔
67
  if #items > 0 then
1,469✔
68
    return { height = items[1].height, width = items[1].width }
1,469✔
69
  else
70
    SU.error("Unable to measure character", char)
×
71
  end
72
end
73

74
-- Given a text and some font options, return a bunch of boxes
75
function shaper.shapeToken (_, _, _)
64✔
76
  SU.error("Abstract function shapeToken called", true)
×
77
end
78

79
-- Given font options, select a font. We will handle
80
-- caching here. Returns an arbitrary, implementation-specific
81
-- object (ie a PAL for Pango, font number for libtexpdf, ...)
82
function shaper.getFace (_)
64✔
83
  SU.error("Abstract function getFace called", true)
×
84
end
85

86
function shaper.addShapedGlyphToNnodeValue (_, _, _)
64✔
87
  SU.error("Abstract function addShapedGlyphToNnodeValue called", true)
×
88
end
89

90
function shaper.preAddNodes (_, _, _) end
64✔
91

92
function shaper:createNnodes (token, options)
64✔
93
  options.tracking = SILE.settings:get("shaper.tracking")
6,914✔
94
  local items, _ = self:shapeToken(token, options)
3,457✔
95
  if #items < 1 then return {} end
3,457✔
96
  local lang = options.language
3,457✔
97
  SILE.languageSupport.loadLanguage(lang)
3,457✔
98
  local nodeMaker = SILE.nodeMakers[lang] or SILE.nodeMakers.unicode
3,457✔
99
  local nodes = {}
3,457✔
100
  for node in nodeMaker(options):iterator(items, token) do
19,985✔
101
    table.insert(nodes, node)
9,614✔
102
  end
103
  return nodes
3,457✔
104
end
105

106
function shaper:formNnode (contents, token, options)
64✔
107
  local nnodeContents = {}
6,605✔
108
  -- local glyphs = {}
109
  local totalWidth = 0
6,605✔
110
  local totalDepth = 0
6,605✔
111
  local totalHeight = 0
6,605✔
112
  -- local glyphNames = {}
113
  local nnodeValue = { text = token, options = options, glyphString = {} }
6,605✔
114
  SILE.shaper:preAddNodes(contents, nnodeValue)
6,605✔
115
  local misfit = false
6,605✔
116
  if SILE.typesetter.frame and SILE.typesetter.frame:writingDirection() == "TTB" then
13,210✔
117
    if options.direction == "LTR" then misfit = true end
2✔
118
  else
119
    if options.direction == "TTB" then misfit = true end
6,603✔
120
  end
121
  for i = 1, #contents do
29,365✔
122
    local glyph = contents[i]
22,760✔
123
    if (options.direction == "TTB") ~= misfit then
22,760✔
124
      if glyph.width > totalHeight then totalHeight = glyph.width end
2✔
125
      totalWidth = totalWidth + glyph.height
2✔
126
    else
127
      if glyph.depth > totalDepth then totalDepth = glyph.depth end
22,758✔
128
      if glyph.height > totalHeight then totalHeight = glyph.height end
22,758✔
129
      totalWidth = totalWidth + glyph.width
22,758✔
130
    end
131
    self:addShapedGlyphToNnodeValue(nnodeValue, glyph)
22,760✔
132
  end
133
  table.insert(nnodeContents, SILE.nodefactory.hbox({
19,815✔
134
        depth = totalDepth,
6,605✔
135
        height = totalHeight,
6,605✔
136
        misfit = misfit,
6,605✔
137
        width = SILE.length(totalWidth),
13,210✔
138
        value = nnodeValue
6,605✔
139
    }))
140
  return SILE.nodefactory.nnode({
6,605✔
141
      nodes = nnodeContents,
6,605✔
142
      text = token,
6,605✔
143
      misfit = misfit,
6,605✔
144
      options = options,
6,605✔
145
      language = options.language
6,605✔
146
    })
6,605✔
147
end
148

149
function shaper.makeSpaceNode (_, options, item)
64✔
150
  local width
151
  if SILE.settings:get("shaper.variablespaces") then
5,784✔
152
    width = shapespace(item.width)
5,784✔
153
  else
154
    width = SILE.shaper:measureSpace(options)
×
155
  end
156
  return SILE.nodefactory.glue(width)
2,892✔
157
end
158

159
function shaper.debugVersions (_) end
64✔
160

161
return shaper
64✔
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