[PDFKit] Extend TextOptions interface to allow features (#41145)

* feat(pdfkit): add opentype features to TextOptions interface

* style(pdfkit): add semicolons to match previous definitions
This commit is contained in:
BamButz
2019-12-26 13:05:10 -06:00
committed by Andrew Branch
parent 6668a171f5
commit f383de8a3d
2 changed files with 31 additions and 1 deletions
+28
View File
@@ -5,6 +5,7 @@
// Jeroen Vervaeke <https://github.com/jeroenvervaeke/>
// Thales Agapito <https://github.com/thalesagapito/>
// Evgeny Baram <https://github.com/r4tz52/>
// BamButz <https://github.com/BamButz/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
@@ -69,6 +70,31 @@ declare namespace PDFKit.Mixins {
// The winding / filling rule accepted by PDFKit:
type RuleValue = 'even-odd' | 'evenodd' | 'non-zero' | 'nonzero';
// Text option opentype features as listed at https://docs.microsoft.com/en-us/typography/opentype/spec/featurelist
type OpenTypeFeatures =
| 'aalt' | 'abvf' | 'abvm' | 'abvs' | 'afrc' | 'akhn' | 'blwf' | 'blwm' | 'blws' | 'calt' | 'case'
| 'cfar' | 'cjct' | 'clig' | 'cpct' | 'cpsp' | 'cswh' | 'curs' | 'cv01' | 'cv02' | 'cv03' | 'cv04'
| 'cv05' | 'cv06' | 'cv07' | 'cv08' | 'cv09' | 'cv10' | 'cv11' | 'cv12' | 'cv13' | 'cv14' | 'cv15'
| 'cv16' | 'cv17' | 'cv18' | 'cv19' | 'cv20' | 'cv21' | 'cv22' | 'cv23' | 'cv24' | 'cv25' | 'cv26'
| 'cv27' | 'cv28' | 'cv29' | 'cv30' | 'cv31' | 'cv32' | 'cv33' | 'cv34' | 'cv35' | 'cv36' | 'cv37'
| 'cv38' | 'cv39' | 'cv40' | 'cv41' | 'cv42' | 'cv43' | 'cv44' | 'cv45' | 'cv46' | 'cv47' | 'cv48'
| 'cv49' | 'cv50' | 'cv51' | 'cv52' | 'cv53' | 'cv54' | 'cv55' | 'cv56' | 'cv57' | 'cv58' | 'cv59'
| 'cv60' | 'cv61' | 'cv62' | 'cv63' | 'cv64' | 'cv65' | 'cv66' | 'cv67' | 'cv68' | 'cv69' | 'cv70'
| 'cv71' | 'cv72' | 'cv73' | 'cv74' | 'cv75' | 'cv76' | 'cv77' | 'cv78' | 'cv79' | 'cv80' | 'cv81'
| 'cv82' | 'cv83' | 'cv84' | 'cv85' | 'cv86' | 'cv87' | 'cv88' | 'cv89' | 'cv90' | 'cv91' | 'cv92'
| 'cv93' | 'cv94' | 'cv95' | 'cv96' | 'cv97' | 'cv98' | 'cv99' | 'c2pc' | 'c2sc' | 'dist' | 'ccmp'
| 'dlig' | 'dnom' | 'dtls' | 'expt' | 'falt' | 'fin2' | 'fin3' | 'fina' | 'flac' | 'frac' | 'fwid'
| 'half' | 'haln' | 'halt' | 'hist' | 'hkna' | 'hlig' | 'hngl' | 'hojo' | 'hwid' | 'init' | 'isol'
| 'ital' | 'jalt' | 'jp78' | 'jp83' | 'jp90' | 'jp04' | 'kern' | 'lfbd' | 'liga' | 'ljmo' | 'lnum'
| 'locl' | 'ltra' | 'ltrm' | 'mark' | 'med2' | 'medi' | 'mgrk' | 'mkmk' | 'mset' | 'nalt' | 'nlck'
| 'nukt' | 'numr' | 'onum' | 'opbd' | 'ordn' | 'ornm' | 'palt' | 'pcap' | 'pkna' | 'pnum' | 'pref'
| 'pres' | 'pstf' | 'psts' | 'pwid' | 'qwid' | 'rand' | 'rclt' | 'rkrf' | 'rlig' | 'rphf' | 'rtbd'
| 'rtla' | 'rtlm' | 'ruby' | 'rvrn' | 'salt' | 'sinf' | 'size' | 'smcp' | 'smpl' | 'ss01' | 'ss02'
| 'ss03' | 'ss04' | 'ss05' | 'ss06' | 'ss07' | 'ss08' | 'ss09' | 'ss10' | 'ss11' | 'ss12' | 'ss13'
| 'ss14' | 'ss15' | 'ss16' | 'ss17' | 'ss18' | 'ss19' | 'ss20' | 'ssty' | 'stch' | 'subs' | 'sups'
| 'swsh' | 'titl' | 'tjmo' | 'tnam' | 'tnum' | 'trad' | 'twid' | 'unic' | 'valt' | 'vatu' | 'vert'
| 'vhal' | 'vjmo' | 'vkna' | 'vkrn' | 'vpal' | 'vrt2' | 'vrtr' | 'zero';
interface PDFColor {
fillColor(color: ColorValue, opacity?: number): this;
strokeColor(color: ColorValue, opacity?: number): this;
@@ -152,6 +178,8 @@ declare namespace PDFKit.Mixins {
align?: 'center' | 'justify' | 'left' | 'right' | string;
/** the vertical alignment of the text with respect to its insertion point */
baseline?: number | 'svg-middle' | 'middle' | 'svg-central' | 'bottom' | 'ideographic' | 'alphabetic' | 'mathematical' | 'hanging' | 'top';
/** an array of OpenType feature tags to apply. If not provided, a set of defaults is used. */
features?: OpenTypeFeatures[];
}
interface PDFText {
+3 -1
View File
@@ -181,6 +181,8 @@ doc.text('Baseline - string literal', { baseline: 'alphabetic' });
doc.text('Baseline - numeric', { baseline: 10 });
doc.text('Text with features', { features: [ "kern" ] });
doc.goTo(0, 0, 0, 0, 'lorem');
doc.image('path/to/image.png', {
@@ -227,4 +229,4 @@ class SubPDFDocument extends PDFDocument {
var subDoc = new SubPDFDocument({});
subDoc.moveTo(subDoc.page.width / 2, subDoc.page.height / 2).text(10);
subDoc.lineWidth(3).segment(10, subDoc.page.width - 10, subDoc.page.height - 10, 10).stroke("#00FFFF");
subDoc.lineWidth(3).segment(10, subDoc.page.width - 10, subDoc.page.height - 10, 10).stroke("#00FFFF");