///
import { FontDescriptor } from './descriptor';
import { Encoding } from '../encoding/index';
import { PDF, Model } from '../models';
import { PDFObject } from '../pdfdom';
/**
Font is a general, partly abstract (see Font#measure) representation of a PDF
Font of any Subtype.
Some uses, which vary in their implementation based on the Type of the font,
require creating a specific Font subclass, e.g., Type1Font().
Beyond the `object` property, common to all Model instances, Font also has a
`Name` field, which is populated when the Font is instantiated from within
Resources#getFont(), for easier debugging. It should not be used for any
material purposes (and is not necessary for any).
*/
export declare abstract class Font extends Model {
Name: string;
readonly Subtype: string;
/**
This returns the object's `Encoding.BaseEncoding`, if it exists, or
the plain `Encoding` value, if it's a string.
*/
readonly BaseEncoding: string;
readonly Differences: Array;
/**
BaseFont is supposed to be a name (i.e., a string).
Maybe not always?
*/
readonly BaseFont: string;
/**
If the Font specifies no FontDescriptor value, this will return `undefined`
rather than an empty Model.
*/
readonly FontDescriptor: FontDescriptor;
readonly FirstChar: number;
readonly LastChar: number;
/**
1. The BaseFont name may contain the string "Bold"
2. The FontDescriptor.FontName may contain the string "Bold"
3. The FontDescriptor.FontWeight may be 700 or higher
*/
readonly bold: boolean;
readonly italic: boolean;
/**
We need the Font's Encoding to map character codes into the glyph name (which
can then easily be mapped to the unicode string representation of that glyph).
The `encoding` getter memoizes the result.
Encoding and ToUnicode are not always specified.
*/
readonly encoding: Encoding;
/**
Returns a native (unicode) Javascript string representing the given character
codes. These character codes may have nothing to do with Latin-1, directly,
but can be mapped to unicode via the Font dictionary's Encoding or ToUnicode
fields, and can be assigned widths via the Font dictionary's Widths or
BaseFont fields.
Uses ES6-like `\u{...}`-style escape sequences if the character code cannot
be resolved to a string (unless the `skipMissing` argument is set to `true`,
in which case, it simply skips those characters).
*/
decodeString(buffer: Buffer, skipMissing?: boolean): string;
/**
This should be overridden by subclasses to return a total width, in text units
(usually somewhere in the range of 250-750 for each character/glyph).
*/
abstract measure(buffer: Buffer): number;
toJSON(): {
Type: string;
Subtype: string;
BaseFont: string;
};
static isFont(object: any): object is Font;
/**
See Table 110 – Font types:
Type0 | Type1 | MMType1 | Type3 | TrueType | CIDFontType0 | CIDFontType2
*/
static getConstructor(Subtype: string): {
new (pdf: PDF, object: PDFObject): Font;
};
}
/**
Type 1 Font (See PDF32000_2008.pdf:9.6.2, Table 111)
## The basics
* `Type: string = 'Font'`
* `Subtype: string = 'Type1'`
* `BaseFont: string`
This is required, but does not always name a Core14 font. From the spec:
> The PostScript name of the font. For Type 1 fonts, this is always the value
> of the FontName entry in the font program. The PostScript name of the font
> may be used to find the font program in the conforming reader or its
> environment
* `Name?: string`
Obsolete. This is a relic of PDF 1.0, when it matched the key of this font in
the current Resources' `Font` dictionary.
## Metrics for non-Core14 fonts
* `FirstChar?: integer`
* `LastChar?: integer`
* `Widths?: array`
The PDF spec actually recommends that `Widths` be an indirect reference.
* `FontDescriptor?`
These four fields are optional for the Core14 ("standard 14") fonts, but are
not precluded for the Core14 fonts. In fact, PDF 1.5 suggests that even the
Core14 fonts specify these fields. They come in a package -- they "shall" all
be present, or all be absent.
## Resolving character codes
* `Encoding?: string | dictionary`
Optional. From the spec:
> A specification of the font's character encoding if different from its built-in encoding. The value of Encoding shall be either the name of a predefined encoding (MacRomanEncoding, MacExpertEncoding, or WinAnsiEncoding) or an encoding dictionary that shall specify differences from the font's built-in encoding or from a specified predefined encoding.
* `ToUnicode?: ContentStream`
Optional. From the spec:
> A stream containing a CMap file that maps character codes to Unicode values.
# Cached objects
* `_widthMapping: {[index: string]: number}`
A cached mapping from unicode strings to character widths (numbers). In the
case that `Widths`, etc., are defined, it'd be easier to map directly from
character codes, but since we might also have to load the widths from a Core14
font metrics file, unicode is the common denominator.
* `_defaultWidth: number`
A cached number representing the default character width, when the character
code cannot be found in `_widthMapping`.
*/
export declare class Type1Font extends Font {
private _widthMapping;
private _defaultWidth;
measure(buffer: Buffer): number;
/**
This may be able to determine character code widths directly from the Font
resource, but may have to load a FontMetrics instance for Core14 fonts.
If `Widths`, `FirstChar`, `LastChar`, and `FontDescriptor` are missing, and
the BaseFont value is not one of the Core14 fonts, this will throw an Error.
*/
private _initializeWidthMapping;
static isType1Font(object: any): object is Type1Font;
}
/**
Composite font (PDF32000_2008.pdf:9.7)
* `Type: string = 'Font'`
* `Subtype: string = 'Type0'`
* `DescendantFonts: Array`
# Cached objects
* `_widthMapping: number[]`
A cached mapping from charCodes to character widths.
* `_defaultWidth: number`
A cached number representing the default character width, when the character
code cannot be found in `_widthMapping`.
*/
export declare class Type0Font extends Font {
private _widthMapping;
private _defaultWidth;
/**
> DescendantFonts: array (Required): A one-element array specifying the
> CIDFont dictionary that is the descendant of this Type 0 font.
*/
readonly DescendantFont: CIDFont;
private _initializeWidthMapping;
measure(buffer: Buffer): number;
static isType0Font(object: any): object is Type0Font;
}
/**
CIDFonts (PDF32000_2008.pdf:9.7.4)
This doesn't need to inherit the full Font class.
Goes well with Type 0 fonts.
> Type: 'Font'
> Subtype: 'CIDFontType0' or 'CIDFontType2'
> CIDSystemInfo: dictionary (Required)
> DW: integer (Optional) The default width for glyphs in the CIDFont. Default
value: 1000 (defined in user units).
> W: array (Optional) A description of the widths for the glyphs in the CIDFont.
The array's elements have a variable format that can specify individual
widths for consecutive CIDs or one width for a range of CIDs. Default
value: none (the DW value shall be used for all glyphs).
*/
export declare class CIDFont extends Model {
readonly CIDSystemInfo: string;
readonly W: Array;
getDefaultWidth(): number;
/**
The W array allows the definition of widths for individual CIDs. The elements
of the array shall be organized in groups of two or three, where each group
shall be in one of these two formats:
1. `c [w1 w2 ... wn]`: `c` shall be an integer specifying a starting CID
value; it shall be followed by an array of `n` numbers that shall specify
the widths for n consecutive CIDs, starting with `c`.
2. `c_first c_last w`: define the same width, `w`, for all CIDs in the range
`c_first` to `c_last` (inclusive).
*/
getWidthMapping(): number[];
}