context-2020-mp.tex /size: 7554 b    last modification: 2021-10-28 13:50
1% language=us
2
3\usemodule[present-boring,abbreviations-logos]
4
5\startdocument
6  [title={METAFUN},
7   banner={simple fonts},
8   location={context\enspace {\bf 2020}\enspace meeting}]
9
10\starttitle[title=Metafonts]
11
12\startitemize
13
14\startitem
15    Because \METAPOST\ is based on \METAFONT\ it make sense to use of for making fonts.
16\stopitem
17
18\startitem
19    Making a font is an art in itself, something that is actually proven by many bad
20    looking fonts, but we have plenty of choice nowadays.
21\stopitem
22
23\startitem
24    We tend to use free fonts and often being made by volunteers we can hardly have any
25    demands.
26\stopitem
27
28\startitem
29    So, instead of complaining (which is not nice anyway) we can try to (at least temporary)
30    come up with a solution ourselves.
31\stopitem
32
33\startitem
34    We're actually talking about missing glyphs here and \METAPOST\ can be of help.
35\stopitem
36
37\startitem
38    Also keep in mind that we always had this option or variants of it in \CONTEXT, it's
39    just that we can make nicer interfaces now.
40\stopitem
41
42\startitem
43    So, don't expect something spectacular.
44\stopitem
45
46\stopitemize
47
48\stoptitle
49
50\starttitle[title=What is is not]
51
52Years ago mechanisms were added to \MKIV\ to come up with more fancy shapes in
53for instance math. Actually Alan needed it and I wanted a root symbol to look
54like school times.
55
56\startbuffer
57\useMPlibrary[mat]
58
59\setupmathradical[color=darkgray,alternative=mp]
60
61% \definemathradical [sqrt] [mp=minifun::math:radical:default]
62\stopbuffer
63
64\typebuffer \getbuffer
65
66So:
67
68\startbuffer
69\scale[height=2cm]{$ \sqrt {a+b+c+d} $}
70\stopbuffer
71
72\typebuffer
73
74Gives:
75
76\startlinecorrection
77\getbuffer
78\stoplinecorrection
79
80\page
81
82And with:
83
84\startbuffer
85\startuniqueMPgraphic{minifun::math:radical:default}
86draw
87    math_radical_simple(OverlayWidth,OverlayHeight,OverlayDepth,OverlayOffset)
88    withpen pencircle
89        xscaled (2OverlayLineWidth)
90        yscaled (1OverlayLineWidth/4)
91        rotated 30
92    dashed evenly
93    withcolor OverlayLineColor ;
94\stopuniqueMPgraphic
95\stopbuffer
96
97\typebuffer
98
99We get
100
101\startlinecorrection
102\getbuffer
103\scale[height=2cm]{$ \sqrt {a+b+c+d} $}
104\stoplinecorrection
105
106\page
107
108Also think of stackers:
109
110\startbuffer
111\setupmathstackers [both]   [color=darkgray,alternative=mp]
112\setupmathstackers [top]    [color=darkgray,alternative=mp]
113\setupmathstackers [bottom] [color=darkgray,alternative=mp]
114\stopbuffer
115
116\typebuffer \getbuffer
117
118\blank[2*line]
119
120\startbuffer
121$
122    \overbracket   {a+b+c+d} \quad
123    \underbracket  {a+b+c+d} \quad
124    \doublebracket {a+b+c+d}
125$
126\blank
127$
128    \overparent   {a+b+c+d} \quad
129    \underparent  {a+b+c+d} \quad
130    \doubleparent {a+b+c+d}
131$
132\blank
133$
134    \overbrace   {a+b+c+d} \quad
135    \underbrace  {a+b+c+d} \quad
136    \doublebrace {a+b+c+d}
137$
138\blank
139$
140    \overbar   {a+b+c+d} \quad
141    \underbar  {a+b+c+d} \quad
142    \doublebar {a+b+c+d}
143$
144\blank
145$
146    \overleftarrow  {a+b+c+d} \quad
147    \overrightarrow {a+b+c+d}
148$
149\blank
150$
151    \underleftarrow  {a+b+c+d} \quad
152    \underrightarrow {a+b+c+d}
153$
154\stopbuffer
155
156\getbuffer
157
158\blank[2*line]
159
160But, these are just overlays and nothing special: we simply don't use the normal
161font route not fancy \LUA\ tricks either (in principle \MKII\ could do this). I
162might upgrade it some day (no real demand so far, just fun stuff).
163
164\stoptitle
165
166\starttitle[title=Real fonts]
167
168\startitemize
169
170\startitem For text we need an efficient way to define extra shapes. \stopitem
171\startitem We don't really want inline graphics every time we use a glyph. \stopitem
172\startitem We also want to cut and paste properly. \stopitem
173\startitem Basically the fact that we drop in shapes should be hidden. \stopitem
174
175\blank[2*line]
176
177\startitem
178    We use the same (generic) subsystem that is also used for color fonts, bitmap
179    emoji, \SVG\ fonts, etc.
180\stopitem
181\startitem
182    Shapes end up as \TYPETHREE\ fonts. These have some specific properties and
183    limitations, but we can actually make \UNICODE\ fonts.
184\stopitem
185\startitem
186    The system is not burdened by much overhead and most happens at embedding time.
187\stopitem
188
189\stopitemize
190
191\page
192
193\startbuffer[font]
194\definefont[DemoFontA][Serif*default @ 10pt]
195\definefont[DemoFontB][Serif*default @ 12pt]
196\definefont[DemoFontC][Serif*default @ 14pt]
197\definefont[DemoFontD][SerifBold*default @ 14pt]
198\stopbuffer
199
200\typebuffer[font] \getbuffer[font]
201
202\startbuffer[demo]
203\startlines
204\DemoFontA first\endash second\emdash third\char"2015\relax fourth
205\DemoFontB first\endash second\emdash third\char"2015\relax fourth
206\DemoFontC first\endash second\emdash third\char"2015\relax fourth
207\DemoFontD first\endash second\emdash third\char"2015\relax fourth
208\stoplines
209\stopbuffer
210
211\typebuffer[demo] \getbuffer[demo]
212
213\page
214
215\startbuffer[mpone]
216\startMPcalculation{simplefun}
217
218    vardef QuotationDashOne =
219        draw image (
220            interim linecap := squared ;
221            save l ; l := 0.2 ;
222            draw (l/2,3) -- (10-l/2,3) withpen pencircle scaled l ;
223        )
224    enddef ;
225
226    lmt_registerglyphs [
227        name     = "symbolsone",
228        units    = 10,
229        usecolor = true,
230        width    = 10,
231        height   = 3.1,
232        depth    = 0,
233    ] ;
234
235    lmt_registerglyph [
236        category = "symbolsone",
237        unicode  = "0x2015",
238        code     = "QuotationDashOne ;"
239    ] ;
240
241\stopMPcalculation
242\stopbuffer
243
244\getbuffer[mpone]
245
246\startbuffer[font]
247\definefontfeature[exampleone][metapost=symbolsone]
248
249\definefont[DemoFontA][Serif*default,exampleone @ 10pt]
250\definefont[DemoFontB][Serif*default,exampleone @ 12pt]
251\definefont[DemoFontC][Serif*default,exampleone @ 14pt]
252\definefont[DemoFontD][SerifBold*default,exampleone @ 14pt]
253\stopbuffer
254
255\typebuffer[font] \getbuffer[font]
256
257\getbuffer[demo]
258
259\page
260
261\typebuffer[mpone][style=\tt\small\small]
262
263\page
264
265\startbuffer[mptwo]
266\startMPcalculation{simplefun}
267
268    vardef QuotationDashTwo =
269        draw image (
270            interim linecap := squared ;
271            save l ; l := 0.4 ;
272            string weight ; weight := getparameter "mpsfont" "parentdata" "shared" "rawdata" "metadata" "weight" ;
273            if     weight = "semibold" : l := l * 2;
274            elseif weight = "bold"     : l := l * 3; fi
275            draw (l/2,3) -- (10-l/2,3) withpen pencircle scaled l
276            withcolor yellow ;
277        )
278    enddef ;
279
280    lmt_registerglyphs [
281        name     = "symbolstwo",
282        units    = 10,
283        usecolor = false,
284        width    = 10,
285        height   = 3.1,
286        depth    = 0,
287    ] ;
288
289    lmt_registerglyph [
290        category = "symbolstwo",
291        unicode  = "0x2015",
292        code     = "QuotationDashTwo ;"
293    ] ;
294
295\stopMPcalculation
296\stopbuffer
297
298\getbuffer[mptwo]
299
300\startbuffer[font]
301\definefontfeature[exampletwo][metapost=symbolstwo]
302
303\definefont[DemoFontA][Serif*default,exampletwo @ 10pt]
304\definefont[DemoFontB][Serif*default,exampletwo @ 12pt]
305\definefont[DemoFontC][Serif*default,exampletwo @ 14pt]
306\definefont[DemoFontD][SerifBold*default,exampletwo @ 14pt]
307\stopbuffer
308
309\typebuffer[font] \getbuffer[font]
310
311\getbuffer[demo]
312
313\page
314
315\typebuffer[mptwo][style=\tt\small\small]
316
317\stoptitle
318
319\starttitle[title=More examples]
320
321We give some examples (these are also in the modules). Overloading math
322symbols:
323
324\starttyping
325meta-imp-kindergarten.mkxl
326\stoptyping
327
328Extending fonts with Don Knuths dices and tiles (symbols, ligatures, proper
329\UNICODE):
330
331\starttyping
332meta-imp-gamesymbols.mkxl
333\stoptyping
334
335An implementation of Don Knuths ThirtySix font in various variants (color,
336random, shapes):
337
338\starttyping
339meta-imp-threesix.mkxl
340\stoptyping
341
342\stopdocument
343