font-col.mklx /size: 6373 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=font-col,
3%D        version=2008.06.11,
4%D          title=\CONTEXT\ Font Macros,
5%D       subtitle=Fallbacks (collections),
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14% todo   : missing only, force always, multiple fallbacks with test, scale
15% beware : only english key/values
16%
17% \resetfontfallback [whatever]
18%
19% \definefontfallback [whatever] [Slanted]     [0x0060-0x007F] [force=yes]
20% \definefontfallback [whatever] [Bold]        [0x0080-0x00FF,0x00A0-0x00AF] [rscale=1.2]
21% \definefontfallback [whatever] [BoldSlanted] [0x00C0-0x00C7] [check=yes,force=yes]
22%
23% \definefontfeature [emboldened]     [effect={width=0.1,delta=0.4,factor=0.3}]
24% \definefontsynonym [SansEmboldened] [Sans]                           [features=emboldened]
25% \definefontfallback[FakeSansCaps]   [SansEmboldened] [0x0000-0xFFFF] [rscale=.8,method=uppercase]
26% \definefontsynonym [SansCaps]       [file:MyriadPro-Regular.otf]     [fallbacks=FakeSansCaps]
27
28\writestatus{loading}{ConTeXt Font Macros / Collections}
29
30\registerctxluafile{font-col}{autosuffix}
31
32\unprotect
33
34\permanent\tolerant\protected\def\definefontfallback[#name]#spacer[#font]#spacer[#ranges]#spacer[#settings]%
35  {\let\mathsizesuffix\relax
36   \clf_fontcollectiondefine{#name}{#font}{#ranges}{#settings}%
37   \lettonothing\mathsizesuffix}
38
39\permanent\tolerant\protected\def\resetfontfallback[#name]#spacer[#font]%
40  {\clf_fontcollectionreset{#name}{#font}}
41
42\def\font_fallbacks_prepare#name%
43  {\clf_fontcollectionprepare{#name}} % add fallbacks to last font
44
45% we might as well move the handling to lua but then we need to pass the
46% fallbacks, skewchar etc.
47
48\newconditional\c_font_fallbacks_in_progress
49
50\def\font_fallbacks_prepare_indeed#fallbacks%
51  {\begingroup
52     \c_font_fallbacks_in_progress\conditionaltrue
53     \lastrawfontcall % sets current font id
54     \font_fallbacks_prepare#fallbacks%
55   \endgroup}
56
57\lettonothing\m_font_fallbacks % set in the font-ini
58
59\appendtoks
60    \ifconditional\c_font_fallbacks_in_progress\else
61        \ifempty\m_font_fallbacks
62            \ifempty\m_font_class_fallbacks\else
63                \font_fallbacks_prepare_indeed\m_font_class_fallbacks
64            \fi
65        \else
66            \font_fallbacks_prepare_indeed\m_font_fallbacks
67        \fi
68   \fi
69\to\everydefinefont
70
71\lettonothing\m_font_fallbacks_spec
72
73\def\font_fallbacks_start_cloning
74  {\begingroup
75   \let\m_font_fallbacks_spec\somefontspec}
76
77\def\font_fallbacks_stop_cloning
78  {\endgroup}
79
80\def\font_fallbacks_clone_unique#specification#scale% kind of dododefinefont
81  {\clf_fontcollectionreport{defining #specification (relative scale: #scale)}% brrr
82   \c_font_auto_size\conditionalfalse
83   \let\lastfontidentifier\s!dummy
84   \def\v_font_size_relative{#scale}%
85   \let\v_font_size_absolute\fontbody
86   \font_helpers_low_level_define{#specification}\v_font_identifier_basic
87   \csname\v_font_identifier_basic\endcsname
88   \c_font_auto_size\conditionalfalse} % no \setfontcharacteristics and \the\everyfontswitch needed
89
90\def\font_fallbacks_clone_inherited#font% also a second argument
91  {\font_fallbacks_clone_unique{#font \m_font_fallbacks_spec}}
92
93\def\font_fallbacks_register_main        #name{\clf_fontcollectionregister{#name}}
94\def\font_fallbacks_prepare_clone_vectors#name{\clf_fontcollectionclone{#name}}
95
96% math (experiment, todo clf_)
97
98% \def\font_fallbacks_register_math#1#2#3#4%
99%   {\ifempty{#3}%
100%      \definedfont[#2 at #4\scaledpoint]%
101%    \else
102%      \definedfont[#2*#3\space at #4\scaledpoint]%
103%    \fi
104%    \clf_registerfontfallbackid#1\space\fontid\font\space{#2}}
105
106% % % \def\font_fallbacks_register_math#1#2#3#4%
107% % %   {\definedfont[#2\iftok{#3}\emptytoks\else*#3 \fi at #4\scaledpoint]%
108% % %    \clf_registerfontfallbackid#1\space\fontid\font\space{#2}}
109% % %
110% % % \def\font_fallbacks_finish_math
111% % %   {\ctxlua{mathematics.finishfallbacks()}}
112
113% check : only replace when present in replacement font (default: no)
114% force : force replacent even when basefont has glyph  (default: yes)
115
116% \definefontfallback [whatever] [Slanted]     [0x0060-0x007F] [force=yes]
117% \definefontfallback [whatever] [Bold]        [0x0080:0x00FF,0x00A0:0x00AF] [rscale=2.0]
118% \definefontfallback [whatever] [BoldSlanted] ["00C0-"00C7] [check=yes,force=yes]
119% \definefontfallback [whatever] [Mono]        [latinextendeda] [force=yes] % 0x0100:0x017F
120% \definefontfallback [whatever] [Mono]        [latin extended a] [force=yes] % 0x0100:0x017F
121%
122% \definefontsynonym[SerifPlus][Serif][fallbacks=whatever]
123%
124% \showfont[SerifPlus][all]
125
126% \definefontfeature[zh][mode=node,script=hang,lang=zhs]
127% \definefontfallback[serifwhatever]          [lmroman10-regular]   [0x0000-0x0400][force=yes]
128% \definefontfallback[serifboldwhatever]      [lmroman10-bold]      [0x0000-0x0400][force=yes]
129% \definefontfallback[serifitalicwhatever]    [lmroman10-italic]    [0x0000-0x0400][force=yes]
130% \definefontfallback[serifbolditalicwhatever][lmroman10-bolditalic][0x0000-0x0400][force=yes]
131%
132% \starttypescript [serif] [zhfont]
133%    \definefontsynonym [zhserif]          [AdobeSongStd-Light]   [features=zh,fallbacks=serifwhatever]
134%    \definefontsynonym [zhserifbold]      [AdobeHeitiStd-Regular][features=zh,fallbacks=serifboldwhatever]
135%    \definefontsynonym [zhserifitalic]    [AdobeKaitiStd-Regular][features=zh,fallbacks=serifitalicwhatever]
136%    \definefontsynonym [zhserifbolditalic][AdobeHeitiStd-Regular][features=zh,fallbacks=serifbolditalicwhatever]
137% \stoptypescript
138%
139% \starttypescript [serif][zhfont][name]
140%    \definefontsynonym[Serif]             [zhserif]             % [fallbacks=serifwhatever]
141%    \definefontsynonym[SerifBold]         [zhserifbold]         % [fallbacks=serifboldwhatever]
142%    \definefontsynonym[SerifItalic]       [zhserifitalic]       % [fallbacks=serifitalicwhatever]
143%    \definefontsynonym[SerifBoldItalic]   [zhserifbolditalic]   % [fallbacks=serifbolditalicwhatever]
144% \stoptypescript
145%
146% \starttypescript[myfont]
147%    \definetypeface[myfont][rm][serif][zhfont]
148% \stoptypescript
149%
150% \usetypescript[myfont] \setupbodyfont[myfont,rm,12pt]
151%
152% \starttext
153%   fonts {\bf fonts} {\bi fonts} {\it fonts}
154% \stoptext
155
156\protect \endinput
157