oxideav-ttf 0.1.8

Pure-Rust TrueType font parser for the oxideav framework — sfnt + cmap + glyf + hmtx + GSUB ligatures + GPOS kerning
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
//! Integration coverage for the `BASE` accessors on
//! [`oxideav_ttf::Font`].
//!
//! Three paths:
//!
//! * **Absent path** — DejaVu Sans Mono / DejaVu Sans / Inter, all of
//!   which do not ship `BASE`. Every accessor must return `None`.
//!
//! * **HorizAxis-only synthetic** — a TrueType-flavoured sfnt that
//!   carries a `BASE` table with one HorizAxis whose BaseTagList is
//!   the alphabetical `ideo` / `romn` pair and whose BaseScriptList
//!   has two entries (`hani` / `latn`) — exactly the shape §6.3.1.3
//!   prescribes for a Latin-on-CJK dominant-run setup. We verify the
//!   table parses, the per-script accessors surface the correct
//!   coordinate for the right baseline, and unknown script / baseline
//!   tags decline cleanly.
//!
//! * **HorizAxis + VertAxis synthetic** — adds a VertAxis with the
//!   `ideo` / `romn` baselines flipped to vertical X coordinates, and
//!   confirms the `base_vert_x_for_script_baseline` accessor walks
//!   the VertAxis tree independently of the horizontal one. §6.3.1.3
//!   notes that the HorizAxis carries Y values and the VertAxis carries
//!   X values; the same tag can mean different baselines in each
//!   direction.

use oxideav_ttf::Font;

const DEJAVU_MONO: &[u8] = include_bytes!("fixtures/DejaVuSansMono.ttf");
const DEJAVU_SANS: &[u8] = include_bytes!("fixtures/DejaVuSans.ttf");
const INTER: &[u8] = include_bytes!("fixtures/InterVariable.ttf");

#[test]
fn dejavu_mono_has_no_base() {
    let f = Font::from_bytes(DEJAVU_MONO).unwrap();
    assert!(!f.has_base());
    assert!(f.base_table().is_none());
    assert!(f
        .base_horiz_y_for_script_baseline(*b"latn", *b"romn")
        .is_none());
    assert!(f
        .base_vert_x_for_script_baseline(*b"latn", *b"romn")
        .is_none());
}

#[test]
fn dejavu_sans_has_no_base() {
    let f = Font::from_bytes(DEJAVU_SANS).unwrap();
    assert!(!f.has_base());
}

#[test]
fn inter_has_no_base() {
    let f = Font::from_bytes(INTER).unwrap();
    assert!(!f.has_base());
}

// ---- synthetic-font scaffolding ------------------------------------------

fn build_minimal_sfnt(tables: &[(&[u8; 4], Vec<u8>)]) -> Vec<u8> {
    let n = tables.len() as u16;
    let mut out = Vec::new();
    out.extend_from_slice(&0x00010000u32.to_be_bytes());
    out.extend_from_slice(&n.to_be_bytes());
    out.extend_from_slice(&0u16.to_be_bytes());
    out.extend_from_slice(&0u16.to_be_bytes());
    out.extend_from_slice(&0u16.to_be_bytes());

    let dir_size = 16usize * n as usize;
    let mut payload_offset = 12usize + dir_size;
    let mut records = Vec::with_capacity(n as usize);
    for (tag, payload) in tables {
        records.push((*tag, payload_offset as u32, payload.len() as u32));
        payload_offset += payload.len();
        while payload_offset % 4 != 0 {
            payload_offset += 1;
        }
    }
    for (tag, offset, length) in &records {
        out.extend_from_slice(tag.as_slice());
        out.extend_from_slice(&0u32.to_be_bytes());
        out.extend_from_slice(&offset.to_be_bytes());
        out.extend_from_slice(&length.to_be_bytes());
    }
    for (_tag, payload) in tables {
        out.extend_from_slice(payload);
        while out.len() % 4 != 0 {
            out.push(0);
        }
    }
    out
}

fn make_head(units_per_em: u16, index_to_loc_format: i16) -> Vec<u8> {
    let mut h = vec![0u8; 54];
    h[0..4].copy_from_slice(&0x00010000u32.to_be_bytes());
    h[4..8].copy_from_slice(&0x00010000u32.to_be_bytes());
    h[12..16].copy_from_slice(&0x5F0F3CF5u32.to_be_bytes());
    h[18..20].copy_from_slice(&units_per_em.to_be_bytes());
    h[50..52].copy_from_slice(&index_to_loc_format.to_be_bytes());
    h
}

fn make_hhea(num_h_metrics: u16) -> Vec<u8> {
    let mut h = vec![0u8; 36];
    h[0..4].copy_from_slice(&0x00010000u32.to_be_bytes());
    h[34..36].copy_from_slice(&num_h_metrics.to_be_bytes());
    h
}

fn make_maxp(num_glyphs: u16) -> Vec<u8> {
    let mut h = vec![0u8; 6];
    h[0..4].copy_from_slice(&0x00005000u32.to_be_bytes());
    h[4..6].copy_from_slice(&num_glyphs.to_be_bytes());
    h
}

fn make_cmap_empty() -> Vec<u8> {
    let mut out = Vec::new();
    out.extend_from_slice(&0u16.to_be_bytes());
    out.extend_from_slice(&1u16.to_be_bytes());
    out.extend_from_slice(&3u16.to_be_bytes());
    out.extend_from_slice(&1u16.to_be_bytes());
    out.extend_from_slice(&12u32.to_be_bytes());
    let mut sub = Vec::new();
    sub.extend_from_slice(&4u16.to_be_bytes());
    sub.extend_from_slice(&32u16.to_be_bytes());
    sub.extend_from_slice(&0u16.to_be_bytes());
    sub.extend_from_slice(&2u16.to_be_bytes());
    sub.extend_from_slice(&2u16.to_be_bytes());
    sub.extend_from_slice(&0u16.to_be_bytes());
    sub.extend_from_slice(&0u16.to_be_bytes());
    sub.extend_from_slice(&0xFFFFu16.to_be_bytes());
    sub.extend_from_slice(&0u16.to_be_bytes());
    sub.extend_from_slice(&0xFFFFu16.to_be_bytes());
    sub.extend_from_slice(&1u16.to_be_bytes());
    sub.extend_from_slice(&0u16.to_be_bytes());
    let total = sub.len() as u16;
    sub[2..4].copy_from_slice(&total.to_be_bytes());
    out.extend_from_slice(&sub);
    out
}

fn make_name_empty() -> Vec<u8> {
    let mut out = vec![0u8; 6];
    out[0..2].copy_from_slice(&0u16.to_be_bytes());
    out[2..4].copy_from_slice(&0u16.to_be_bytes());
    out[4..6].copy_from_slice(&6u16.to_be_bytes());
    out
}

fn make_hmtx(num_h_metrics: u16, num_glyphs: u16) -> Vec<u8> {
    let mut out = Vec::new();
    for _ in 0..num_h_metrics {
        out.extend_from_slice(&0u16.to_be_bytes());
        out.extend_from_slice(&0i16.to_be_bytes());
    }
    for _ in num_h_metrics..num_glyphs {
        out.extend_from_slice(&0i16.to_be_bytes());
    }
    out
}

fn make_loca_short(num_glyphs: u16) -> Vec<u8> {
    let mut out = Vec::new();
    for _ in 0..=num_glyphs {
        out.extend_from_slice(&0u16.to_be_bytes());
    }
    out
}

fn make_glyf_empty() -> Vec<u8> {
    vec![0u8; 2]
}

// ---- BASE-table builders -------------------------------------------------

/// Build a §6.3.1.3 HorizAxis-only BASE table: BaseTagList lists
/// `ideo` / `romn` (alphabetical); BaseScriptList lists `hani` / `latn`
/// (alphabetical). The Latin BaseValues gives roman = 0,
/// ideographic = -120 with the roman baseline as default; the Han
/// BaseValues gives ideographic = 0, roman = +120 with the
/// ideographic baseline as default. Neither script ships extents or
/// language-specific overrides.
fn make_base_horiz_two_scripts() -> Vec<u8> {
    let mut buf: Vec<u8> = Vec::new();
    // BASE header (v1.0).
    buf.extend_from_slice(&1u16.to_be_bytes());
    buf.extend_from_slice(&0u16.to_be_bytes());
    let horiz_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());
    buf.extend_from_slice(&0u16.to_be_bytes()); // vertAxis = NULL

    // HorizAxis.
    let horiz_start = buf.len();
    buf[horiz_off_pos..horiz_off_pos + 2].copy_from_slice(&(horiz_start as u16).to_be_bytes());
    let tag_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());
    let script_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());

    // BaseTagList: ideo, romn (alphabetical per §6.3.1.3).
    let tag_start = buf.len();
    buf[tag_off_pos..tag_off_pos + 2]
        .copy_from_slice(&((tag_start - horiz_start) as u16).to_be_bytes());
    buf.extend_from_slice(&2u16.to_be_bytes());
    buf.extend_from_slice(b"ideo");
    buf.extend_from_slice(b"romn");

    // BaseScriptList: hani, latn (alphabetical).
    let script_start = buf.len();
    buf[script_off_pos..script_off_pos + 2]
        .copy_from_slice(&((script_start - horiz_start) as u16).to_be_bytes());
    buf.extend_from_slice(&2u16.to_be_bytes()); // baseScriptCount
    buf.extend_from_slice(b"hani");
    let hani_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());
    buf.extend_from_slice(b"latn");
    let latn_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());

    // BaseScript hani.
    let hani_start = buf.len();
    buf[hani_off_pos..hani_off_pos + 2]
        .copy_from_slice(&((hani_start - script_start) as u16).to_be_bytes());
    let hani_bv_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());
    buf.extend_from_slice(&0u16.to_be_bytes()); // defaultMinMax NULL
    buf.extend_from_slice(&0u16.to_be_bytes()); // baseLangSysCount = 0

    // hani BaseValues: defaultBaselineIndex = 0 (ideo), 2 coords.
    let hani_bv_start = buf.len();
    buf[hani_bv_off_pos..hani_bv_off_pos + 2]
        .copy_from_slice(&((hani_bv_start - hani_start) as u16).to_be_bytes());
    buf.extend_from_slice(&0u16.to_be_bytes()); // defaultBaselineIndex = ideo
    buf.extend_from_slice(&2u16.to_be_bytes()); // baseCoordCount
    let hani_bc0_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes()); // ideo offset
    let hani_bc1_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes()); // romn offset

    // hani ideo (Format 1, 0).
    let hani_bc0_start = buf.len();
    buf[hani_bc0_off_pos..hani_bc0_off_pos + 2]
        .copy_from_slice(&((hani_bc0_start - hani_bv_start) as u16).to_be_bytes());
    buf.extend_from_slice(&1u16.to_be_bytes());
    buf.extend_from_slice(&0i16.to_be_bytes());
    // hani romn (Format 1, 120).
    let hani_bc1_start = buf.len();
    buf[hani_bc1_off_pos..hani_bc1_off_pos + 2]
        .copy_from_slice(&((hani_bc1_start - hani_bv_start) as u16).to_be_bytes());
    buf.extend_from_slice(&1u16.to_be_bytes());
    buf.extend_from_slice(&120i16.to_be_bytes());

    // BaseScript latn.
    let latn_start = buf.len();
    buf[latn_off_pos..latn_off_pos + 2]
        .copy_from_slice(&((latn_start - script_start) as u16).to_be_bytes());
    let latn_bv_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());
    buf.extend_from_slice(&0u16.to_be_bytes()); // defaultMinMax NULL
    buf.extend_from_slice(&0u16.to_be_bytes()); // baseLangSysCount = 0

    // latn BaseValues: defaultBaselineIndex = 1 (romn), 2 coords.
    let latn_bv_start = buf.len();
    buf[latn_bv_off_pos..latn_bv_off_pos + 2]
        .copy_from_slice(&((latn_bv_start - latn_start) as u16).to_be_bytes());
    buf.extend_from_slice(&1u16.to_be_bytes()); // defaultBaselineIndex = romn
    buf.extend_from_slice(&2u16.to_be_bytes());
    let latn_bc0_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());
    let latn_bc1_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());

    // latn ideo (Format 1, -120).
    let latn_bc0_start = buf.len();
    buf[latn_bc0_off_pos..latn_bc0_off_pos + 2]
        .copy_from_slice(&((latn_bc0_start - latn_bv_start) as u16).to_be_bytes());
    buf.extend_from_slice(&1u16.to_be_bytes());
    buf.extend_from_slice(&(-120i16).to_be_bytes());
    // latn romn (Format 1, 0).
    let latn_bc1_start = buf.len();
    buf[latn_bc1_off_pos..latn_bc1_off_pos + 2]
        .copy_from_slice(&((latn_bc1_start - latn_bv_start) as u16).to_be_bytes());
    buf.extend_from_slice(&1u16.to_be_bytes());
    buf.extend_from_slice(&0i16.to_be_bytes());

    buf
}

/// Build a HorizAxis + VertAxis BASE table. The HorizAxis is the
/// `latn`-only Latin tree (BaseTagList = `[romn]`; latn baseline = 0).
/// The VertAxis is the `hani`-only Han tree (BaseTagList = `[ideo]`;
/// hani baseline = 50). The two axes carry independent BaseScriptList
/// arrays per §6.3.1.3 ("If a font has values for only one text
/// direction, the Axis table offset value for the other direction will
/// be set to NULL" — here we exercise the inverse: both axes
/// present with disjoint script coverage).
fn make_base_horiz_and_vert() -> Vec<u8> {
    let mut buf: Vec<u8> = Vec::new();
    buf.extend_from_slice(&1u16.to_be_bytes());
    buf.extend_from_slice(&0u16.to_be_bytes());
    let horiz_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());
    let vert_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());

    // HorizAxis with `latn` -> romn = 0.
    let horiz_start = buf.len();
    buf[horiz_off_pos..horiz_off_pos + 2].copy_from_slice(&(horiz_start as u16).to_be_bytes());
    let tag_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());
    let script_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());

    let tag_start = buf.len();
    buf[tag_off_pos..tag_off_pos + 2]
        .copy_from_slice(&((tag_start - horiz_start) as u16).to_be_bytes());
    buf.extend_from_slice(&1u16.to_be_bytes());
    buf.extend_from_slice(b"romn");

    let script_start = buf.len();
    buf[script_off_pos..script_off_pos + 2]
        .copy_from_slice(&((script_start - horiz_start) as u16).to_be_bytes());
    buf.extend_from_slice(&1u16.to_be_bytes());
    buf.extend_from_slice(b"latn");
    let latn_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());

    let latn_start = buf.len();
    buf[latn_off_pos..latn_off_pos + 2]
        .copy_from_slice(&((latn_start - script_start) as u16).to_be_bytes());
    let latn_bv_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());
    buf.extend_from_slice(&0u16.to_be_bytes());
    buf.extend_from_slice(&0u16.to_be_bytes());

    let latn_bv_start = buf.len();
    buf[latn_bv_off_pos..latn_bv_off_pos + 2]
        .copy_from_slice(&((latn_bv_start - latn_start) as u16).to_be_bytes());
    buf.extend_from_slice(&0u16.to_be_bytes());
    buf.extend_from_slice(&1u16.to_be_bytes());
    let latn_bc0_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());

    let latn_bc0_start = buf.len();
    buf[latn_bc0_off_pos..latn_bc0_off_pos + 2]
        .copy_from_slice(&((latn_bc0_start - latn_bv_start) as u16).to_be_bytes());
    buf.extend_from_slice(&1u16.to_be_bytes());
    buf.extend_from_slice(&0i16.to_be_bytes());

    // VertAxis with `hani` -> ideo = 50.
    let vert_start = buf.len();
    buf[vert_off_pos..vert_off_pos + 2].copy_from_slice(&(vert_start as u16).to_be_bytes());
    let vtag_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());
    let vscript_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());

    let vtag_start = buf.len();
    buf[vtag_off_pos..vtag_off_pos + 2]
        .copy_from_slice(&((vtag_start - vert_start) as u16).to_be_bytes());
    buf.extend_from_slice(&1u16.to_be_bytes());
    buf.extend_from_slice(b"ideo");

    let vscript_start = buf.len();
    buf[vscript_off_pos..vscript_off_pos + 2]
        .copy_from_slice(&((vscript_start - vert_start) as u16).to_be_bytes());
    buf.extend_from_slice(&1u16.to_be_bytes());
    buf.extend_from_slice(b"hani");
    let hani_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());

    let hani_start = buf.len();
    buf[hani_off_pos..hani_off_pos + 2]
        .copy_from_slice(&((hani_start - vscript_start) as u16).to_be_bytes());
    let hani_bv_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());
    buf.extend_from_slice(&0u16.to_be_bytes());
    buf.extend_from_slice(&0u16.to_be_bytes());

    let hani_bv_start = buf.len();
    buf[hani_bv_off_pos..hani_bv_off_pos + 2]
        .copy_from_slice(&((hani_bv_start - hani_start) as u16).to_be_bytes());
    buf.extend_from_slice(&0u16.to_be_bytes());
    buf.extend_from_slice(&1u16.to_be_bytes());
    let hani_bc0_off_pos = buf.len();
    buf.extend_from_slice(&0u16.to_be_bytes());

    let hani_bc0_start = buf.len();
    buf[hani_bc0_off_pos..hani_bc0_off_pos + 2]
        .copy_from_slice(&((hani_bc0_start - hani_bv_start) as u16).to_be_bytes());
    buf.extend_from_slice(&1u16.to_be_bytes());
    buf.extend_from_slice(&50i16.to_be_bytes());

    buf
}

#[test]
fn synth_horiz_only_table_walks_both_scripts() {
    let num_glyphs = 16u16;
    let tables: Vec<(&[u8; 4], Vec<u8>)> = vec![
        (b"head", make_head(1000, 0)),
        (b"hhea", make_hhea(1)),
        (b"maxp", make_maxp(num_glyphs)),
        (b"cmap", make_cmap_empty()),
        (b"name", make_name_empty()),
        (b"hmtx", make_hmtx(1, num_glyphs)),
        (b"loca", make_loca_short(num_glyphs)),
        (b"glyf", make_glyf_empty()),
        (b"BASE", make_base_horiz_two_scripts()),
    ];
    let font_bytes = build_minimal_sfnt(&tables);
    let font = Font::from_bytes(&font_bytes).expect("parse synth");
    assert!(font.has_base());
    let base = font.base_table().unwrap();
    assert_eq!(base.major_version, 1);
    assert_eq!(base.minor_version, 0);
    let h = base.horiz_axis.as_ref().unwrap();
    let tags = h.baseline_tags.as_ref().unwrap();
    assert_eq!(tags, &vec![*b"ideo", *b"romn"]);
    assert_eq!(h.base_scripts.len(), 2);

    // Latin: roman = 0 (the default), ideographic = -120.
    assert_eq!(
        font.base_horiz_y_for_script_baseline(*b"latn", *b"romn"),
        Some(0)
    );
    assert_eq!(
        font.base_horiz_y_for_script_baseline(*b"latn", *b"ideo"),
        Some(-120)
    );
    // Han: ideographic = 0 (the default), roman = 120.
    assert_eq!(
        font.base_horiz_y_for_script_baseline(*b"hani", *b"ideo"),
        Some(0)
    );
    assert_eq!(
        font.base_horiz_y_for_script_baseline(*b"hani", *b"romn"),
        Some(120)
    );

    // Default-baseline-index per BaseValues.
    let latn = h.base_script_for_tag(*b"latn").unwrap();
    assert_eq!(latn.base_values.as_ref().unwrap().default_baseline_index, 1);
    let hani = h.base_script_for_tag(*b"hani").unwrap();
    assert_eq!(hani.base_values.as_ref().unwrap().default_baseline_index, 0);

    // Unknown scripts / baselines decline cleanly.
    assert!(font
        .base_horiz_y_for_script_baseline(*b"arab", *b"romn")
        .is_none());
    assert!(font
        .base_horiz_y_for_script_baseline(*b"latn", *b"hang")
        .is_none());
    // VertAxis-side lookups on a HorizAxis-only font return None.
    assert!(font
        .base_vert_x_for_script_baseline(*b"latn", *b"romn")
        .is_none());
}

#[test]
fn synth_table_with_horiz_and_vert_axes() {
    let num_glyphs = 16u16;
    let tables: Vec<(&[u8; 4], Vec<u8>)> = vec![
        (b"head", make_head(1000, 0)),
        (b"hhea", make_hhea(1)),
        (b"maxp", make_maxp(num_glyphs)),
        (b"cmap", make_cmap_empty()),
        (b"name", make_name_empty()),
        (b"hmtx", make_hmtx(1, num_glyphs)),
        (b"loca", make_loca_short(num_glyphs)),
        (b"glyf", make_glyf_empty()),
        (b"BASE", make_base_horiz_and_vert()),
    ];
    let font_bytes = build_minimal_sfnt(&tables);
    let font = Font::from_bytes(&font_bytes).expect("parse synth");
    assert!(font.has_base());
    let base = font.base_table().unwrap();
    assert!(base.horiz_axis.is_some());
    assert!(base.vert_axis.is_some());

    // HorizAxis: Latin -> romn = 0; no Han.
    assert_eq!(
        font.base_horiz_y_for_script_baseline(*b"latn", *b"romn"),
        Some(0)
    );
    assert!(font
        .base_horiz_y_for_script_baseline(*b"hani", *b"ideo")
        .is_none());
    // VertAxis: Han -> ideo = 50; no Latin.
    assert_eq!(
        font.base_vert_x_for_script_baseline(*b"hani", *b"ideo"),
        Some(50)
    );
    assert!(font
        .base_vert_x_for_script_baseline(*b"latn", *b"romn")
        .is_none());
}