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% \definefontfeature [emboldened] [effect={width=0.1,delta=0.4,factor=0.3}] 28% \definefontsynonym [SansEmboldened] [Sans] [features=emboldened] 29% \definefontfallback[FakeSansCaps] [SansEmboldened] [0x0000-0xFFFF] [rscale=.8,method=uppercase] 30% \definefontsynonym [SansCaps] [file:MyriadPro-Regular.otf] [fallbacks=FakeSansCaps] 31 32\writestatus{loading}{ConTeXt Font Macros / Collections} 33 34\registerctxluafile{font-col}{} 35 36\unprotect 37 38\unexpanded\def\definefontfallback{\doquadrupleempty\font_fallbacks_define} 39\unexpanded\def\resetfontfallback {\dodoubleempty \font_fallbacks_reset } 40 41\def\font_fallbacks_define[#name][#font][#ranges][#settings]% 42 {\let\mathsizesuffix\relax 43 {#name}{#font}{#ranges}{#settings}% 44 \let\mathsizesuffix\empty} 45 46\def\font_fallbacks_reset[#name][#font]% 47 {{#name}{#font}} 48 49\def\font_fallbacks_prepare#name% 50 {{#name}} % add fallbacks to last font 51 52% we might as well move the handling to lua but then we need to pass the 53% fallbacks, skewchar etc. 54 55\newconditional\c_font_fallbacks_in_progress 56 57\def\font_fallbacks_prepare_indeed#fallbacks% 58 {\begingroup 59 \settrue\c_font_fallbacks_in_progress 60 \lastrawfontcall % sets current font id 61 \font_fallbacks_prepare#fallbacks% 62 \endgroup} 63 64\let\m_font_fallbacks\empty % set in the font-ini 65 66\appendtoks 67 \ifconditional\c_font_fallbacks_in_progress\else 68 \ifx\m_font_fallbacks\empty 69 \ifx\m_font_class_fallbacks\empty 70 \else 71 \font_fallbacks_prepare_indeed\m_font_class_fallbacks 72 \fi 73 \else 74 \font_fallbacks_prepare_indeed\m_font_fallbacks 75 \fi 76 \fi 77\to\everydefinefont 78 79\def\font_fallbacks_start_cloning 80 {\begingroup 81 \let\savedfontspec\somefontspec} 82 83\def\font_fallbacks_stop_cloning 84 {\endgroup} 85 86\def\font_fallbacks_clone_unique#specification#scale% kind of dododefinefont 87 {{defining #specification (relative scale: #scale)}% brrr 88 \setfalse\c_font_auto_size 89 \let\lastfontidentifier\s!dummy 90 \def\v_font_size_relative{#scale}% 91 \let\v_font_size_absolute\fontbody 92 \font_helpers_low_level_define{#specification}\v_font_identifier_basic 93 \csname\v_font_identifier_basic\endcsname 94 \setfalse\c_font_auto_size} % no \setfontcharacteristics and \the\everyfontswitch needed 95 96\def\font_fallbacks_clone_inherited#font% also a second argument 97 {\font_fallbacks_clone_unique{#font \savedfontspec}} 98 99\def\font_fallbacks_register_main #name{{#name}} 100\def\font_fallbacks_prepare_clone_vectors#name{{#name}} 101 102% math (experiment, todo clf_) 103 104\def\font_fallbacks_register_math#1#2#3#4% 105 {\doifelsenothing{#3}% 106 {\definedfont[#2 at #4sp]}% 107 {\definedfont[#2*#3\space at #4\scaledpoint]}% 108 #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 |