interplane.Get Omega
Read in your language

omega-pdf

Omega PDF: read and write PDF files in Omega

Brought by drakestapleton

branch main Branches Tags History

omega-pdf / src / text.om

1848 lines · 34861 bytes Raw Blame History
1note Text extraction from ISO 32000-1:2008 clauses 7.3.4, 8.3, 9.3-9.4, 9.6-9.7, 9.10.3 and Annex D.
2note Public standard: https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf
3note SHA256 9de0ca9e8570d6209e8bd48a355be8eb6ec376acfc3fc3ae97cd8730351417ff.
4note Independent implementation; no vendor program source. Annex D DATA is transcribed below.
5note Bounds: page content/output 16 MiB each; token 65536 bytes; literal depth 256;
6note operands 4096, operand bytes 1 MiB, nested containers 64, q stack 32.
7note One active font: reload on change, at most 4096 loads and 256 MiB CMap bytes per page.
8note ToUnicode: 65536 entries, 131072 hash slots, 4 MiB UTF16 destination pool, 512 bytes/destination.
9note Codespaces 64; hash probe work 8388608 per font (insertion and extraction combined).
10note CID fonts require Identity-H and ToUnicode; every other CID Encoding is refused.
11note Numeric inputs at most 32 bytes, absolute value <= 1e9; derived geometry <= 1e12.
12note No layout sorting, dehyphenation, ligature normalization or guessed Unicode: reading order is the
13note order written in the file, not layout analysis.
14text terrtxt "malformed text, font or CMap"
15text terrsup "unsupported font, encoding, CMap or text-bearing graphics"
16text terrlim "text engine bound exceeded"
17text terrio "text output write failed"
18text tkcont "Contents"
19text tkfont "Font"
20text tksub "Subtype"
21text tktoun "ToUnicode"
22text tkenc "Encoding"
23text tkbase "BaseEncoding"
24text tkdiff "Differences"
25text tkfirst "FirstChar"
26text tklast "LastChar"
27text tkwidth "Widths"
28text tkdesc "FontDescriptor"
29text tkmiss "MissingWidth"
30text tkflags "Flags"
31text tkbf "BaseFont"
32text tkdf "DescendantFonts"
33text tkdw "DW"
34text tkw "W"
35text tkwmode "WMode"
36text tkuse "UseCMap"
37text tkmatrix "FontMatrix"
38text tkxobj "XObject"
39text tnstd "StandardEncoding"
40text tnwin "WinAnsiEncoding"
41text tnmac "MacRomanEncoding"
42text tntype0 "Type0"
43text tntype1 "Type1"
44text tntype3 "Type3"
45text tntrue "TrueType"
46text tnmm "MMType1"
47text tnidh "Identity-H"
48text tnidv "Identity-V"
49text tnimage "Image"
50global tcs uchar 16777216
51global tobuf uchar 16777216
52global tstr uchar 65536
53global topool uchar 1048576
54global tokind ulong 4096
55global tostart ulong 4096
56global tolen ulong 4096
57global tovalue f64 4096
58global tlx ulong 8
59note tlx: source 0 tcs/1 pdbuf; position; limit; token kind; token bytes; operands; pool bytes; output bytes.
60global tvalue f64 1
61global tmat f64 18
62note tmat: CTM, text matrix, line matrix; each a b c d e f.
63global tstate f64 6
64note tstate: Tc Tw horizontal-scale TL Ts font-size.
65global tqmat f64 384
66global tqfont ulong 32
67global tqdepth ulong 1
68global tfont ulong 1
69global tloaded ulong 1
70global tpage ulong 1
71global tinbt ulong 1
72global tlast f64 2
73note tlast: expected baseline origin x/y; survives BT/ET and q/Q.
74global thave ulong 1
75global tloads ulong 1
76global tcbytes ulong 1
77global tmetrics f64 65536
78global tbasecp ulong 256
79global tfinfo ulong 7
80note tfinfo: composite; has ToUnicode; codespaces; entries; destination bytes; reserved; probe work.
81global tmk ulong 131072
82global tmoff ulong 131072
83global tmlen ulong 131072
84global tmb uchar 4194304
85global tslo ulong 64
86global tshi ulong 64
87global tsbytes ulong 64
88global tcmaptmp uchar 512
89note tcv, tcp: the cm operands and the product being formed.
90global tcv f64 6
91global tcp f64 6
92global tfontmx f64 2
93global tgeo f64 3
94
95fn tbad to void
96pquit 66 terrtxt
97end
98fn tunsup to void
99pquit 65 terrsup
100end
101fn tlimit to void
102pquit 63 terrlim
103end
104fn tfinite v f64 to f64
105if or ne v v gt fabs v 1.0e12f64
106tlimit
107end
108ret v
109end
110fn tnumber n ulong to f64
111v = pderef n
112k = get ptype v
113if and ne k 3 ne k 4
114tbad
115end
116ret tfinite pnumber v
117end
118fn tint n ulong maxv ulong to ulong
119v = pderef n
120if ne get ptype v 3
121tbad
122end
123z = get pnum v
124if lt z 0
125tbad
126end
127if gt ulong z maxv
128tlimit
129end
130ret ulong z
131end
132fn tkind n ulong k ulong to ulong
133v = pderef n
134if ne get ptype v k
135tbad
136end
137ret v
138end
139fn twhite c ulong to bool
140ret or or eq c 0 eq c 9 or or eq c 10 eq c 12 or eq c 13 eq c 32
141end
142fn tdelim c ulong to bool
143if twhite c
144ret true
145end
146if or or eq c 40 eq c 41 or eq c 60 eq c 62
147ret true
148end
149ret or or eq c 91 eq c 93 or or eq c 123 eq c 125 or eq c 47 eq c 37
150end
151fn tpeek to ulong
152p = get tlx 1
153if ge p get tlx 2
154tbad
155end
156if eq get tlx 0 0
157ret ulong get tcs p
158end
159ret ulong get pdbuf p
160end
161fn ttake to ulong
162c = tpeek
163put tlx 1 add get tlx 1 1
164ret c
165end
166fn tsput c ulong to void
167n = get tlx 4
168if ge n 65536
169tlimit
170end
171put tstr n uchar c
172put tlx 4 add n 1
173end
174fn tskip to void
175while lt get tlx 1 get tlx 2 bound 16777217
176c = tpeek
177if twhite c
178put tlx 1 add get tlx 1 1
179continue
180end
181if ne c 37
182ret
183end
184while lt get tlx 1 get tlx 2 bound 16777217
185c = ttake
186if or eq c 10 eq c 13
187break
188end
189end
190end
191end
192fn tescaped to void
193c = ttake
194if eq c 10
195ret
196end
197if eq c 13
198if lt get tlx 1 get tlx 2
199if eq tpeek 10
200c = ttake
201end
202end
203ret
204end
205if and ge c 48 le c 55
206v = sub c 48
207j = ulong 0
208while lt j 2 bound 3
209if ge get tlx 1 get tlx 2
210break
211end
212c = tpeek
213if or lt c 48 gt c 55
214break
215end
216c = ttake
217v = add mul v 8 sub c 48
218j = add j 1
219end
220tsput and v 255
221ret
222end
223if eq c 110
224c = 10
225else
226if eq c 114
227c = 13
228else
229if eq c 116
230c = 9
231else
232if eq c 98
233c = 8
234else
235if eq c 102
236c = 12
237end
238end
239end
240end
241end
242tsput c
243end
244fn tliteral to void
245depth = ulong 1
246while ne depth 0 bound 16777217
247c = ttake
248if eq c 92
249tescaped
250continue
251end
252if eq c 40
253if ge depth 256
254tlimit
255end
256depth = add depth 1
257end
258if eq c 41
259depth = sub depth 1
260if eq depth 0
261break
262end
263end
264if eq c 13
265c = 10
266if lt get tlx 1 get tlx 2
267if eq tpeek 10
268q = ttake
269end
270end
271end
272tsput c
273end
274end
275fn thex to void
276hi = ulong 16
277while true bound 16777217
278c = ttake
279if eq c 62
280if ne hi 16
281tsput mul hi 16
282end
283ret
284end
285if twhite c
286continue
287end
288v = tx_hexv uchar c
289if eq v 16
290tbad
291end
292if eq hi 16
293hi = v
294else
295tsput add mul hi 16 v
296hi = 16
297end
298end
299end
300fn tparsenum to bool
301n = get tlx 4
302if eq n 0
303ret false
304end
305c = ulong get tstr 0
306if not or and ge c 48 le c 57 or eq c 43 or eq c 45 eq c 46
307ret false
308end
309if gt n 32
310tlimit
311end
312i = ulong 0
313sgn = 1.0f64
314if or eq c 43 eq c 45
315i = 1
316if eq c 45
317sgn = -1.0f64
318end
319end
320v = 0.0f64
321scale = 1.0f64
322dot = false
323digits = ulong 0
324while lt i n bound 33
325c = ulong get tstr i
326i = add i 1
327if eq c 46
328if dot
329tbad
330end
331dot = true
332continue
333end
334if or lt c 48 gt c 57
335tbad
336end
337digits = add digits 1
338if dot
339scale = mul scale 0.1f64
340v = add v mul f64 sub c 48 scale
341else
342v = add mul v 10.0f64 f64 sub c 48
343end
344if gt v 1.0e9f64
345tlimit
346end
347end
348if eq digits 0
349tbad
350end
351put tvalue 0 mul v sgn
352ret true
353end
354note Token kinds: 0 EOF, 1 number, 2 name, 3 string, 4 word, 5 [, 6 ], 7 <<, 8 >>, 9 {, 10 }.
355fn tlex to void
356tskip
357put tlx 3 0
358put tlx 4 0
359if eq get tlx 1 get tlx 2
360ret
361end
362c = ttake
363if eq c 40
364put tlx 3 3
365tliteral
366ret
367end
368if eq c 60
369if lt get tlx 1 get tlx 2
370if eq tpeek 60
371c = ttake
372put tlx 3 7
373ret
374end
375end
376put tlx 3 3
377thex
378ret
379end
380if eq c 62
381if ne ttake 62
382tbad
383end
384put tlx 3 8
385ret
386end
387if or eq c 91 eq c 93
388put tlx 3 5
389if eq c 93
390put tlx 3 6
391end
392ret
393end
394if or eq c 123 eq c 125
395put tlx 3 9
396if eq c 125
397put tlx 3 10
398end
399ret
400end
401if eq c 41
402tbad
403end
404if eq c 47
405put tlx 3 2
406else
407put tlx 3 4
408tsput c
409end
410while lt get tlx 1 get tlx 2 bound 16777217
411c = tpeek
412if tdelim c
413break
414end
415c = ttake
416if and eq get tlx 3 2 eq c 35
417h = tx_hexv uchar ttake
418l = tx_hexv uchar ttake
419if or eq h 16 eq l 16
420tbad
421end
422c = add mul h 16 l
423if eq c 0
424tbad
425end
426end
427tsput c
428end
429if eq get tlx 3 2
430if gt get tlx 4 256
431tlimit
432end
433end
434if eq get tlx 3 4
435if tparsenum
436put tlx 3 1
437end
438end
439end
440fn teq s view uchar * to bool
441n = get tlx 4
442if ne n len s
443ret false
444end
445i = ulong 0
446while lt i n bound 65537
447if ne get tstr i get s i
448ret false
449end
450i = add i 1
451end
452ret true
453end
454fn texpect k ulong to void
455tlex
456if ne get tlx 3 k
457tbad
458end
459end
460fn tendword s view uchar * to void
461texpect 4
462if not teq s
463tbad
464end
465end
466fn topush to void
467j = get tlx 5
468if ge j 4096
469tlimit
470end
471n = get tlx 4
472p = get tlx 6
473if gt n sub 1048576 p
474tlimit
475end
476put tokind j get tlx 3
477put tostart j p
478put tolen j n
479put tovalue j get tvalue 0
480i = ulong 0
481while lt i n bound 65537
482put topool add p i get tstr i
483i = add i 1
484end
485put tlx 6 add p n
486put tlx 5 add j 1
487end
488fn targs n ulong to void
489if ne get tlx 5 n
490tbad
491end
492end
493fn targnum j ulong to f64
494if ge j get tlx 5
495tbad
496end
497if ne get tokind j 1
498tbad
499end
500ret get tovalue j
501end
502fn targname j ulong d ulong to ulong
503if ge j get tlx 5
504tbad
505end
506if ne get tokind j 2
507tbad
508end
509n = get tolen j
510p = get tostart j
511obj = pderef d
512if and ne get ptype obj 8 ne get ptype obj 10
513tbad
514end
515k = get pfirst obj
516while ne k 0 bound 262145
517v = get pnext k
518if eq v 0
519tbad
520end
521if tkeyeq k p n
522ret pderef v
523end
524k = get pnext v
525end
526ret 0
527end
528note tkeyeq: name node k equals operand bytes topool[p .. p+n).
529fn tkeyeq k ulong p ulong n ulong to bool
530if ne get plen k n
531ret false
532end
533s = get pstart k
534for i ulong n bound 65537
535if ne get pbytes add s i get topool add p i
536ret false
537end
538end
539ret true
540end
541fn temit c ulong to void
542n = get tlx 7
543if ge n 16777216
544tlimit
545end
546put tobuf n uchar c
547put tlx 7 add n 1
548end
549fn tu8 cp ulong to void
550if or gt cp 1114111 and ge cp 55296 le cp 57343
551tbad
552end
553if lt cp 128
554temit cp
555ret
556end
557if lt cp 2048
558temit add 192 shr cp 6
559temit add 128 and cp 63
560ret
561end
562if lt cp 65536
563temit add 224 shr cp 12
564temit add 128 and shr cp 6 63
565temit add 128 and cp 63
566ret
567end
568temit add 240 shr cp 18
569temit add 128 and shr cp 12 63
570temit add 128 and shr cp 6 63
571temit add 128 and cp 63
572end
573fn tbreak c ulong to void
574n = get tlx 7
575if eq n 0
576ret
577end
578v = ulong get tobuf sub n 1
579if eq v 10
580ret
581end
582if eq c 32
583if or eq v 32 eq v 9
584ret
585end
586end
587temit c
588end
589fn tflush to void
590p = ulong 0
591n = get tlx 7
592while lt p n bound 16777217
593r = write 1 tobuf p sub n p
594if le r 0
595pquit 64 terrio
596end
597p = add p ulong r
598end
599put tlx 7 0
600end
601
602note Annex D.2 glyph names and encoding octal codes, converted to decimal; Unicode from D.3.
603note 229 rows; STD 149, MAC 207, WIN 216 assignments. 256 denotes unencoded.
604text tlatin "A,65,65,65,65|AE,198,225,174,198|Aacute,193,256,231,193|Acircumflex,194,256,229,194|Adieresis,196,256,128,196|Agrave,192,256,203,192|Aring,197,256,129,197|Atilde,195,256,204,195|B,66,66,66,66|C,67,67,67,67|Ccedilla,199,256,130,199|D,68,68,68,68|E,69,69,69,69|Eacute,201,256,131,201|Ecircumflex,202,256,230,202|Edieresis,203,256,232,203|Egrave,200,256,233,200|Eth,208,256,256,208|Euro,8364,256,256,128|F,70,70,70,70|G,71,71,71,71|H,72,72,72,72|I,73,73,73,73|Iacute,205,256,234,205|Icircumflex,206,256,235,206|Idieresis,207,256,236,207|Igrave,204,256,237,204|J,74,74,74,74|K,75,75,75,75|L,76,76,76,76|Lslash,321,232,256,256|M,77,77,77,77|N,78,78,78,78|Ntilde,209,256,132,209|O,79,79,79,79|OE,338,234,206,140|Oacute,211,256,238,211|Ocircumflex,212,256,239,212|Odieresis,214,256,133,214|Ograve,210,256,241,210|Oslash,216,233,175,216|Otilde,213,256,205,213|P,80,80,80,80|Q,81,81,81,81|R,82,82,82,82|S,83,83,83,83|Scaron,352,256,256,138|T,84,84,84,84|Thorn,222,256,256,222|U,85,85,85,85|Uacute,218,256,242,218|Ucircumflex,219,256,243,219|Udieresis,220,256,134,220|Ugrave,217,256,244,217|V,86,86,86,86|W,87,87,87,87|X,88,88,88,88|Y,89,89,89,89|Yacute,221,256,256,221|Ydieresis,376,256,217,159|Z,90,90,90,90|Zcaron,381,256,256,142|a,97,97,97,97|aacute,225,256,135,225|acircumflex,226,256,137,226|acute,180,194,171,180|adieresis,228,256,138,228|ae,230,241,190,230|agrave,224,256,136,224|ampersand,38,38,38,38|aring,229,256,140,229|asciicircum,94,94,94,94|asciitilde,126,126,126,126|asterisk,42,42,42,42|at,64,64,64,64|atilde,227,256,139,227|b,98,98,98,98|backslash,92,92,92,92|bar,124,124,124,124|braceleft,123,123,123,123|braceright,125,125,125,125|bracketleft,91,91,91,91|bracketright,93,93,93,93|breve,728,198,249,256|brokenbar,166,256,256,166|bullet,8226,183,165,149|c,99,99,99,99|caron,711,207,255,256|ccedilla,231,256,141,231|cedilla,184,203,252,184|cent,162,162,162,162|circumflex,710,195,246,136|colon,58,58,58,58|comma,44,44,44,44|copyright,169,256,169,169|currency,164,168,219,164|d,100,100,100,100|dagger,8224,178,160,134|daggerdbl,8225,179,224,135|degree,176,256,161,176|dieresis,168,200,172,168|divide,247,256,214,247|dollar,36,36,36,36|dotaccent,729,199,250,256|dotlessi,305,245,245,256|e,101,101,101,101|eacute,233,256,142,233|ecircumflex,234,256,144,234|edieresis,235,256,145,235|egrave,232,256,143,232|eight,56,56,56,56|ellipsis,8230,188,201,133|emdash,8212,208,209,151|endash,8211,177,208,150|equal,61,61,61,61|eth,240,256,256,240|exclam,33,33,33,33|exclamdown,161,161,193,161|f,102,102,102,102|fi,64257,174,222,256|five,53,53,53,53|fl,64258,175,223,256|florin,402,166,196,131|four,52,52,52,52|fraction,8260,164,218,256|g,103,103,103,103|germandbls,223,251,167,223|grave,96,193,96,96|greater,62,62,62,62|guillemotleft,171,171,199,171|guillemotright,187,187,200,187|guilsinglleft,8249,172,220,139|guilsinglright,8250,173,221,155|h,104,104,104,104|hungarumlaut,733,205,253,256|hyphen,45,45,45,45|i,105,105,105,105|iacute,237,256,146,237|icircumflex,238,256,148,238|idieresis,239,256,149,239|igrave,236,256,147,236|j,106,106,106,106|k,107,107,107,107|l,108,108,108,108|less,60,60,60,60|logicalnot,172,256,194,172|lslash,322,248,256,256|m,109,109,109,109|macron,175,197,248,175|minus,8722,256,256,256|mu,181,256,181,181|multiply,215,256,256,215|n,110,110,110,110|nine,57,57,57,57|ntilde,241,256,150,241|numbersign,35,35,35,35|o,111,111,111,111|oacute,243,256,151,243|ocircumflex,244,256,153,244|odieresis,246,256,154,246|oe,339,250,207,156|ogonek,731,206,254,256|ograve,242,256,152,242|one,49,49,49,49|onehalf,189,256,256,189|onequarter,188,256,256,188|onesuperior,185,256,256,185|ordfeminine,170,227,187,170|ordmasculine,186,235,188,186|oslash,248,249,191,248|otilde,245,256,155,245|p,112,112,112,112|paragraph,182,182,166,182|parenleft,40,40,40,40|parenright,41,41,41,41|percent,37,37,37,37|period,46,46,46,46|periodcentered,183,180,225,183|perthousand,8240,189,228,137|plus,43,43,43,43|plusminus,177,256,177,177|q,113,113,113,113|question,63,63,63,63|questiondown,191,191,192,191|quotedbl,34,34,34,34|quotedblbase,8222,185,227,132|quotedblleft,8220,170,210,147|quotedblright,8221,186,211,148|quoteleft,8216,96,212,145|quoteright,8217,39,213,146|quotesinglbase,8218,184,226,130|quotesingle,39,169,39,39|r,114,114,114,114|registered,174,256,168,174|ring,730,202,251,256|s,115,115,115,115|scaron,353,256,256,154|section,167,167,164,167|semicolon,59,59,59,59|seven,55,55,55,55|six,54,54,54,54|slash,47,47,47,47|space,32,32,32,32|sterling,163,163,163,163|t,116,116,116,116|thorn,254,256,256,254|three,51,51,51,51|threequarters,190,256,256,190|threesuperior,179,256,256,179|tilde,732,196,247,152|trademark,8482,256,170,153|two,50,50,50,50|twosuperior,178,256,256,178|u,117,117,117,117|uacute,250,256,156,250|ucircumflex,251,256,158,251|udieresis,252,256,159,252|ugrave,249,256,157,249|underscore,95,95,95,95|v,118,118,118,118|w,119,119,119,119|x,120,120,120,120|y,121,121,121,121|yacute,253,256,256,253|ydieresis,255,256,216,255|yen,165,165,180,165|z,122,122,122,122|zcaron,382,256,256,158|zero,48,48,48,48|"
605
606global tdrow ulong 5
607fn trow p ulong to ulong
608i = p
609while ne get tlatin i 44 bound 32
610i = add i 1
611end
612put tdrow 0 sub i p
613i = add i 1
614j = ulong 1
615while le j 4 bound 5
616v = ulong 0
617while true bound 8
618c = ulong get tlatin i
619i = add i 1
620if or eq c 44 eq c 124
621break
622end
623v = add mul v 10 sub c 48
624end
625put tdrow j v
626j = add j 1
627end
628ret i
629end
630fn tbase enc ulong to void
631i = ulong 0
632while lt i 256 bound 257
633put tbasecp i 0
634i = add i 1
635end
636if eq enc 0
637ret
638end
639p = ulong 0
640while lt p len tlatin bound 230
641p = trow p
642c = get tdrow add enc 1
643if lt c 256
644put tbasecp c get tdrow 1
645end
646end
647note Annex D.2 notes 3,5,6: bullet holes; soft hyphen; nonbreaking space glyph duplicates.
648if eq enc 3
649i = 33
650while lt i 256 bound 257
651if eq get tbasecp i 0
652put tbasecp i 8226
653end
654i = add i 1
655end
656put tbasecp 173 45
657put tbasecp 160 32
658end
659if eq enc 2
660put tbasecp 202 32
661end
662end
663note Differences names outside ISO 32000-1 Annex D.2 map to U+FFFD, emitted only when shown.
664note Difference class: the oracle may resolve more names through the Adobe Glyph List; we use Annex D only.
665note No Annex D row has Unicode U+FFFD, so the replacement is unambiguous and costs nothing if unused.
666fn tglyph n ulong to ulong
667v = tkind n 5
668p = ulong 0
669while lt p len tlatin bound 230
670q = trow p
671if tlateq v p get tdrow 0
672ret get tdrow 1
673end
674p = q
675end
676ret 65533
677end
678note tlateq: name node v equals tlatin[p .. p+n).
679fn tlateq v ulong p ulong n ulong to bool
680if ne get plen v n
681ret false
682end
683s = get pstart v
684for i ulong n bound 33
685if ne get pbytes add s i get tlatin add p i
686ret false
687end
688end
689ret true
690end
691fn tencoding fontn ulong to void
692enc = pderef pget fontn tkenc
693base = enc
694if eq get ptype enc 8
695base = pderef pget enc tkbase
696end
697which = ulong 1
698if ne base 0
699if pne base tnwin
700which = 3
701else
702if pne base tnmac
703which = 2
704else
705if not pne base tnstd
706tunsup
707end
708end
709end
710else
711if pne pget fontn tksub tntype3
712which = 0
713else
714which = timplicit fontn
715end
716end
717tbase which
718if eq get ptype enc 8
719diff = pderef pget enc tkdiff
720if ne diff 0
721diff = tkind diff 7
722v = get pfirst diff
723code = ulong 256
724while ne v 0 bound 262145
725n = pderef v
726if eq get ptype n 3
727code = tint n 255
728else
729if ge code 256
730tbad
731end
732put tbasecp code tglyph n
733code = add code 1
734end
735v = get pnext v
736end
737end
738end
739end
740fn tmapkey code ulong nb ulong to ulong
741ret add add code shl nb 32 1
742end
743fn tmapfind key ulong to ulong
744slot = rem key 131072
745while true bound 131073
746work = get tfinfo 6
747if ge work 8388608
748tlimit
749end
750put tfinfo 6 add work 1
751v = get tmk slot
752if or eq v 0 eq v key
753ret slot
754end
755slot = rem add slot 1 131072
756end
757ret 0
758end
759fn tmapinsert code ulong nb ulong dn ulong to void
760if or eq dn 0 gt dn 512
761tbad
762end
763if ne rem dn 2 0
764tbad
765end
766tvaliddest dn
767slot = tmapfind tmapkey code nb
768if eq get tmk slot 0
769if ge get tfinfo 3 65536
770tlimit
771end
772put tfinfo 3 add get tfinfo 3 1
773end
774p = get tfinfo 4
775if gt dn sub 4194304 p
776tlimit
777end
778i = ulong 0
779while lt i dn bound 513
780put tmb add p i get tcmaptmp i
781i = add i 1
782end
783put tmk slot tmapkey code nb
784put tmoff slot p
785put tmlen slot dn
786put tfinfo 4 add p dn
787end
788fn tcode to ulong
789n = get tlx 4
790if or eq n 0 gt n 4
791tunsup
792end
793v = ulong 0
794i = ulong 0
795while lt i n bound 5
796v = add mul v 256 ulong get tstr i
797i = add i 1
798end
799ret v
800end
801fn tdest to ulong
802texpect 3
803n = get tlx 4
804if gt n 512
805tlimit
806end
807if or eq n 0 ne rem n 2 0
808tbad
809end
810i = ulong 0
811while lt i n bound 513
812put tcmaptmp i get tstr i
813i = add i 1
814end
815ret n
816end
817text tbegcs "begincodespacerange"
818text tendcs "endcodespacerange"
819text tbegbf "beginbfchar"
820text tendbf "endbfchar"
821text tbegr "beginbfrange"
822text tendr "endbfrange"
823text tusecm "usecmap"
824text twmoden "WMode"
825fn tcspace count ulong to void
826i = ulong 0
827while lt i count bound 65537
828j = get tfinfo 2
829if ge j 64
830tlimit
831end
832texpect 3
833lo = tcode
834nb = get tlx 4
835texpect 3
836hi = tcode
837if or ne nb get tlx 4 gt lo hi
838tbad
839end
840tspacecheck lo hi nb
841put tslo j lo
842put tshi j hi
843put tsbytes j nb
844put tfinfo 2 add j 1
845i = add i 1
846end
847tendword tendcs
848end
849fn tcbf count ulong to void
850i = ulong 0
851while lt i count bound 65537
852texpect 3
853code = tcode
854nb = get tlx 4
855dn = tdest
856tmapinsert code nb dn
857i = add i 1
858end
859tendword tendbf
860end
861fn trarray lo ulong hi ulong nb ulong to void
862code = lo
863while le code hi bound 65537
864dn = tdest
865tmapinsert code nb dn
866code = add code 1
867end
868texpect 6
869end
870fn trstring lo ulong hi ulong nb ulong to void
871if ne get tlx 3 3
872tbad
873end
874dn = get tlx 4
875if gt dn 512
876tlimit
877end
878if or eq dn 0 ne rem dn 2 0
879tbad
880end
881j = ulong 0
882while lt j dn bound 513
883put tcmaptmp j get tstr j
884j = add j 1
885end
886lastb = ulong get tcmaptmp sub dn 1
887if gt sub hi lo sub 255 lastb
888tbad
889end
890code = lo
891while le code hi bound 65537
892put tcmaptmp sub dn 1 uchar add lastb sub code lo
893tmapinsert code nb dn
894code = add code 1
895end
896end
897fn tcrange count ulong to void
898i = ulong 0
899while lt i count bound 65537
900texpect 3
901lo = tcode
902nb = get tlx 4
903texpect 3
904hi = tcode
905if or ne nb get tlx 4 gt lo hi
906tbad
907end
908if ge sub hi lo 65536
909tlimit
910end
911tlex
912if eq get tlx 3 5
913trarray lo hi nb
914else
915trstring lo hi nb
916end
917i = add i 1
918end
919tendword tendr
920end
921fn tcmap node ulong to void
922if ne pderef pget node tkuse 0
923tunsup
924end
925wm = pderef pget node tkwmode
926if ne wm 0
927if ne tint wm 1 0
928tunsup
929end
930end
931pdecode node
932n = get pdlen 0
933b = get tcbytes 0
934if gt n sub 268435456 b
935tlimit
936end
937put tcbytes 0 add b n
938put tlx 0 1
939put tlx 1 0
940put tlx 2 n
941count = ulong 0
942while true bound 16777217
943tlex
944k = get tlx 3
945if eq k 0
946break
947end
948if eq k 1
949v = get tvalue 0
950if or lt v 0.0f64 gt v 65536.0f64
951tlimit
952end
953count = ulong v
954if ne f64 count v
955tbad
956end
957continue
958end
959if eq k 2
960if teq twmoden
961texpect 1
962if ne get tvalue 0 0.0f64
963tunsup
964end
965end
966continue
967end
968if eq k 4
969if teq tusecm
970tunsup
971end
972if teq tbegcs
973tcspace count
974end
975if teq tbegbf
976tcbf count
977end
978if teq tbegr
979tcrange count
980end
981end
982end
983if or eq get tfinfo 2 0 eq get tfinfo 3 0
984tbad
985end
986end
987fn tsimplewidth fontn ulong to void
988missing = 500.0f64
989desc = pderef pget fontn tkdesc
990n = pderef pget desc tkmiss
991if ne n 0
992missing = tnumber n
993end
994i = ulong 0
995while lt i 65536 bound 65537
996put tmetrics i missing
997i = add i 1
998end
999w = pderef pget fontn tkwidth
1000if eq w 0
1001ret
1002end
1003w = tkind w 7
1004first = tint pget fontn tkfirst 255
1005last = tint pget fontn tklast 255
1006if gt first last
1007tbad
1008end
1009v = get pfirst w
1010code = first
1011while ne v 0 bound 257
1012if gt code last
1013tbad
1014end
1015put tmetrics code tnumber v
1016code = add code 1
1017v = get pnext v
1018end
1019if ne code add last 1
1020tbad
1021end
1022end
1023fn tcidwidth fontn ulong to void
1024arr = tkind pget fontn tkdf 7
1025v = get pfirst arr
1026if eq v 0
1027tbad
1028end
1029if ne get pnext v 0
1030tbad
1031end
1032desc = tkind v 8
1033dw = 1000.0f64
1034v = pderef pget desc tkdw
1035if ne v 0
1036dw = tnumber v
1037end
1038i = ulong 0
1039while lt i 65536 bound 65537
1040put tmetrics i dw
1041i = add i 1
1042end
1043arr = pderef pget desc tkw
1044if eq arr 0
1045ret
1046end
1047arr = tkind arr 7
1048v = get pfirst arr
1049while ne v 0 bound 262145
1050lo = tint v 65535
1051v = get pnext v
1052if eq v 0
1053tbad
1054end
1055n = pderef v
1056if eq get ptype n 7
1057x = get pfirst n
1058while ne x 0 bound 65537
1059if ge lo 65536
1060tlimit
1061end
1062put tmetrics lo tnumber x
1063lo = add lo 1
1064x = get pnext x
1065end
1066v = get pnext v
1067else
1068hi = tint n 65535
1069if lt hi lo
1070tbad
1071end
1072v = get pnext v
1073if eq v 0
1074tbad
1075end
1076width = tnumber v
1077while le lo hi bound 65537
1078put tmetrics lo width
1079lo = add lo 1
1080end
1081v = get pnext v
1082end
1083end
1084end
1085fn tfontload fontn ulong to void
1086nloads = get tloads 0
1087if ge nloads 4096
1088tlimit
1089end
1090put tloads 0 add nloads 1
1091put tloaded 0 fontn
1092put tfontmx 0 0.001f64
1093put tfontmx 1 0.0f64
1094i = ulong 0
1095while lt i 7 bound 8
1096put tfinfo i 0
1097i = add i 1
1098end
1099i = 0
1100while lt i 131072 bound 131073
1101put tmk i 0
1102i = add i 1
1103end
1104if pne pget fontn tksub tntype0
1105put tfinfo 0 1
1106enc = pderef pget fontn tkenc
1107if not pne enc tnidh
1108tunsup
1109end
1110tcidwidth fontn
1111else
1112subtyp = pget fontn tksub
1113ok = or pne subtyp tntype1 pne subtyp tntrue
1114ok = or ok pne subtyp tnmm
1115ok = or ok pne subtyp tntype3
1116if not ok
1117tunsup
1118end
1119tsimplewidth fontn
1120if pne subtyp tntype3
1121ttype3matrix fontn
1122end
1123end
1124note With a ToUnicode CMap no base encoding is built: codes it does not map print U+FFFD (tnomap).
1125for bi ulong 256
1126put tbasecp bi 0
1127end
1128cmap = pderef pget fontn tktoun
1129if ne cmap 0
1130put tfinfo 1 1
1131tcmap cmap
1132else
1133if ne get tfinfo 0 0
1134tunsup
1135end
1136tencoding fontn
1137end
1138end
1139fn tensurefont to void
1140f = get tfont 0
1141if eq f 0
1142tbad
1143end
1144if eq f get tloaded 0
1145ret
1146end
1147saved = new ulong 5 0
1148i = ulong 0
1149while lt i 5 bound 6
1150put saved i get tlx i
1151i = add i 1
1152end
1153tfontload f
1154i = 0
1155while lt i 5 bound 6
1156put tlx i get saved i
1157i = add i 1
1158end
1159end
1160
1161note Geometry is content order only. Width fallback 500/1000 em for absent simple Widths,
1162note overridden by descriptor MissingWidth. It affects inferred spaces only, not Unicode.
1163note This known difference class can disagree with a standard-14 font's actual advance.
1164note tgeo: baseline unit x/y and effective font size.
1165fn tidentity off ulong to void
1166i = ulong 0
1167while lt i 6 bound 7
1168v = 0.0f64
1169if or eq i 0 eq i 3
1170v = 1.0f64
1171end
1172put tmat add off i v
1173i = add i 1
1174end
1175end
1176fn ttranslate dx f64 dy f64 to void
1177x = add mul dx get tmat 6 mul dy get tmat 8
1178y = add mul dx get tmat 7 mul dy get tmat 9
1179put tmat 10 tfinite add get tmat 10 x
1180put tmat 11 tfinite add get tmat 11 y
1181end
1182fn tmove dx f64 dy f64 to void
1183i = ulong 0
1184while lt i 6 bound 7
1185put tmat add i 6 get tmat add i 12
1186i = add i 1
1187end
1188ttranslate dx dy
1189i = 0
1190while lt i 6 bound 7
1191put tmat add i 12 get tmat add i 6
1192i = add i 1
1193end
1194end
1195fn tnextline to void
1196tmove 0.0f64 neg get tstate 3
1197end
1198fn tconcat to void
1199targs 6
1200for i ulong 6
1201put tcv i targnum i
1202end
1203for i ulong 6
1204put tcp i tcmel i
1205end
1206note Separate product storage preserves all original matrix coefficients.
1207for i ulong 6
1208put tmat i get tcp i
1209end
1210end
1211note tcmel: element i of the product tcv x CTM (9.4.4 / 8.3.4: cm replaces CTM by M x CTM).
1212fn tcmel i ulong to f64
1213j = rem i 2
1214k = mul div i 2 2
1215v = add mul get tcv k get tmat j mul get tcv add k 1 get tmat add j 2
1216if ge i 4
1217v = add v get tmat add j 4
1218end
1219ret tfinite v
1220end
1221fn tpushq to void
1222targs 0
1223d = get tqdepth 0
1224if ge d 32
1225tlimit
1226end
1227i = ulong 0
1228while lt i 6 bound 7
1229put tqmat add mul d 12 i get tmat i
1230put tqmat add add mul d 12 6 i get tstate i
1231i = add i 1
1232end
1233put tqfont d get tfont 0
1234put tqdepth 0 add d 1
1235end
1236fn tpopq to void
1237targs 0
1238d = get tqdepth 0
1239if eq d 0
1240tbad
1241end
1242d = sub d 1
1243put tqdepth 0 d
1244i = ulong 0
1245while lt i 6 bound 7
1246put tmat i get tqmat add mul d 12 i
1247put tstate i get tqmat add add mul d 12 6 i
1248i = add i 1
1249end
1250put tfont 0 get tqfont d
1251end
1252fn tgeometry to void
1253bx = add mul get tmat 6 get tmat 0 mul get tmat 7 get tmat 2
1254by = add mul get tmat 6 get tmat 1 mul get tmat 7 get tmat 3
1255mag = fsqrt add mul bx bx mul by by
1256if eq mag 0.0f64
1257tbad
1258end
1259put tgeo 0 div bx mag
1260put tgeo 1 div by mag
1261sz = tfinite mul fabs get tstate 5 mag
1262put tgeo 2 sz
1263end
1264fn torigin coord ulong to f64
1265note Rise affects painted glyphs, not the text baseline used for spacing.
1266x = get tmat 10
1267y = get tmat 11
1268v = add mul x get tmat coord mul y get tmat add coord 2
1269ret tfinite add v get tmat add coord 4
1270end
1271fn tseparate to void
1272tgeometry
1273x = torigin 0
1274y = torigin 1
1275if ne get thave 0 0
1276dx = sub x get tlast 0
1277dy = sub y get tlast 1
1278across = sub mul dy get tgeo 0 mul dx get tgeo 1
1279if gt fabs across mul get tgeo 2 0.5f64
1280tbreak 10
1281else
1282along = add mul dx get tgeo 0 mul dy get tgeo 1
1283if ge along mul get tgeo 2 0.12f64
1284if gt along 0.0f64
1285tbreak 32
1286end
1287end
1288end
1289end
1290put thave 0 1
1291end
1292fn tpen to void
1293put tlast 0 torigin 0
1294put tlast 1 torigin 1
1295end
1296note tmb16: the big-endian 16-bit unit at tmb[q].
1297fn tmb16 q ulong to ulong
1298hi = ulong get tmb q
1299lo = ulong get tmb add q 1
1300ret or shl hi 8 lo
1301end
1302fn tmapemit slot ulong to void
1303p = get tmoff slot
1304n = get tmlen slot
1305i = ulong 0
1306while lt i n bound 513
1307cp = tmb16 add p i
1308i = add i 2
1309if and ge cp 55296 le cp 56319
1310if ge i n
1311tbad
1312end
1313lo = tmb16 add p i
1314if or lt lo 56320 gt lo 57343
1315tbad
1316end
1317cp = add 65536 add mul sub cp 55296 1024 sub lo 56320
1318i = add i 2
1319else
1320if and ge cp 56320 le cp 57343
1321tbad
1322end
1323end
1324tu8 cp
1325end
1326end
1327fn tmatchspace code ulong nb ulong to bool
1328i = ulong 0
1329while lt i get tfinfo 2 bound 65
1330if eq get tsbytes i nb
1331if and ge code get tslo i le code get tshi i
1332ret true
1333end
1334end
1335i = add i 1
1336end
1337ret false
1338end
1339note tnomap: a code the ToUnicode CMap does not map (9.10.2) prints one U+FFFD (the base table is empty
1340note while a ToUnicode CMap is in use, so the lookup below only guards the table index).
1341fn tnomap code ulong to void
1342if lt code 256
1343cp = get tbasecp code
1344if ne cp 0
1345tu8 cp
1346ret
1347end
1348end
1349tu8 65533
1350end
1351fn tshowglyph code ulong nb ulong to void
1352tseparate
1353if ne get tfinfo 1 0
1354slot = tmapfind tmapkey code nb
1355if eq get tmk slot 0
1356tnomap code
1357else
1358tmapemit slot
1359end
1360else
1361cp = get tbasecp code
1362if eq cp 0
1363cp = 65533
1364end
1365tu8 cp
1366end
1367if ge code 65536
1368tlimit
1369end
1370width = get tmetrics code
1371size = get tstate 5
1372dx = mul mul width get tfontmx 0 size
1373dy = mul mul width get tfontmx 1 size
1374dx = add dx get tstate 0
1375if and eq nb 1 eq code 32
1376dx = add dx get tstate 1
1377end
1378ttranslate mul dx get tstate 2 dy
1379tpen
1380end
1381fn tshow j ulong to void
1382if eq get tinbt 0 0
1383tbad
1384end
1385if ne get tokind j 3
1386tbad
1387end
1388tensurefont
1389p = get tostart j
1390n = get tolen j
1391i = ulong 0
1392while lt i n bound 65537
1393if eq get tfinfo 1 0
1394tshowglyph ulong get topool add p i 1
1395i = add i 1
1396continue
1397end
1398code = ulong 0
1399nb = ulong 0
1400matched = false
1401while and lt nb 4 lt i n bound 5
1402code = add mul code 256 ulong get topool add p i
1403nb = add nb 1
1404i = add i 1
1405if tmatchspace code nb
1406matched = true
1407break
1408end
1409end
1410if not matched
1411tbad
1412end
1413if eq get tfinfo 0 0
1414if ne nb 1
1415tbad
1416end
1417end
1418tshowglyph code nb
1419end
1420end
1421fn tadjust v f64 to void
1422if eq get tinbt 0 0
1423tbad
1424end
1425ttranslate neg mul mul div v 1000.0f64 get tstate 5 get tstate 2 0.0f64
1426end
1427fn tshowarray to void
1428n = get tlx 5
1429if lt n 2
1430tbad
1431end
1432if or ne get tokind 0 5 ne get tokind sub n 1 6
1433tbad
1434end
1435i = ulong 1
1436while lt i sub n 1 bound 4097
1437k = get tokind i
1438if eq k 3
1439tshow i
1440else
1441if ne k 1
1442tbad
1443end
1444tadjust get tovalue i
1445end
1446i = add i 1
1447end
1448end
1449fn tsetfont to void
1450targs 2
1451fontn = targname 0 pget get pres get tpage 0 tkfont
1452if eq fontn 0
1453tbad
1454end
1455put tfont 0 fontn
1456put tstate 5 targnum 1
1457end
1458fn tsetmatrix to void
1459targs 6
1460i = ulong 0
1461while lt i 6 bound 7
1462v = targnum i
1463put tmat add i 6 v
1464put tmat add i 12 v
1465i = add i 1
1466end
1467end
1468text topbt "BT"
1469text topet "ET"
1470text toptf "Tf"
1471text toptd "Td"
1472text toptD "TD"
1473text toptm "Tm"
1474text topts "T*"
1475text toptj "Tj"
1476text toptJ "TJ"
1477text topquot "'"
1478text topdquo "\""
1479text toptc "Tc"
1480text toptw "Tw"
1481text toptz "Tz"
1482text toptl "TL"
1483text toprise "Ts"
1484text toprend "Tr"
1485text topq "q"
1486text topQ "Q"
1487text topcm "cm"
1488text topdo "Do"
1489text topbi "BI"
1490text topbmc "BMC"
1491text topbdc "BDC"
1492text topemc "EMC"
1493fn ttextstate ix ulong to void
1494targs 1
1495v = targnum 0
1496if eq ix 2
1497v = div v 100.0f64
1498end
1499put tstate ix v
1500end
1501fn toperator to void
1502if teq topbt
1503targs 0
1504if ne get tinbt 0 0
1505tbad
1506end
1507put tinbt 0 1
1508tidentity 6
1509tidentity 12
1510ret
1511end
1512if teq topet
1513targs 0
1514if eq get tinbt 0 0
1515tbad
1516end
1517put tinbt 0 0
1518ret
1519end
1520if teq topq
1521tpushq
1522ret
1523end
1524if teq topQ
1525tpopq
1526ret
1527end
1528if teq topcm
1529tconcat
1530ret
1531end
1532if teq toptf
1533tsetfont
1534ret
1535end
1536if teq toptc
1537ttextstate 0
1538ret
1539end
1540if teq toptw
1541ttextstate 1
1542ret
1543end
1544if teq toptz
1545ttextstate 2
1546ret
1547end
1548if teq toptl
1549ttextstate 3
1550ret
1551end
1552if teq toprise
1553ttextstate 4
1554ret
1555end
1556if teq toprend
1557targs 1
1558v = targnum 0
1559if or lt v 0.0f64 gt v 7.0f64
1560tbad
1561end
1562if ne v f64 ulong v
1563tbad
1564end
1565ret
1566end
1567if or teq toptd teq toptD
1568if eq get tinbt 0 0
1569tbad
1570end
1571targs 2
1572if teq toptD
1573put tstate 3 neg targnum 1
1574end
1575tmove targnum 0 targnum 1
1576ret
1577end
1578if teq toptm
1579if eq get tinbt 0 0
1580tbad
1581end
1582tsetmatrix
1583ret
1584end
1585if teq topts
1586if eq get tinbt 0 0
1587tbad
1588end
1589targs 0
1590tnextline
1591ret
1592end
1593if teq toptj
1594targs 1
1595tshow 0
1596ret
1597end
1598if teq toptJ
1599tshowarray
1600ret
1601end
1602if teq topquot
1603targs 1
1604tnextline
1605tshow 0
1606ret
1607end
1608if teq topdquo
1609targs 3
1610put tstate 1 targnum 0
1611put tstate 0 targnum 1
1612tnextline
1613tshow 2
1614ret
1615end
1616if teq topdo
1617targs 1
1618n = targname 0 pget get pres get tpage 0 tkxobj
1619if eq n 0
1620tbad
1621end
1622if not pne pget n tksub tnimage
1623tunsup
1624end
1625ret
1626end
1627if teq topbi
1628tunsup
1629end
1630note Other graphics operators have no effect on text state. Containers have already been bounded.
1631end
1632fn tinterpret to void
1633put tlx 0 0
1634put tlx 1 0
1635put tlx 5 0
1636put tlx 6 0
1637depth = ulong 0
1638stack = new ulong 64 0
1639while true bound 16777217
1640tlex
1641k = get tlx 3
1642if eq k 0
1643break
1644end
1645if or or eq k 5 eq k 7 eq k 9
1646if ge depth 64
1647tlimit
1648end
1649put stack depth k
1650depth = add depth 1
1651topush
1652continue
1653end
1654if or or eq k 6 eq k 8 eq k 10
1655if eq depth 0
1656tbad
1657end
1658depth = sub depth 1
1659if ne k add get stack depth 1
1660tbad
1661end
1662topush
1663continue
1664end
1665if and eq k 4 eq depth 0
1666toperator
1667put tlx 5 0
1668put tlx 6 0
1669else
1670topush
1671end
1672end
1673if or ne depth 0 ne get tlx 5 0
1674tbad
1675end
1676if ne get tinbt 0 0
1677tbad
1678end
1679if ne get tqdepth 0 0
1680tbad
1681end
1682end
1683fn tappendstream n ulong to void
1684pdecode n
1685p = get tlx 2
1686nbytes = get pdlen 0
1687if ge nbytes sub 16777216 p
1688tlimit
1689end
1690i = ulong 0
1691while lt i nbytes bound 16777217
1692put tcs add p i get pdbuf i
1693i = add i 1
1694end
1695put tcs add p nbytes 32
1696put tlx 2 add add p nbytes 1
1697end
1698fn tpagecontent pageix ulong to void
1699put tlx 2 0
1700cont = pderef pget get ppages pageix tkcont
1701if eq cont 0
1702ret
1703end
1704if eq get ptype cont 10
1705tappendstream cont
1706ret
1707end
1708cont = tkind cont 7
1709n = get pfirst cont
1710while ne n 0 bound 262145
1711tappendstream n
1712n = get pnext n
1713end
1714end
1715fn tpages first ulong last ulong to void
1716if or eq first 0 lt last first
1717tbad
1718end
1719if gt last get pcount 0
1720tbad
1721end
1722ix = sub first 1
1723while lt ix last bound 4097
1724put tpage 0 ix
1725put tfont 0 0
1726put tloaded 0 0
1727put tloads 0 0
1728put tcbytes 0 0
1729put tqdepth 0 0
1730put tinbt 0 0
1731put thave 0 0
1732put tlx 7 0
1733i = ulong 0
1734while lt i 6 bound 7
1735put tstate i 0.0f64
1736i = add i 1
1737end
1738put tstate 2 1.0f64
1739tidentity 0
1740tpagecontent ix
1741tinterpret
1742note Each page ends with LF then FF (form feed), so page boundaries survive in the output.
1743if eq get tlx 7 0
1744temit 10
1745else
1746tbreak 10
1747end
1748temit 12
1749tflush
1750ix = add ix 1
1751end
1752end
1753
1754fn ttype3matrix fontn ulong to void
1755m = tkind pget fontn tkmatrix 7
1756v = get pfirst m
1757i = ulong 0
1758while ne v 0 bound 7
1759if ge i 6
1760tbad
1761end
1762x = tnumber v
1763if lt i 2
1764put tfontmx i x
1765end
1766i = add i 1
1767v = get pnext v
1768end
1769if ne i 6
1770tbad
1771end
1772end
1773fn tvaliddest dn ulong to void
1774i = ulong 0
1775while lt i dn bound 513
1776cp = add mul ulong get tcmaptmp i 256 ulong get tcmaptmp add i 1
1777i = add i 2
1778if and ge cp 55296 le cp 56319
1779if ge i dn
1780tbad
1781end
1782lo = add mul ulong get tcmaptmp i 256 ulong get tcmaptmp add i 1
1783if or lt lo 56320 gt lo 57343
1784tbad
1785end
1786i = add i 2
1787else
1788if and ge cp 56320 le cp 57343
1789tbad
1790end
1791end
1792end
1793end
1794
1795note Codespaces must not overlap or admit one code as a prefix of another length.
1796fn tspacecheck lo ulong hi ulong nb ulong to void
1797j = ulong 0
1798while lt j get tfinfo 2 bound 65
1799left = lo
1800right = hi
1801otherlo = get tslo j
1802otherhi = get tshi j
1803ob = get tsbytes j
1804if lt nb ob
1805bitsn = mul sub ob nb 8
1806otherlo = shr otherlo bitsn
1807otherhi = shr otherhi bitsn
1808else
1809if gt nb ob
1810bitsn = mul sub nb ob 8
1811left = shr left bitsn
1812right = shr right bitsn
1813end
1814end
1815if and le left otherhi ge right otherlo
1816tbad
1817end
1818j = add j 1
1819end
1820end
1821
1822text tnsymbol "Symbol"
1823text tnzapf "ZapfDingbats"
1824note timplicit: the base encoding when the font names none (9.6.6.1, Table 114): StandardEncoding (1) for a
1825note nonsymbolic font; for a symbolic font (Flags bit 3) or Symbol/ZapfDingbats the font program's built-in
1826note encoding, which this reader does not read: an empty base (0), so only Differences codes are mapped
1827note and any other shown code prints U+FFFD.
1828fn timplicit fontn ulong to ulong
1829bf = pget fontn tkbf
1830if or pne bf tnsymbol pne bf tnzapf
1831ret 0
1832end
1833flags = pderef pget pget fontn tkdesc tkflags
1834if ne flags 0
1835f = tint flags 4294967295
1836if ne and f 4 0
1837ret 0
1838end
1839end
1840ret 1
1841end
1842note Wolfram symbolic matrix product verified: a*g+b*i,a*h+b*j,c*g+d*i,c*h+d*j,
1843note e*g+f*i+k,e*h+f*j+l. ISO example D840DC3E -> 131134 (U+2003E).
1844note Spacing rules (stated, not layout analysis: text is printed in the order the content streams draw it):
1845note a move across the baseline larger than 0.5 times the effective font size starts a new line; a move
1846note along the baseline of at least 0.12 times the effective font size after the previous glyph ends
1847note inserts one space. 0.12 em is below the narrowest justified word space seen in the corpus (pdfTeX
1848note Times, 0.25 em less shrink) and above kerning adjustments.