[pdfmake][pdfkit] a font can also be a Buffer (#45377)

* [pdfmake] a font can also be a Buffer

ref: https://github.com/foliojs/pdfkit/blob/master/lib/font_factory.js#L9-L22

* [pdfkit] the source of a font can be a Buffer

ref: https://github.com/foliojs/pdfkit/blob/master/lib/font_factory.js#L9-L22

* fix lint

* fix lint

* fix lint

* add some tests to register a font with a buffer

* use pdfkit font type definition
This commit is contained in:
Mathieu Dutour 2020-06-23 21:21:55 +02:00 committed by GitHub
parent 755394db83
commit cbb7dee568
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 5 deletions

View File

@ -105,12 +105,14 @@ declare namespace PDFKit.Mixins {
radialGradient(x1: number, y1: number, r1: number, x2: number, y2: number, r2: number): PDFRadialGradient;
}
type PDFFontSource = string | Buffer | Uint8Array | ArrayBuffer;
interface PDFFont {
font(buffer: Buffer): this;
font(src: string, family?: string, size?: number): this;
fontSize(size: number): this;
currentLineHeight(includeGap?: boolean): number;
registerFont(name: string, src?: string, family?: string): this;
registerFont(name: string, src?: PDFFontSource, family?: string): this;
}
interface ImageOption {

View File

@ -12,6 +12,8 @@ import pdfData = require('pdfkit/js/data');
import text = require('pdfkit/js/mixins/text');
font.registerFont('Arial');
font.registerFont('CustomFont', 'path/to/font.ttf');
font.registerFont('CustomFontWithBuffer', Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]));
text.widthOfString('Kila', { ellipsis: true });
var doc = new PDFDocument({

View File

@ -32,10 +32,10 @@ export interface TFontDictionary {
}
export interface TFontFamilyTypes {
normal?: string;
bold?: string;
italics?: string;
bolditalics?: string;
normal?: PDFKit.Mixins.PDFFontSource;
bold?: PDFKit.Mixins.PDFFontSource;
italics?: PDFKit.Mixins.PDFFontSource;
bolditalics?: PDFKit.Mixins.PDFFontSource;
}
export interface TDocumentInformation {