GetUnicode(CharacterCode, Span, out UnicodeSource) Method

Definition

Namespace Broadside.Fonts
Assembly Broadside.dll

Maps a character code to the Unicode text it stands for.

public int GetUnicode(CharacterCode code, Span<char> destination, scoped out UnicodeSource source)

Parameters

code
CharacterCode

The code: for a simple font one byte (Length 1); for a Type 0 font as its CMap reads it (ReadGlyph(ReadOnlySpan<Byte>), ReadCode(ReadOnlySpan<Byte>)), an invalid code selecting CID 0.

destination
Span<Char>

Where the UTF-16 text goes. One code can stand for several characters (a ligature, a surrogate pair, a decomposed sequence); 512 units always suffice, and text that does not fit is cut at a character boundary.

source
UnicodeSource

Which method mapped the code; Unmapped when none did.

Returns

Int32
The number of UTF-16 units written: 0 for a code a ToUnicode CMap maps to an empty string.

Remarks

ISO 32000-2 §9.10.2, in its priority order, per code (a ToUnicode CMap that lacks a code falls through to the next method): the font's ToUnicode CMap (§9.10.3; a code is looked up under its own length, then by value under the other lengths); for a simple font, the glyph name its encoding gives the code (§9.6.5) through the Adobe Glyph List specification's algorithm; for a Type 0 font whose CMap is a predefined CMap other than Identity-H/V, or whose CIDFont uses the Adobe-GB1, -CNS1, -Japan1, -Korea1 or -KR collection, the code's CID through the collection's Registry-Ordering-UCS2 table (from the engine's font resolvers: the Broadside.Fonts.Cmaps package). When all fail, the glyph's code point in a Unicode "cmap" subtable of the embedded TrueType program, as PDFBox does. Otherwise the text is U+FFFD, never the code itself.

An unmapped code is recorded once per font as an information diagnostic (§9.10.2 allows it; strict mode does not throw), or, when the UCS2 table is missing, that is recorded instead. A malformed ToUnicode CMap is recorded when first used and throws in strict mode. The tables are built on first use and kept until the font's dictionaries or ToUnicode stream change; a lookup then allocates nothing. Safe for concurrent use.