font-sym.mklx /size: 8972 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=font-mat,
3
%D version=2011.01.13, % (copied fron font-ini)
4
%D title=\CONTEXT\ Font Macros,
5
%D subtitle=Symbolic Access,
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
\writestatus
{
loading
}{
ConTeXt
Font
Macros
/
Symbolic
Access
}
15 16
\unprotect
17 18
%D \macros
19
%D {getglyph, symbolicfont}
20
%D
21
%D Individual glyphs can be accessed by using
22
%D
23
%D \starttyping
24
%D \getglyph{fontname}{character}
25
%D \stoptyping
26
%D
27
%D This macro is used in for instance the symbol modules and as one can see, it does
28
%D obey the small and even smaller sizes. The \type {\symbolicfont} macro can be
29
%D used to switch to a font named \type {fontname} (see \type {cont-log} and \type
30
%D {symb-eur} for examples of symbolic definitions.
31 32
\def
\v_font_string_a
33
{
\ifx
\fontstyle
\s!rm
\s!Serif
\orelse
34
\ifx
\fontstyle
\s!ss
\s!Sans
\orelse
35
\ifx
\fontstyle
\s!tt
\s!Mono
\else
36
\s!Serif
\fi
}
37 38
\def
\v_font_string_b
39
{
\ifx
\fontstyle
\s!rm
\s!Regular
\orelse
40
\ifx
\fontstyle
\s!ss
\s!Support
\orelse
41
\ifx
\fontstyle
\s!tt
\s!Type
\else
42
\s!Serif
\fi
}
43 44
\def
\v_font_string_c
45
{
\ifx
\fontalternative
\s!bf
\s!Bold
\orelse
46
\ifx
\fontalternative
\s!sl
\s!Slanted
\orelse
47
\ifx
\fontalternative
\s!it
\s!Italic
\orelse
48
\ifx
\fontalternative
\s!bs
\s!BoldSlanted
\orelse
49
\ifx
\fontalternative
\s!bi
\s!BoldItalic
\fi
}
50 51
\let
\v_font_string_d
\s!Serif
% default fontstyle (will be redefined in type-ini)
52 53
\definefontsynonym
54
[
CurrentFont
]
55
[
\noexpand
\v_font_string_a
\noexpand
\v_font_string_c
]
56 57
% potential generalization:
58
%
59
% \letvalue{\??fontfile:t:\s!rm}\s!Serif
60
% \letvalue{\??fontfile:t:\s!ss}\s!Sans
61
% \letvalue{\??fontfile:t:\s!tt}\s!Mono
62
%
63
% \letvalue{\??fontfile:a:\s!rm}\s!Regular
64
% \letvalue{\??fontfile:a:\s!ss}\s!Support
65
% \letvalue{\??fontfile:a:\s!tt}\s!Type
66
%
67
% \letvalue{\??fontfile:s:\s!bf}\s!Bold
68
% \letvalue{\??fontfile:s:\s!sl}\s!Slanted
69
% \letvalue{\??fontfile:s:\s!it}\s!Italic
70
% \letvalue{\??fontfile:s:\s!bs}\s!BoldSlanted
71
% \letvalue{\??fontfile:s:\s!bi}\s!BoldItalic
72
%
73
% \def\v_font_string_a{\executeifdefined{\??fontfile:t:\fontstyle}\s!Serif}
74
% \def\v_font_string_a{\executeifdefined{\??fontfile:t:\fontstyle}\s!Serif}
75
% \def\v_font_string_b{\executeifdefined{\??fontfile:a:\fontstyle}\s!Serif}
76
% \def\v_font_string_c{\executeifdefined{\??fontfile:s:\fontstyle}\empty}
77
% \def\v_font_string_d{\executeifdefined{\??fontfile:t:\csname\??typescriptdefaultstyles\fontclass\endcsname}\s!Serif}
78 79
%D \macros
80
%D {fontstylesuffix}
81
%D
82
%D The next macro is used to map non latin fontnames on fonts. See \type
83
%D {font-uni} for an example of its use.
84 85
\def
\fontstylesuffix
% why the \s!Regular ? see \getglyph
86
{
\ifx
\fontalternative
\s!tf
\s!Regular
\orelse
87
\ifx
\fontalternative
\s!bf
\s!Bold
\orelse
88
\ifx
\fontalternative
\s!sl
\s!Slanted
\orelse
89
\ifx
\fontalternative
\s!it
\s!Italic
\orelse
90
\ifx
\fontalternative
\s!bs
\s!BoldSlanted
\orelse
91
\ifx
\fontalternative
\s!bi
\s!BoldItalic
\orelse
92
\ifx
\fontalternative
\s!sc
\s!Caps
\else
93
\s!Regular
\fi
}
94 95
\def
\glyphfontfile
#
base
% appends
96
{
#
base
%
97
\ifcsname
\??fontfile
#
base
\v_font_string_a
\v_font_string_c
\endcsname
98
\v_font_string_a
\v_font_string_c
99
\orelse\ifcsname
\??fontfile
#
base
\v_font_string_b
\v_font_string_c
\endcsname
100
\v_font_string_b
\v_font_string_c
101
\orelse\ifcsname
\??fontfile
#
base
\v_font_string_a
\endcsname
102
\v_font_string_a
103
\orelse\ifcsname
\??fontfile
#
base
\v_font_string_b
\endcsname
104
\v_font_string_b
105
\orelse\ifcsname
\??fontfile
#
base
\v_font_string_c
\endcsname
106
\v_font_string_c
107
\fi
}
108 109
%D The next macro can be used to make decisions based on the shape:
110 111
\def
\doifelseitalic
#
yes
#
nop
%
112
{
\ifx
\fontalternative
\s!sl
#
yes
\orelse
113
\ifx
\fontalternative
\s!it
#
yes
\orelse
114
\ifx
\fontalternative
\s!bs
#
yes
\orelse
115
\ifx
\fontalternative
\s!bi
#
yes
\else
#
nop
\fi
}
116 117
\let
\doifitalicelse\doifelseitalic
118 119
%D For an example of usage of the following command, see \type {cont-log.tex}.
120
%D
121
%D \starttyping
122
%D \def\symbolicfont#specification{\definedfont[\glyphfontfile{#specification} sa *]}
123
%D \stoptyping
124
%D
125
%D Since we know what scaling it to be applied, we can implement a much faster
126
%D alternative:
127 128
\installcorenamespace
{
symbolfont
}
129 130
\let
\thedefinedfont
\relax
131 132
\def
\setscaledstyledsymbolicfont
#
1
#
2
#
3
% quite a slowdown, glyphfontfile
133
{
\edef
\askedsymbolfont
{
\truefontname
{
\glyphfontfile
{
#
3
}}
at
\the\dimexpr
#
2
\dimexpr
\currentfontbodyscale
\dimexpr
#
1
}
%
134
\ifcsname
\??symbolfont
\askedsymbolfont
\endcsname
135
\lastnamedcs
136
\else
137
\font_basics_define_symbolic_font
138
\fi
}
139 140
\def
\setscaleddirectsymbolicfont
#
1
#
2
#
3
% quite a slowdown, glyphfontfile
141
{
\edef
\askedsymbolfont
{
\truefontname
{
#
3
}
at
\the\dimexpr
#
2
\dimexpr
\currentfontbodyscale
\dimexpr
#
1
}
%
142
\ifcsname
\??symbolfont
\askedsymbolfont
\endcsname
143
\lastnamedcs
144
\else
145
\font_basics_define_symbolic_font
146
\fi
}
147 148
\def
\setstyledsymbolicfont
#
fontname
% quite a slowdown, glyphfontfile
149
{
\edef
\askedsymbolfont
{
\truefontname
{
\glyphfontfile
{
#
fontname
}}
at
\the\dimexpr
\currentfontbodyscale
\dimexpr
\fontbody
}
%
150
\ifcsname
\??symbolfont
\askedsymbolfont
\endcsname
151
\lastnamedcs
152
\else
153
\font_basics_define_symbolic_font
154
\fi
}
155 156
\def
\setdirectsymbolicfont
#
fontname
%
157
{
\edef
\askedsymbolfont
{
\truefontname
{
#
fontname
}
at
\the\dimexpr
\currentfontbodyscale
\dimexpr
\fontbody
}
%
158
\ifcsname
\??symbolfont
\askedsymbolfont
\endcsname
159
\lastnamedcs
160
\else
161
\font_basics_define_symbolic_font
162
\fi
}
163 164
\def
\font_basics_define_symbolic_font
165
{
\definefont
[
currentsymbolfont
][
\askedsymbolfont
]
%
166
\currentsymbolfont
167
\expandafter
\glet
\csname
\??symbolfont
\askedsymbolfont
\endcsname
\lastrawfontcall
}
168 169
\unexpanded
\def
\getnamedglyphstyled
#
fontname
#
character
{{
\setstyledsymbolicfont
{
#
fontname
}
\clf_fontchar
{
#
character
}}}
170
\unexpanded
\def
\getnamedglyphdirect
#
fontname
#
character
{{
\setdirectsymbolicfont
{
#
fontname
}
\clf_fontchar
{
#
character
}}}
171
\unexpanded
\def
\getglyphstyled
#
fontname
#
character
{{
\setstyledsymbolicfont
{
#
fontname
}
\doifelsenumber
{
#
character
}
\char
\donothing
#
character
}}
172
\unexpanded
\def
\getglyphdirect
#
fontname
#
character
{{
\setdirectsymbolicfont
{
#
fontname
}
\doifelsenumber
{
#
character
}
\char
\donothing
#
character
}}
173
\unexpanded
\def
\resolvedglyphstyled
#
fontname
#
character
{{
\setstyledsymbolicfont
{
#
fontname
}
\clf_tochar
{
#
character
}}}
174
\unexpanded
\def
\resolvedglyphdirect
#
fontname
#
character
{{
\setdirectsymbolicfont
{
#
fontname
}
\clf_tochar
{
#
character
}}}
175 176
% this one is wrong:
177 178
\unexpanded
\def
\getscaledglyph
#
scale
#
name
#
content
%
179
{{
\setscaledstyledsymbolicfont
\fontbody
{
#
scale
}{
#
name
}
\doifelsenumber
{
#
content
}
\char
\donothing
#
content
}}
180 181
\let
\getglyph
\getglyphstyled
% old
182
\let
\getrawglyph
\getglyphdirect
% old
183
\let
\symbolicsizedfont
\setscaledstyledsymbolicfont
% old
184
\let
\symbolicfont
\setstyledsymbolicfont
% old
185 186
\unexpanded
\def
\symbolicscaledfont
{
\setsscaledstyledsymbolicfont
\fontbody
}
187
\unexpanded
\def
\symbolicscaledfont
{
\setscaledstyledsymbolicfont
\fontbody
}
188 189
%D The last implementation of \type {\getglyph} permits definitions like:
190
%D
191
%D \starttyping
192
%D \definefontsynonym [EuroSans] [eurose]
193
%D \definefontsynonym [EuroSansBold] [euroseb]
194
%D \definefontsynonym [EuroSansItalic] [eurosei]
195
%D \definefontsynonym [EuroSansSlanted] [eurosei]
196
%D \definefontsynonym [EuroSansBoldItalic] [eurosebi]
197
%D \definefontsynonym [EuroSansBoldSlanted] [eurosebi]
198
%D
199
%D \definesymbol [euro] [\getglyph{Euro}{\char160}]
200
%D
201
%D \def\euro{\symbol[euro]}
202
%D \stoptyping
203
%D
204
%D These definitions guarantee that the next calls work okay:
205
%D
206
%D \starttyping
207
%D \ss \tf\euro \bf\euro \sla\euro \itd\euro \bs\euro \bic\euro
208
%D \stoptyping
209
%D
210
%D The shape as well as the size is adapted to the current environment.
211 212
%D \macros
213
%D {setfont}
214
%D
215
%D Every now and then we want to define a font directly, for instance when we
216
%D typeset title pages. The next macro saves some typing:
217 218
\unexpanded
\def
\setfont
% geen \font_helpers_set_font mogelijk
219
{
\afterassignment
\font_basics_set_font
\font
\nextfont
=
}
220 221
\def
\font_basics_set_font
222
{
\nextfont
\setupinterlinespace
}
% hm, we need to use \setuplocalinterlinespace
223 224
%D One can call this macro as:
225
%D
226
%D \starttyping
227
%D \setfont cmr10 at 60pt
228
%D \stoptyping
229
%D
230
%D After which the font is active and the baselines and struts are set.
231 232
%D \macros{doiffontcharelse}
233 234
\unexpanded
\def
\doifelsefontchar
#
specification
#
unicode
% this could be a direct lua call
235
{
\begingroup
236
\font_basics_define_font_without_parameters
{
thedefinedfont
}{
#
specification
}
%
237
\iffontchar
\font
#
unicode
\relax
238
\endgroup\expandafter
\firstoftwoarguments
239
\else
240
\endgroup\expandafter
\secondoftwoarguments
241
\fi
}
242 243
\let
\doiffontcharelse\doifelsefontchar
244 245
\protect
\endinput
246