f-office-docx 0.2.1

DOCX model and Word's layout rules.
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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
//! The keyed form of a font environment, in which a profile writes it: each entry is a table
//! keyed by what it names, so that a later layer of a profile adds or changes one entry, and
//! every value of an entry is optional until the layers are merged. [`environment`] builds the
//! environment from the merged table and refuses an incomplete entry and a name that the table
//! holds twice as [`FamilyName`] compares names, and `table` gives the table back. The widths of
//! the symbol fonts (`symbol_font`) are no part of the environment and stay with the table.

use std::collections::BTreeMap;

use f_office_fonts::environment::{
    EnvironmentError, FaceName, FontEnvironment, Lacking, MetafileFaces, OwnFace, WordLine,
};
use f_office_fonts::{FamilyName, KerningSource};
use serde::{Deserialize, Serialize};

/// A font environment, or the entries that one layer of a profile adds to it.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Table {
    /// The name of a whole font environment that the profile's reader takes in place of the one
    /// that this layer inherits, before the entries of this layer.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub environment: Option<String>,
    /// The faces that the layout takes as the target's own, by family and then by style.
    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
    pub face: BTreeMap<String, BTreeMap<String, FaceEntry>>,
    /// The families that the target lacks, by family.
    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
    pub lacking: BTreeMap<String, LackingEntry>,
    /// The requested names of the target's full font listing: `true` for a name in it, `false`
    /// for a name that a later layer takes out of it.
    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
    pub available: BTreeMap<String, bool>,
    /// The faces that the target's font mapper gives a metafile font of a missing face, by the
    /// character set (`lfCharSet`) as a decimal number.
    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
    pub metafile_faces: BTreeMap<String, MetafileEntry>,
    /// The names outside the full listing that the target's font mapper knows: `true` for a
    /// name that it knows, `false` for a name that a later layer takes out.
    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
    pub mapper_names: BTreeMap<String, bool>,
    /// The lines that Word gives families drawn with another family's face, by family.
    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
    pub line: BTreeMap<String, LineEntry>,
    /// Other names of the target's faces, their full and PostScript names, by name.
    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
    pub face_names: BTreeMap<String, FaceNameEntry>,
    /// Word's widths of the symbol fonts, by family.
    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
    pub symbol_font: BTreeMap<String, SymbolFontEntry>,
}

/// Word's symbol-font metrics for the target environment: the advance of each
/// code that the file maps and of its missing glyph, the sizes at which the file's instructions
/// give one of them a device width one dot wider or narrower than the plain device width of its
/// advance, the width that the target's PDF writer writes for one where it differs from its
/// advance's, and the file's names, device heights and line, decoration and script metrics. A
/// code is written as the four hexadecimal digits of its private use form, F020 to F0FF, and the
/// missing glyph, which the file draws for a character that it does not map, as
/// [`SymbolFontEntry::MISSING_GLYPH`].
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct SymbolFontEntry {
    /// The PostScript name of the file (name ID 6).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub postscript_name: Option<String>,
    /// The version string of the file (name ID 5), such as "Version 5.01".
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub version: Option<String>,
    /// The units per em of the file, which measure the advances and the metrics.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub units_per_em: Option<u16>,
    /// The largest size in device dots per em that `wider` and `narrower` cover, from one dot
    /// per em on: above it, every code is taken at the plain device width of its advance.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub measured_sizes: Option<u16>,
    /// The device heights of the file's `VDMX` table: each size in pixels per em that its group
    /// for square pixels and the Windows ANSI character set lists, with the largest height above
    /// the baseline and the largest depth below it at that size, in pixels and with the signs
    /// that the file stores. A size that it does not list has no device heights.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub heights: Vec<[i16; 3]>,
    /// The file's metrics, as its tables store them.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub metrics: Option<SymbolFileMetrics>,
    /// The advance of each code and of the missing glyph in font units, by code.
    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
    pub advance: BTreeMap<String, u16>,
    /// The width in thousandths of an em of each code whose advance at 1000 pixels per em, as
    /// bi-level rendering of the file gives it, differs from its advance in font units times
    /// 1000 over the units per em, a half rounded up, by code.
    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
    pub written: BTreeMap<String, u16>,
    /// The sizes in device dots per em at which a code's device width is one dot wider than the
    /// plain device width of its advance, by code.
    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
    pub wider: BTreeMap<String, Vec<u16>>,
    /// The sizes in device dots per em at which a code's device width is one dot narrower than
    /// the plain device width of its advance, by code.
    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
    pub narrower: BTreeMap<String, Vec<u16>>,
}

impl SymbolFontEntry {
    /// The key of the missing glyph in the tables of codes.
    pub const MISSING_GLYPH: &'static str = "missing";
}

/// The line, decoration and script metrics of a symbol font's file in font units, with the
/// values and signs that its `hhea`, `OS/2` and `post` tables store, and its PANOSE numbers.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct SymbolFileMetrics {
    /// The ascender, descender and line gap of `hhea`.
    pub hhea: [i16; 3],
    /// `sTypoAscender`, `sTypoDescender` and `sTypoLineGap`.
    pub typo: [i16; 3],
    /// `usWinAscent` and `usWinDescent`.
    pub win: [u16; 2],
    /// The `USE_TYPO_METRICS` bit of `fsSelection`.
    pub use_typo_metrics: bool,
    /// `xAvgCharWidth`.
    pub average_width: i16,
    /// `yStrikeoutPosition` and `yStrikeoutSize`.
    pub strikeout: [i16; 2],
    /// The underline position and thickness of `post`.
    pub underline: [i16; 2],
    /// The `ySubscript` fields: the x size, y size, x offset and y offset.
    pub subscript: [i16; 4],
    /// The `ySuperscript` fields: the x size, y size, x offset and y offset.
    pub superscript: [i16; 4],
    /// Whether `ulCodePageRange1` names an East Asian code page.
    pub east_asian: bool,
    /// The ten numbers of the PANOSE classification.
    pub panose: [u8; 10],
}

/// The line that Word gives a family drawn with another family's face, in thousandths of an em.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct LineEntry {
    /// The part above the baseline.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub ascent: Option<i16>,
    /// The part below the baseline.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub descent: Option<i16>,
    /// Whether the line also holds over the family's own file where a document names the
    /// family itself; `false` when not given.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub over_own_file: Option<bool>,
}

/// The face that another name names.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct FaceNameEntry {
    /// The face's family.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub family: Option<String>,
    /// The face's style for a full name, or none for a PostScript name, which gives the face of
    /// a run's style.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub style: Option<String>,
}

/// An own face of one family and style.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct FaceEntry {
    /// The version string (name ID 5), or the version strings when the target has several
    /// faces of the family and style.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub version: Option<Versions>,
    /// The kerning source that the layout takes for the face in place of its tables' own.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub kerning_source: Option<Kerning>,
}

/// A kerning source by its name in a profile.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum Kerning {
    /// The `GPOS` table ([`KerningSource::Gpos`]).
    #[serde(rename = "gpos")]
    Gpos,
    /// The `kern` table ([`KerningSource::KernTable`]).
    #[serde(rename = "kern table")]
    KernTable,
}

impl From<Kerning> for KerningSource {
    fn from(kerning: Kerning) -> Self {
        match kerning {
            Kerning::Gpos => Self::Gpos,
            Kerning::KernTable => Self::KernTable,
        }
    }
}

impl From<KerningSource> for Kerning {
    fn from(source: KerningSource) -> Self {
        match source {
            KerningSource::Gpos => Self::Gpos,
            KerningSource::KernTable => Self::KernTable,
        }
    }
}

/// One version string, or several.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Versions {
    /// The one version of the family and style.
    One(String),
    /// Every version of the family and style.
    Several(Vec<String>),
}

impl Versions {
    /// The version strings.
    #[must_use]
    pub fn all(&self) -> &[String] {
        match self {
            Self::One(version) => std::slice::from_ref(version),
            Self::Several(versions) => versions,
        }
    }
}

/// A family that the target lacks.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct LackingEntry {
    /// The family that Word draws the family with, after the document's alternate, when it is
    /// confirmed.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub word_uses: Option<String>,
}

/// The faces that the font mapper gives a metafile font of one character set.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct MetafileEntry {
    /// The faces, by family and then by pitch.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub faces: Option<Vec<String>>,
}

impl Table {
    /// Takes in the entries of `later`, a later layer: tables merge key by key, and a value of
    /// `later` replaces this table's. `set` hears the path of each value that `later` sets, from
    /// the table's own key on, such as `["face", "Arial", "Regular", "version"]`. The name of a
    /// whole environment (`environment`) is the reader's, which takes it in before the merge. A
    /// symbol font's widths are one value: a later layer's entry replaces the whole entry.
    pub fn merge(&mut self, later: &Self, set: &mut dyn FnMut(&[&str])) {
        for (family, styles) in &later.face {
            for (style, entry) in styles {
                let own = self
                    .face
                    .entry(family.clone())
                    .or_default()
                    .entry(style.clone())
                    .or_default();
                let version = entry.version.as_ref();
                take(
                    &mut own.version,
                    version,
                    &["face", family, style, "version"],
                    set,
                );
                let source = entry.kerning_source.as_ref();
                let path = ["face", family, style, "kerning_source"];
                take(&mut own.kerning_source, source, &path, set);
            }
        }
        for (family, entry) in &later.lacking {
            let own = self.lacking.entry(family.clone()).or_default();
            let word_uses = entry.word_uses.as_ref();
            take(
                &mut own.word_uses,
                word_uses,
                &["lacking", family, "word_uses"],
                set,
            );
        }
        for (charset, entry) in &later.metafile_faces {
            let own = self.metafile_faces.entry(charset.clone()).or_default();
            let faces = entry.faces.as_ref();
            take(
                &mut own.faces,
                faces,
                &["metafile_faces", charset, "faces"],
                set,
            );
        }
        for (family, entry) in &later.line {
            let own = self.line.entry(family.clone()).or_default();
            take(
                &mut own.ascent,
                entry.ascent.as_ref(),
                &["line", family, "ascent"],
                set,
            );
            take(
                &mut own.descent,
                entry.descent.as_ref(),
                &["line", family, "descent"],
                set,
            );
            let over = entry.over_own_file.as_ref();
            take(
                &mut own.over_own_file,
                over,
                &["line", family, "over_own_file"],
                set,
            );
        }
        for (name, entry) in &later.face_names {
            let own = self.face_names.entry(name.clone()).or_default();
            take(
                &mut own.family,
                entry.family.as_ref(),
                &["face_names", name, "family"],
                set,
            );
            take(
                &mut own.style,
                entry.style.as_ref(),
                &["face_names", name, "style"],
                set,
            );
        }
        for (family, entry) in &later.symbol_font {
            self.symbol_font.insert(family.clone(), entry.clone());
            set(&["symbol_font", family]);
        }
        take_names(&mut self.available, &later.available, "available", set);
        take_names(
            &mut self.mapper_names,
            &later.mapper_names,
            "mapper_names",
            set,
        );
    }
}

/// Takes the value `later` into `own` when a later layer sets it, and tells `set` its path.
fn take<T: Clone>(
    own: &mut Option<T>,
    later: Option<&T>,
    path: &[&str],
    set: &mut dyn FnMut(&[&str]),
) {
    if let Some(value) = later {
        *own = Some(value.clone());
        set(path);
    }
}

/// Takes each name of a later layer's `later` into `own`, the table `section`, and tells `set`
/// its path.
fn take_names(
    own: &mut BTreeMap<String, bool>,
    later: &BTreeMap<String, bool>,
    section: &str,
    set: &mut dyn FnMut(&[&str]),
) {
    for (name, value) in later {
        own.insert(name.clone(), *value);
        set(&[section, name]);
    }
}

/// The environment of a merged table. The symbol fonts' widths (`symbol_font`) stay with the
/// table.
///
/// # Errors
///
/// Returns an error when an entry lacks a value or has a wrong one, and when the table holds a
/// face, family, name or character set twice, as [`FamilyName`] compares names.
pub fn environment(table: &Table) -> Result<FontEnvironment, EnvironmentError> {
    let mut faces = Vec::new();
    for (family, styles) in &table.face {
        for (style, entry) in styles {
            let versions = entry
                .version
                .as_ref()
                .filter(|versions| !versions.all().is_empty() && !family.is_empty())
                .ok_or_else(|| EnvironmentError::Entry(format!("{family}, {style}")))?;
            faces.extend(versions.all().iter().map(|version| OwnFace {
                family: family.clone(),
                style: style.clone(),
                version: version.clone(),
                kerning: entry.kerning_source.map(KerningSource::from),
            }));
        }
    }
    let lacking = table
        .lacking
        .iter()
        .map(|(family, entry)| {
            if family.is_empty() || entry.word_uses.as_deref() == Some("") {
                return Err(EnvironmentError::Entry(family.clone()));
            }
            Ok(Lacking {
                family: FamilyName::new(family.clone()),
                drawn_with: entry.word_uses.clone(),
            })
        })
        .collect::<Result<Vec<_>, _>>()?;
    let metafile_faces = table
        .metafile_faces
        .iter()
        .map(|(charset, entry)| {
            let wrong = || EnvironmentError::Entry(format!("metafile faces {charset}"));
            let faces = entry.faces.clone().ok_or_else(wrong)?;
            if faces.is_empty() || faces.iter().any(String::is_empty) {
                return Err(wrong());
            }
            Ok(MetafileFaces {
                charset: charset.parse().map_err(|_| wrong())?,
                faces,
            })
        })
        .collect::<Result<Vec<_>, _>>()?;
    let lines = lines(table)?;
    let face_names = face_names(table)?;
    let available = names(&table.available)?;
    let mapper_names = names(&table.mapper_names)?;
    let built = FontEnvironment::new(faces.clone())
        .with_lacking(lacking.clone())
        .with_available(available.clone())
        .with_metafile_faces(metafile_faces.clone())
        .with_mapper_names(mapper_names.clone())
        .with_lines(lines.clone())
        .with_face_names(face_names.clone());
    if let Some(face) = repeated(&faces, built.faces().len(), |a, b| {
        (&a.family, &a.style, &a.version) == (&b.family, &b.style, &b.version)
    }) {
        return Err(EnvironmentError::Repeated(format!(
            "{}, {}, {}",
            face.family, face.style, face.version
        )));
    }
    if let Some(entry) = repeated(&lacking, built.lacking().len(), |a, b| a.family == b.family) {
        return Err(EnvironmentError::Repeated(entry.family.as_str().to_owned()));
    }
    for (names, kept) in [
        (&available, built.available().len()),
        (&mapper_names, built.mapper_names().len()),
    ] {
        if let Some(name) = repeated(names, kept, PartialEq::eq) {
            return Err(EnvironmentError::Repeated(name.as_str().to_owned()));
        }
    }
    if let Some(line) = repeated(&lines, built.lines().len(), |a, b| a.family == b.family) {
        return Err(EnvironmentError::Repeated(line.family.as_str().to_owned()));
    }
    if let Some(name) = repeated(&face_names, built.face_names().len(), |a, b| {
        a.name == b.name
    }) {
        return Err(EnvironmentError::Repeated(name.name.as_str().to_owned()));
    }
    if let Some(entry) = repeated(&metafile_faces, built.metafile_faces().len(), |a, b| {
        a.charset == b.charset
    }) {
        return Err(EnvironmentError::Repeated(format!(
            "metafile faces {}",
            entry.charset
        )));
    }
    Ok(built)
}

/// Word's lines of the families of a merged table.
fn lines(table: &Table) -> Result<Vec<WordLine>, EnvironmentError> {
    table
        .line
        .iter()
        .map(|(family, entry)| match (entry.ascent, entry.descent) {
            (Some(ascent), Some(descent)) if !family.is_empty() => Ok(WordLine {
                family: FamilyName::new(family.clone()),
                ascent,
                descent,
                over_own_file: entry.over_own_file.unwrap_or(false),
            }),
            _ => Err(EnvironmentError::Entry(format!("line {family}"))),
        })
        .collect()
}

/// The other names of faces of a merged table.
fn face_names(table: &Table) -> Result<Vec<FaceName>, EnvironmentError> {
    table
        .face_names
        .iter()
        .map(|(name, entry)| match &entry.family {
            Some(family) if !name.is_empty() && !family.is_empty() => Ok(FaceName {
                name: FamilyName::new(name.clone()),
                family: family.clone(),
                style: entry.style.clone(),
            }),
            _ => Err(EnvironmentError::Entry(format!("face name {name}"))),
        })
        .collect()
}

/// The names that `listed` holds as `true`.
fn names(listed: &BTreeMap<String, bool>) -> Result<Vec<FamilyName>, EnvironmentError> {
    listed
        .iter()
        .filter(|(_, listed)| **listed)
        .map(|(name, _)| {
            if name.is_empty() {
                return Err(EnvironmentError::Entry(String::new()));
            }
            Ok(FamilyName::new(name.clone()))
        })
        .collect()
}

/// An item of `items` that another one before it is the same as, when the environment kept
/// only `kept` of them.
fn repeated<T>(items: &[T], kept: usize, same: impl Fn(&T, &T) -> bool) -> Option<&T> {
    if kept == items.len() {
        return None;
    }
    items
        .iter()
        .enumerate()
        .find(|(at, item)| items.iter().take(*at).any(|earlier| same(earlier, item)))
        .map(|(_, item)| item)
}

/// The table of `environment`, from which [`environment`] builds the same environment. It has
/// no symbol font's widths, which are no part of the environment.
#[cfg(any(test, feature = "development"))]
#[must_use]
pub fn table(environment: &FontEnvironment) -> Table {
    let mut table = Table::default();
    for face in environment.faces() {
        let entry = table
            .face
            .entry(face.family.clone())
            .or_default()
            .entry(face.style.clone())
            .or_default();
        entry.version = Some(match entry.version.take() {
            None => Versions::One(face.version.clone()),
            Some(versions) => {
                let mut all = versions.all().to_vec();
                all.push(face.version.clone());
                Versions::Several(all)
            }
        });
        entry.kerning_source = entry.kerning_source.or(face.kerning.map(Kerning::from));
    }
    for lacking in environment.lacking() {
        table.lacking.insert(
            lacking.family.as_str().to_owned(),
            LackingEntry {
                word_uses: lacking.drawn_with.clone(),
            },
        );
    }
    let listed = |names: &[FamilyName]| -> BTreeMap<String, bool> {
        names
            .iter()
            .map(|name| (name.as_str().to_owned(), true))
            .collect()
    };
    table.available = listed(environment.available());
    for entry in environment.metafile_faces() {
        table.metafile_faces.insert(
            entry.charset.to_string(),
            MetafileEntry {
                faces: Some(entry.faces.clone()),
            },
        );
    }
    table.mapper_names = listed(environment.mapper_names());
    for line in environment.lines() {
        table.line.insert(
            line.family.as_str().to_owned(),
            LineEntry {
                ascent: Some(line.ascent),
                descent: Some(line.descent),
                over_own_file: line.over_own_file.then_some(true),
            },
        );
    }
    for name in environment.face_names() {
        table.face_names.insert(
            name.name.as_str().to_owned(),
            FaceNameEntry {
                family: Some(name.family.clone()),
                style: name.style.clone(),
            },
        );
    }
    table
}