PdfContentFont class

Font information sufficient to turn Tj/TJ bytes into text and widths.

Honesty about the reach

  • with /ToUnicode present, the text comes out right, subsetted Type0 included;
  • without /ToUnicode, simple fonts fall back to WinAnsi/latin-1, which gets ordinary Western documents right and any exotic encoding wrong;
  • without /ToUnicode, a subsetted Type0 font is undecipherable: the codes are arbitrary glyph indices. In that case the characters come out as � and PdfContentGlyph.mapped is false. There is no way around this without reading the cmap table of the embedded font file, which is out of scope here;
  • /Encoding with /Differences is only honored for uniXXXX names, uXXXX names with four or more hex digits, and the names of the standard Latin set;
  • Type3 is not handled: the font's own matrix is ignored and the widths come out wrong.

Constructors

PdfContentFont({String? resourceName, String? baseFont, String? subtype, bool composite = false, int codeByteLength = 1, Map<int, String>? toUnicode, Map<int, String>? differences, bool winAnsi = true, int firstChar = 0, List<double>? widths, Map<int, double>? cidWidths, double? defaultWidth, double? missingWidth})
Creates the description of a font.

Properties

baseFont → String?
/BaseFont.
final
cidWidths → Map<int, double>
Per-CID widths of a composite font (/W).
final
codeByteLength → int
How many bytes each code takes up (1 or 2).
final
composite → bool
true for Type0 (multi-byte codes).
final
defaultWidth → double
/DW of a composite font, or the guess used when there is no /Widths.
final
differences → Map<int, String>
Map coming from /Encoding /Differences, code → text.
final
firstChar → int
/FirstChar of a simple font.
final
hashCode → int
The hash code for this object.
no setterinherited
hasReliableTextMapping → bool
true when the text mapping is reliable for any code.
no setter
missingWidth → double?
/MissingWidth of the descriptor, when declared.
final
resourceName → String?
Resource name on the page (/F1), when known.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
subtype → String?
/Subtype (/Type1, /TrueType, /Type0, /Type3).
final
toUnicode → Map<int, String>
/ToUnicode map, code → text.
final
widths → List<double>
/Widths of a simple font, in thousandths of an em.
final
winAnsi → bool
true when /Encoding is WinAnsi (or absent, which is the common case).
final

Methods

decode(Uint8List bytes) → List<PdfContentGlyph>
Decodes the bytes of a text string into glyphs.
decodeText(Uint8List bytes) → String
Text matching a content string.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited
widthOf(int code) → double
Width of code code in thousandths of an em.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

decodeUtf16Be(Uint8List bytes) → String
Converts UTF-16BE bytes (the format of /ToUnicode destinations) into text, respecting surrogate pairs.
glyphNameToText(String name) → String?
Translates a glyph name into text.
parseToUnicode(Uint8List bytes) → PdfToUnicodeCMap
Reads an already decompressed /ToUnicode CMap.
unknown([String? resourceName]) → PdfContentFont
Generic font used when the resource could not be resolved.