Class CharacterMap
One character map of a face, as stored: a cmap subtable for one (platform, encoding) pair, or a CFF font's own encoding as FreeType presents it (platform 7). Codes are the subtable's own: bytes for a Macintosh (1,0) map or a symbol font's (3,0) map, never translated to Unicode.
public sealed class CharacterMap
- Inheritance
-
CharacterMap
- Inherited Members
Examples
// A symbolic TrueType font in PDF looks a code up in (3,0) first, then (1,0); a non-symbolic one uses (3,1).
CharacterMap? map = trueType.FindCharacterMap(3, 0) ?? trueType.FindCharacterMap(1, 0) ?? trueType.FindCharacterMap(3, 1);
ushort forA = map?.GetGlyph('A') ?? 0;
// A Type1C font without /Encoding uses the CFF program's own encoding.
CharacterMap? own = face.BuiltInEncoding; // platform 7, encoding 0: the Standard Encoding
ushort forB = own?.GetGlyph('B') ?? 0;
// Every code the map gives a glyph, in code order, for a PDF writer's /Widths or a ToUnicode table.
int mapped = map?.GetMappings().Count() ?? 0;
Remarks
The subtable is parsed on first use, once, and the map is safe to use from several threads. A subtable that cannot be read maps nothing and reports a warning through the context's diagnostics.
Fields
AdobePlatform
The platform id of a CFF font's own encoding, as FreeType numbers it (TT_PLATFORM_ADOBE).
public const int AdobePlatform = 7
Field Value
Properties
EncodingId
Gets the encoding id within the platform, such as 1 (Unicode BMP) or 0 (symbol) on Windows. For platform 7: 0 the Standard Encoding, 1 the Expert Encoding, 2 a custom encoding.
public int EncodingId { get; }
Property Value
Format
Gets the subtable format: 0, 2, 4, 6, 10, 12 or 13, or another the map cannot read (it maps nothing); 0 for platform 7.
public int Format { get; }
Property Value
Language
Gets the subtable's language field: nonzero only in some Macintosh subtables (the Mac language code plus one).
public int Language { get; }
Property Value
PlatformId
Gets the platform id: 0 Unicode, 1 Macintosh, 3 Windows, 7 a CFF font's own encoding.
public int PlatformId { get; }
Property Value
Methods
GetGlyph(int)
Gets the glyph a code maps to.
public ushort GetGlyph(int code)
Parameters
codeintThe character code, in this map's encoding.
Returns
- ushort
The glyph id, 0 (.notdef) when the code is not mapped or maps past the face's glyphs (as FreeType's FT_Get_Char_Index).
GetMappings()
Gets every code that maps to a glyph other than 0 within the face's glyphs, in ascending code order.
public IEnumerable<CharacterMapping> GetMappings()
Returns
- IEnumerable<CharacterMapping>
The mappings.
ToString()
Returns the platform, encoding and format, such as "(3,1) format 4".
public override string ToString()
Returns
- string
The text.