Debian Codegraph @

src/nametable.rs

raw symbols SCIP
1 /// Utility functions for name table handling.
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#;
3
4 use fontationsrust-analyzer cargo fontations 0.2.0 crate/::skrifarust-analyzer cargo skrifa 0.32.0 crate/::{stringrust-analyzer cargo skrifa 0.32.0 string/::StringIdrust-analyzer cargo font-types 0.9.0 name_id/NameId#, FontRefrust-analyzer cargo read-fonts 0.30.1 FontRef#, MetadataProviderrust-analyzer cargo skrifa 0.32.0 provider/MetadataProvider#};
5 use fontationsrust-analyzer cargo fontations 0.2.0 crate/::writerust-analyzer cargo write-fonts 0.39.0 crate/::tablesrust-analyzer cargo write-fonts 0.39.0 tables/::namerust-analyzer cargo write-fonts 0.39.0 tables/name/::NameRecordrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#;
6
7 pub(craterust-analyzer cargo google-fonts-axisregistry 0.4.15 crate/) fn get_best_namerust-analyzer cargo google-fonts-axisregistry 0.4.15 nametable/get_best_name().(font: &FontRefrust-analyzer cargo read-fonts 0.30.1 FontRef#, ids: &[StringIdrust-analyzer cargo font-types 0.9.0 name_id/NameId#]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
8 for id in ids {
9 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name) = font.localized_stringsrust-analyzer cargo skrifa 0.32.0 provider/impl#[`FontRef<'a>`][`MetadataProvider<'a>`]localized_strings().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().id).english_or_firstrust-analyzer cargo skrifa 0.32.0 string/impl#[`LocalizedStrings<'a>`]english_or_first().() {
10 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name.charsrust-analyzer cargo skrifa 0.32.0 string/impl#[`LocalizedString<'a>`]chars().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().());
11 }
12 }
13 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
14 }
15
16 pub(craterust-analyzer cargo google-fonts-axisregistry 0.4.15 crate/) fn best_familynamerust-analyzer cargo google-fonts-axisregistry 0.4.15 nametable/best_familyname().(font: &FontRefrust-analyzer cargo read-fonts 0.30.1 FontRef#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
17 get_best_namerust-analyzer cargo google-fonts-axisregistry 0.4.15 nametable/get_best_name().(
18 font,
19 &[
20 StringIdrust-analyzer cargo font-types 0.9.0 name_id/NameId#::WWS_FAMILY_NAMErust-analyzer cargo font-types 0.9.0 name_id/impl#[NameId]WWS_FAMILY_NAME.,
21 StringIdrust-analyzer cargo font-types 0.9.0 name_id/NameId#::TYPOGRAPHIC_FAMILY_NAMErust-analyzer cargo font-types 0.9.0 name_id/impl#[NameId]TYPOGRAPHIC_FAMILY_NAME.,
22 StringIdrust-analyzer cargo font-types 0.9.0 name_id/NameId#::FAMILY_NAMErust-analyzer cargo font-types 0.9.0 name_id/impl#[NameId]FAMILY_NAME.,
23 ],
24 )
25 }
26
27 pub(craterust-analyzer cargo google-fonts-axisregistry 0.4.15 crate/) fn best_subfamilynamerust-analyzer cargo google-fonts-axisregistry 0.4.15 nametable/best_subfamilyname().(font: &FontRefrust-analyzer cargo read-fonts 0.30.1 FontRef#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
28 get_best_namerust-analyzer cargo google-fonts-axisregistry 0.4.15 nametable/get_best_name().(
29 font,
30 &[
31 StringIdrust-analyzer cargo font-types 0.9.0 name_id/NameId#::WWS_SUBFAMILY_NAMErust-analyzer cargo font-types 0.9.0 name_id/impl#[NameId]WWS_SUBFAMILY_NAME.,
32 StringIdrust-analyzer cargo font-types 0.9.0 name_id/NameId#::TYPOGRAPHIC_SUBFAMILY_NAMErust-analyzer cargo font-types 0.9.0 name_id/impl#[NameId]TYPOGRAPHIC_SUBFAMILY_NAME.,
33 StringIdrust-analyzer cargo font-types 0.9.0 name_id/NameId#::SUBFAMILY_NAMErust-analyzer cargo font-types 0.9.0 name_id/impl#[NameId]SUBFAMILY_NAME.,
34 ],
35 )
36 }
37
38 pub(craterust-analyzer cargo google-fonts-axisregistry 0.4.15 crate/) fn rewrite_or_insertrust-analyzer cargo google-fonts-axisregistry 0.4.15 nametable/rewrite_or_insert().(records: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<NameRecordrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#>, name_id: StringIdrust-analyzer cargo font-types 0.9.0 name_id/NameId#, string: &str) {
39 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(existing) = records.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`IterMut<'a, T>`][Iterator]find().(|r| {
40 r.name_idrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#name_id. rust-analyzer cargo font-types 0.9.0 name_id/impl#[NameId][`PartialEq<Self>`]eq().==rust-analyzer cargo font-types 0.9.0 name_id/impl#[NameId][`PartialEq<Self>`]eq(). rust-analyzer cargo font-types 0.9.0 name_id/impl#[NameId][`PartialEq<Self>`]eq().name_id && r.platform_idrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#platform_id. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().3 && r.encoding_idrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#encoding_id. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().1 && r.language_idrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#language_id. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().0x409
41 }) {
42 *rust-analyzer cargo write-fonts 0.39.0 offsets/impl#[`OffsetMarker<T, N>`][DerefMut]deref_mut().existing.stringrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#string. = string.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
43 } else {
44 records.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(NameRecordrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord# {
45 platform_idrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#platform_id.: 3,
46 encoding_idrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#encoding_id.: 1,
47 language_idrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#language_id.: 0x409,
48 name_idrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#name_id.,
49 stringrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#string.: string.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
50 });
51 }
52 }
53
54 pub(craterust-analyzer cargo google-fonts-axisregistry 0.4.15 crate/) fn find_or_add_namerust-analyzer cargo google-fonts-axisregistry 0.4.15 nametable/find_or_add_name().(records: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<NameRecordrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#>, string: &str) -> StringIdrust-analyzer cargo font-types 0.9.0 name_id/NameId# {
55 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(existing) = records.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find().(|r| {
56 r.stringrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#string..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().string
57 && r.platform_idrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#platform_id. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().3
58 && r.encoding_idrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#encoding_id. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().1
59 && r.language_idrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#language_id. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]eq().0x409
60 }) {
61 return existing.name_idrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#name_id.;
62 }
63 add_namerust-analyzer cargo google-fonts-axisregistry 0.4.15 nametable/add_name().(records, string)
64 }
65
66 pub(craterust-analyzer cargo google-fonts-axisregistry 0.4.15 crate/) fn add_namerust-analyzer cargo google-fonts-axisregistry 0.4.15 nametable/add_name().(records: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<NameRecordrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#>, string: &str) -> StringIdrust-analyzer cargo font-types 0.9.0 name_id/NameId# {
67 let existing_ids: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<u16> = records.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|r| r.name_idrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#name_id..to_u16rust-analyzer cargo font-types 0.9.0 name_id/impl#[NameId]to_u16().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
68 let mut id: u16 = 256;
69 while existing_ids.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&id) {
70 id rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`AddAssign<Self>`]add_assign().1;
71 }
72 let name_id = StringIdrust-analyzer cargo font-types 0.9.0 name_id/NameId#::newrust-analyzer cargo font-types 0.9.0 name_id/impl#[NameId]new().(id);
73 records.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(NameRecordrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord# {
74 platform_idrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#platform_id.: 3,
75 encoding_idrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#encoding_id.: 1,
76 language_idrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#language_id.: 0x409,
77 name_idrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#name_id.,
78 stringrust-analyzer cargo write-fonts 0.39.0 tables/name/NameRecord#string.: string.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
79 });
80 name_id
81 }