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

sile-typesetter / sile / 6932773445

20 Nov 2023 04:11PM UTC coverage: 60.703% (-1.6%) from 62.266%
6932773445

Pull #1904

github

alerque
feat(utilities): Add Greek alphabetical (non-arithmetic) numbering

Useful in some context such as biblical annotations etc. where greek
characters are used orderly for numbering.
Pull Request #1904: Merge develop into master (commit to next release being breaking)

66 of 193 new or added lines in 19 files covered. (34.2%)

321 existing lines in 26 files now uncovered.

9452 of 15571 relevant lines covered (60.7%)

2104.43 hits per line

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

88.46
/core/font.lua
1
local icu = require("justenoughicu")
120✔
2

3
local lastshaper
4

5
SILE.registerCommand("font", function (options, content)
240✔
6
  if SU.hasContent(content) then SILE.settings:pushState() end
988✔
7
  if options.filename then SILE.settings:set("font.filename", options.filename) end
494✔
8
  if options.family then
494✔
9
    SILE.settings:set("font.family", options.family)
374✔
10
    SILE.settings:set("font.filename", "")
374✔
11
  end
12
  if options.size then
494✔
13
    local size = SU.cast("measurement", options.size)
416✔
14
    if not size then SU.error("Couldn't parse font size "..options.size) end
416✔
15
    SILE.settings:set("font.size", size:absolute())
832✔
16
  end
17
  if options.weight then SILE.settings:set("font.weight", 0+options.weight) end
494✔
18
  if options.style then SILE.settings:set("font.style", options.style) end
494✔
19
  if options.variant then SILE.settings:set("font.variant", options.variant) end
494✔
20
  if options.features then SILE.settings:set("font.features", options.features) end
494✔
21
  if options.variations then SILE.settings:set("font.variations", options.variations) end
494✔
22
  if options.direction then SILE.settings:set("font.direction", options.direction) end
494✔
23
  if options.language then
494✔
24
    if options.language ~= "und" and icu and icu.canonicalize_language then
357✔
25
      local newlang = icu.canonicalize_language(options.language)
357✔
26
      -- if newlang ~= options.language then
27
        -- SU.warn("Language '"..options.language.."' not canonical, '"..newlang.."' will be used instead.")
28
      -- end
29
      options.language = newlang
357✔
30
    end
31
    SILE.settings:set("document.language", options.language)
357✔
32
    fluent:set_locale(options.language)
357✔
33
    SILE.languageSupport.loadLanguage(options.language)
357✔
34
  end
35
  if options.script then SILE.settings:set("font.script", options.script)
849✔
36
  elseif SILE.settings:get("document.language") then
278✔
37
    local lang = SILE.languageSupport.languages[SILE.settings:get("document.language")]
278✔
38
    if lang and lang.defaultScript then
139✔
39
      SILE.settings:set("font.script", lang.defaultScript)
1✔
40
    end
41
  end
42
  if options.hyphenchar then
494✔
43
    -- must be in the form of, for example, "-" or "U+2010" or "0x2010" (Unicode hex codepoint)
44
    SILE.settings:set("font.hyphenchar", SU.utf8charfromcodepoint(options.hyphenchar))
710✔
45
  end
46

47
  -- We must *actually* load the font here, because by the time we're inside
48
  -- SILE.shaper.shapeToken, it's too late to respond appropriately to things
49
  -- that the post-load hook might want to do.
50
  SILE.font.cache(SILE.font.loadDefaults({}), SILE.shaper.getFace)
988✔
51

52
  if SU.hasContent(content) then
988✔
53
    SILE.process(content)
117✔
54
    SILE.settings:popState()
117✔
55
    if SILE.shaper._name == "harfbuzzWithColor" and lastshaper then
117✔
UNCOV
56
      SU.debug("color-fonts", "Switching from color fonts shaper back to previous shaper")
×
UNCOV
57
      SILE.typesetter:leaveHmode(true)
×
UNCOV
58
      lastshaper, SILE.shaper = nil, lastshaper
×
59
    end
60
  end
61
end, "Set current font family, size, weight, style, variant, script, direction and language", nil, true)
614✔
62

63
SILE.settings:declare({ parameter = "font.family", type = "string or nil", default = "Gentium Plus" })
120✔
64
SILE.settings:declare({ parameter = "font.size", type = "number or integer", default = 10 })
120✔
65
SILE.settings:declare({ parameter = "font.weight", type = "integer", default = 400 })
120✔
66
SILE.settings:declare({ parameter = "font.variant", type = "string", default = "normal" })
120✔
67
SILE.settings:declare({ parameter = "font.script", type = "string", default = "" })
120✔
68
SILE.settings:declare({ parameter = "font.style", type = "string", default = "" })
120✔
69
SILE.settings:declare({ parameter = "font.direction", type = "string", default = "" })
120✔
70
SILE.settings:declare({ parameter = "font.filename", type = "string or nil", default = "" })
120✔
71
SILE.settings:declare({ parameter = "font.features", type = "string", default = "" })
120✔
72
SILE.settings:declare({ parameter = "font.variations", type = "string", default = "" })
120✔
73
SILE.settings:declare({ parameter = "font.hyphenchar", type = "string", default = "-" })
120✔
74

75
SILE.fontCache = {}
120✔
76

77
local _key = function (options)
78
  return table.concat({
19,636✔
79
      options.family,
19,636✔
80
      ("%g"):format(SILE.measurement(options.size):tonumber()),
58,908✔
81
      ("%d"):format(options.weight or 0),
19,636✔
82
      options.style,
19,636✔
83
      options.variant,
19,636✔
84
      options.features,
19,636✔
85
      options.variations,
19,636✔
86
      options.direction,
19,636✔
87
      options.filename,
19,636✔
88
    }, ";")
19,636✔
89
end
90

91
local font = {
120✔
92

93
  loadDefaults = function (options)
94
    if not options.family then options.family = SILE.settings:get("font.family") end
6,933✔
95
    if not options.size then options.size = SILE.settings:get("font.size") end
6,933✔
96
    if not options.weight then options.weight = SILE.settings:get("font.weight") end
6,995✔
97
    if not options.style then options.style = SILE.settings:get("font.style") end
6,995✔
98
    if not options.variant then options.variant = SILE.settings:get("font.variant") end
8,744✔
99
    if SILE.settings:get("font.filename") ~= "" then
8,744✔
UNCOV
100
      options.filename = SILE.settings:get("font.filename")
×
UNCOV
101
      options.family = ""
×
102
    end
103
    if not options.language then options.language = SILE.settings:get("document.language") end
8,682✔
104
    if not options.script then options.script = SILE.settings:get("font.script") end
8,744✔
105
    if not options.direction then
4,372✔
106
      options.direction = SILE.settings:get("font.direction")
8,744✔
107
      if not options.direction or options.direction == "" then
4,372✔
108
        options.direction = SILE.typesetter and SILE.typesetter.frame and SILE.typesetter.frame:writingDirection() or "LTR"
7,954✔
109
      end
110
    end
111
    if not options.features then options.features = SILE.settings:get("font.features") end
8,744✔
112
    if not options.variations then options.variations = SILE.settings:get("font.variations") end
8,744✔
113
    if not options.hyphenchar then options.hyphenchar = SILE.settings:get("font.hyphenchar") end
8,744✔
114
    return options
4,372✔
115
  end,
116

117
  cache = function (options, callback)
118
    local key = _key(options)
3,791✔
119
    if not SILE.fontCache[key] then
3,791✔
120
      SU.debug("fonts", "Looking for", key)
137✔
121
      local face = callback(options)
137✔
122
      SILE.fontCache[key] = face
137✔
123
    end
124
    local cached = SILE.fontCache[key]
3,791✔
125
    SILE.font.postLoadHook(cached)
3,791✔
126
    return cached
3,791✔
127
  end,
128

129
  finish = function ()
130
    for key, font in pairs(SILE.fontCache) do
199✔
131
      if font.tempfilename ~= font.filename then
137✔
132
        SU.debug("fonts", "Removing temporary file of", key, ":", font.tempfilename)
×
133
        os.remove(font.tempfilename)
×
134
      end
135
    end
136
  end,
137

138
  postLoadHook = function(face)
139
    local ot = require("core.opentype-parser")
3,791✔
140
    local font = ot.parseFont(face)
3,791✔
141
    if font.cpal then
3,791✔
UNCOV
142
      SILE.require("packages.color-fonts")
×
UNCOV
143
      if SILE.shaper._name ~= "harfbuzzWithColor" then
×
UNCOV
144
        SU.debug("color-fonts", "Switching to color font Shaper")
×
UNCOV
145
        SILE.typesetter:leaveHmode(true)
×
UNCOV
146
        lastshaper, SILE.shaper = SILE.shaper, SILE.shapers.harfbuzzWithColor()
×
147
      end
148
    end
149
  end,
150

151
  _key = _key
120✔
152
}
153

154
return font
120✔
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