summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/font-sym.mkvi
blob: 3ff85fb4a848575c31dd45ed1ff02ecf0aa8871b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
%D \module
%D   [       file=font-mat,
%D        version=2011.01.13, % (copied fron font-ini)
%D          title=\CONTEXT\ Font Macros,
%D       subtitle=Symbolic Access,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Font Macros / Symbolic Access}

\unprotect

%D \macros
%D   {getglyph, symbolicfont}
%D
%D Individual glyphs can be accessed by using
%D
%D \starttyping
%D \getglyph{fontname}{character}
%D \stoptyping
%D
%D This macro is used in for instance the symbol modules and
%D as one can see, it does obey the small and even smaller
%D sizes. The \type {\symbolicfont} macro can be used to
%D switch to a font named \type {fontname} (see \type
%D {cont-log} and \type {symb-eur} for examples of symbolic
%D definitions.

\def\v_font_string_a
  {\ifx\fontstyle\s!rm \s!Serif \else
   \ifx\fontstyle\s!ss \s!Sans  \else
   \ifx\fontstyle\s!tt \s!Mono  \else
                       \s!Serif \fi\fi\fi}

\def\v_font_string_b
  {\ifx\fontstyle\s!rm \s!Regular \else
   \ifx\fontstyle\s!ss \s!Support \else
   \ifx\fontstyle\s!tt \s!Type    \else
                       \s!Serif   \fi\fi\fi}

\def\v_font_string_c
  {\ifx\fontalternative\s!bf \s!Bold        \else
   \ifx\fontalternative\s!sl \s!Slanted     \else
   \ifx\fontalternative\s!it \s!Italic      \else
   \ifx\fontalternative\s!bs \s!BoldSlanted \else
   \ifx\fontalternative\s!bi \s!BoldItalic  \fi\fi\fi\fi\fi}

\let\v_font_string_d\s!Serif % default fontstyle (will be redefined in type-ini)

\definefontsynonym
  [CurrentFont]
  [\noexpand\v_font_string_a\noexpand\v_font_string_c]

% potential generalization:
%
% \letvalue{\??fontfile:t:\s!rm}\s!Serif
% \letvalue{\??fontfile:t:\s!ss}\s!Sans
% \letvalue{\??fontfile:t:\s!tt}\s!Mono
%
% \letvalue{\??fontfile:a:\s!rm}\s!Regular
% \letvalue{\??fontfile:a:\s!ss}\s!Support
% \letvalue{\??fontfile:a:\s!tt}\s!Type
%
% \letvalue{\??fontfile:s:\s!bf}\s!Bold
% \letvalue{\??fontfile:s:\s!sl}\s!Slanted
% \letvalue{\??fontfile:s:\s!it}\s!Italic
% \letvalue{\??fontfile:s:\s!bs}\s!BoldSlanted
% \letvalue{\??fontfile:s:\s!bi}\s!BoldItalic
%
% \def\v_font_string_a{\executeifdefined{\??fontfile:t:\fontstyle}\s!Serif}
% \def\v_font_string_a{\executeifdefined{\??fontfile:t:\fontstyle}\s!Serif}
% \def\v_font_string_b{\executeifdefined{\??fontfile:a:\fontstyle}\s!Serif}
% \def\v_font_string_c{\executeifdefined{\??fontfile:s:\fontstyle}\empty}
% \def\v_font_string_d{\executeifdefined{\??fontfile:t:\csname\??typescriptdefaultstyles\fontclass\endcsname}\s!Serif}

%D \macros
%D   {fontstylesuffix}
%D
%D The next macro is used to map non latin fontnames on fonts. See \type
%D {font-uni} for an example of its use.

\def\fontstylesuffix% why the \s!Regular ? see \getglyph
  {\ifx\fontalternative\s!tf     \s!Regular \else
   \ifx\fontalternative\s!bf        \s!Bold \else
   \ifx\fontalternative\s!sl     \s!Slanted \else
   \ifx\fontalternative\s!it      \s!Italic \else
   \ifx\fontalternative\s!bs \s!BoldSlanted \else
   \ifx\fontalternative\s!bi  \s!BoldItalic \else
   \ifx\fontalternative\s!sc        \s!Caps \else
                                 \s!Regular \fi\fi\fi\fi\fi\fi\fi}%

\def\glyphfontfile#base% appends
  {#base%
   \ifcsname\??fontfile#base\v_font_string_a\v_font_string_c\endcsname
     \v_font_string_a\v_font_string_c
   \else\ifcsname\??fontfile#base\v_font_string_b\v_font_string_c\endcsname
     \v_font_string_b\v_font_string_c
   \else\ifcsname\??fontfile#base\v_font_string_a\endcsname
     \v_font_string_a
   \else\ifcsname\??fontfile#base\v_font_string_b\endcsname
     \v_font_string_b
   \else\ifcsname\??fontfile#base\v_font_string_c\endcsname
     \v_font_string_c
   \fi\fi\fi\fi\fi}

%D The next macro can be used to make decisions based on the shape:

\def\doifelseitalic#yes#nop%
  {\ifx\fontalternative\s!sl#yes\else
   \ifx\fontalternative\s!it#yes\else
   \ifx\fontalternative\s!bs#yes\else
   \ifx\fontalternative\s!bi#yes\else#nop\fi\fi\fi\fi}

\let\doifitalicelse\doifelseitalic

%D For an example of usage of the following command,
%D see \type {cont-log.tex}.
%D
%D \starttyping
%D \def\symbolicfont#specification{\definedfont[\glyphfontfile{#specification} sa *]}
%D \stoptyping
%D
%D Since we know what scaling it to be applied, we can
%D implement a much faster alternative:

\installcorenamespace{symbolfont}

\let\thedefinedfont\relax

\def\setscaledstyledsymbolicfont#1#2#3% quite a slowdown, glyphfontfile
  {\edef\askedsymbolfont{\truefontname{\glyphfontfile{#3}} at \the\dimexpr#2\dimexpr\currentfontbodyscale\dimexpr#1}%
   \ifcsname\??symbolfont\askedsymbolfont\endcsname
     \lastnamedcs
   \else
     \font_basics_define_symbolic_font
   \fi}

\def\setscaleddirectsymbolicfont#1#2#3% quite a slowdown, glyphfontfile
  {\edef\askedsymbolfont{\truefontname{#3} at \the\dimexpr#2\dimexpr\currentfontbodyscale\dimexpr#1}%
   \ifcsname\??symbolfont\askedsymbolfont\endcsname
     \lastnamedcs
   \else
     \font_basics_define_symbolic_font
   \fi}

\def\setstyledsymbolicfont#fontname% quite a slowdown, glyphfontfile
  {\edef\askedsymbolfont{\truefontname{\glyphfontfile{#fontname}} at \the\dimexpr\currentfontbodyscale\dimexpr\fontbody}%
   \ifcsname\??symbolfont\askedsymbolfont\endcsname
     \lastnamedcs
   \else
     \font_basics_define_symbolic_font
   \fi}

\def\setdirectsymbolicfont#fontname%
  {\edef\askedsymbolfont{\truefontname{#fontname} at \the\dimexpr\currentfontbodyscale\dimexpr\fontbody}%
   \ifcsname\??symbolfont\askedsymbolfont\endcsname
     \lastnamedcs
   \else
     \font_basics_define_symbolic_font
   \fi}

\def\font_basics_define_symbolic_font
  {\definefont[currentsymbolfont][\askedsymbolfont]%
   \currentsymbolfont
   \expandafter\glet\csname\??symbolfont\askedsymbolfont\endcsname\lastrawfontcall}

\unexpanded\def\getnamedglyphstyled#fontname#character{{\setstyledsymbolicfont{#fontname}\clf_fontchar{#character}}}
\unexpanded\def\getnamedglyphdirect#fontname#character{{\setdirectsymbolicfont{#fontname}\clf_fontchar{#character}}}
\unexpanded\def\getglyphstyled     #fontname#character{{\setstyledsymbolicfont{#fontname}\doifelsenumber{#character}\char\donothing#character}}
\unexpanded\def\getglyphdirect     #fontname#character{{\setdirectsymbolicfont{#fontname}\doifelsenumber{#character}\char\donothing#character}}
\unexpanded\def\resolvedglyphstyled#fontname#character{{\setstyledsymbolicfont{#fontname}\clf_tochar{#character}}}
\unexpanded\def\resolvedglyphdirect#fontname#character{{\setdirectsymbolicfont{#fontname}\clf_tochar{#character}}}

% this one is wrong:

\unexpanded\def\getscaledglyph#scale#name#content%
  {{\setscaledstyledsymbolicfont\fontbody{#scale}{#name}\doifelsenumber{#content}\char\donothing#content}}

\let\getglyph         \getglyphstyled               % old
\let\getrawglyph      \getglyphdirect               % old
\let\symbolicsizedfont\setscaledstyledsymbolicfont  % old
\let\symbolicfont     \setstyledsymbolicfont        % old

\unexpanded\def\symbolicscaledfont{\setsscaledstyledsymbolicfont\fontbody}
\unexpanded\def\symbolicscaledfont{\setscaledstyledsymbolicfont\fontbody}

%D The last implementation of \type {\getglyph} permits
%D definitions like:
%D
%D \starttyping
%D \definefontsynonym [EuroSans]            [eurose]
%D \definefontsynonym [EuroSansBold]        [euroseb]
%D \definefontsynonym [EuroSansItalic]      [eurosei]
%D \definefontsynonym [EuroSansSlanted]     [eurosei]
%D \definefontsynonym [EuroSansBoldItalic]  [eurosebi]
%D \definefontsynonym [EuroSansBoldSlanted] [eurosebi]
%D
%D \definesymbol [euro] [\getglyph{Euro}{\char160}]
%D
%D \def\euro{\symbol[euro]}
%D \stoptyping
%D
%D These definitions guarantee that the next calls work okay:
%D
%D \starttyping
%D \ss \tf\euro \bf\euro \sla\euro \itd\euro \bs\euro \bic\euro
%D \stoptyping
%D
%D The shape as well as the size is adapted to the current
%D environment.

%D \macros
%D   {setfont}
%D
%D Every now and then we want to define a font directly, for
%D instance when we typeset title pages. The next macro saves
%D some typing:

\unexpanded\def\setfont% geen \font_helpers_set_font mogelijk
  {\afterassignment\font_basics_set_font\font\nextfont=}

\def\font_basics_set_font
  {\nextfont\setupinterlinespace}% hm, we need to use \setuplocalinterlinespace

%D One can call this macro as:
%D
%D \starttyping
%D \setfont cmr10 at 60pt
%D \stoptyping
%D
%D After which the font is active and the baselines and
%D struts are set.

%D \macros{doiffontcharelse}

\unexpanded\def\doifelsefontchar#specification#unicode% this could be a direct lua call
  {\begingroup
   \font_basics_define_font_without_parameters{thedefinedfont}{#specification}%
   \iffontchar\font#unicode\relax
     \endgroup\expandafter\firstoftwoarguments
   \else
     \endgroup\expandafter\secondoftwoarguments
   \fi}

\let\doiffontcharelse\doifelsefontchar

\protect \endinput