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

sile-typesetter / sile / 11135083927

01 Oct 2024 11:26PM UTC coverage: 62.071% (-7.3%) from 69.333%
11135083927

push

github

alerque
style: Reformat Lua with stylua

0 of 9 new or added lines in 2 files covered. (0.0%)

1678 existing lines in 57 files now uncovered.

11071 of 17836 relevant lines covered (62.07%)

5220.48 hits per line

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

35.71
/packages/font-fallback/init.lua
1
local base = require("packages.base")
2✔
2

3
local package = pl.class(base)
2✔
4
package._name = "font-fallback"
2✔
5

6
local lastShaperType
7

8
function package:registerCommands ()
2✔
9
   self:registerCommand("font:clear-fallbacks", function ()
4✔
UNCOV
10
      if SILE.shaper._name == "fallback" and lastShaperType then
×
UNCOV
11
         SU.debug("font-fallback", "Clearing fallbacks, switching from fallback enabled back to previous shaper")
×
UNCOV
12
         SILE.shaper:clearFallbacks()
×
UNCOV
13
         SILE.typesetter:leaveHmode(true)
×
UNCOV
14
         SILE.shapers[lastShaperType]:cast(SILE.shaper)
×
UNCOV
15
         lastShaperType = nil
×
16
      end
17
   end)
18

19
   self:registerCommand("font:add-fallback", function (options, _)
4✔
UNCOV
20
      if SILE.shaper._name ~= "fallback" then
×
UNCOV
21
         SU.debug("font-fallback", "Switching to fallback enabaled shaper")
×
UNCOV
22
         SILE.typesetter:leaveHmode(true)
×
UNCOV
23
         lastShaperType = SILE.shaper._name
×
UNCOV
24
         SILE.shapers.fallback:cast(SILE.shaper)
×
25
      end
UNCOV
26
      SILE.shaper:addFallback(options)
×
27
   end)
28

29
   self:registerCommand("font:remove-fallback", function ()
4✔
UNCOV
30
      SILE.shaper:removeFallback()
×
UNCOV
31
      if #SILE.shaper:dumpFallbacks() == 0 and SILE.shaper._name == "fallback" and lastShaperType then
×
UNCOV
32
         SU.debug("font-fallback", "Fallback list empty, switching from fallback enabled back to previous shaper")
×
UNCOV
33
         SILE.typesetter:leaveHmode(true)
×
UNCOV
34
         SILE.shapers[lastShaperType]:cast(SILE.shaper)
×
UNCOV
35
         lastShaperType = nil
×
36
      end
37
   end, "Pop last added fallback from fallback stack")
2✔
38
end
39

40
package.documentation = [[
41
\begin{document}
42
What happens when SILE is asked to typeset a character which is not in the current font?
43
For instance, we are currently using the Gentium font, which covers a wide range of European scripts; however, it doesn’t contain any Japanese characters.
44
  So what if I ask SILE to typeset \code{abc \font[family=Noto Sans CJK JP]{あ}}?
45

46
Many applications will find another font on the system containing the appropriate character and use that font instead.
47
But which font should be chosen?
48
SILE is designed for typesetting situations where the document or class author wants complete control over the typographic appearance of the output, so it’s not appropriate for it to make a guess—besides, you asked for Gentium.
49
So where the glyph is not defined, SILE will give you the current font’s “glyph not defined” symbol (a glyph called \code{.notdef}) instead.
50

51
But there are times when this is just too strict.
52
If you’re typesetting a document in English and Japanese, you should be able to choose your English font and choose your Japanese font, and if the glyph isn’t available in one, SILE should try the other.
53
  The \autodoc:package{font-fallback} package gives you a way to specify a list of font specifications, and it will try each one in turn if glyphs cannot be found.
54

55
It provides two commands, \autodoc:command{\font:add-fallback} and \autodoc:command{\font:clear-fallbacks}.
56
The parameters to \autodoc:command{\font:add-fallback} are the same as the parameters to \autodoc:command{\font}.
57
So this code:
58

59
\begin[type=autodoc:codeblock]{raw}
60
\font:add-fallback[family=Symbola]
61
\font:add-fallback[family=Noto Sans CJK JP]
62
\end{raw}
63

64
will add two fonts to try if characters are not found in the current font.
65
Now we can say:
66

67
\font:add-fallback[family=Symbola]
68
\font:add-fallback[family=Noto Sans CJK JP]
69

70
\begin{verbatim}
71
あば x 😼 Hello world. あ
72
\end{verbatim}
73

74
and SILE will produce:
75

76
\autodoc:example{あば x 😼 Hello world. あ}
77

78
\font:remove-fallback
79
\font:remove-fallback
80

81
\autodoc:command{\font:clear-fallbacks} removes all font fallbacks from the list of fonts to try.
82

83
\autodoc:command{\font:remove-fallback} removes the last added fallback from the list of fonts to try.
84
\end{document}
85
]]
2✔
86

87
return package
2✔
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