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

sile-typesetter / sile / 14860011647

06 May 2025 12:44PM UTC coverage: 67.057% (+32.5%) from 34.559%
14860011647

push

github

alerque
chore(typesetters): Fixup access to class from typesetter functions

7 of 7 new or added lines in 2 files covered. (100.0%)

1344 existing lines in 103 files now uncovered.

14880 of 22190 relevant lines covered (67.06%)

11549.16 hits per line

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

86.57
/core/font.lua
1
--- font
2
-- @module SILE.font
3

4
SILE.fontCache = {}
302✔
5

6
local _key = function (options)
7
   return table.concat({
40,977✔
8
      options.family or "",
40,977✔
9
      ("%g"):format(SILE.types.measurement(options.size):tonumber()),
122,931✔
10
      ("%d"):format(options.weight or 0),
40,977✔
11
      options.style,
40,977✔
12
      options.variant,
40,977✔
13
      options.features,
40,977✔
14
      options.variations,
40,977✔
15
      options.direction,
40,977✔
16
      options.filename or "",
40,977✔
17
   }, ";")
40,977✔
18
end
19

20
local font = {
302✔
21

22
   loadDefaults = function (options)
23
      if not options.family then
8,104✔
24
         options.family = SILE.settings:get("font.family")
13,371✔
25
      end
26
      if not options.size then
8,104✔
27
         options.size = SILE.settings:get("font.size")
12,966✔
28
      end
29
      if not options.weight then
8,104✔
30
         options.weight = SILE.settings:get("font.weight")
13,911✔
31
      end
32
      if not options.style then
8,104✔
33
         options.style = SILE.settings:get("font.style")
13,791✔
34
      end
35
      if not options.variant then
8,104✔
36
         options.variant = SILE.settings:get("font.variant")
22,299✔
37
      end
38
      local fn = SILE.settings:get("font.filename")
16,208✔
39
      if fn ~= "" and fn ~= nil then
8,104✔
UNCOV
40
         options.filename = fn
×
UNCOV
41
         options.family = ""
×
42
      end
43
      if not options.language then
8,104✔
44
         options.language = SILE.settings:get("document.language")
21,786✔
45
      end
46
      if not options.script then
8,104✔
47
         options.script = SILE.settings:get("font.script")
13,983✔
48
      end
49
      if not options.direction then
8,104✔
50
         options.direction = SILE.settings:get("font.direction")
22,293✔
51
         if not options.direction or options.direction == "" then
7,431✔
52
            options.direction = SILE.typesetter and SILE.typesetter.frame and SILE.typesetter.frame:writingDirection()
7,401✔
53
               or "LTR"
7,401✔
54
         end
55
      end
56
      if not options.features then
8,104✔
57
         options.features = SILE.settings:get("font.features")
22,281✔
58
      end
59
      if not options.variations then
8,104✔
60
         options.variations = SILE.settings:get("font.variations")
22,299✔
61
      end
62
      if not options.hyphenchar then
8,104✔
63
         options.hyphenchar = SILE.settings:get("font.hyphenchar")
22,296✔
64
      end
65
      return options
8,104✔
66
   end,
67

68
   -- TODO: See _getFaceCallback workaround in shaper, work on a better interaction
69
   cache = function (options, callback)
70
      local key = _key(options)
6,823✔
71
      if not SILE.fontCache[key] then
6,823✔
72
         SU.debug("fonts", "Looking for", key)
321✔
73
         local face = callback(options)
321✔
74
         SILE.fontCache[key] = face
321✔
75
      end
76
      local cached = SILE.fontCache[key]
6,823✔
77
      SILE.font.postLoadHook(cached)
6,823✔
78
      return cached
6,823✔
79
   end,
80

81
   finish = function ()
82
      for key, font in pairs(SILE.fontCache) do
474✔
83
         -- Don't do anything for Pango fonts
84
         if type(font) ~= "userdata" and type(font.insert) ~= "function" then
321✔
85
            if font.tempfilename ~= font.filename then
321✔
UNCOV
86
               SU.debug("fonts", "Removing temporary file of", key, ":", font.tempfilename)
×
UNCOV
87
               os.remove(font.tempfilename)
×
88
            end
89
         end
90
      end
91
   end,
92

93
   postLoadHook = function (face)
94
      -- Don't do anything for Pango fonts (here face could be a Pango Attribute Lists)
95
      if type(face) == "userdata" and type(face.insert) == "function" then
6,823✔
UNCOV
96
         return
×
97
      end
98
      local ot = require("core.opentype-parser")
6,823✔
99
      local font = ot.parseFont(face)
6,823✔
100
      if font.cpal then
6,823✔
UNCOV
101
         if SILE.shaper._name ~= "harfbuzz-color" then
×
UNCOV
102
            SU.debug("color-fonts", "Switching to color font Shaper")
×
UNCOV
103
            SILE.typesetter:leaveHmode(true)
×
UNCOV
104
            SILE.scratch._lastshaper, SILE.shaper = SILE.shaper, SILE.shapers["harfbuzz-color"]()
×
105
         end
106
      end
107
   end,
108

109
   _key = _key,
302✔
110
}
111

112
return font
302✔
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