Type 1 charstrings: decryption and drawing.
Module fontType1Charstring | Source packages/front/office/fonts/src/type1/charstring.js | Deps fontErrors, encodingStandard | Worker-safe yes
The interpreter behind type1's glyph(name) (Adobe Type 1 Font Format, ch. 6–8).
Exports
| Symbol | Type | Description |
|---|---|---|
decrypt |
function | (bytes, key, skip) => Uint8Array: the plain bytes of an encrypted run (key 55665 for eexec, 4330 for a charstring), the first skip dropped. |
draw |
function | (charstring, { subrs, glyph }) => { advanceWidth, leftSideBearing, path }: a decrypted charstring run. subrs are the decrypted subroutines; glyph(name) gives a glyph's decrypted charstring or null (for seac). |
fontType1Charstring |
factory | Factory. |
Notes
- Path: the commands
{ type: 'M' | 'L' | 'C', x, y, … }and{ type: 'Z' }, in character space, as the other outline modules write them. hsbwandsbwset the side bearing point (the current point) and the advance.rmoveto,hmoveto,vmovetostart a subpath (M). A line or curve with no open subpath starts one at the current point.closepathcloses it (Z) and keeps the current point.callothersubrhands its arguments to a PostScript operand stack, whichpopreads back:- 1, 2, 0 — flex: the seven points the moves reach between
1and0are drawn as two curves, and the final point is handed back forsetcurrentpoint; - 3 — hint replacement: hands back its subroutine number;
- any other number — hands its arguments back in order.
- 1, 2, 0 — flex: the seven points the moves reach between
seacdraws the base and the accent byStandardEncodingthroughglyph(name). The accent is moved byadx − asbplus the composite's side bearing; aseacinside aseacthrows.divdivides. The hints (hstem,vstem,hstem3,vstem3,dotsection) are read and ignored.- Errors (
ParseError): subroutines nested past 10 levels, or a charstring past 65,536 operators, throwfonts/type1-charstring-budget. A call to a subroutine the font lacks throwsfonts/type1-missing-subr.