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

sile-typesetter / sile / 6713098919

31 Oct 2023 10:21PM UTC coverage: 52.831% (-21.8%) from 74.636%
6713098919

push

github

web-flow
Merge d0a2a1ee9 into b185d4972

45 of 45 new or added lines in 3 files covered. (100.0%)

8173 of 15470 relevant lines covered (52.83%)

6562.28 hits per line

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

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

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

6
local lastShaperType
7

8
function package:registerCommands ()
×
9

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

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

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

40
end
41

42
package.documentation = [[
43
\begin{document}
44
What happens when SILE is asked to typeset a character which is not in the current font?
45
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.
46
  So what if I ask SILE to typeset \code{abc \font[family=Noto Sans CJK JP]{あ}}?
47

48
Many applications will find another font on the system containing the appropriate character and use that font instead.
49
But which font should be chosen?
50
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.
51
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.
52

53
But there are times when this is just too strict.
54
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.
55
  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.
56

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

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

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

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

72
\begin{verbatim}
73
あば x 😼 Hello world. あ
74
\end{verbatim}
75

76
and SILE will produce:
77

78
\autodoc:example{あば x 😼 Hello world. あ}
79

80
\font:remove-fallback
81
\font:remove-fallback
82

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

85
\autodoc:command{\font:remove-fallback} removes the last added fallback from the list of fonts to try.
86
\end{document}
87
]]
×
88

89
return package
×
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

© 2025 Coveralls, Inc