Skip to main content

pdfboss_encoding/
afm.rs

1//! Standard-14 advance-width tables, from the public Adobe Core-14
2//! AFM metrics (see ISO 32000-1 Annex D / Adobe's PDF Reference for the
3//! standard-14 font names). Widths are in the 1000-unit glyph space
4//! used throughout PDF (ISO 32000-1 9.2.4), i.e. thousandths of the
5//! font's em square; multiply by `font_size / 1000` for text space.
6//!
7//! These tables back [`standard_14_width`], used as a fallback advance
8//! when a PDF's `/Widths` array is absent or incomplete and the font
9//! program itself isn't embedded (font substitution).
10
11/// Strips a PDF font-subset tag (`ISO 32000-1` 9.6.4: six uppercase
12/// letters followed by `+`, e.g. `ABCDEF+Times-Bold`) from `base_font`.
13///
14/// Covers ISO 32000-1 §9.6.4.
15fn strip_subset_prefix(base_font: &str) -> &str {
16    let bytes = base_font.as_bytes();
17    // `> 7`, not `> 6`: the guard must require at least one character after
18    // the `+` for the strip to be meaningful, so the degenerate
19    // `"ABCDEF+"` (len 7) is left unstripped instead of yielding an empty
20    // name. Matches `substitute.rs`'s `strip_subset_prefix` guard exactly.
21    if bytes.len() > 7 && bytes[6] == b'+' && bytes[..6].iter().all(u8::is_ascii_uppercase) {
22        &base_font[7..]
23    } else {
24        base_font
25    }
26}
27
28/// A standard-14 font family (weight/slant resolved separately).
29#[derive(Clone, Copy, PartialEq, Eq, Debug)]
30enum Family {
31    Helvetica,
32    Times,
33    Courier,
34}
35
36/// Recognized family stems, longest first. Ordering matters: a shorter
37/// stem that is itself a prefix of a longer one (`times` vs.
38/// `timesnewroman` vs. `timesnewromanps`, `courier` vs. `couriernew`)
39/// must never shadow the more specific match, or the leftover
40/// remainder handed to [`strip_style_tokens`] would contain stem
41/// characters instead of style/noise ones. `classify` walks this list
42/// in order and takes the first hit.
43const FAMILY_STEMS: &[(&str, Family)] = &[
44    ("timesnewromanps", Family::Times),
45    ("timesnewroman", Family::Times),
46    ("couriernew", Family::Courier),
47    ("helvetica", Family::Helvetica),
48    ("courier", Family::Courier),
49    ("arial", Family::Helvetica),
50    ("times", Family::Times),
51];
52
53/// Style/noise tokens recognized after the family stem, longest first
54/// (so, e.g., `psmt` is tried whole rather than stopping at `ps`).
55/// `mt`/`ps`/`psmt` are TrueType-alias noise suffixes (`Arial-BoldMT`,
56/// `TimesNewRomanPSMT`). Anything left over after greedily stripping
57/// these tokens means the name carries a real, metrically distinct
58/// qualifier (`Narrow`, `Neue`, `Condensed`, `Light`, `Ten`, ...) and
59/// so isn't one of the standard 14.
60const STYLE_TOKENS: &[&str] = &[
61    "oblique", "regular", "italic", "roman", "bold", "book", "psmt", "ps", "mt",
62];
63
64/// Greedily strips [`STYLE_TOKENS`] from the front of `rest`, folding
65/// them into `(bold, italic)` flags, until `rest` is fully consumed.
66/// Returns `None` the moment a prefix token isn't recognized, i.e. the
67/// name has a qualifier this module doesn't tabulate.
68fn strip_style_tokens(mut rest: &str) -> Option<(bool, bool)> {
69    let mut bold = false;
70    let mut italic = false;
71    while !rest.is_empty() {
72        let tok = *STYLE_TOKENS.iter().find(|&&t| rest.starts_with(t))?;
73        match tok {
74            "bold" => bold = true,
75            "italic" | "oblique" => italic = true,
76            _ => {}
77        }
78        rest = &rest[tok.len()..];
79    }
80    Some((bold, italic))
81}
82
83/// Classifies a (subset-prefix-stripped) `/BaseFont` name into a
84/// standard-14 family plus bold/italic flags. The name is lowercased
85/// and separator-stripped (`-`, `,`, space) before matching, so
86/// `Arial-BoldMT`, `arial-bold`, and `Arial,Bold` all resolve alike.
87/// The (separator-stripped) name must then start with one of the
88/// [`FAMILY_STEMS`] (recognizing the common PostScript and TrueType
89/// aliases: `Arial` -> Helvetica, `TimesNewRoman`/`TimesNewRomanPS` ->
90/// Times, `CourierNew` -> Courier), and everything after the stem must
91/// fully reduce to [`STYLE_TOKENS`] noise.
92///
93/// This is deliberately strict: a font that merely shares a standard-14
94/// prefix but is metrically distinct — `Helvetica-Narrow`, `Helvetica
95/// Neue`, `HelveticaNeue-Bold`, `TimesTen-Bold`, `Helvetica-Light`,
96/// `Times New Roman Condensed` — leaves an unrecognized token after the
97/// stem and so classifies as `None`, same as Symbol, ZapfDingbats, or
98/// any other name that isn't one of the standard 14. Returning `None`
99/// here is correct even though it's plausible-looking: the caller then
100/// falls back to the substitute face's own `hmtx` widths rather than a
101/// wrong Core-14 advance.
102fn classify(base_font: &str) -> Option<(Family, bool, bool)> {
103    let stripped = strip_subset_prefix(base_font);
104    let lower = stripped.to_lowercase();
105    let compact: String = lower
106        .chars()
107        .filter(|c| !matches!(c, '-' | ',' | ' '))
108        .collect();
109    let (family, rest) = FAMILY_STEMS
110        .iter()
111        .find_map(|&(stem, family)| compact.strip_prefix(stem).map(|rest| (family, rest)))?;
112    let (bold, italic) = strip_style_tokens(rest)?;
113    Some((family, bold, italic))
114}
115
116/// Binary-searches a `(glyph_name, width)` table sorted by name.
117fn lookup(table: &[(&str, u16)], glyph_name: &str) -> Option<f32> {
118    table
119        .binary_search_by_key(&glyph_name, |&(name, _)| name)
120        .ok()
121        .map(|i| table[i].1 as f32)
122}
123
124/// The advance width (1000-unit glyph space) of `glyph_name` in the
125/// standard-14 font whose PDF `/BaseFont` (or a recognized alias, or a
126/// subsetted variant) is `base_font`, or `None` if `base_font` isn't one
127/// of the standard 14 or `glyph_name` is unknown to that font. Symbol and
128/// ZapfDingbats match only by their exact names, with no aliases, and take
129/// the glyph names of their built-in encodings (Annex D.5 and D.6).
130/// Courier's four variants are monospaced (every glyph is 600 units wide
131/// per the Adobe Core-14 AFM metrics) and so always return `Some(600.0)`.
132/// Oblique variants share their upright counterpart's widths (Helvetica
133/// and Helvetica-Oblique are metrically identical, likewise the bold
134/// pair), so only upright/bold tables are stored.
135///
136/// Covers ISO 32000-1 §9.6.2.2.
137pub fn standard_14_width(base_font: &str, glyph_name: &str) -> Option<f32> {
138    if let Some(table) = symbolic_table(base_font) {
139        return lookup(table, glyph_name);
140    }
141    let (family, bold, italic) = classify(base_font)?;
142    match family {
143        Family::Courier => Some(600.0),
144        Family::Helvetica => {
145            let table = if bold { HELVETICA_BOLD } else { HELVETICA };
146            lookup(table, glyph_name)
147        }
148        Family::Times => {
149            let table = match (bold, italic) {
150                (true, true) => TIMES_BOLD_ITALIC,
151                (true, false) => TIMES_BOLD,
152                (false, true) => TIMES_ITALIC,
153                (false, false) => TIMES_ROMAN,
154            };
155            lookup(table, glyph_name)
156        }
157    }
158}
159
160/// The width table of Symbol or ZapfDingbats when `base_font`, after
161/// subset-prefix stripping, is exactly that name.
162fn symbolic_table(base_font: &str) -> Option<&'static [(&'static str, u16)]> {
163    match strip_subset_prefix(base_font) {
164        "Symbol" => Some(SYMBOL),
165        "ZapfDingbats" => Some(ZAPF_DINGBATS),
166        _ => None,
167    }
168}
169
170/// Whether `base_font` (after subset-prefix stripping and alias
171/// normalization) names one of the twelve standard-14 text faces. Symbol
172/// and ZapfDingbats are symbolic fonts with their own built-in encodings
173/// and are not included.
174///
175/// Covers ISO 32000-1 §9.6.2.2.
176pub fn is_standard_14(base_font: &str) -> bool {
177    classify(base_font).is_some()
178}
179
180/// `Helvetica` glyph widths, sorted by
181/// glyph name for binary search (Adobe Core-14 AFM metrics).
182#[rustfmt::skip]
183const HELVETICA: &[(&str, u16)] = &[
184    ("A", 667),
185    ("AE", 1000),
186    ("Aacute", 667),
187    ("Acircumflex", 667),
188    ("Adieresis", 667),
189    ("Agrave", 667),
190    ("Aring", 667),
191    ("Atilde", 667),
192    ("B", 667),
193    ("C", 722),
194    ("Ccedilla", 722),
195    ("D", 722),
196    ("E", 667),
197    ("Eacute", 667),
198    ("Ecircumflex", 667),
199    ("Edieresis", 667),
200    ("Egrave", 667),
201    ("Eth", 722),
202    ("F", 611),
203    ("G", 778),
204    ("H", 722),
205    ("I", 278),
206    ("Iacute", 278),
207    ("Icircumflex", 278),
208    ("Idieresis", 278),
209    ("Igrave", 278),
210    ("J", 500),
211    ("K", 667),
212    ("L", 556),
213    ("Lslash", 556),
214    ("M", 833),
215    ("N", 722),
216    ("Ntilde", 722),
217    ("O", 778),
218    ("OE", 1000),
219    ("Oacute", 778),
220    ("Ocircumflex", 778),
221    ("Odieresis", 778),
222    ("Ograve", 778),
223    ("Oslash", 778),
224    ("Otilde", 778),
225    ("P", 667),
226    ("Q", 778),
227    ("R", 722),
228    ("S", 667),
229    ("Scaron", 667),
230    ("T", 611),
231    ("Thorn", 667),
232    ("U", 722),
233    ("Uacute", 722),
234    ("Ucircumflex", 722),
235    ("Udieresis", 722),
236    ("Ugrave", 722),
237    ("V", 667),
238    ("W", 944),
239    ("X", 667),
240    ("Y", 667),
241    ("Yacute", 667),
242    ("Ydieresis", 667),
243    ("Z", 611),
244    ("Zcaron", 611),
245    ("a", 556),
246    ("aacute", 556),
247    ("acircumflex", 556),
248    ("acute", 333),
249    ("adieresis", 556),
250    ("ae", 889),
251    ("agrave", 556),
252    ("ampersand", 667),
253    ("aring", 556),
254    ("asciicircum", 469),
255    ("asciitilde", 584),
256    ("asterisk", 389),
257    ("at", 1015),
258    ("atilde", 556),
259    ("b", 556),
260    ("backslash", 278),
261    ("bar", 260),
262    ("braceleft", 334),
263    ("braceright", 334),
264    ("bracketleft", 278),
265    ("bracketright", 278),
266    ("breve", 333),
267    ("brokenbar", 260),
268    ("bullet", 350),
269    ("c", 500),
270    ("caron", 333),
271    ("ccedilla", 500),
272    ("cedilla", 333),
273    ("cent", 556),
274    ("circumflex", 333),
275    ("colon", 278),
276    ("comma", 278),
277    ("copyright", 737),
278    ("currency", 556),
279    ("d", 556),
280    ("dagger", 556),
281    ("daggerdbl", 556),
282    ("degree", 400),
283    ("dieresis", 333),
284    ("divide", 584),
285    ("dollar", 556),
286    ("dotaccent", 333),
287    ("dotlessi", 278),
288    ("e", 556),
289    ("eacute", 556),
290    ("ecircumflex", 556),
291    ("edieresis", 556),
292    ("egrave", 556),
293    ("eight", 556),
294    ("ellipsis", 1000),
295    ("emdash", 1000),
296    ("endash", 556),
297    ("equal", 584),
298    ("eth", 556),
299    ("exclam", 278),
300    ("exclamdown", 333),
301    ("f", 278),
302    ("fi", 500),
303    ("five", 556),
304    ("fl", 500),
305    ("florin", 556),
306    ("four", 556),
307    ("fraction", 167),
308    ("g", 556),
309    ("germandbls", 611),
310    ("grave", 333),
311    ("greater", 584),
312    ("guillemotleft", 556),
313    ("guillemotright", 556),
314    ("guilsinglleft", 333),
315    ("guilsinglright", 333),
316    ("h", 556),
317    ("hungarumlaut", 333),
318    ("hyphen", 333),
319    ("i", 222),
320    ("iacute", 278),
321    ("icircumflex", 278),
322    ("idieresis", 278),
323    ("igrave", 278),
324    ("j", 222),
325    ("k", 500),
326    ("l", 222),
327    ("less", 584),
328    ("logicalnot", 584),
329    ("lslash", 222),
330    ("m", 833),
331    ("macron", 333),
332    ("minus", 584),
333    ("mu", 556),
334    ("multiply", 584),
335    ("n", 556),
336    ("nine", 556),
337    ("ntilde", 556),
338    ("numbersign", 556),
339    ("o", 556),
340    ("oacute", 556),
341    ("ocircumflex", 556),
342    ("odieresis", 556),
343    ("oe", 944),
344    ("ogonek", 333),
345    ("ograve", 556),
346    ("one", 556),
347    ("onehalf", 834),
348    ("onequarter", 834),
349    ("onesuperior", 333),
350    ("ordfeminine", 370),
351    ("ordmasculine", 365),
352    ("oslash", 611),
353    ("otilde", 556),
354    ("p", 556),
355    ("paragraph", 537),
356    ("parenleft", 333),
357    ("parenright", 333),
358    ("percent", 889),
359    ("period", 278),
360    ("periodcentered", 278),
361    ("perthousand", 1000),
362    ("plus", 584),
363    ("plusminus", 584),
364    ("q", 556),
365    ("question", 556),
366    ("questiondown", 611),
367    ("quotedbl", 355),
368    ("quotedblbase", 333),
369    ("quotedblleft", 333),
370    ("quotedblright", 333),
371    ("quoteleft", 222),
372    ("quoteright", 222),
373    ("quotesinglbase", 222),
374    ("quotesingle", 191),
375    ("r", 333),
376    ("registered", 737),
377    ("ring", 333),
378    ("s", 500),
379    ("scaron", 500),
380    ("section", 556),
381    ("semicolon", 278),
382    ("seven", 556),
383    ("six", 556),
384    ("slash", 278),
385    ("space", 278),
386    ("sterling", 556),
387    ("t", 278),
388    ("thorn", 556),
389    ("three", 556),
390    ("threequarters", 834),
391    ("threesuperior", 333),
392    ("tilde", 333),
393    ("trademark", 1000),
394    ("two", 556),
395    ("twosuperior", 333),
396    ("u", 556),
397    ("uacute", 556),
398    ("ucircumflex", 556),
399    ("udieresis", 556),
400    ("ugrave", 556),
401    ("underscore", 556),
402    ("v", 500),
403    ("w", 722),
404    ("x", 500),
405    ("y", 500),
406    ("yacute", 500),
407    ("ydieresis", 500),
408    ("yen", 556),
409    ("z", 500),
410    ("zcaron", 500),
411    ("zero", 556),
412];
413
414/// `Helvetica Bold` glyph widths, sorted by
415/// glyph name for binary search (Adobe Core-14 AFM metrics).
416#[rustfmt::skip]
417const HELVETICA_BOLD: &[(&str, u16)] = &[
418    ("A", 722),
419    ("AE", 1000),
420    ("Aacute", 722),
421    ("Acircumflex", 722),
422    ("Adieresis", 722),
423    ("Agrave", 722),
424    ("Aring", 722),
425    ("Atilde", 722),
426    ("B", 722),
427    ("C", 722),
428    ("Ccedilla", 722),
429    ("D", 722),
430    ("E", 667),
431    ("Eacute", 667),
432    ("Ecircumflex", 667),
433    ("Edieresis", 667),
434    ("Egrave", 667),
435    ("Eth", 722),
436    ("F", 611),
437    ("G", 778),
438    ("H", 722),
439    ("I", 278),
440    ("Iacute", 278),
441    ("Icircumflex", 278),
442    ("Idieresis", 278),
443    ("Igrave", 278),
444    ("J", 556),
445    ("K", 722),
446    ("L", 611),
447    ("Lslash", 611),
448    ("M", 833),
449    ("N", 722),
450    ("Ntilde", 722),
451    ("O", 778),
452    ("OE", 1000),
453    ("Oacute", 778),
454    ("Ocircumflex", 778),
455    ("Odieresis", 778),
456    ("Ograve", 778),
457    ("Oslash", 778),
458    ("Otilde", 778),
459    ("P", 667),
460    ("Q", 778),
461    ("R", 722),
462    ("S", 667),
463    ("Scaron", 667),
464    ("T", 611),
465    ("Thorn", 667),
466    ("U", 722),
467    ("Uacute", 722),
468    ("Ucircumflex", 722),
469    ("Udieresis", 722),
470    ("Ugrave", 722),
471    ("V", 667),
472    ("W", 944),
473    ("X", 667),
474    ("Y", 667),
475    ("Yacute", 667),
476    ("Ydieresis", 667),
477    ("Z", 611),
478    ("Zcaron", 611),
479    ("a", 556),
480    ("aacute", 556),
481    ("acircumflex", 556),
482    ("acute", 333),
483    ("adieresis", 556),
484    ("ae", 889),
485    ("agrave", 556),
486    ("ampersand", 722),
487    ("aring", 556),
488    ("asciicircum", 584),
489    ("asciitilde", 584),
490    ("asterisk", 389),
491    ("at", 975),
492    ("atilde", 556),
493    ("b", 611),
494    ("backslash", 278),
495    ("bar", 280),
496    ("braceleft", 389),
497    ("braceright", 389),
498    ("bracketleft", 333),
499    ("bracketright", 333),
500    ("breve", 333),
501    ("brokenbar", 280),
502    ("bullet", 350),
503    ("c", 556),
504    ("caron", 333),
505    ("ccedilla", 556),
506    ("cedilla", 333),
507    ("cent", 556),
508    ("circumflex", 333),
509    ("colon", 333),
510    ("comma", 278),
511    ("copyright", 737),
512    ("currency", 556),
513    ("d", 611),
514    ("dagger", 556),
515    ("daggerdbl", 556),
516    ("degree", 400),
517    ("dieresis", 333),
518    ("divide", 584),
519    ("dollar", 556),
520    ("dotaccent", 333),
521    ("dotlessi", 278),
522    ("e", 556),
523    ("eacute", 556),
524    ("ecircumflex", 556),
525    ("edieresis", 556),
526    ("egrave", 556),
527    ("eight", 556),
528    ("ellipsis", 1000),
529    ("emdash", 1000),
530    ("endash", 556),
531    ("equal", 584),
532    ("eth", 611),
533    ("exclam", 333),
534    ("exclamdown", 333),
535    ("f", 333),
536    ("fi", 611),
537    ("five", 556),
538    ("fl", 611),
539    ("florin", 556),
540    ("four", 556),
541    ("fraction", 167),
542    ("g", 611),
543    ("germandbls", 611),
544    ("grave", 333),
545    ("greater", 584),
546    ("guillemotleft", 556),
547    ("guillemotright", 556),
548    ("guilsinglleft", 333),
549    ("guilsinglright", 333),
550    ("h", 611),
551    ("hungarumlaut", 333),
552    ("hyphen", 333),
553    ("i", 278),
554    ("iacute", 278),
555    ("icircumflex", 278),
556    ("idieresis", 278),
557    ("igrave", 278),
558    ("j", 278),
559    ("k", 556),
560    ("l", 278),
561    ("less", 584),
562    ("logicalnot", 584),
563    ("lslash", 278),
564    ("m", 889),
565    ("macron", 333),
566    ("minus", 584),
567    ("mu", 611),
568    ("multiply", 584),
569    ("n", 611),
570    ("nine", 556),
571    ("ntilde", 611),
572    ("numbersign", 556),
573    ("o", 611),
574    ("oacute", 611),
575    ("ocircumflex", 611),
576    ("odieresis", 611),
577    ("oe", 944),
578    ("ogonek", 333),
579    ("ograve", 611),
580    ("one", 556),
581    ("onehalf", 834),
582    ("onequarter", 834),
583    ("onesuperior", 333),
584    ("ordfeminine", 370),
585    ("ordmasculine", 365),
586    ("oslash", 611),
587    ("otilde", 611),
588    ("p", 611),
589    ("paragraph", 556),
590    ("parenleft", 333),
591    ("parenright", 333),
592    ("percent", 889),
593    ("period", 278),
594    ("periodcentered", 278),
595    ("perthousand", 1000),
596    ("plus", 584),
597    ("plusminus", 584),
598    ("q", 611),
599    ("question", 611),
600    ("questiondown", 611),
601    ("quotedbl", 474),
602    ("quotedblbase", 500),
603    ("quotedblleft", 500),
604    ("quotedblright", 500),
605    ("quoteleft", 278),
606    ("quoteright", 278),
607    ("quotesinglbase", 278),
608    ("quotesingle", 238),
609    ("r", 389),
610    ("registered", 737),
611    ("ring", 333),
612    ("s", 556),
613    ("scaron", 556),
614    ("section", 556),
615    ("semicolon", 333),
616    ("seven", 556),
617    ("six", 556),
618    ("slash", 278),
619    ("space", 278),
620    ("sterling", 556),
621    ("t", 333),
622    ("thorn", 611),
623    ("three", 556),
624    ("threequarters", 834),
625    ("threesuperior", 333),
626    ("tilde", 333),
627    ("trademark", 1000),
628    ("two", 556),
629    ("twosuperior", 333),
630    ("u", 611),
631    ("uacute", 611),
632    ("ucircumflex", 611),
633    ("udieresis", 611),
634    ("ugrave", 611),
635    ("underscore", 556),
636    ("v", 556),
637    ("w", 778),
638    ("x", 556),
639    ("y", 556),
640    ("yacute", 556),
641    ("ydieresis", 556),
642    ("yen", 556),
643    ("z", 500),
644    ("zcaron", 500),
645    ("zero", 556),
646];
647
648/// `Times Roman` glyph widths, sorted by
649/// glyph name for binary search (Adobe Core-14 AFM metrics).
650#[rustfmt::skip]
651const TIMES_ROMAN: &[(&str, u16)] = &[
652    ("A", 722),
653    ("AE", 889),
654    ("Aacute", 722),
655    ("Acircumflex", 722),
656    ("Adieresis", 722),
657    ("Agrave", 722),
658    ("Aring", 722),
659    ("Atilde", 722),
660    ("B", 667),
661    ("C", 667),
662    ("Ccedilla", 667),
663    ("D", 722),
664    ("E", 611),
665    ("Eacute", 611),
666    ("Ecircumflex", 611),
667    ("Edieresis", 611),
668    ("Egrave", 611),
669    ("Eth", 722),
670    ("F", 556),
671    ("G", 722),
672    ("H", 722),
673    ("I", 333),
674    ("Iacute", 333),
675    ("Icircumflex", 333),
676    ("Idieresis", 333),
677    ("Igrave", 333),
678    ("J", 389),
679    ("K", 722),
680    ("L", 611),
681    ("Lslash", 611),
682    ("M", 889),
683    ("N", 722),
684    ("Ntilde", 722),
685    ("O", 722),
686    ("OE", 889),
687    ("Oacute", 722),
688    ("Ocircumflex", 722),
689    ("Odieresis", 722),
690    ("Ograve", 722),
691    ("Oslash", 722),
692    ("Otilde", 722),
693    ("P", 556),
694    ("Q", 722),
695    ("R", 667),
696    ("S", 556),
697    ("Scaron", 556),
698    ("T", 611),
699    ("Thorn", 556),
700    ("U", 722),
701    ("Uacute", 722),
702    ("Ucircumflex", 722),
703    ("Udieresis", 722),
704    ("Ugrave", 722),
705    ("V", 722),
706    ("W", 944),
707    ("X", 722),
708    ("Y", 722),
709    ("Yacute", 722),
710    ("Ydieresis", 722),
711    ("Z", 611),
712    ("Zcaron", 611),
713    ("a", 444),
714    ("aacute", 444),
715    ("acircumflex", 444),
716    ("acute", 333),
717    ("adieresis", 444),
718    ("ae", 667),
719    ("agrave", 444),
720    ("ampersand", 778),
721    ("aring", 444),
722    ("asciicircum", 469),
723    ("asciitilde", 541),
724    ("asterisk", 500),
725    ("at", 921),
726    ("atilde", 444),
727    ("b", 500),
728    ("backslash", 278),
729    ("bar", 200),
730    ("braceleft", 480),
731    ("braceright", 480),
732    ("bracketleft", 333),
733    ("bracketright", 333),
734    ("breve", 333),
735    ("brokenbar", 200),
736    ("bullet", 350),
737    ("c", 444),
738    ("caron", 333),
739    ("ccedilla", 444),
740    ("cedilla", 333),
741    ("cent", 500),
742    ("circumflex", 333),
743    ("colon", 278),
744    ("comma", 250),
745    ("copyright", 760),
746    ("currency", 500),
747    ("d", 500),
748    ("dagger", 500),
749    ("daggerdbl", 500),
750    ("degree", 400),
751    ("dieresis", 333),
752    ("divide", 564),
753    ("dollar", 500),
754    ("dotaccent", 333),
755    ("dotlessi", 278),
756    ("e", 444),
757    ("eacute", 444),
758    ("ecircumflex", 444),
759    ("edieresis", 444),
760    ("egrave", 444),
761    ("eight", 500),
762    ("ellipsis", 1000),
763    ("emdash", 1000),
764    ("endash", 500),
765    ("equal", 564),
766    ("eth", 500),
767    ("exclam", 333),
768    ("exclamdown", 333),
769    ("f", 333),
770    ("fi", 556),
771    ("five", 500),
772    ("fl", 556),
773    ("florin", 500),
774    ("four", 500),
775    ("fraction", 167),
776    ("g", 500),
777    ("germandbls", 500),
778    ("grave", 333),
779    ("greater", 564),
780    ("guillemotleft", 500),
781    ("guillemotright", 500),
782    ("guilsinglleft", 333),
783    ("guilsinglright", 333),
784    ("h", 500),
785    ("hungarumlaut", 333),
786    ("hyphen", 333),
787    ("i", 278),
788    ("iacute", 278),
789    ("icircumflex", 278),
790    ("idieresis", 278),
791    ("igrave", 278),
792    ("j", 278),
793    ("k", 500),
794    ("l", 278),
795    ("less", 564),
796    ("logicalnot", 564),
797    ("lslash", 278),
798    ("m", 778),
799    ("macron", 333),
800    ("minus", 564),
801    ("mu", 500),
802    ("multiply", 564),
803    ("n", 500),
804    ("nine", 500),
805    ("ntilde", 500),
806    ("numbersign", 500),
807    ("o", 500),
808    ("oacute", 500),
809    ("ocircumflex", 500),
810    ("odieresis", 500),
811    ("oe", 722),
812    ("ogonek", 333),
813    ("ograve", 500),
814    ("one", 500),
815    ("onehalf", 750),
816    ("onequarter", 750),
817    ("onesuperior", 300),
818    ("ordfeminine", 276),
819    ("ordmasculine", 310),
820    ("oslash", 500),
821    ("otilde", 500),
822    ("p", 500),
823    ("paragraph", 453),
824    ("parenleft", 333),
825    ("parenright", 333),
826    ("percent", 833),
827    ("period", 250),
828    ("periodcentered", 250),
829    ("perthousand", 1000),
830    ("plus", 564),
831    ("plusminus", 564),
832    ("q", 500),
833    ("question", 444),
834    ("questiondown", 444),
835    ("quotedbl", 408),
836    ("quotedblbase", 444),
837    ("quotedblleft", 444),
838    ("quotedblright", 444),
839    ("quoteleft", 333),
840    ("quoteright", 333),
841    ("quotesinglbase", 333),
842    ("quotesingle", 180),
843    ("r", 333),
844    ("registered", 760),
845    ("ring", 333),
846    ("s", 389),
847    ("scaron", 389),
848    ("section", 500),
849    ("semicolon", 278),
850    ("seven", 500),
851    ("six", 500),
852    ("slash", 278),
853    ("space", 250),
854    ("sterling", 500),
855    ("t", 278),
856    ("thorn", 500),
857    ("three", 500),
858    ("threequarters", 750),
859    ("threesuperior", 300),
860    ("tilde", 333),
861    ("trademark", 980),
862    ("two", 500),
863    ("twosuperior", 300),
864    ("u", 500),
865    ("uacute", 500),
866    ("ucircumflex", 500),
867    ("udieresis", 500),
868    ("ugrave", 500),
869    ("underscore", 500),
870    ("v", 500),
871    ("w", 722),
872    ("x", 500),
873    ("y", 500),
874    ("yacute", 500),
875    ("ydieresis", 500),
876    ("yen", 500),
877    ("z", 444),
878    ("zcaron", 444),
879    ("zero", 500),
880];
881
882/// `Times Bold` glyph widths, sorted by
883/// glyph name for binary search (Adobe Core-14 AFM metrics).
884#[rustfmt::skip]
885const TIMES_BOLD: &[(&str, u16)] = &[
886    ("A", 722),
887    ("AE", 1000),
888    ("Aacute", 722),
889    ("Acircumflex", 722),
890    ("Adieresis", 722),
891    ("Agrave", 722),
892    ("Aring", 722),
893    ("Atilde", 722),
894    ("B", 667),
895    ("C", 722),
896    ("Ccedilla", 722),
897    ("D", 722),
898    ("E", 667),
899    ("Eacute", 667),
900    ("Ecircumflex", 667),
901    ("Edieresis", 667),
902    ("Egrave", 667),
903    ("Eth", 722),
904    ("F", 611),
905    ("G", 778),
906    ("H", 778),
907    ("I", 389),
908    ("Iacute", 389),
909    ("Icircumflex", 389),
910    ("Idieresis", 389),
911    ("Igrave", 389),
912    ("J", 500),
913    ("K", 778),
914    ("L", 667),
915    ("Lslash", 667),
916    ("M", 944),
917    ("N", 722),
918    ("Ntilde", 722),
919    ("O", 778),
920    ("OE", 1000),
921    ("Oacute", 778),
922    ("Ocircumflex", 778),
923    ("Odieresis", 778),
924    ("Ograve", 778),
925    ("Oslash", 778),
926    ("Otilde", 778),
927    ("P", 611),
928    ("Q", 778),
929    ("R", 722),
930    ("S", 556),
931    ("Scaron", 556),
932    ("T", 667),
933    ("Thorn", 611),
934    ("U", 722),
935    ("Uacute", 722),
936    ("Ucircumflex", 722),
937    ("Udieresis", 722),
938    ("Ugrave", 722),
939    ("V", 722),
940    ("W", 1000),
941    ("X", 722),
942    ("Y", 722),
943    ("Yacute", 722),
944    ("Ydieresis", 722),
945    ("Z", 667),
946    ("Zcaron", 667),
947    ("a", 500),
948    ("aacute", 500),
949    ("acircumflex", 500),
950    ("acute", 333),
951    ("adieresis", 500),
952    ("ae", 722),
953    ("agrave", 500),
954    ("ampersand", 833),
955    ("aring", 500),
956    ("asciicircum", 581),
957    ("asciitilde", 520),
958    ("asterisk", 500),
959    ("at", 930),
960    ("atilde", 500),
961    ("b", 556),
962    ("backslash", 278),
963    ("bar", 220),
964    ("braceleft", 394),
965    ("braceright", 394),
966    ("bracketleft", 333),
967    ("bracketright", 333),
968    ("breve", 333),
969    ("brokenbar", 220),
970    ("bullet", 350),
971    ("c", 444),
972    ("caron", 333),
973    ("ccedilla", 444),
974    ("cedilla", 333),
975    ("cent", 500),
976    ("circumflex", 333),
977    ("colon", 333),
978    ("comma", 250),
979    ("copyright", 747),
980    ("currency", 500),
981    ("d", 556),
982    ("dagger", 500),
983    ("daggerdbl", 500),
984    ("degree", 400),
985    ("dieresis", 333),
986    ("divide", 570),
987    ("dollar", 500),
988    ("dotaccent", 333),
989    ("dotlessi", 278),
990    ("e", 444),
991    ("eacute", 444),
992    ("ecircumflex", 444),
993    ("edieresis", 444),
994    ("egrave", 444),
995    ("eight", 500),
996    ("ellipsis", 1000),
997    ("emdash", 1000),
998    ("endash", 500),
999    ("equal", 570),
1000    ("eth", 500),
1001    ("exclam", 333),
1002    ("exclamdown", 333),
1003    ("f", 333),
1004    ("fi", 556),
1005    ("five", 500),
1006    ("fl", 556),
1007    ("florin", 500),
1008    ("four", 500),
1009    ("fraction", 167),
1010    ("g", 500),
1011    ("germandbls", 556),
1012    ("grave", 333),
1013    ("greater", 570),
1014    ("guillemotleft", 500),
1015    ("guillemotright", 500),
1016    ("guilsinglleft", 333),
1017    ("guilsinglright", 333),
1018    ("h", 556),
1019    ("hungarumlaut", 333),
1020    ("hyphen", 333),
1021    ("i", 278),
1022    ("iacute", 278),
1023    ("icircumflex", 278),
1024    ("idieresis", 278),
1025    ("igrave", 278),
1026    ("j", 333),
1027    ("k", 556),
1028    ("l", 278),
1029    ("less", 570),
1030    ("logicalnot", 570),
1031    ("lslash", 278),
1032    ("m", 833),
1033    ("macron", 333),
1034    ("minus", 570),
1035    ("mu", 556),
1036    ("multiply", 570),
1037    ("n", 556),
1038    ("nine", 500),
1039    ("ntilde", 556),
1040    ("numbersign", 500),
1041    ("o", 500),
1042    ("oacute", 500),
1043    ("ocircumflex", 500),
1044    ("odieresis", 500),
1045    ("oe", 722),
1046    ("ogonek", 333),
1047    ("ograve", 500),
1048    ("one", 500),
1049    ("onehalf", 750),
1050    ("onequarter", 750),
1051    ("onesuperior", 300),
1052    ("ordfeminine", 300),
1053    ("ordmasculine", 330),
1054    ("oslash", 500),
1055    ("otilde", 500),
1056    ("p", 556),
1057    ("paragraph", 540),
1058    ("parenleft", 333),
1059    ("parenright", 333),
1060    ("percent", 1000),
1061    ("period", 250),
1062    ("periodcentered", 250),
1063    ("perthousand", 1000),
1064    ("plus", 570),
1065    ("plusminus", 570),
1066    ("q", 556),
1067    ("question", 500),
1068    ("questiondown", 500),
1069    ("quotedbl", 555),
1070    ("quotedblbase", 500),
1071    ("quotedblleft", 500),
1072    ("quotedblright", 500),
1073    ("quoteleft", 333),
1074    ("quoteright", 333),
1075    ("quotesinglbase", 333),
1076    ("quotesingle", 278),
1077    ("r", 444),
1078    ("registered", 747),
1079    ("ring", 333),
1080    ("s", 389),
1081    ("scaron", 389),
1082    ("section", 500),
1083    ("semicolon", 333),
1084    ("seven", 500),
1085    ("six", 500),
1086    ("slash", 278),
1087    ("space", 250),
1088    ("sterling", 500),
1089    ("t", 333),
1090    ("thorn", 556),
1091    ("three", 500),
1092    ("threequarters", 750),
1093    ("threesuperior", 300),
1094    ("tilde", 333),
1095    ("trademark", 1000),
1096    ("two", 500),
1097    ("twosuperior", 300),
1098    ("u", 556),
1099    ("uacute", 556),
1100    ("ucircumflex", 556),
1101    ("udieresis", 556),
1102    ("ugrave", 556),
1103    ("underscore", 500),
1104    ("v", 500),
1105    ("w", 722),
1106    ("x", 500),
1107    ("y", 500),
1108    ("yacute", 500),
1109    ("ydieresis", 500),
1110    ("yen", 500),
1111    ("z", 444),
1112    ("zcaron", 444),
1113    ("zero", 500),
1114];
1115
1116/// `Times Italic` glyph widths, sorted by
1117/// glyph name for binary search (Adobe Core-14 AFM metrics).
1118#[rustfmt::skip]
1119const TIMES_ITALIC: &[(&str, u16)] = &[
1120    ("A", 611),
1121    ("AE", 889),
1122    ("Aacute", 611),
1123    ("Acircumflex", 611),
1124    ("Adieresis", 611),
1125    ("Agrave", 611),
1126    ("Aring", 611),
1127    ("Atilde", 611),
1128    ("B", 611),
1129    ("C", 667),
1130    ("Ccedilla", 667),
1131    ("D", 722),
1132    ("E", 611),
1133    ("Eacute", 611),
1134    ("Ecircumflex", 611),
1135    ("Edieresis", 611),
1136    ("Egrave", 611),
1137    ("Eth", 722),
1138    ("F", 611),
1139    ("G", 722),
1140    ("H", 722),
1141    ("I", 333),
1142    ("Iacute", 333),
1143    ("Icircumflex", 333),
1144    ("Idieresis", 333),
1145    ("Igrave", 333),
1146    ("J", 444),
1147    ("K", 667),
1148    ("L", 556),
1149    ("Lslash", 556),
1150    ("M", 833),
1151    ("N", 667),
1152    ("Ntilde", 667),
1153    ("O", 722),
1154    ("OE", 944),
1155    ("Oacute", 722),
1156    ("Ocircumflex", 722),
1157    ("Odieresis", 722),
1158    ("Ograve", 722),
1159    ("Oslash", 722),
1160    ("Otilde", 722),
1161    ("P", 611),
1162    ("Q", 722),
1163    ("R", 611),
1164    ("S", 500),
1165    ("Scaron", 500),
1166    ("T", 556),
1167    ("Thorn", 611),
1168    ("U", 722),
1169    ("Uacute", 722),
1170    ("Ucircumflex", 722),
1171    ("Udieresis", 722),
1172    ("Ugrave", 722),
1173    ("V", 611),
1174    ("W", 833),
1175    ("X", 611),
1176    ("Y", 556),
1177    ("Yacute", 556),
1178    ("Ydieresis", 556),
1179    ("Z", 556),
1180    ("Zcaron", 556),
1181    ("a", 500),
1182    ("aacute", 500),
1183    ("acircumflex", 500),
1184    ("acute", 333),
1185    ("adieresis", 500),
1186    ("ae", 667),
1187    ("agrave", 500),
1188    ("ampersand", 778),
1189    ("aring", 500),
1190    ("asciicircum", 422),
1191    ("asciitilde", 541),
1192    ("asterisk", 500),
1193    ("at", 920),
1194    ("atilde", 500),
1195    ("b", 500),
1196    ("backslash", 278),
1197    ("bar", 275),
1198    ("braceleft", 400),
1199    ("braceright", 400),
1200    ("bracketleft", 389),
1201    ("bracketright", 389),
1202    ("breve", 333),
1203    ("brokenbar", 275),
1204    ("bullet", 350),
1205    ("c", 444),
1206    ("caron", 333),
1207    ("ccedilla", 444),
1208    ("cedilla", 333),
1209    ("cent", 500),
1210    ("circumflex", 333),
1211    ("colon", 333),
1212    ("comma", 250),
1213    ("copyright", 760),
1214    ("currency", 500),
1215    ("d", 500),
1216    ("dagger", 500),
1217    ("daggerdbl", 500),
1218    ("degree", 400),
1219    ("dieresis", 333),
1220    ("divide", 675),
1221    ("dollar", 500),
1222    ("dotaccent", 333),
1223    ("dotlessi", 278),
1224    ("e", 444),
1225    ("eacute", 444),
1226    ("ecircumflex", 444),
1227    ("edieresis", 444),
1228    ("egrave", 444),
1229    ("eight", 500),
1230    ("ellipsis", 889),
1231    ("emdash", 889),
1232    ("endash", 500),
1233    ("equal", 675),
1234    ("eth", 500),
1235    ("exclam", 333),
1236    ("exclamdown", 389),
1237    ("f", 278),
1238    ("fi", 500),
1239    ("five", 500),
1240    ("fl", 500),
1241    ("florin", 500),
1242    ("four", 500),
1243    ("fraction", 167),
1244    ("g", 500),
1245    ("germandbls", 500),
1246    ("grave", 333),
1247    ("greater", 675),
1248    ("guillemotleft", 500),
1249    ("guillemotright", 500),
1250    ("guilsinglleft", 333),
1251    ("guilsinglright", 333),
1252    ("h", 500),
1253    ("hungarumlaut", 333),
1254    ("hyphen", 333),
1255    ("i", 278),
1256    ("iacute", 278),
1257    ("icircumflex", 278),
1258    ("idieresis", 278),
1259    ("igrave", 278),
1260    ("j", 278),
1261    ("k", 444),
1262    ("l", 278),
1263    ("less", 675),
1264    ("logicalnot", 675),
1265    ("lslash", 278),
1266    ("m", 722),
1267    ("macron", 333),
1268    ("minus", 675),
1269    ("mu", 500),
1270    ("multiply", 675),
1271    ("n", 500),
1272    ("nine", 500),
1273    ("ntilde", 500),
1274    ("numbersign", 500),
1275    ("o", 500),
1276    ("oacute", 500),
1277    ("ocircumflex", 500),
1278    ("odieresis", 500),
1279    ("oe", 667),
1280    ("ogonek", 333),
1281    ("ograve", 500),
1282    ("one", 500),
1283    ("onehalf", 750),
1284    ("onequarter", 750),
1285    ("onesuperior", 300),
1286    ("ordfeminine", 276),
1287    ("ordmasculine", 310),
1288    ("oslash", 500),
1289    ("otilde", 500),
1290    ("p", 500),
1291    ("paragraph", 523),
1292    ("parenleft", 333),
1293    ("parenright", 333),
1294    ("percent", 833),
1295    ("period", 250),
1296    ("periodcentered", 250),
1297    ("perthousand", 1000),
1298    ("plus", 675),
1299    ("plusminus", 675),
1300    ("q", 500),
1301    ("question", 500),
1302    ("questiondown", 500),
1303    ("quotedbl", 420),
1304    ("quotedblbase", 556),
1305    ("quotedblleft", 556),
1306    ("quotedblright", 556),
1307    ("quoteleft", 333),
1308    ("quoteright", 333),
1309    ("quotesinglbase", 333),
1310    ("quotesingle", 214),
1311    ("r", 389),
1312    ("registered", 760),
1313    ("ring", 333),
1314    ("s", 389),
1315    ("scaron", 389),
1316    ("section", 500),
1317    ("semicolon", 333),
1318    ("seven", 500),
1319    ("six", 500),
1320    ("slash", 278),
1321    ("space", 250),
1322    ("sterling", 500),
1323    ("t", 278),
1324    ("thorn", 500),
1325    ("three", 500),
1326    ("threequarters", 750),
1327    ("threesuperior", 300),
1328    ("tilde", 333),
1329    ("trademark", 980),
1330    ("two", 500),
1331    ("twosuperior", 300),
1332    ("u", 500),
1333    ("uacute", 500),
1334    ("ucircumflex", 500),
1335    ("udieresis", 500),
1336    ("ugrave", 500),
1337    ("underscore", 500),
1338    ("v", 444),
1339    ("w", 667),
1340    ("x", 444),
1341    ("y", 444),
1342    ("yacute", 444),
1343    ("ydieresis", 444),
1344    ("yen", 500),
1345    ("z", 389),
1346    ("zcaron", 389),
1347    ("zero", 500),
1348];
1349
1350/// `Times Bold Italic` glyph widths, sorted by
1351/// glyph name for binary search (Adobe Core-14 AFM metrics).
1352#[rustfmt::skip]
1353const TIMES_BOLD_ITALIC: &[(&str, u16)] = &[
1354    ("A", 667),
1355    ("AE", 944),
1356    ("Aacute", 667),
1357    ("Acircumflex", 667),
1358    ("Adieresis", 667),
1359    ("Agrave", 667),
1360    ("Aring", 667),
1361    ("Atilde", 667),
1362    ("B", 667),
1363    ("C", 667),
1364    ("Ccedilla", 667),
1365    ("D", 722),
1366    ("E", 667),
1367    ("Eacute", 667),
1368    ("Ecircumflex", 667),
1369    ("Edieresis", 667),
1370    ("Egrave", 667),
1371    ("Eth", 722),
1372    ("F", 667),
1373    ("G", 722),
1374    ("H", 778),
1375    ("I", 389),
1376    ("Iacute", 389),
1377    ("Icircumflex", 389),
1378    ("Idieresis", 389),
1379    ("Igrave", 389),
1380    ("J", 500),
1381    ("K", 667),
1382    ("L", 611),
1383    ("Lslash", 611),
1384    ("M", 889),
1385    ("N", 722),
1386    ("Ntilde", 722),
1387    ("O", 722),
1388    ("OE", 944),
1389    ("Oacute", 722),
1390    ("Ocircumflex", 722),
1391    ("Odieresis", 722),
1392    ("Ograve", 722),
1393    ("Oslash", 722),
1394    ("Otilde", 722),
1395    ("P", 611),
1396    ("Q", 722),
1397    ("R", 667),
1398    ("S", 556),
1399    ("Scaron", 556),
1400    ("T", 611),
1401    ("Thorn", 611),
1402    ("U", 722),
1403    ("Uacute", 722),
1404    ("Ucircumflex", 722),
1405    ("Udieresis", 722),
1406    ("Ugrave", 722),
1407    ("V", 667),
1408    ("W", 889),
1409    ("X", 667),
1410    ("Y", 611),
1411    ("Yacute", 611),
1412    ("Ydieresis", 611),
1413    ("Z", 611),
1414    ("Zcaron", 611),
1415    ("a", 500),
1416    ("aacute", 500),
1417    ("acircumflex", 500),
1418    ("acute", 333),
1419    ("adieresis", 500),
1420    ("ae", 722),
1421    ("agrave", 500),
1422    ("ampersand", 778),
1423    ("aring", 500),
1424    ("asciicircum", 570),
1425    ("asciitilde", 570),
1426    ("asterisk", 500),
1427    ("at", 832),
1428    ("atilde", 500),
1429    ("b", 500),
1430    ("backslash", 278),
1431    ("bar", 220),
1432    ("braceleft", 348),
1433    ("braceright", 348),
1434    ("bracketleft", 333),
1435    ("bracketright", 333),
1436    ("breve", 333),
1437    ("brokenbar", 220),
1438    ("bullet", 350),
1439    ("c", 444),
1440    ("caron", 333),
1441    ("ccedilla", 444),
1442    ("cedilla", 333),
1443    ("cent", 500),
1444    ("circumflex", 333),
1445    ("colon", 333),
1446    ("comma", 250),
1447    ("copyright", 747),
1448    ("currency", 500),
1449    ("d", 500),
1450    ("dagger", 500),
1451    ("daggerdbl", 500),
1452    ("degree", 400),
1453    ("dieresis", 333),
1454    ("divide", 570),
1455    ("dollar", 500),
1456    ("dotaccent", 333),
1457    ("dotlessi", 278),
1458    ("e", 444),
1459    ("eacute", 444),
1460    ("ecircumflex", 444),
1461    ("edieresis", 444),
1462    ("egrave", 444),
1463    ("eight", 500),
1464    ("ellipsis", 1000),
1465    ("emdash", 1000),
1466    ("endash", 500),
1467    ("equal", 570),
1468    ("eth", 500),
1469    ("exclam", 389),
1470    ("exclamdown", 389),
1471    ("f", 333),
1472    ("fi", 556),
1473    ("five", 500),
1474    ("fl", 556),
1475    ("florin", 500),
1476    ("four", 500),
1477    ("fraction", 167),
1478    ("g", 500),
1479    ("germandbls", 500),
1480    ("grave", 333),
1481    ("greater", 570),
1482    ("guillemotleft", 500),
1483    ("guillemotright", 500),
1484    ("guilsinglleft", 333),
1485    ("guilsinglright", 333),
1486    ("h", 556),
1487    ("hungarumlaut", 333),
1488    ("hyphen", 333),
1489    ("i", 278),
1490    ("iacute", 278),
1491    ("icircumflex", 278),
1492    ("idieresis", 278),
1493    ("igrave", 278),
1494    ("j", 278),
1495    ("k", 500),
1496    ("l", 278),
1497    ("less", 570),
1498    ("logicalnot", 606),
1499    ("lslash", 278),
1500    ("m", 778),
1501    ("macron", 333),
1502    ("minus", 606),
1503    ("mu", 576),
1504    ("multiply", 570),
1505    ("n", 556),
1506    ("nine", 500),
1507    ("ntilde", 556),
1508    ("numbersign", 500),
1509    ("o", 500),
1510    ("oacute", 500),
1511    ("ocircumflex", 500),
1512    ("odieresis", 500),
1513    ("oe", 722),
1514    ("ogonek", 333),
1515    ("ograve", 500),
1516    ("one", 500),
1517    ("onehalf", 750),
1518    ("onequarter", 750),
1519    ("onesuperior", 300),
1520    ("ordfeminine", 266),
1521    ("ordmasculine", 300),
1522    ("oslash", 500),
1523    ("otilde", 500),
1524    ("p", 500),
1525    ("paragraph", 500),
1526    ("parenleft", 333),
1527    ("parenright", 333),
1528    ("percent", 833),
1529    ("period", 250),
1530    ("periodcentered", 250),
1531    ("perthousand", 1000),
1532    ("plus", 570),
1533    ("plusminus", 570),
1534    ("q", 500),
1535    ("question", 500),
1536    ("questiondown", 500),
1537    ("quotedbl", 555),
1538    ("quotedblbase", 500),
1539    ("quotedblleft", 500),
1540    ("quotedblright", 500),
1541    ("quoteleft", 333),
1542    ("quoteright", 333),
1543    ("quotesinglbase", 333),
1544    ("quotesingle", 278),
1545    ("r", 389),
1546    ("registered", 747),
1547    ("ring", 333),
1548    ("s", 389),
1549    ("scaron", 389),
1550    ("section", 500),
1551    ("semicolon", 333),
1552    ("seven", 500),
1553    ("six", 500),
1554    ("slash", 278),
1555    ("space", 250),
1556    ("sterling", 500),
1557    ("t", 278),
1558    ("thorn", 500),
1559    ("three", 500),
1560    ("threequarters", 750),
1561    ("threesuperior", 300),
1562    ("tilde", 333),
1563    ("trademark", 1000),
1564    ("two", 500),
1565    ("twosuperior", 300),
1566    ("u", 556),
1567    ("uacute", 556),
1568    ("ucircumflex", 556),
1569    ("udieresis", 556),
1570    ("ugrave", 556),
1571    ("underscore", 500),
1572    ("v", 444),
1573    ("w", 667),
1574    ("x", 500),
1575    ("y", 444),
1576    ("yacute", 444),
1577    ("ydieresis", 444),
1578    ("yen", 500),
1579    ("z", 389),
1580    ("zcaron", 389),
1581    ("zero", 500),
1582];
1583
1584/// `Symbol` glyph widths, sorted by
1585/// glyph name for binary search (Adobe Core-14 AFM metrics).
1586#[rustfmt::skip]
1587const SYMBOL: &[(&str, u16)] = &[
1588    ("Alpha", 722),
1589    ("Beta", 667),
1590    ("Chi", 722),
1591    ("Delta", 612),
1592    ("Epsilon", 611),
1593    ("Eta", 722),
1594    ("Euro", 750),
1595    ("Gamma", 603),
1596    ("Ifraktur", 686),
1597    ("Iota", 333),
1598    ("Kappa", 722),
1599    ("Lambda", 686),
1600    ("Mu", 889),
1601    ("Nu", 722),
1602    ("Omega", 768),
1603    ("Omicron", 722),
1604    ("Phi", 763),
1605    ("Pi", 768),
1606    ("Psi", 795),
1607    ("Rfraktur", 795),
1608    ("Rho", 556),
1609    ("Sigma", 592),
1610    ("Tau", 611),
1611    ("Theta", 741),
1612    ("Upsilon", 690),
1613    ("Upsilon1", 620),
1614    ("Xi", 645),
1615    ("Zeta", 611),
1616    ("aleph", 823),
1617    ("alpha", 631),
1618    ("ampersand", 778),
1619    ("angle", 768),
1620    ("angleleft", 329),
1621    ("angleright", 329),
1622    ("apple", 790),
1623    ("approxequal", 549),
1624    ("arrowboth", 1042),
1625    ("arrowdblboth", 1042),
1626    ("arrowdbldown", 603),
1627    ("arrowdblleft", 987),
1628    ("arrowdblright", 987),
1629    ("arrowdblup", 603),
1630    ("arrowdown", 603),
1631    ("arrowhorizex", 1000),
1632    ("arrowleft", 987),
1633    ("arrowright", 987),
1634    ("arrowup", 603),
1635    ("arrowvertex", 603),
1636    ("asteriskmath", 500),
1637    ("bar", 200),
1638    ("beta", 549),
1639    ("braceex", 494),
1640    ("braceleft", 480),
1641    ("braceleftbt", 494),
1642    ("braceleftmid", 494),
1643    ("bracelefttp", 494),
1644    ("braceright", 480),
1645    ("bracerightbt", 494),
1646    ("bracerightmid", 494),
1647    ("bracerighttp", 494),
1648    ("bracketleft", 333),
1649    ("bracketleftbt", 384),
1650    ("bracketleftex", 384),
1651    ("bracketlefttp", 384),
1652    ("bracketright", 333),
1653    ("bracketrightbt", 384),
1654    ("bracketrightex", 384),
1655    ("bracketrighttp", 384),
1656    ("bullet", 460),
1657    ("carriagereturn", 658),
1658    ("chi", 549),
1659    ("circlemultiply", 768),
1660    ("circleplus", 768),
1661    ("club", 753),
1662    ("colon", 278),
1663    ("comma", 250),
1664    ("congruent", 549),
1665    ("copyrightsans", 790),
1666    ("copyrightserif", 790),
1667    ("degree", 400),
1668    ("delta", 494),
1669    ("diamond", 753),
1670    ("divide", 549),
1671    ("dotmath", 250),
1672    ("eight", 500),
1673    ("element", 713),
1674    ("ellipsis", 1000),
1675    ("emptyset", 823),
1676    ("epsilon", 439),
1677    ("equal", 549),
1678    ("equivalence", 549),
1679    ("eta", 603),
1680    ("exclam", 333),
1681    ("existential", 549),
1682    ("five", 500),
1683    ("florin", 500),
1684    ("four", 500),
1685    ("fraction", 167),
1686    ("gamma", 411),
1687    ("gradient", 713),
1688    ("greater", 549),
1689    ("greaterequal", 549),
1690    ("heart", 753),
1691    ("infinity", 713),
1692    ("integral", 274),
1693    ("integralbt", 686),
1694    ("integralex", 686),
1695    ("integraltp", 686),
1696    ("intersection", 768),
1697    ("iota", 329),
1698    ("kappa", 549),
1699    ("lambda", 549),
1700    ("less", 549),
1701    ("lessequal", 549),
1702    ("logicaland", 603),
1703    ("logicalnot", 713),
1704    ("logicalor", 603),
1705    ("lozenge", 494),
1706    ("minus", 549),
1707    ("minute", 247),
1708    ("mu", 576),
1709    ("multiply", 549),
1710    ("nine", 500),
1711    ("notelement", 713),
1712    ("notequal", 549),
1713    ("notsubset", 713),
1714    ("nu", 521),
1715    ("numbersign", 500),
1716    ("omega", 686),
1717    ("omega1", 713),
1718    ("omicron", 549),
1719    ("one", 500),
1720    ("parenleft", 333),
1721    ("parenleftbt", 384),
1722    ("parenleftex", 384),
1723    ("parenlefttp", 384),
1724    ("parenright", 333),
1725    ("parenrightbt", 384),
1726    ("parenrightex", 384),
1727    ("parenrighttp", 384),
1728    ("partialdiff", 494),
1729    ("percent", 833),
1730    ("period", 250),
1731    ("perpendicular", 658),
1732    ("phi", 521),
1733    ("phi1", 603),
1734    ("pi", 549),
1735    ("plus", 549),
1736    ("plusminus", 549),
1737    ("product", 823),
1738    ("propersubset", 713),
1739    ("propersuperset", 713),
1740    ("proportional", 713),
1741    ("psi", 686),
1742    ("question", 444),
1743    ("radical", 549),
1744    ("radicalex", 500),
1745    ("reflexsubset", 713),
1746    ("reflexsuperset", 713),
1747    ("registersans", 790),
1748    ("registerserif", 790),
1749    ("rho", 549),
1750    ("second", 411),
1751    ("semicolon", 278),
1752    ("seven", 500),
1753    ("sigma", 603),
1754    ("sigma1", 439),
1755    ("similar", 549),
1756    ("six", 500),
1757    ("slash", 278),
1758    ("space", 250),
1759    ("spade", 753),
1760    ("suchthat", 439),
1761    ("summation", 713),
1762    ("tau", 439),
1763    ("therefore", 863),
1764    ("theta", 521),
1765    ("theta1", 631),
1766    ("three", 500),
1767    ("trademarksans", 786),
1768    ("trademarkserif", 890),
1769    ("two", 500),
1770    ("underscore", 500),
1771    ("union", 768),
1772    ("universal", 713),
1773    ("upsilon", 576),
1774    ("weierstrass", 987),
1775    ("xi", 493),
1776    ("zero", 500),
1777    ("zeta", 494),
1778];
1779
1780/// `ZapfDingbats` glyph widths, sorted by
1781/// glyph name for binary search (Adobe Core-14 AFM metrics).
1782#[rustfmt::skip]
1783const ZAPF_DINGBATS: &[(&str, u16)] = &[
1784    ("a1", 974),
1785    ("a10", 692),
1786    ("a100", 668),
1787    ("a101", 732),
1788    ("a102", 544),
1789    ("a103", 544),
1790    ("a104", 910),
1791    ("a105", 911),
1792    ("a106", 667),
1793    ("a107", 760),
1794    ("a108", 760),
1795    ("a109", 626),
1796    ("a11", 960),
1797    ("a110", 694),
1798    ("a111", 595),
1799    ("a112", 776),
1800    ("a117", 690),
1801    ("a118", 791),
1802    ("a119", 790),
1803    ("a12", 939),
1804    ("a120", 788),
1805    ("a121", 788),
1806    ("a122", 788),
1807    ("a123", 788),
1808    ("a124", 788),
1809    ("a125", 788),
1810    ("a126", 788),
1811    ("a127", 788),
1812    ("a128", 788),
1813    ("a129", 788),
1814    ("a13", 549),
1815    ("a130", 788),
1816    ("a131", 788),
1817    ("a132", 788),
1818    ("a133", 788),
1819    ("a134", 788),
1820    ("a135", 788),
1821    ("a136", 788),
1822    ("a137", 788),
1823    ("a138", 788),
1824    ("a139", 788),
1825    ("a14", 855),
1826    ("a140", 788),
1827    ("a141", 788),
1828    ("a142", 788),
1829    ("a143", 788),
1830    ("a144", 788),
1831    ("a145", 788),
1832    ("a146", 788),
1833    ("a147", 788),
1834    ("a148", 788),
1835    ("a149", 788),
1836    ("a15", 911),
1837    ("a150", 788),
1838    ("a151", 788),
1839    ("a152", 788),
1840    ("a153", 788),
1841    ("a154", 788),
1842    ("a155", 788),
1843    ("a156", 788),
1844    ("a157", 788),
1845    ("a158", 788),
1846    ("a159", 788),
1847    ("a16", 933),
1848    ("a160", 894),
1849    ("a161", 838),
1850    ("a162", 924),
1851    ("a163", 1016),
1852    ("a164", 458),
1853    ("a165", 924),
1854    ("a166", 918),
1855    ("a167", 927),
1856    ("a168", 928),
1857    ("a169", 928),
1858    ("a17", 945),
1859    ("a170", 834),
1860    ("a171", 873),
1861    ("a172", 828),
1862    ("a173", 924),
1863    ("a174", 917),
1864    ("a175", 930),
1865    ("a176", 931),
1866    ("a177", 463),
1867    ("a178", 883),
1868    ("a179", 836),
1869    ("a18", 974),
1870    ("a180", 867),
1871    ("a181", 696),
1872    ("a182", 874),
1873    ("a183", 760),
1874    ("a184", 946),
1875    ("a185", 865),
1876    ("a186", 967),
1877    ("a187", 831),
1878    ("a188", 873),
1879    ("a189", 927),
1880    ("a19", 755),
1881    ("a190", 970),
1882    ("a191", 918),
1883    ("a192", 748),
1884    ("a193", 836),
1885    ("a194", 771),
1886    ("a195", 888),
1887    ("a196", 748),
1888    ("a197", 771),
1889    ("a198", 888),
1890    ("a199", 867),
1891    ("a2", 961),
1892    ("a20", 846),
1893    ("a200", 696),
1894    ("a201", 874),
1895    ("a202", 974),
1896    ("a203", 762),
1897    ("a204", 759),
1898    ("a205", 509),
1899    ("a206", 410),
1900    ("a21", 762),
1901    ("a22", 761),
1902    ("a23", 571),
1903    ("a24", 677),
1904    ("a25", 763),
1905    ("a26", 760),
1906    ("a27", 759),
1907    ("a28", 754),
1908    ("a29", 786),
1909    ("a3", 980),
1910    ("a30", 788),
1911    ("a31", 788),
1912    ("a32", 790),
1913    ("a33", 793),
1914    ("a34", 794),
1915    ("a35", 816),
1916    ("a36", 823),
1917    ("a37", 789),
1918    ("a38", 841),
1919    ("a39", 823),
1920    ("a4", 719),
1921    ("a40", 833),
1922    ("a41", 816),
1923    ("a42", 831),
1924    ("a43", 923),
1925    ("a44", 744),
1926    ("a45", 723),
1927    ("a46", 749),
1928    ("a47", 790),
1929    ("a48", 792),
1930    ("a49", 695),
1931    ("a5", 789),
1932    ("a50", 776),
1933    ("a51", 768),
1934    ("a52", 792),
1935    ("a53", 759),
1936    ("a54", 707),
1937    ("a55", 708),
1938    ("a56", 682),
1939    ("a57", 701),
1940    ("a58", 826),
1941    ("a59", 815),
1942    ("a6", 494),
1943    ("a60", 789),
1944    ("a61", 789),
1945    ("a62", 707),
1946    ("a63", 687),
1947    ("a64", 696),
1948    ("a65", 689),
1949    ("a66", 786),
1950    ("a67", 787),
1951    ("a68", 713),
1952    ("a69", 791),
1953    ("a7", 552),
1954    ("a70", 785),
1955    ("a71", 791),
1956    ("a72", 873),
1957    ("a73", 761),
1958    ("a74", 762),
1959    ("a75", 759),
1960    ("a76", 892),
1961    ("a77", 892),
1962    ("a78", 788),
1963    ("a79", 784),
1964    ("a8", 537),
1965    ("a81", 438),
1966    ("a82", 138),
1967    ("a83", 277),
1968    ("a84", 415),
1969    ("a85", 509),
1970    ("a86", 410),
1971    ("a87", 234),
1972    ("a88", 234),
1973    ("a89", 390),
1974    ("a9", 577),
1975    ("a90", 390),
1976    ("a91", 276),
1977    ("a92", 276),
1978    ("a93", 317),
1979    ("a94", 317),
1980    ("a95", 334),
1981    ("a96", 334),
1982    ("a97", 392),
1983    ("a98", 392),
1984    ("a99", 668),
1985    ("space", 278),
1986];
1987
1988#[cfg(test)]
1989mod tests {
1990    use super::*;
1991
1992    // Covers ISO 32000-1 §9.6.2.2.
1993    #[test]
1994    fn standard_14_known_widths() {
1995        assert_eq!(standard_14_width("Helvetica", "space"), Some(278.0));
1996        assert_eq!(standard_14_width("Helvetica", "A"), Some(667.0));
1997        assert_eq!(standard_14_width("Helvetica-Bold", "A"), Some(722.0));
1998        assert_eq!(standard_14_width("Times-Roman", "A"), Some(722.0));
1999        assert_eq!(standard_14_width("Times-Italic", "a"), Some(500.0));
2000        // Courier is monospaced: every glyph is 600 units wide.
2001        assert_eq!(standard_14_width("Courier", "A"), Some(600.0));
2002        assert_eq!(standard_14_width("Courier-BoldOblique", "m"), Some(600.0));
2003        // Oblique variants share their upright counterpart's widths.
2004        assert_eq!(
2005            standard_14_width("Helvetica-Oblique", "A"),
2006            standard_14_width("Helvetica", "A")
2007        );
2008        assert_eq!(
2009            standard_14_width("Helvetica-BoldOblique", "A"),
2010            standard_14_width("Helvetica-Bold", "A")
2011        );
2012    }
2013
2014    // Covers ISO 32000-1 §9.6.2.2 and §9.6.4.
2015    #[test]
2016    fn standard_14_aliases_and_non_members() {
2017        assert_eq!(standard_14_width("Arial", "space"), Some(278.0)); // Arial -> Helvetica
2018        assert_eq!(standard_14_width("ABCDEF+Times-Bold", "A"), Some(722.0)); // subset prefix stripped
2019        assert_eq!(standard_14_width("TimesNewRomanPSMT", "A"), Some(722.0)); // TrueType alias -> Times-Roman
2020        assert_eq!(standard_14_width("CourierNewPS-BoldMT", "A"), Some(600.0)); // TrueType alias -> Courier-Bold
2021        assert!(standard_14_width("SomeEmbeddedFont", "A").is_none());
2022        assert!(is_standard_14("Courier-Bold") && !is_standard_14("Comic Sans"));
2023        assert!(is_standard_14("Arial-BoldMT"));
2024        assert!(!is_standard_14("ZapfDingbats"));
2025        assert!(!is_standard_14("Symbol"));
2026    }
2027
2028    // Covers ISO 32000-1 §9.6.2.2, Annex D.5 and Annex D.6.
2029    #[test]
2030    fn symbol_and_zapf_dingbats_widths() {
2031        assert_eq!(standard_14_width("Symbol", "alpha"), Some(631.0));
2032        assert_eq!(standard_14_width("Symbol", "exclam"), Some(333.0));
2033        assert_eq!(standard_14_width("Symbol", "arrowright"), Some(987.0));
2034        assert_eq!(standard_14_width("ABCDEF+Symbol", "Omega"), Some(768.0));
2035        assert_eq!(standard_14_width("ZapfDingbats", "a1"), Some(974.0));
2036        assert_eq!(standard_14_width("ZapfDingbats", "a161"), Some(838.0));
2037        assert_eq!(standard_14_width("ZapfDingbats", "space"), Some(278.0));
2038        assert!(standard_14_width("Symbol", "A").is_none());
2039        assert!(standard_14_width("ZapfDingbats", "alpha").is_none());
2040        assert!(standard_14_width("SymbolMT", "alpha").is_none());
2041    }
2042
2043    #[test]
2044    fn every_symbolic_encoding_glyph_has_a_width() {
2045        for code in 0u8..=255 {
2046            if let Some(name) = crate::symbol_glyph_name(code) {
2047                assert!(standard_14_width("Symbol", name).is_some(), "{name}");
2048            }
2049            if let Some(name) = crate::zapf_dingbats_glyph_name(code) {
2050                assert!(standard_14_width("ZapfDingbats", name).is_some(), "{name}");
2051            }
2052        }
2053    }
2054
2055    #[test]
2056    fn width_tables_are_sorted_for_binary_search() {
2057        for table in [
2058            HELVETICA,
2059            HELVETICA_BOLD,
2060            TIMES_ROMAN,
2061            TIMES_BOLD,
2062            TIMES_ITALIC,
2063            TIMES_BOLD_ITALIC,
2064            SYMBOL,
2065            ZAPF_DINGBATS,
2066        ] {
2067            assert!(table.windows(2).all(|pair| pair[0].0 < pair[1].0));
2068        }
2069    }
2070
2071    // Review-fix regression: `classify()` must reject metrically-distinct
2072    // siblings that merely share a standard-14 prefix (see module docs on
2073    // `classify`), rather than silently returning a wrong-but-plausible
2074    // Core-14 width.
2075    #[test]
2076    fn standard_14_review_fix_positive() {
2077        assert_eq!(standard_14_width("Helvetica-Bold", "A"), Some(722.0));
2078        assert_eq!(standard_14_width("Arial-BoldMT", "space"), Some(278.0));
2079        assert!(standard_14_width("TimesNewRomanPS-BoldItalicMT", "A").is_some());
2080        assert_eq!(standard_14_width("CourierNew-Bold", "x"), Some(600.0));
2081        // Internal spaces are handled (stripped before stem matching).
2082        assert!(standard_14_width("TimesNewRoman", "A").is_some());
2083        assert!(standard_14_width("Times New Roman", "A").is_some());
2084    }
2085
2086    #[test]
2087    fn standard_14_rejects_metrically_distinct_siblings() {
2088        assert!(standard_14_width("Helvetica-Narrow", "A").is_none());
2089        assert!(standard_14_width("HelveticaNeue-Bold", "A").is_none());
2090        assert!(standard_14_width("Helvetica Neue", "A").is_none());
2091        assert!(standard_14_width("TimesTen-Bold", "A").is_none());
2092        assert!(standard_14_width("Helvetica-Light", "A").is_none());
2093        assert!(standard_14_width("Times New Roman Condensed", "A").is_none());
2094    }
2095
2096    #[test]
2097    fn standard_14_classify_case_folds() {
2098        // classify() lowercases internally, same as
2099        // `FaceRequest::from_font_dict`'s normalization.
2100        assert_eq!(standard_14_width("arial-bold", "A"), Some(722.0));
2101    }
2102}