1
2
3\startcomponent ontargetnostalgic
4
5\environment ontargetstyle
6
7\startchapter[title={Getting nostalgic}]
8
9When Mikael and I were playing with \POTRACE\ we eventually ended up by turning
10some old rune font defined in \METAFONT\ into a quite useable outline font. In
11the process we went from a \TYPETHREE\ to a proper \OPENTYPE\ (\CFF) instance.
12When doing this I remembered that in the times of active \PDFTEX\ development,
13Thanh, Taco and I played with what we called \PDF\ glyph containers. I had done
14experiments with using xforms (small images) as replacement for bitmap characters
15but that is not what we want with fonts, so after discussing it with Thanh
16\TYPETHREE\ support was extended with a user driven variant. Due to the way
17\METAFONT s are defined the results were mixed. Filled shapes could be made to
18work but outlines often looked bad and much had to do with the fact that these
19fonts were never defined with oddeven rules in mind. So, Taco made a bitmap to
20outline program that we could hook in and in the end we had a reasonable
21workflow. Were talking of the period 1997 to 1998, some 25 years ago!
22
23So, when in 2023 we came back to bitmap fonts in the perspective of \LUAMETATEX,
24some memories returned but I couldnt find the files or code at that time, which
25might relate to the fact that I always start from specifications. However, when
26in January 2024 I had to fix some issue with embedding an old \TYPEONE\ font and
27after succeeding in that I decided again to search for that old code. This time I
28just grepd the \PDFTEX\ code base (as I had the \TEXLIVE\ git checkout) and I
29found back this feature. In the end I had been looking at the wrong \quote
30{strings} because it looked like the interface evolved a little.
31
32The basics are as follows. When we have a file (in \PDFTEX) the \TFM\ blob is
33what matters for the frontend. The backend that does the inclusion links that to
34a suitable font resource, most likely in \TYPEONE\ format. This is specified in a
35map file that also permits specifying an encoding vector. For some reason it is
36not possible to map to other font formats other than \TYPEONE\ and \TRUETYPE. No
37mapping means that a \PK\ file is used and then we end up in some complicated
38semi automatic bitmap generation.
39
40When I tested how these containers worked out nowadays, once \PDFTEX \footnote
41{Version 3.1415926532.61.40.25 and older.} is happy to include a font it will
42bark about a missing font resource: it always wants a bitmap. Now, you can
43complain about this but I bet no one ever used this 25 year old feature so no one
44ever requested a check for a \type {pgc} file. Basically, when such a file is
45found instead of a \type{600pk} file, all should be fine, even if that is a zero
46length file. Given that the backend actually checks for it and not considers a
47container file useable, one can consider it an oversight, or maybe it just got
48lost in the \KPSE\ library that manages \PK\ fonts and its generation.
49
50Anyway, so how does it work? When the backend checks for a glyph container it
51expects this:
52
53\starttyping
54\pdffontscale factor
55\pdfglyph slot width height depth llx lly urx ury =
56
57\endglyph
58\stoptyping
59
60One can add a \type {\pdffont} and \type{\endfont} wrapper because \PDFTEX\ only
61searches for the mandate scale and one or more glyphs. A simple test then becomes:
62
63\startitemize[packed]
64\startitem
65 Copy a \TFM\ file to a new name, say \type {cmr10mine.tfm}.
66\stopitem
67\startitem
68 Create a bogus \PK\ file, for instance a zero byte \type {cmr10mine.600pk}.
69\stopitem
70\startitem
71 Make sure it can be found, I had to set \type {set MISCFONTS=.}.
72\stopitem
73\startitem
74 Create a glyph container with suffix \type {pgc} with some valid \PDF\ code.
75\stopitem
76\stopitemize
77
78And then use a safe character for testing present in most fonts at the same
79position in the used encoding:
80
81\starttyping
82\starttext
83 \font\test=cmr10mine \test \char 65
84\stoptext
85\stoptyping
86
87This should produce something, assuming an entry like:
88
89\starttyping
90\pdffontscale 0.01
91\pdfglyph 65 200 0 0 0 0 200 200 =
92 10 M 1 j 1 J 5 w
93
94 h S
95\endglyph
96\stoptyping
97
98Just for completeness, I could find a \PERL\ program on my disk that I wrote at
99that time and that has the banner:
100
101\starttyping
102mptopgc 1.01 pdfTeX HH 1998
103\stoptyping
104
105It produces help like:
106
107\starttyping
108 silent use logfile instead of screen (no)
109 autorun run MetaPost first (no)
110 optimize convert gray into eofill (no)
111 ignore ignore gray path (no)
112 gray permit the gray operator (no)
113 merge substitute gray using glyphs (no)
114magnification set MetaPost mag factor (1)
115 rounding alternative rounding offset (0)
116 pgcpath pgc path
117 tfmpath tfm file path
118 tfmtopl ftmtopl binary name (tfmtopl)
119 metapost metapost binary name (mpost)
120\stoptyping
121
122But it is a long time since I installed \PERL\ on my laptop so I didnt check it.
123I also found a manual that could be updated but I dont see much use for it now.
124There is even a \MKII\ \TEX\ file that one can run with \type {pdftex plain
125\input supppgc.mkii \MPtoPGC} that produces container files but I didnt test
126that either.
127
128However, what I did test was if it still works. For that I used the following
129test file:
130
131\starttyping
132
133
134\startTEXpage[offset=10pt]
135
136\pdfmapline{texnansilmr10 < texnansi.enc}
137
138\font\test=texnansilmr10 \test
139
140\input tufte
141
142\stopTEXpage
143\stoptyping
144
145Here I use a normal \TFM\ file because after all we need the metrics. Then I made
146an empty \typ {texnansilmr10.600pk} so that we can fool the \PK\ generator. Using
147Latin Modern files is more convenient. The glyph container file was made by
148abusing some features of \LMTX:
149
150
151
152\startitemize
153
154\startitem
155 With the module \type {sfontsoutlines} I made a font sample that as
156 byproduct generates a file with outline definitions. Basically any attempt to
157 use an outline in \METAFUN\ will populate the cache. We load the font \type
158 {lmr10.afm} and it will get the outlines from \type {lmr10.pfb}. Of course
159 there are more that 256 characters in there but that doesnt matter.
160\stopitem
161
162\startitem
163 I also generated a \type {texnansi} vector file which can be done from a
164 normal \TEX\ run using the \LUA\ call \typ {fonts.encodings.load
165 ("texnansi.enc"))}. It locates and converts a regular \type{enc} into a \LUA\
166 representation. I picked up the file from the cache.
167\stopitem
168
169\startitem
170 From these files I generated a glyph container file \typ {texnansilmr10.pgc}
171 that can be used instead of the \PK\ file. The file \typ {mtxpgc.lua} is
172 shown below.
173\stopitem
174
175\startitem
176 I made sure to set \type {MISCFONTS} to a sensible value because otherwise
177 the container file is not found (who knows what location strategy is used).
178\stopitem
179
180\stopitemize
181
182This is the \quote {quick and dirty} conversion file:
183
184\starttyping
185local round = math.round
186local concat = table.concat
187
188local result = { "\\pdffontscale 0.001\n" }
189local r = 1
190
191local fpdfglyph = string.formatters["\\pdfglyph
192local sendglyph = "\\endglyph\n"
193local fcomment = string.formatters["
194
195local shapes = table.load("lmr10pfb.tma")
196local encoding = table.load("texnansi.tma")
197
198local glyphs = shapes.glyphs
199local hash = encoding.hash
200
201for index=0,#glyphs do
202 local glyph = glyphs[index]
203 local segments = glyph.segments or { }
204 local bounds = glyph.boundingbox or { 0, 0, 0, 0 }
205 local width = round(glyph.width or 0)
206 local name = glyph.name
207 local slotused = hash[name]
208 if slotused then
209 local llx, lly = bounds[1], bounds[2]
210 local urx, ury = bounds[3], bounds[4]
211 r = r 1 ; result[r] = fcomment(name,index,slotused)
212 r = r 1 ; result[r] = fpdfglyph(slotused,width,0,0,llx,lly,urx,ury)
213 if #segments > 0 then
214 r = r 1 ; result[r] = "10 M 1 j 1 J 0 w"
215 for i=1,#segments do
216 local s = segments[i]
217 if s[1] = "close" then
218 r = r 1 ; result[r] = concat(s," ")
219 end
220 end
221 r = r 1 ; result[r] = "h f*"
222 end
223 r = r 1 ; result[r] = sendglyph
224 end
225end
226
227io.savedata("texnansilmr10.pgc",concat(result,"\n"))
228\stoptyping
229
230Of course for a proper workflow we need to make this into a real helper script
231but here I just want to show the idea. The result is shown in \in {figure}
232[fig:pgcresult]. There is however one drawback: because \PDFTEX\ goes via the
233\PK\ route using the same font with a different scale will result in an extra
234copy while actually we have a scalable \TYPETHREE\ font. It is for that reason
235that I will not waste any more time on this. I could provide a patch to deal with
236it but changing a long time ago frozen \TEX\ program is tricky because bug(let)s
237have become features.
238
239\startplacefigure[title={This is what we get with glyph containers.},reference=fig:pgcresult]
240 \externalfigure
241 [ontargetnostalgicpgc.pdf]
242 [width=\textwidth,
243 background=color,
244 backgroundcolor=gray]
245\stopplacefigure
246
247So where does this bring us? Because \MKII\ is frozen and \PDFTEX\ only works
248with that version it makes no sense to add some kind of \TYPETHREE\ support. In
249\MKIV\ and \MKXL\ we have several mechanisms for creating these fonts anyway. I
250cannot comment on use outside \CONTEXT\ but because of the strong connection with
251\PK\ fonts being required in order for glyph containers to kick in at all, I
252suspect that its a mostly unknown feature, but one that actually can be made to
253work. It could even work better (with respect to file lookup and font scaling)
254when it is decoupled from the \PK\ requirements and listen to na map file line
255that also signals if the font can be reused. But what worries me a bit more is
256that after 25 years I hardly recognize the (reasonable) \PERL\ code and little
257manual although it slowly came back. At that I time I could not have predicted
258where we are now with respect to \TYPETHREE\ support, which in \LMTX\ is very
259much kicking and alive. \footnote {At that time \TYPETHREE\ in the perspective of
260\TEX\ always had a bad ring, probably because the many files that were around
261with too low resolution bitmap fonts. The \PDF\ readers were not particularly
262good in rendering them either. But with outlines this format can be fun!}
263
264\stopchapter
265
266\stopcomponent
267
268
269 |