MCPcopy
hub / github.com/diegomura/react-pdf / open

Method open

packages/pdfkit/src/font.js:6–29  ·  view source on GitHub ↗
(document, src, family, id)

Source from the content-addressed store, hash-verified

4
5export class PDFFont {
6 static open(document, src, family, id) {
7 let font;
8
9 if (typeof src === 'string') {
10 if (StandardFont.isStandardFont(src)) {
11 return new StandardFont(document, src, id);
12 }
13 font = fontkit.openSync(src, family);
14 } else if (Buffer.isBuffer(src)) {
15 font = fontkit.create(src, family);
16 } else if (src instanceof Uint8Array) {
17 font = fontkit.create(Buffer.from(src), family);
18 } else if (src instanceof ArrayBuffer) {
19 font = fontkit.create(Buffer.from(new Uint8Array(src)), family);
20 } else if (typeof src === 'object') {
21 font = src;
22 }
23
24 if (font == null) {
25 throw new Error('Not a supported font format or standard PDF font.');
26 }
27
28 return new EmbeddedFont(document, font, id);
29 }
30
31 encode(text) {
32 throw new Error('Must be implemented by subclasses');

Callers 2

constructorMethod · 0.45
loadMethod · 0.45

Calls 2

isStandardFontMethod · 0.80
createMethod · 0.80

Tested by

no test coverage detected