beta 2014.02.14 17:07
[context.git] / tex / context / base / font-col.mkvi
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 % ! EXPERIMENTAL ! code will be made more nice
15 %
16 % actually we can now do more at the lua end
17
18 % todo   : missing only, force always, multiple fallbacks with test, scale
19 % beware : only english key/values
20 %
21 % \resetfontfallback [whatever]
22 %
23 % \definefontfallback [whatever] [Slanted]     [0x0060-0x007F] [force=yes]
24 % \definefontfallback [whatever] [Bold]        [0x0080-0x00FF,0x00A0-0x00AF] [rscale=1.2]
25 % \definefontfallback [whatever] [BoldSlanted] [0x00C0-0x00C7] [check=yes,force=yes]
26
27 \writestatus{loading}{ConTeXt Font Macros / Collections}
28
29 \registerctxluafile{font-col}{1.001}
30
31 \unprotect
32
33 \unexpanded\def\definefontfallback{\doquadrupleempty\font_fallbacks_define}
34 \unexpanded\def\resetfontfallback {\dodoubleempty   \font_fallbacks_reset }
35
36 \def\font_fallbacks_define[#name][#font][#ranges][#settings]%
37   {\ctxcommand{fontcollectiondefine("#name","#font",\!!bs#ranges\!!es,\!!bs#settings\!!es)}}
38
39 \def\font_fallbacks_reset[#name][#font]%
40   {\ctxcommand{fontcollectionreset("#name","#font")}}
41
42 \def\font_fallbacks_prepare#name%
43   {\ctxcommand{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      \settrue\c_font_fallbacks_in_progress
53      \lastrawfontcall % sets current font id
54      \font_fallbacks_prepare#fallbacks%
55    \endgroup}
56
57 \let\m_font_fallbacks\empty % set in the font-ini
58
59 \appendtoks
60     \ifconditional\c_font_fallbacks_in_progress\else
61         \ifx\m_font_fallbacks\empty
62             \ifx\m_font_class_fallbacks\empty
63             \else
64                 \font_fallbacks_prepare_indeed\m_font_class_fallbacks
65             \fi
66         \else
67             \font_fallbacks_prepare_indeed\m_font_fallbacks
68         \fi
69    \fi
70 \to\everydefinefont
71
72 \def\font_fallbacks_start_cloning
73   {\begingroup
74    \let\savedfontspec\somefontspec}
75
76 \def\font_fallbacks_stop_cloning
77   {\endgroup}
78
79 \def\font_fallbacks_clone_unique#specification#scale% kind of dododefinefont
80   {\ctxcommand{fontcollectionreport("defining #specification (relative scale: #scale)")}% brrr
81    \setfalse\c_font_auto_size
82    \let\lastfontidentifier\s!dummy
83    \def\v_font_size_relative{#scale}%
84    \let\v_font_size_absolute\fontbody
85    \font_helpers_low_level_define{#specification}\v_font_identifier_basic
86    \csname\v_font_identifier_basic\endcsname
87    \setfalse\c_font_auto_size} % no \setfontcharacteristics and \the\everyfontswitch needed
88
89 \def\font_fallbacks_clone_inherited#font% also a second argument
90   {\font_fallbacks_clone_unique{#font \savedfontspec}}
91
92 \def\font_fallbacks_register_main        #name{\ctxcommand{fontcollectionregister("#name")}}
93 \def\font_fallbacks_prepare_clone_vectors#name{\ctxcommand{fontcollectionclone("#name")}}
94
95 % check : only replace when present in replacement font (default: no)
96 % force : force replacent even when basefont has glyph  (default: yes)
97
98 % \definefontfallback [whatever] [Slanted]     [0x0060-0x007F] [force=yes]
99 % \definefontfallback [whatever] [Bold]        [0x0080:0x00FF,0x00A0:0x00AF] [rscale=2.0]
100 % \definefontfallback [whatever] [BoldSlanted] ["00C0-"00C7] [check=yes,force=yes]
101 % \definefontfallback [whatever] [Mono]        [latinextendeda] [force=yes] % 0x0100:0x017F
102 % \definefontfallback [whatever] [Mono]        [latin extended a] [force=yes] % 0x0100:0x017F
103 %
104 % \definefontsynonym[SerifPlus][Serif][fallbacks=whatever]
105 %
106 % \showfont[SerifPlus][all]
107
108 % \definefontfeature[zh][mode=node,script=hang,lang=zhs]
109 % \definefontfallback[serifwhatever]          [lmroman10-regular]   [0x0000-0x0400][force=yes]
110 % \definefontfallback[serifboldwhatever]      [lmroman10-bold]      [0x0000-0x0400][force=yes]
111 % \definefontfallback[serifitalicwhatever]    [lmroman10-italic]    [0x0000-0x0400][force=yes]
112 % \definefontfallback[serifbolditalicwhatever][lmroman10-bolditalic][0x0000-0x0400][force=yes]
113 %
114 % \starttypescript [serif] [zhfont]
115 %    \definefontsynonym [zhserif]          [AdobeSongStd-Light]   [features=zh,fallbacks=serifwhatever]
116 %    \definefontsynonym [zhserifbold]      [AdobeHeitiStd-Regular][features=zh,fallbacks=serifboldwhatever]
117 %    \definefontsynonym [zhserifitalic]    [AdobeKaitiStd-Regular][features=zh,fallbacks=serifitalicwhatever]
118 %    \definefontsynonym [zhserifbolditalic][AdobeHeitiStd-Regular][features=zh,fallbacks=serifbolditalicwhatever]
119 % \stoptypescript
120 %
121 % \starttypescript [serif][zhfont][name]
122 %    \definefontsynonym[Serif]             [zhserif]             % [fallbacks=serifwhatever]
123 %    \definefontsynonym[SerifBold]         [zhserifbold]         % [fallbacks=serifboldwhatever]
124 %    \definefontsynonym[SerifItalic]       [zhserifitalic]       % [fallbacks=serifitalicwhatever]
125 %    \definefontsynonym[SerifBoldItalic]   [zhserifbolditalic]   % [fallbacks=serifbolditalicwhatever]
126 % \stoptypescript
127 %
128 % \starttypescript[myfont]
129 %    \definetypeface[myfont][rm][serif][zhfont]
130 % \stoptypescript
131 %
132 % \usetypescript[myfont] \setupbodyfont[myfont,rm,12pt]
133 %
134 % \starttext
135 %   fonts {\bf fonts} {\bi fonts} {\it fonts}
136 % \stoptext
137
138 \protect \endinput