Module string

Source
Expand description

Localized strings describing font names and other metadata.

This provides higher level interfaces for accessing the data in the OpenType name table.

ยงExample

The following function will print all localized strings from the set of predefined identifiers in a font:

use skrifa::{string::StringId, MetadataProvider};

fn print_well_known_strings<'a>(font: &impl MetadataProvider<'a>) {
    for id in StringId::predefined() {
        let strings = font.localized_strings(id);
        if strings.clone().next().is_some() {
            println!("[{:?}]", id);
            for string in font.localized_strings(id) {
                println!("{:?} {}", string.language(), string.to_string());
            }
        }
    }
}

Structsยง

Chars
Iterator over the characters of a string.
LocalizedString
String containing a name or other font metadata in a specific language.
LocalizedStrings
Iterator over a collection of localized strings for a specific identifier.
StringId
Identifier for an informational string (or name).

Enumsยง

Language ๐Ÿ”’

Constantsยง

LANGUAGE_ID_TO_BCP47 ๐Ÿ”’
Mapping of OpenType name table language identifier to BCP-47 language tag. Borrowed from Skia: https://skia.googlesource.com/skia/+/refs/heads/main/src/sfnt/SkOTTable_name.cpp#98
MAX_INLINE_LANGUAGE_LEN ๐Ÿ”’
This value is chosen arbitrarily to accommodate common language tags that are almost always <= 11 bytes (LLL-SSSS-RR where L is primary language, S is script and R is region) and to keep the Language enum at a reasonable 32 bytes in size.

Functionsยง

language_id_to_bcp47 ๐Ÿ”’
Converts an OpenType language identifier to a BCP-47 language tag.