Module embedded_graphics::mono_font::mapping
source · [−]Expand description
Glyph mapping.
A glyph mapping defines the position of characters in a MonoFont
image. This module provides
predefined mappings for common glyph subsets, but custom mappings are also supported.
Custom mappings
Custom mappings can be defined in three different ways:
- The
StrGlyphMapping
type can be used to specify a character mapping by encoding the mapping as a string. - The
GlyphMapping
trait is implemented for all functionsFn(char) -> usize
. - The
GlyphMapping
trait can be implemented by a custom type.
StrGlyphMapping
encoding
Strings without a \0
character can be used to directly map a character to its position in
the mapping string:
use embedded_graphics::mono_font::mapping::{GlyphMapping, StrGlyphMapping};
let mapping = StrGlyphMapping::new("abcdef1234", 0);
assert_eq!(mapping.index('a'), 0);
assert_eq!(mapping.index('b'), 1);
assert_eq!(mapping.index('1'), 6);
assert_eq!(mapping.index('2'), 7);
This direct mapping is inefficient for mappings that map consecutive ranges of characters to
consecutive index ranges. To define a range of characters a \0
character followed by the
start and end characters of the inclusive range can be used. This way the mapping in the previous
example can be abbreviated to:
use embedded_graphics::mono_font::mapping::{GlyphMapping, StrGlyphMapping};
let mapping = StrGlyphMapping::new("\0af\014", 0);
assert_eq!(mapping.index('a'), 0);
assert_eq!(mapping.index('b'), 1);
assert_eq!(mapping.index('1'), 6);
assert_eq!(mapping.index('2'), 7);
Structs
Glyph mapping stored as a UTF-8 string.
Enums
Mapping.
Constants
ASCII.
ISO/IEC 8859 Part 1: Latin-1, Western European.
ISO/IEC 8859 Part 2: Latin-2, Central European.
ISO/IEC 8859 Part 3: Latin-3, South European.
ISO/IEC 8859 Part 4: Latin-4, North European.
ISO/IEC 8859 Part 5: Latin/Cyrillic.
ISO/IEC 8859 Part 7: Latin/Greek.
ISO/IEC 8859 Part 9: Latin-5, Turkish.
ISO/IEC 8859 Part 10: Latin-6, Nordic.
ISO/IEC 8859 Part 13: Latin-7, Baltic Rim.
ISO/IEC 8859 Part 14: Latin-8, Celtic.
ISO/IEC 8859 Part 15: Latin-9 (revised Latin-1).
ISO/IEC 8859 Part 16: Latin-10: South-East European.
JIS X 0201: Japanese katakana (halfwidth).
Traits
Mapping from characters to glyph indices.