Struct truetype::naming_table::Record
source · pub struct Record {
pub platform_id: PlatformID,
pub encoding_id: EncodingID,
pub language_id: LanguageID,
pub name_id: NameID,
pub length: u16,
pub offset: u16,
}
Expand description
A record of a naming table.
Fields§
§platform_id: PlatformID
§encoding_id: EncodingID
§language_id: LanguageID
§name_id: NameID
§length: u16
§offset: u16
Implementations§
source§impl Record
impl Record
sourcepub fn language_tag(&self, language_tags: &[Option<String>]) -> Option<String>
pub fn language_tag(&self, language_tags: &[Option<String>]) -> Option<String>
Return the IETF-BCP-47 language.
Examples found in repository?
src/naming_table/mod.rs (line 115)
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
pub fn collect<T>(&self) -> T
where
T: FromIterator<((NameID, Option<String>), Option<String>)>,
{
let (records, language_tags, data) = match self {
&NamingTable::Format0(ref table) => (&table.records, &[][..], &table.data),
&NamingTable::Format1(ref table) => {
(&table.records, &table.language_tags[..], &table.data)
}
};
let language_tags: Vec<_> = language_tags
.iter()
.map(|record| {
let (offset, length) = (record.offset as usize, record.length as usize);
encoding::unicode::decode_utf16(&data[offset..(offset + length)])
})
.collect();
records
.iter()
.map(|record| {
let language_tag = record.language_tag(&language_tags);
let (offset, length) = (record.offset as usize, record.length as usize);
let value = decode(
record.platform_id,
record.encoding_id,
record.language_id,
language_tag.as_deref(),
&data[offset..(offset + length)],
);
((record.name_id, language_tag), value)
})
.collect()
}