bachotex-2017-variablefonts.tex /size: 12 Kb    last modification: 2020-07-01 14:35
1% language=uk
2
3\setuppapersize
4  [S6]
5
6\setupbackgrounds
7  [page]
8  [background=color,
9   backgroundcolor=darkblue]
10
11\setuplayout
12  [backspace=24pt,
13   topspace=20pt,
14   bottomspace=8pt,
15   width=middle,
16   height=middle,
17   footerdistance=8pt,
18   footer=8pt,
19   header=0pt]
20
21\setupcolors
22  [textcolor=white]
23
24\setupbodyfont
25  [dejavu,14.4pt]
26
27\definecolor[trace:o] [s=1]
28\definecolor[trace:r] [s=1]
29\definecolor[trace:do][s=1]
30\definecolor[trace:dr][s=1]
31
32\usemodule[abr-03]
33
34\definefontfeature[noligatures][liga=no]
35
36\setuphead
37  [section]
38  [page=yes,
39   style=\bfb,
40   after={\blank[3*medium]}]
41
42\setuphead
43  [subsection]
44  [page=no,
45   style=\bf\addfeature{noligatures},
46   before={\blank[3*medium]},
47   after={\blank}]
48
49\setupfooter
50  [strut=no,
51   style=\bf]
52
53\startuseMPgraphic{pagenumber}
54    if LastPageNumber > 0 :
55        draw outlinetext.f
56            (decimal RealPageNumber)
57            (withcolor "darkgray")
58            xysized ((RealPageNumber/LastPageNumber) * TextWidth/2,FooterHeight) ;
59    fi ;
60\stopuseMPgraphic
61
62\setupfootertexts
63  [\useMPgraphic{pagenumber}]
64
65\startdocument
66  [title={Variable Fonts},
67   subtitle={we're ready for them},
68   author={Hans Hagen},
69   occasion={BachoTUG 2017}]
70
71\startstandardmakeup
72    \vskip32pt
73    \bfd \setupinterlinespace
74    \documentvariable{title}
75    \crlf
76    \bfb \setupinterlinespace
77    \vskip12pt
78    \documentvariable{subtitle}
79    \vfill
80    \bfb \setupinterlinespace
81    \documentvariable{author}
82    \crlf
83    \documentvariable{occasion}
84\stopstandardmakeup
85
86\startsubject[title=A Summary]
87
88\startitemize
89\startitem
90    {\bf the macro package's view:} just a font but with many possible variations
91    in shapes (width, weight, slope, etc) and therefore a bit more complex user
92    interface
93\stopitem
94\startitem
95    {\bf the engine's view:} an abstraction not different from other fonts but
96    that needs a special treatment in the backend
97\stopitem
98\startitem
99    {\bf the viewer's view:} a font to be displayed like any other with outlines
100    in cff of ttf format
101\stopitem
102\startitem
103    {\bf the user's view:} an opentype font with possibly surprising shapes of
104    which you need to know a bit more than usual if you want to profit from it
105\stopitem
106\stopitemize
107
108So, in practice, for most \TEX\ users it's just a font that has to be supported by
109\TEX\ and friends.
110
111\stopsubject
112
113\startsubject[title=Starting point]
114
115\startitemize
116\startitem
117    The OpenType 1.8 specification at the MicroSoft website defined the extra
118    tables and explains bits and pieces.
119\stopitem
120\startitem
121    There a few fonts that have relevant tables (not all) and implement variants
122    as well as features.
123\stopitem
124\startitem
125    There are some posts on the internet that show a bit about axis and other things
126    that go on in these fonts.
127\stopitem
128\startitem
129    Luckily we have ways (in \CONTEXT) to explore what goes on in these fonts and
130    how they could look.
131\stopitem
132\startitem
133    Condition: no tricks, no fuzzy heuristics, just the specification should be
134    enough.
135\stopitem
136\stopitemize
137
138\stopsubject
139
140\startsubject[title=Implementation steps]
141
142\startitemize
143\startitem
144    First try to render variants in order to see what we're dealing with. This was not too
145    hard (starting with cff) because we have already virtual font support.
146\stopitem
147\startitem
148    Next try to load the relevant tables and figure out what these deltas and such really
149    mean and how axis and regions and \unknown\ have to be applied.
150\stopitem
151\startitem
152    Try to make it all work on a real piece of text, so not only shapes but also features
153    and dimensions.
154\stopitem
155\startitem
156    Finally make sure that the font can get embedded as a normal font and not as inline
157    (tagged) graphic.
158\stopitem
159\startitem
160    Also, try to generalize the helpers and methods in such ways that we can experiment
161    with additional tricks (after all, \TEX\ is about control).
162\stopitem
163\startitem
164    Todo: once there are more fonts (with the right data tables), check the code with the
165    specification.
166\stopitem
167\stopitemize
168
169\stopsubject
170
171\setupTABLE[c][1][style=tttf,align={flushleft,lohi}]
172
173\startsubject[title=Adobe Variable Font Prototype (cff)]
174
175\unexpanded\def\SampleFont#1#2% weight / contrast
176  {\definedfont[name:adobevariablefontprototype#1*default at 32pt]It looks like this!}
177
178\bTABLE[distance=2em,frame=off]
179\bTR \bTD extralight               0/0   \eTD \bTD \SampleFont {extralight}          \eTD \eTR
180\bTR \bTD light                  150/0   \eTD \bTD \SampleFont {light}               \eTD \eTR
181\bTR \bTD regular                394/0   \eTD \bTD \SampleFont {regular}             \eTD \eTR
182\bTR \bTD semibold               600/0   \eTD \bTD \SampleFont {semibold}            \eTD \eTR
183\bTR \bTD bold                   824/0   \eTD \bTD \SampleFont {bold}                \eTD \eTR
184\bTR \bTD black high contrast   1000/100 \eTD \bTD \SampleFont {blackhighcontrast}   \eTD \eTR
185\bTR \bTD black medium contrast 1000/50  \eTD \bTD \SampleFont {blackmediumcontrast} \eTD \eTR
186\bTR \bTD black                 1000/0   \eTD \bTD \SampleFont {black}               \eTD \eTR
187\eTABLE
188
189\stopsubject
190
191% \starttyping
192% \definefont
193%   [MyLightFont]
194%   [name:adobevariablefontprototypelight*default]
195% \stoptyping
196
197\unexpanded\def\SampleFont#1#2% weight / width
198  {\definedfont[name:avenirnextvariable#1*default at 32pt]It looks like this!}
199
200\startsubject[title=Avenir Next Variable (ttf)]
201
202\bTABLE[distance=2em,frame=off]
203\bTR \bTD regular           400/100 \eTD \bTD \SampleFont {regular}         \eTD \eTR
204\bTR \bTD medium            500/100 \eTD \bTD \SampleFont {medium}          \eTD \eTR
205\bTR \bTD bold              700/100 \eTD \bTD \SampleFont {bold}            \eTD \eTR
206\bTR \bTD heavy             900/100 \eTD \bTD \SampleFont {heavy}           \eTD \eTR
207\bTR \bTD condensed         400/75  \eTD \bTD \SampleFont {condensed}       \eTD \eTR
208\bTR \bTD medium condensed  500/75  \eTD \bTD \SampleFont {mediumcondensed} \eTD \eTR
209\bTR \bTD bold condensed    700/75  \eTD \bTD \SampleFont {boldcondensed}   \eTD \eTR
210\bTR \bTD heavy condensed   900/75  \eTD \bTD \SampleFont {heavycondensed}  \eTD \eTR
211\eTABLE
212
213\stopsubject
214
215\startbuffer[both]
216\vfill
217\startMPcode
218  draw outlinetext.b
219    ("\getbuffer[a]")
220    (withcolor "white")
221    (withcolor "red" withpen pencircle scaled 1/10)
222    xsized .9TextWidth ;
223\stopMPcode
224\vfill
225\startMPcode
226  draw outlinetext.b
227    ("\getbuffer[b]")
228    (withcolor "white")
229    (withcolor "red" withpen pencircle scaled 1/10)
230    xsized .9TextWidth ;
231\stopMPcode
232\vfill
233\startMPcode
234  draw outlinetext.b
235    ("\getbuffer[c]")
236    (withcolor "white")
237    (withcolor "red" withpen pencircle scaled 1/10)
238    xsized .90TextWidth ;
239\stopMPcode
240\vfill
241\stopbuffer
242
243\startbuffer[fill]
244\vfill
245\startMPcode
246  draw outlinetext.f
247    ("\getbuffer[a]")
248    (withcolor "white")
249    xsized .9TextWidth ;
250\stopMPcode
251\vfill
252\startMPcode
253  draw outlinetext.f
254    ("\getbuffer[b]")
255    (withcolor "white")
256    xsized .9TextWidth ;
257\stopMPcode
258\vfill
259\startMPcode
260  draw outlinetext.f
261    ("\getbuffer[c]")
262    (withcolor "white")
263    xsized .9TextWidth ;
264\stopMPcode
265\vfill
266\stopbuffer
267
268\startbuffer[draw]
269\vfill
270\startMPcode
271  draw outlinetext.d
272    ("\getbuffer[a]")
273    (withcolor "white" withpen pencircle scaled 1/10)
274    xsized .9TextWidth ;
275\stopMPcode
276\vfill
277\startMPcode
278  draw outlinetext.d
279    ("\getbuffer[b]")
280    (withcolor "white" withpen pencircle scaled 1/10)
281    xsized .9TextWidth ;
282\stopMPcode
283\vfill
284\startMPcode
285  draw outlinetext.d
286    ("\getbuffer[c]")
287    (withcolor "white" withpen pencircle scaled 1/10)
288    xsized .9TextWidth ;
289\stopMPcode
290\vfill
291\stopbuffer
292
293\startbuffer[overlay]
294\startoverlay{%
295\startMPcode
296  draw outlinetext.d
297    ("\getbuffer[a]")
298    (withcolor "green" withtransparency (3,0.5) withpen pencircle scaled 1/10)
299    xsized .9TextWidth ;
300\stopMPcode
301}{%
302\startMPcode
303  draw outlinetext.d
304    ("\getbuffer[b]")
305    (withcolor "yellow" withtransparency (3,0.5) withpen pencircle scaled 1/10)
306    xsized .9TextWidth ;
307\stopMPcode
308}{%
309\startMPcode
310  draw outlinetext.d
311    ("\getbuffer[c]")
312    (withcolor "red" withtransparency (3,0.5) withpen pencircle scaled 1/10)
313    xsized .9TextWidth ;
314\stopMPcode
315}
316\stopoverlay
317\stopbuffer
318
319\startbuffer[a]
320\definedfont[name:adobevariablefontprototypeextralight]bachotex%
321\stopbuffer
322
323\startbuffer[b]
324\definedfont[name:adobevariablefontprototypelight]bachotex%
325\stopbuffer
326
327\startbuffer[c]
328\definedfont[name:adobevariablefontprototypebold]bachotex%
329\stopbuffer
330
331\startsubject[title=Metafontisch overlap (1)]
332    \getbuffer[both]
333\stopsubject
334
335\startbuffer[a]
336\definefontfeature[whatever][axis={weight:50}]%
337\definedfont[name:adobevariablefontprototype*whatever]bachotex%
338\stopbuffer
339
340\startbuffer[b]
341\definefontfeature[whatever][axis={weight:300}]%
342\definedfont[name:adobevariablefontprototype*whatever]bachotex%
343\stopbuffer
344
345\startbuffer[c]
346\definefontfeature[whatever][axis={weight:700}]%
347\definedfont[name:adobevariablefontprototype*whatever]bachotex%
348\stopbuffer
349
350\startsubject[title=Metafontisch overlap (2)]
351    \getbuffer[both]
352\stopsubject
353\startsubject[title=Fills hide the details]
354    \getbuffer[fill]
355\stopsubject
356\startsubject[title=Unsuitable outlines]
357    \getbuffer[draw]
358\stopsubject
359
360\startbuffer[a]
361\definefontfeature[whatever][axis={weight:100,contrast:0}]%
362\definedfont[name:adobevariablefontprototype*whatever]bachotex%
363\stopbuffer
364
365\startbuffer[b]
366\definefontfeature[whatever][axis={weight:200,contrast:20}]%
367\definedfont[name:adobevariablefontprototype*whatever]bachotex%
368\stopbuffer
369
370\startbuffer[c]
371\definefontfeature[whatever][axis={weight:200,contrast:50}]%
372\definedfont[name:adobevariablefontprototype*whatever]bachotex%
373\stopbuffer
374
375\startsubject[title=Stay within specification]
376    \getbuffer[draw]
377\stopsubject
378
379\startsubject[title=Subjective choices]
380    \getbuffer[fill]
381\stopsubject
382
383\startbuffer[a]
384\definefontfeature[whatever][axis={weight:100,contrast:0}]%
385\definedfont[name:adobevariablefontprototype*whatever]tex%
386\stopbuffer
387
388\startbuffer[b]
389\definefontfeature[whatever][axis={weight:200,contrast:20}]%
390\definedfont[name:adobevariablefontprototype*whatever]tex%
391\stopbuffer
392
393\startbuffer[c]
394\definefontfeature[whatever][axis={weight:200,contrast:50}]%
395\definedfont[name:adobevariablefontprototype*whatever]tex%
396\stopbuffer
397
398\startsubject[title=Difficult choices]
399    \getbuffer[overlay]
400\stopsubject
401
402\startsubject[title=Definitions (1)]
403
404\startbuffer
405\definefontfeature
406  [default:shaped]
407  [default]
408  [axis={width:10}]
409
410\definefont
411  [SomeFont]
412  [file:avenirnextvariable*default:shaped]
413\stopbuffer
414
415\typebuffer \getbuffer
416
417\start \setupinterlinespace \showglyphs \showfontkerns \SomeFont \input zapf \wordright{Hermann Zapf}\par \stop
418
419\stopsubject
420
421\startsubject[title=Definitions (2)]
422
423\startbuffer
424\definefontfeature
425  [default:shaped]
426  [default]
427  [axis={width:100,weight=200}]
428
429\definefont
430  [SomeFont]
431  [file:avenirnextvariable*default:shaped @ 12pt]
432\stopbuffer
433
434\typebuffer \getbuffer
435
436\start \setupinterlinespace  \showglyphs \showfontkerns \SomeFont \input zapf \wordright{Hermann Zapf}\par \stop
437
438\stopsubject
439
440\startsubject[title=Transformations]
441
442\subsubject{correction:}
443
444\startformula
445    x^\prime = x
446             + s_{x1} \cdot x_1
447             + s_{x2} \cdot x_2
448             + s_{x3} \cdot x_3
449             + s_{x4} \cdot x_4
450\stopformula
451
452\startformula
453    y^\prime = y
454             + s_{y1} \cdot y_1
455             + s_{y2} \cdot y_2
456             + s_{y3} \cdot y_3
457             + s_{y4} \cdot y_4
458\stopformula
459
460\subsubject{internal cff:}
461
462\starttyping
4631 <setvstore>
464120 [10 -30 40 -60] 1 <blend> ... <operator>
465100 120 [10 -30 40 -60] [30 -10 -30 20] 2 <blend> .. <operator>
466\stoptyping
467
468\subsubject{external ttf:}
469
470\starttyping
471apply x deltas [10 -30 40 -60] to x 120
472apply y deltas [30 -10 -30 20] to y 100
473\stoptyping
474
475\stopsubject
476
477\startsubject[title=Follow up]
478
479\startitemize
480\startitem
481    Performance is quite okay because we cache instances. I might come up with an
482    alternative way but there is not much to gain.
483\stopitem
484\startitem
485    Once fonts show up alternative interfaces to axis and scaling can be explored
486    and provided.
487\stopitem
488\startitem
489    I will look into ways to do all the backend font code in \CONTEXT\ in \LUA\
490    (easier to update and more flexible).
491\stopitem
492\startitem
493    Luigi and I will play with variable fonts defined in the traditional meta tools
494    that come with \TEX.
495\stopitem
496\stopitemize
497
498\stopsubject
499
500\stopdocument
501