Module embedded_graphics::mono_font::mapping[][src]

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 functions Fn(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

StrGlyphMapping

Glyph mapping stored as a UTF-8 string.

Enums

Mapping

Mapping.

Constants

ASCII

ASCII.

ISO_8859_1

ISO/IEC 8859 Part 1: Latin-1, Western European.

ISO_8859_2

ISO/IEC 8859 Part 2: Latin-2, Central European.

ISO_8859_3

ISO/IEC 8859 Part 3: Latin-3, South European.

ISO_8859_4

ISO/IEC 8859 Part 4: Latin-4, North European.

ISO_8859_5

ISO/IEC 8859 Part 5: Latin/Cyrillic.

ISO_8859_7

ISO/IEC 8859 Part 7: Latin/Greek.

ISO_8859_9

ISO/IEC 8859 Part 9: Latin-5, Turkish.

ISO_8859_10

ISO/IEC 8859 Part 10: Latin-6, Nordic.

ISO_8859_13

ISO/IEC 8859 Part 13: Latin-7, Baltic Rim.

ISO_8859_14

ISO/IEC 8859 Part 14: Latin-8, Celtic.

ISO_8859_15

ISO/IEC 8859 Part 15: Latin-9 (revised Latin-1).

ISO_8859_16

ISO/IEC 8859 Part 16: Latin-10: South-East European.

JIS_X0201

JIS X 0201: Japanese katakana (halfwidth).

Traits

GlyphMapping

Mapping from characters to glyph indices.