@pdfme/pdf-lib 6.1.13-dev.8 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/PDFPageOptions.d.ts +17 -1
- package/dist/api/svg.d.ts +1 -1
- package/dist/core/embedders/CustomFontEmbedder.d.ts +14 -0
- package/dist/core/embedders/CustomFontSubsetEmbedder.d.ts +1 -0
- package/dist/index.js +163 -30
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/scriptRuns.d.ts +17 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Color } from './colors.js';
|
|
1
|
+
import type { Color, RGB } from './colors.js';
|
|
2
2
|
import PDFFont from './PDFFont.js';
|
|
3
3
|
import { Rotation } from './rotations.js';
|
|
4
4
|
import { FillRule, LineCapStyle } from './operators.js';
|
|
@@ -159,6 +159,21 @@ export interface PDFPageDrawCircleOptions extends SvgOptions {
|
|
|
159
159
|
borderLineCap?: LineCapStyle;
|
|
160
160
|
blendMode?: BlendMode;
|
|
161
161
|
}
|
|
162
|
+
export type SvgColorMapper = (input: {
|
|
163
|
+
color: string;
|
|
164
|
+
parsed: {
|
|
165
|
+
rgb: RGB;
|
|
166
|
+
alpha?: number;
|
|
167
|
+
};
|
|
168
|
+
kind: 'fill' | 'stroke';
|
|
169
|
+
inherited?: {
|
|
170
|
+
color?: Color;
|
|
171
|
+
opacity?: number;
|
|
172
|
+
};
|
|
173
|
+
}) => {
|
|
174
|
+
color: Color;
|
|
175
|
+
alpha?: number;
|
|
176
|
+
} | undefined;
|
|
162
177
|
export interface PDFPageDrawSVGElementOptions {
|
|
163
178
|
x?: number;
|
|
164
179
|
y?: number;
|
|
@@ -168,5 +183,6 @@ export interface PDFPageDrawSVGElementOptions {
|
|
|
168
183
|
fonts?: {
|
|
169
184
|
[fontName: string]: PDFFont;
|
|
170
185
|
};
|
|
186
|
+
mapColor?: SvgColorMapper;
|
|
171
187
|
}
|
|
172
188
|
export {};
|
package/dist/api/svg.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HTMLElement } from 'node-html-better-parser';
|
|
2
|
-
import { Color } from './colors.js';
|
|
2
|
+
import { type Color } from './colors.js';
|
|
3
3
|
import { Degrees } from './rotations.js';
|
|
4
4
|
import PDFPage from './PDFPage.js';
|
|
5
5
|
import { PDFPageDrawSVGElementOptions } from './PDFPageOptions.js';
|
|
@@ -18,6 +18,7 @@ declare class CustomFontEmbedder {
|
|
|
18
18
|
readonly fontFeatures: TypeFeatures | undefined;
|
|
19
19
|
protected baseFontName: string;
|
|
20
20
|
protected glyphCache: Cache<Glyph[]>;
|
|
21
|
+
private readonly shapedGlyphsById;
|
|
21
22
|
protected constructor(font: Font, fontData: Uint8Array, customName?: string, fontFeatures?: TypeFeatures);
|
|
22
23
|
/**
|
|
23
24
|
* Encode the JavaScript string into this font. (JavaScript encodes strings in
|
|
@@ -25,6 +26,19 @@ declare class CustomFontEmbedder {
|
|
|
25
26
|
*/
|
|
26
27
|
encodeText(text: string): PDFHexString;
|
|
27
28
|
widthOfTextAtSize(text: string, size: number): number;
|
|
29
|
+
/**
|
|
30
|
+
* Layout `text` as one or more fontkit runs. Thai/Lao spans are shaped
|
|
31
|
+
* separately so GSUB mark variants are selected even when Latin/CJK leads.
|
|
32
|
+
* A script tag is never passed — each run has one strong script, so fontkit
|
|
33
|
+
* auto-detection matches the script we would have specified.
|
|
34
|
+
*/
|
|
35
|
+
protected layoutGlyphs(text: string): Glyph[];
|
|
36
|
+
/**
|
|
37
|
+
* GSUB can emit glyphs that are not in `font.characterSet` (e.g. Sarabun
|
|
38
|
+
* tone gid 736). Retain those objects so `computeWidths()` and
|
|
39
|
+
* `embedUnicodeCmap()` include them when the full font is embedded.
|
|
40
|
+
*/
|
|
41
|
+
protected registerShapedGlyphs(glyphs: Glyph[]): void;
|
|
28
42
|
heightOfFontAtSize(size: number, options?: {
|
|
29
43
|
descender?: boolean;
|
|
30
44
|
}): number;
|
|
@@ -12,6 +12,7 @@ declare class CustomFontSubsetEmbedder extends CustomFontEmbedder {
|
|
|
12
12
|
private readonly glyphs;
|
|
13
13
|
private readonly glyphIdMap;
|
|
14
14
|
private constructor();
|
|
15
|
+
protected registerShapedGlyphs(_glyphs: Glyph[]): void;
|
|
15
16
|
encodeText(text: string): PDFHexString;
|
|
16
17
|
protected isCFF(): boolean;
|
|
17
18
|
protected glyphId(glyph?: Glyph): number;
|
package/dist/index.js
CHANGED
|
@@ -815,6 +815,45 @@ var pdfDocEncodingDecode = (bytes) => {
|
|
|
815
815
|
return String.fromCodePoint(...codePoints);
|
|
816
816
|
};
|
|
817
817
|
//#endregion
|
|
818
|
+
//#region src/utils/scriptRuns.ts
|
|
819
|
+
var MARK_CRITICAL_SCRIPTS = [{
|
|
820
|
+
name: "thai",
|
|
821
|
+
test: /\p{Script=Thai}/u
|
|
822
|
+
}, {
|
|
823
|
+
name: "lao",
|
|
824
|
+
test: /\p{Script=Lao}/u
|
|
825
|
+
}];
|
|
826
|
+
var MARK_CRITICAL_ANY = /[\p{Script=Thai}\p{Script=Lao}]/u;
|
|
827
|
+
var NEUTRAL = /[\p{Script=Common}\p{Script=Inherited}]/u;
|
|
828
|
+
var classifyCodePoint = (ch) => {
|
|
829
|
+
if (NEUTRAL.test(ch)) return null;
|
|
830
|
+
for (const { name, test } of MARK_CRITICAL_SCRIPTS) if (test.test(ch)) return name;
|
|
831
|
+
return "default";
|
|
832
|
+
};
|
|
833
|
+
/**
|
|
834
|
+
* Split `text` into shaping runs at Thai/Lao script boundaries.
|
|
835
|
+
* Concatenating the result always reproduces the input.
|
|
836
|
+
*/
|
|
837
|
+
var splitTextIntoShapingRuns = (text) => {
|
|
838
|
+
if (text.length === 0) return [];
|
|
839
|
+
if (!MARK_CRITICAL_ANY.test(text)) return [text];
|
|
840
|
+
const runs = [];
|
|
841
|
+
let current = "";
|
|
842
|
+
let currentClass = null;
|
|
843
|
+
for (const ch of text) {
|
|
844
|
+
const cls = classifyCodePoint(ch);
|
|
845
|
+
if (!(cls === null || currentClass === null || currentClass === cls) && current.length > 0) {
|
|
846
|
+
runs.push(current);
|
|
847
|
+
current = "";
|
|
848
|
+
currentClass = null;
|
|
849
|
+
}
|
|
850
|
+
current += ch;
|
|
851
|
+
if (cls !== null) currentClass = cls;
|
|
852
|
+
}
|
|
853
|
+
if (current.length > 0) runs.push(current);
|
|
854
|
+
return runs;
|
|
855
|
+
};
|
|
856
|
+
//#endregion
|
|
818
857
|
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/typeof.js
|
|
819
858
|
function _typeof(o) {
|
|
820
859
|
"@babel/helpers - typeof";
|
|
@@ -3314,12 +3353,15 @@ var CustomFontEmbedder = class CustomFontEmbedder {
|
|
|
3314
3353
|
_defineProperty(this, "fontFeatures", void 0);
|
|
3315
3354
|
_defineProperty(this, "baseFontName", void 0);
|
|
3316
3355
|
_defineProperty(this, "glyphCache", void 0);
|
|
3356
|
+
_defineProperty(this, "shapedGlyphsById", void 0);
|
|
3317
3357
|
_defineProperty(this, "allGlyphsInFontSortedById", () => {
|
|
3318
|
-
const glyphs = Array(this.font.characterSet.length);
|
|
3319
|
-
for (let idx = 0, len =
|
|
3358
|
+
const glyphs = Array(this.font.characterSet.length + this.shapedGlyphsById.size);
|
|
3359
|
+
for (let idx = 0, len = this.font.characterSet.length; idx < len; idx++) {
|
|
3320
3360
|
const codePoint = this.font.characterSet[idx];
|
|
3321
3361
|
glyphs[idx] = this.font.glyphForCodePoint(codePoint);
|
|
3322
3362
|
}
|
|
3363
|
+
let extraIdx = this.font.characterSet.length;
|
|
3364
|
+
for (const glyph of this.shapedGlyphsById.values()) glyphs[extraIdx++] = glyph;
|
|
3323
3365
|
return sortedUniq(glyphs.sort(byAscendingId), (g) => g.id);
|
|
3324
3366
|
});
|
|
3325
3367
|
this.font = font;
|
|
@@ -3329,6 +3371,7 @@ var CustomFontEmbedder = class CustomFontEmbedder {
|
|
|
3329
3371
|
this.customName = customName;
|
|
3330
3372
|
this.fontFeatures = fontFeatures;
|
|
3331
3373
|
this.baseFontName = "";
|
|
3374
|
+
this.shapedGlyphsById = /* @__PURE__ */ new Map();
|
|
3332
3375
|
this.glyphCache = Cache.populatedBy(this.allGlyphsInFontSortedById);
|
|
3333
3376
|
}
|
|
3334
3377
|
/**
|
|
@@ -3336,18 +3379,54 @@ var CustomFontEmbedder = class CustomFontEmbedder {
|
|
|
3336
3379
|
* Unicode, but embedded fonts use their own custom encodings)
|
|
3337
3380
|
*/
|
|
3338
3381
|
encodeText(text) {
|
|
3339
|
-
const
|
|
3382
|
+
const glyphs = this.layoutGlyphs(text);
|
|
3340
3383
|
const hexCodes = Array(glyphs.length);
|
|
3341
3384
|
for (let idx = 0, len = glyphs.length; idx < len; idx++) hexCodes[idx] = toHexStringOfMinLength(glyphs[idx].id, 4);
|
|
3342
3385
|
return PDFHexString.of(hexCodes.join(""));
|
|
3343
3386
|
}
|
|
3344
3387
|
widthOfTextAtSize(text, size) {
|
|
3345
|
-
const
|
|
3388
|
+
const glyphs = this.layoutGlyphs(text);
|
|
3346
3389
|
let totalWidth = 0;
|
|
3347
3390
|
for (let idx = 0, len = glyphs.length; idx < len; idx++) totalWidth += glyphs[idx].advanceWidth * this.scale;
|
|
3348
3391
|
const scale = size / 1e3;
|
|
3349
3392
|
return totalWidth * scale;
|
|
3350
3393
|
}
|
|
3394
|
+
/**
|
|
3395
|
+
* Layout `text` as one or more fontkit runs. Thai/Lao spans are shaped
|
|
3396
|
+
* separately so GSUB mark variants are selected even when Latin/CJK leads.
|
|
3397
|
+
* A script tag is never passed — each run has one strong script, so fontkit
|
|
3398
|
+
* auto-detection matches the script we would have specified.
|
|
3399
|
+
*/
|
|
3400
|
+
layoutGlyphs(text) {
|
|
3401
|
+
const runs = splitTextIntoShapingRuns(text);
|
|
3402
|
+
let glyphs;
|
|
3403
|
+
if (runs.length <= 1) glyphs = this.font.layout(runs[0] ?? "", this.fontFeatures).glyphs;
|
|
3404
|
+
else {
|
|
3405
|
+
glyphs = [];
|
|
3406
|
+
for (const run of runs) {
|
|
3407
|
+
const runGlyphs = this.font.layout(run, this.fontFeatures).glyphs;
|
|
3408
|
+
for (let idx = 0, len = runGlyphs.length; idx < len; idx++) glyphs.push(runGlyphs[idx]);
|
|
3409
|
+
}
|
|
3410
|
+
}
|
|
3411
|
+
this.registerShapedGlyphs(glyphs);
|
|
3412
|
+
return glyphs;
|
|
3413
|
+
}
|
|
3414
|
+
/**
|
|
3415
|
+
* GSUB can emit glyphs that are not in `font.characterSet` (e.g. Sarabun
|
|
3416
|
+
* tone gid 736). Retain those objects so `computeWidths()` and
|
|
3417
|
+
* `embedUnicodeCmap()` include them when the full font is embedded.
|
|
3418
|
+
*/
|
|
3419
|
+
registerShapedGlyphs(glyphs) {
|
|
3420
|
+
let added = false;
|
|
3421
|
+
for (let idx = 0, len = glyphs.length; idx < len; idx++) {
|
|
3422
|
+
const glyph = glyphs[idx];
|
|
3423
|
+
if (!this.shapedGlyphsById.has(glyph.id)) {
|
|
3424
|
+
this.shapedGlyphsById.set(glyph.id, glyph);
|
|
3425
|
+
added = true;
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
if (added) this.glyphCache.invalidate();
|
|
3429
|
+
}
|
|
3351
3430
|
heightOfFontAtSize(size, options = {}) {
|
|
3352
3431
|
const { descender = true } = options;
|
|
3353
3432
|
const { ascent, descent, bbox } = this.font;
|
|
@@ -3484,8 +3563,9 @@ var CustomFontSubsetEmbedder = class CustomFontSubsetEmbedder extends CustomFont
|
|
|
3484
3563
|
this.glyphCache = Cache.populatedBy(() => this.glyphs);
|
|
3485
3564
|
this.glyphIdMap = /* @__PURE__ */ new Map();
|
|
3486
3565
|
}
|
|
3566
|
+
registerShapedGlyphs(_glyphs) {}
|
|
3487
3567
|
encodeText(text) {
|
|
3488
|
-
const
|
|
3568
|
+
const glyphs = this.layoutGlyphs(text);
|
|
3489
3569
|
const hexCodes = Array(glyphs.length);
|
|
3490
3570
|
for (let idx = 0, len = glyphs.length; idx < len; idx++) {
|
|
3491
3571
|
const glyph = glyphs[idx];
|
|
@@ -17091,7 +17171,8 @@ var runnersToPage = (page, options) => ({
|
|
|
17091
17171
|
const isBold = style.fontWeight === "bold" || Number(style.fontWeight) >= 700;
|
|
17092
17172
|
const isItalic = style.fontStyle === "italic";
|
|
17093
17173
|
const getFont = (bold, italic, family) => fonts[family + (bold ? "_bold" : "") + (italic ? "_italic" : "")];
|
|
17094
|
-
|
|
17174
|
+
const matchingFontFamily = Object.keys(fonts).find((fontFamily) => fontFamily.startsWith(family));
|
|
17175
|
+
return getFont(isBold, isItalic, family) || getFont(isBold, false, family) || getFont(false, isItalic, family) || getFont(false, false, family) || (matchingFontFamily ? fonts[matchingFontFamily] : void 0);
|
|
17095
17176
|
}
|
|
17096
17177
|
const font = options.fonts && getBestFont(element.svgAttributes, options.fonts);
|
|
17097
17178
|
const textWidth = (font || page.getFont()[0]).widthOfTextAtSize(text, fontSize);
|
|
@@ -17210,25 +17291,78 @@ var parseStyles = (style) => {
|
|
|
17210
17291
|
}
|
|
17211
17292
|
return css;
|
|
17212
17293
|
};
|
|
17213
|
-
var
|
|
17294
|
+
var stripImportantSuffix = (value) => {
|
|
17295
|
+
const suffix = "!important";
|
|
17296
|
+
const trimmed = value.trim();
|
|
17297
|
+
return trimmed.toLowerCase().endsWith(suffix) ? trimmed.slice(0, -10).trimEnd() : trimmed;
|
|
17298
|
+
};
|
|
17299
|
+
var splitFontFamilies = (fontFamily) => {
|
|
17300
|
+
const families = [];
|
|
17301
|
+
let current = "";
|
|
17302
|
+
let quote;
|
|
17303
|
+
for (const char of fontFamily) {
|
|
17304
|
+
if ((char === "\"" || char === "'") && (!quote || quote === char)) {
|
|
17305
|
+
quote = quote ? void 0 : char;
|
|
17306
|
+
continue;
|
|
17307
|
+
}
|
|
17308
|
+
if (char === "," && !quote) {
|
|
17309
|
+
if (current.trim()) families.push(current.trim());
|
|
17310
|
+
current = "";
|
|
17311
|
+
continue;
|
|
17312
|
+
}
|
|
17313
|
+
current += char;
|
|
17314
|
+
}
|
|
17315
|
+
if (current.trim()) families.push(current.trim());
|
|
17316
|
+
return families.map(stripImportantSuffix).filter(Boolean);
|
|
17317
|
+
};
|
|
17318
|
+
var normalizeFontFamily = (fontFamily) => {
|
|
17319
|
+
return splitFontFamilies(fontFamily)[0] || fontFamily.trim();
|
|
17320
|
+
};
|
|
17321
|
+
var parseColor = (color, kind, options, inherited) => {
|
|
17214
17322
|
if (!color || color.length === 0) return void 0;
|
|
17215
17323
|
if (["none", "transparent"].includes(color)) return void 0;
|
|
17216
|
-
if (color === "currentColor")
|
|
17324
|
+
if (color === "currentColor") {
|
|
17325
|
+
if (inherited?.color) return {
|
|
17326
|
+
rgb: inherited.color,
|
|
17327
|
+
alpha: inherited.opacity?.toString()
|
|
17328
|
+
};
|
|
17329
|
+
return parseColor("#000000", kind, options);
|
|
17330
|
+
}
|
|
17217
17331
|
const parsedColor = colorString(color);
|
|
17332
|
+
const parsed = {
|
|
17333
|
+
rgb: parsedColor.rgb,
|
|
17334
|
+
alpha: parsedColor.alpha
|
|
17335
|
+
};
|
|
17336
|
+
const mappedColor = options.mapColor?.({
|
|
17337
|
+
color,
|
|
17338
|
+
parsed,
|
|
17339
|
+
kind,
|
|
17340
|
+
inherited
|
|
17341
|
+
});
|
|
17342
|
+
if (mappedColor) return {
|
|
17343
|
+
rgb: mappedColor.color,
|
|
17344
|
+
alpha: mappedColor.alpha !== void 0 ? mappedColor.alpha.toString() : parsedColor.alpha !== void 0 ? parsedColor.alpha.toString() : void 0
|
|
17345
|
+
};
|
|
17218
17346
|
return {
|
|
17219
17347
|
rgb: parsedColor.rgb,
|
|
17220
|
-
alpha: parsedColor.alpha ? parsedColor.alpha
|
|
17348
|
+
alpha: parsedColor.alpha !== void 0 ? parsedColor.alpha.toString() : void 0
|
|
17221
17349
|
};
|
|
17222
17350
|
};
|
|
17223
|
-
var parseAttributes = (element, inherited, matrix) => {
|
|
17351
|
+
var parseAttributes = (element, inherited, matrix, options) => {
|
|
17224
17352
|
const attributes = element.attributes;
|
|
17225
17353
|
const style = parseStyles(attributes.style);
|
|
17226
17354
|
const widthRaw = styleOrAttribute(attributes, style, "width", "");
|
|
17227
17355
|
const heightRaw = styleOrAttribute(attributes, style, "height", "");
|
|
17228
|
-
const fillRaw = parseColor(styleOrAttribute(attributes, style, "fill")
|
|
17356
|
+
const fillRaw = parseColor(styleOrAttribute(attributes, style, "fill"), "fill", options, {
|
|
17357
|
+
color: inherited.fill,
|
|
17358
|
+
opacity: inherited.fillOpacity
|
|
17359
|
+
});
|
|
17229
17360
|
const fillOpacityRaw = styleOrAttribute(attributes, style, "fill-opacity");
|
|
17230
17361
|
const opacityRaw = styleOrAttribute(attributes, style, "opacity");
|
|
17231
|
-
const strokeRaw = parseColor(styleOrAttribute(attributes, style, "stroke")
|
|
17362
|
+
const strokeRaw = parseColor(styleOrAttribute(attributes, style, "stroke"), "stroke", options, {
|
|
17363
|
+
color: inherited.stroke,
|
|
17364
|
+
opacity: inherited.strokeOpacity
|
|
17365
|
+
});
|
|
17232
17366
|
const strokeOpacityRaw = styleOrAttribute(attributes, style, "stroke-opacity");
|
|
17233
17367
|
const strokeLineCapRaw = styleOrAttribute(attributes, style, "stroke-linecap");
|
|
17234
17368
|
const strokeLineJoinRaw = styleOrAttribute(attributes, style, "stroke-linejoin");
|
|
@@ -17327,10 +17461,7 @@ var parseAttributes = (element, inherited, matrix) => {
|
|
|
17327
17461
|
newMatrix = combineTransformation(newMatrix, "scale", [1, -1]);
|
|
17328
17462
|
svgAttributes.d = attributes.d;
|
|
17329
17463
|
}
|
|
17330
|
-
if (newInherited.fontFamily)
|
|
17331
|
-
const inner = newInherited.fontFamily.match(/^"(.*?)"|^'(.*?)'/);
|
|
17332
|
-
if (inner) newInherited.fontFamily = inner[1] || inner[2];
|
|
17333
|
-
}
|
|
17464
|
+
if (newInherited.fontFamily) newInherited.fontFamily = normalizeFontFamily(newInherited.fontFamily);
|
|
17334
17465
|
if (newInherited.strokeWidth) svgAttributes.strokeWidth = newInherited.strokeWidth;
|
|
17335
17466
|
return {
|
|
17336
17467
|
inherited: newInherited,
|
|
@@ -17401,18 +17532,18 @@ var getAspectRatioTransformation = (matrix, originalWidth, originalHeight, targe
|
|
|
17401
17532
|
content: combineTransformation(combineTransformation(matrix, "translate", [x, y]), "scale", [scale])
|
|
17402
17533
|
};
|
|
17403
17534
|
};
|
|
17404
|
-
var parseHTMLNode = (node, inherited, matrix, clipSpaces) => {
|
|
17535
|
+
var parseHTMLNode = (node, inherited, matrix, clipSpaces, options) => {
|
|
17405
17536
|
if (node.nodeType === NodeType.COMMENT_NODE) return [];
|
|
17406
17537
|
else if (node.nodeType === NodeType.TEXT_NODE) return [];
|
|
17407
|
-
else if (node.tagName === "g") return parseGroupNode(node, inherited, matrix, clipSpaces);
|
|
17408
|
-
else if (node.tagName === "svg") return parseSvgNode(node, inherited, matrix, clipSpaces);
|
|
17538
|
+
else if (node.tagName === "g") return parseGroupNode(node, inherited, matrix, clipSpaces, options);
|
|
17539
|
+
else if (node.tagName === "svg") return parseSvgNode(node, inherited, matrix, clipSpaces, options);
|
|
17409
17540
|
else {
|
|
17410
17541
|
if (node.tagName === "polygon") {
|
|
17411
17542
|
node.tagName = "path";
|
|
17412
17543
|
node.attributes.d = `M${node.attributes.points}Z`;
|
|
17413
17544
|
delete node.attributes.points;
|
|
17414
17545
|
}
|
|
17415
|
-
const attributes = parseAttributes(node, inherited, matrix);
|
|
17546
|
+
const attributes = parseAttributes(node, inherited, matrix, options);
|
|
17416
17547
|
const svgAttributes = {
|
|
17417
17548
|
...attributes.inherited,
|
|
17418
17549
|
...attributes.svgAttributes,
|
|
@@ -17423,10 +17554,10 @@ var parseHTMLNode = (node, inherited, matrix, clipSpaces) => {
|
|
|
17423
17554
|
return [node];
|
|
17424
17555
|
}
|
|
17425
17556
|
};
|
|
17426
|
-
var parseSvgNode = (node, inherited, matrix, clipSpaces) => {
|
|
17557
|
+
var parseSvgNode = (node, inherited, matrix, clipSpaces, options) => {
|
|
17427
17558
|
if (!node.attributes.width) node.setAttribute("width", inherited.viewBox.width + "");
|
|
17428
17559
|
if (!node.attributes.height) node.setAttribute("height", inherited.viewBox.height + "");
|
|
17429
|
-
const attributes = parseAttributes(node, inherited, matrix);
|
|
17560
|
+
const attributes = parseAttributes(node, inherited, matrix, options);
|
|
17430
17561
|
const result = [];
|
|
17431
17562
|
const viewBox = node.attributes.viewBox ? parseViewBox(node.attributes.viewBox) : node.attributes.width && node.attributes.height ? parseViewBox(`0 0 ${node.attributes.width} ${node.attributes.height}`) : inherited.viewBox;
|
|
17432
17563
|
let newMatrix = combineTransformation(matrix, "translate", [parseFloat(node.attributes.x) || 0, parseFloat(node.attributes.y) || 0]);
|
|
@@ -17454,16 +17585,16 @@ var parseSvgNode = (node, inherited, matrix, clipSpaces) => {
|
|
|
17454
17585
|
const parsedNodes = parseHTMLNode(child, {
|
|
17455
17586
|
...attributes.inherited,
|
|
17456
17587
|
viewBox
|
|
17457
|
-
}, newMatrix, [...clipSpaces, baseClipSpace]);
|
|
17588
|
+
}, newMatrix, [...clipSpaces, baseClipSpace], options);
|
|
17458
17589
|
result.push(...parsedNodes);
|
|
17459
17590
|
});
|
|
17460
17591
|
return result;
|
|
17461
17592
|
};
|
|
17462
|
-
var parseGroupNode = (node, inherited, matrix, clipSpaces) => {
|
|
17463
|
-
const attributes = parseAttributes(node, inherited, matrix);
|
|
17593
|
+
var parseGroupNode = (node, inherited, matrix, clipSpaces, options) => {
|
|
17594
|
+
const attributes = parseAttributes(node, inherited, matrix, options);
|
|
17464
17595
|
const result = [];
|
|
17465
17596
|
node.childNodes.forEach((child) => {
|
|
17466
|
-
result.push(...parseHTMLNode(child, attributes.inherited, attributes.matrix, clipSpaces));
|
|
17597
|
+
result.push(...parseHTMLNode(child, attributes.inherited, attributes.matrix, clipSpaces, options));
|
|
17467
17598
|
});
|
|
17468
17599
|
return result;
|
|
17469
17600
|
};
|
|
@@ -17484,7 +17615,7 @@ var parseViewBox = (viewBox) => {
|
|
|
17484
17615
|
height: heightViewBox
|
|
17485
17616
|
};
|
|
17486
17617
|
};
|
|
17487
|
-
var parse$1 = (svg, { width, height, fontSize }, size, matrix) => {
|
|
17618
|
+
var parse$1 = (svg, { width, height, fontSize, mapColor }, size, matrix) => {
|
|
17488
17619
|
const htmlElement = parse(svg).firstChild;
|
|
17489
17620
|
if (width) htmlElement.setAttribute("width", width + "");
|
|
17490
17621
|
if (height) htmlElement.setAttribute("height", height + "");
|
|
@@ -17492,7 +17623,7 @@ var parse$1 = (svg, { width, height, fontSize }, size, matrix) => {
|
|
|
17492
17623
|
return parseHTMLNode(htmlElement, {
|
|
17493
17624
|
...size,
|
|
17494
17625
|
viewBox: parseViewBox(htmlElement.attributes.viewBox || "0 0 1 1")
|
|
17495
|
-
}, matrix, []);
|
|
17626
|
+
}, matrix, [], { mapColor });
|
|
17496
17627
|
};
|
|
17497
17628
|
var drawSvg = async (page, svg, options) => {
|
|
17498
17629
|
if (!svg) return;
|
|
@@ -18862,12 +18993,14 @@ var PDFPage = class {
|
|
|
18862
18993
|
assertOrUndefined(options.y, "options.y", ["number"]);
|
|
18863
18994
|
assertOrUndefined(options.width, "options.width", ["number"]);
|
|
18864
18995
|
assertOrUndefined(options.height, "options.height", ["number"]);
|
|
18996
|
+
assertOrUndefined(options.mapColor, "options.mapColor", [Function]);
|
|
18865
18997
|
await drawSvg(this, svg, {
|
|
18866
18998
|
x: options.x ?? this.x,
|
|
18867
18999
|
y: options.y ?? this.y,
|
|
18868
19000
|
fonts: options.fonts,
|
|
18869
19001
|
width: options.width,
|
|
18870
|
-
height: options.height
|
|
19002
|
+
height: options.height,
|
|
19003
|
+
mapColor: options.mapColor
|
|
18871
19004
|
});
|
|
18872
19005
|
}
|
|
18873
19006
|
getFont() {
|
|
@@ -19117,6 +19250,6 @@ var PDFButton = class extends PDFField {
|
|
|
19117
19250
|
_PDFButton = PDFButton;
|
|
19118
19251
|
_defineProperty(PDFButton, "of", (acroPushButton, ref, doc) => new _PDFButton(acroPushButton, ref, doc));
|
|
19119
19252
|
//#endregion
|
|
19120
|
-
export { AFRelationship, AcroButtonFlags, AcroChoiceFlags, AcroFieldFlags, AcroTextFlags, AnnotationFlags, AppearanceCharacteristics, BlendMode, Cache, CharCodes, ColorTypes, CombedTextLayoutError, CorruptPageTreeError, CustomFontEmbedder, CustomFontSubsetEmbedder, DecompressionBombError, Duplex, EncryptedPDFError, ExceededMaxLengthError, FieldAlreadyExistsError, FieldExistsAsNonTerminalError, FileEmbedder, FillRule, FontkitNotRegisteredError, ForeignPageError, ImageAlignment, IndexOutOfBoundsError, InvalidAcroFieldValueError, InvalidFieldNamePartError, InvalidMaxLengthError, InvalidPDFDateStringError, InvalidTargetIndexError, JpegEmbedder, LineCapStyle, LineJoinStyle, MethodNotImplementedError, MissingCatalogError, MissingDAEntryError, MissingKeywordError, MissingOnValueCheckError, MissingPDFHeaderError, MissingPageContentsEmbeddingError, MissingTfOperatorError, MultiSelectValueError, NextByteAssertionError, NoSuchFieldError, NonFullScreenPageMode, NumberParsingError, PDFAcroButton, PDFAcroCheckBox, PDFAcroChoice, PDFAcroComboBox, PDFAcroField, PDFAcroForm, PDFAcroListBox, PDFAcroNonTerminal, PDFAcroPushButton, PDFAcroRadioButton, PDFAcroSignature, PDFAcroTerminal, PDFAcroText, PDFAnnotation, PDFArray, PDFArrayIsNotRectangleError, PDFBool, PDFButton, PDFCatalog, PDFCheckBox, PDFContentStream, PDFContext, PDFCrossRefSection, PDFCrossRefStream, PDFDict, PDFDocument, PDFDropdown, PDFEmbeddedPage, PDFField, PDFFlateStream, PDFFont, PDFForm, PDFHeader, PDFHexString, PDFImage, PDFInvalidObject, PDFInvalidObjectParsingError, PDFJavaScript, PDFName, PDFNull_default as PDFNull, PDFNumber, PDFObject, PDFObjectCopier, PDFObjectParser, PDFObjectParsingError, PDFObjectStream, PDFObjectStreamParser, PDFOperator, PDFOperatorNames, PDFOptionList, PDFPage, PDFPageEmbedder, PDFPageLeaf, PDFPageTree, PDFParser, PDFParsingError, PDFRadioGroup, PDFRawStream, PDFRef, PDFSignature, PDFStream, PDFStreamParsingError, PDFStreamWriter, PDFString, PDFTextField, PDFTrailer, PDFTrailerDict, PDFWidgetAnnotation, PDFWriter, PDFXRefStreamParser, PageEmbeddingMismatchedContextError, PageSizes, ParseSpeeds, PngEmbedder, PrintScaling, PrivateConstructorError, ReadingDirection, RemovePageFromEmptyDocumentError, ReparseError, RichTextFieldReadError, RotationTypes, StalledParserError, StandardFontEmbedder, StandardFontValues, StandardFonts, TextAlignment, TextRenderingMode, UnbalancedParenthesisError, UnexpectedFieldTypeError, UnexpectedObjectTypeError, UnrecognizedStreamTypeError, UnsupportedEncodingError, ViewerPreferences, addRandomSuffix, adjustDimsForRotation, appendBezierCurve, appendQuadraticCurve, arrayAsString, asNumber, asPDFName, asPDFNumber, assertEachIs, assertInteger, assertIs, assertIsOneOf, assertIsOneOfOrUndefined, assertIsSubset, assertMultiple, assertOrUndefined, assertPositive, assertRange, assertRangeOrUndefined, backtick, beginMarkedContent, beginText, breakTextIntoLines, byAscendingId, bytesFor, canBeConvertedToUint8Array, charAtIndex, charFromCode, charFromHexCode, charSplit, cleanText, clip, clipEvenOdd, closePath, cmyk, colorString, colorToComponents, componentsToColor, concatTransformationMatrix, copyStringIntoBuffer, createPDFAcroField, createPDFAcroFields, createTypeErrorMsg, createValueErrorMsg, decodeFromBase64, decodeFromBase64DataUri, decodePDFRawStream, defaultButtonAppearanceProvider, defaultCheckBoxAppearanceProvider, defaultDropdownAppearanceProvider, defaultOptionListAppearanceProvider, defaultRadioGroupAppearanceProvider, defaultTextFieldAppearanceProvider, degrees, degreesToRadians, drawButton, drawCheckBox, drawCheckMark, drawEllipse, drawEllipsePath, drawImage, drawLine, drawLinesOfText, drawObject, drawOptionList, drawPage, drawRadioButton, drawRectangle, drawSvgPath, drawText, drawTextField, drawTextLines, encodeToBase64, endMarkedContent, endPath, endText, error, escapeRegExp, escapedNewlineChars, fill, fillAndStroke, fillEvenOdd, findLastMatch, getType, grayscale, hasSurrogates, hasUtf16BOM, highSurrogate, isArrayEqual, isNewlineChar, isStandardFont, isType, isWithinBMP, last, layoutCombedText, layoutMultilineText, layoutSinglelineText, lineSplit, lineTo, lowSurrogate, mergeIntoTypedArray, mergeLines, mergeUint8Arrays, moveText, moveTo, newlineChars, nextLine, normalizeAppearance, numberToString, padStart, parseDate, pdfDocEncodingDecode, pluckIndices, popGraphicsState, pushGraphicsState, radians, radiansToDegrees, range, rectangle, rectanglesAreEqual, reduceRotation, restoreDashPattern, reverseArray, rgb, rotateAndSkewTextDegreesAndTranslate, rotateAndSkewTextRadiansAndTranslate, rotateDegrees, rotateInPlace, rotateRadians, rotateRectangle, scale, setCharacterSpacing, setCharacterSqueeze, setDashPattern, setFillingCmykColor, setFillingColor, setFillingGrayscaleColor, setFillingRgbColor, setFontAndSize, setGraphicsState, setLineCap, setLineHeight, setLineJoin, setLineWidth, setStrokingCmykColor, setStrokingColor, setStrokingGrayscaleColor, setStrokingRgbColor, setTextMatrix, setTextRenderingMode, setTextRise, setWordSpacing, showText, singleQuote, sizeInBytes, skewDegrees, skewRadians, sortedUniq, square, stringAsByteArray, stroke, sum, toCharCode, toCodePoint, toDegrees, toHexString, toHexStringOfMinLength, toRadians, toUint8Array, translate, typedArrayFor, utf16Decode, utf16Encode, utf8Encode, values, waitForTick };
|
|
19253
|
+
export { AFRelationship, AcroButtonFlags, AcroChoiceFlags, AcroFieldFlags, AcroTextFlags, AnnotationFlags, AppearanceCharacteristics, BlendMode, Cache, CharCodes, ColorTypes, CombedTextLayoutError, CorruptPageTreeError, CustomFontEmbedder, CustomFontSubsetEmbedder, DecompressionBombError, Duplex, EncryptedPDFError, ExceededMaxLengthError, FieldAlreadyExistsError, FieldExistsAsNonTerminalError, FileEmbedder, FillRule, FontkitNotRegisteredError, ForeignPageError, ImageAlignment, IndexOutOfBoundsError, InvalidAcroFieldValueError, InvalidFieldNamePartError, InvalidMaxLengthError, InvalidPDFDateStringError, InvalidTargetIndexError, JpegEmbedder, LineCapStyle, LineJoinStyle, MethodNotImplementedError, MissingCatalogError, MissingDAEntryError, MissingKeywordError, MissingOnValueCheckError, MissingPDFHeaderError, MissingPageContentsEmbeddingError, MissingTfOperatorError, MultiSelectValueError, NextByteAssertionError, NoSuchFieldError, NonFullScreenPageMode, NumberParsingError, PDFAcroButton, PDFAcroCheckBox, PDFAcroChoice, PDFAcroComboBox, PDFAcroField, PDFAcroForm, PDFAcroListBox, PDFAcroNonTerminal, PDFAcroPushButton, PDFAcroRadioButton, PDFAcroSignature, PDFAcroTerminal, PDFAcroText, PDFAnnotation, PDFArray, PDFArrayIsNotRectangleError, PDFBool, PDFButton, PDFCatalog, PDFCheckBox, PDFContentStream, PDFContext, PDFCrossRefSection, PDFCrossRefStream, PDFDict, PDFDocument, PDFDropdown, PDFEmbeddedPage, PDFField, PDFFlateStream, PDFFont, PDFForm, PDFHeader, PDFHexString, PDFImage, PDFInvalidObject, PDFInvalidObjectParsingError, PDFJavaScript, PDFName, PDFNull_default as PDFNull, PDFNumber, PDFObject, PDFObjectCopier, PDFObjectParser, PDFObjectParsingError, PDFObjectStream, PDFObjectStreamParser, PDFOperator, PDFOperatorNames, PDFOptionList, PDFPage, PDFPageEmbedder, PDFPageLeaf, PDFPageTree, PDFParser, PDFParsingError, PDFRadioGroup, PDFRawStream, PDFRef, PDFSignature, PDFStream, PDFStreamParsingError, PDFStreamWriter, PDFString, PDFTextField, PDFTrailer, PDFTrailerDict, PDFWidgetAnnotation, PDFWriter, PDFXRefStreamParser, PageEmbeddingMismatchedContextError, PageSizes, ParseSpeeds, PngEmbedder, PrintScaling, PrivateConstructorError, ReadingDirection, RemovePageFromEmptyDocumentError, ReparseError, RichTextFieldReadError, RotationTypes, StalledParserError, StandardFontEmbedder, StandardFontValues, StandardFonts, TextAlignment, TextRenderingMode, UnbalancedParenthesisError, UnexpectedFieldTypeError, UnexpectedObjectTypeError, UnrecognizedStreamTypeError, UnsupportedEncodingError, ViewerPreferences, addRandomSuffix, adjustDimsForRotation, appendBezierCurve, appendQuadraticCurve, arrayAsString, asNumber, asPDFName, asPDFNumber, assertEachIs, assertInteger, assertIs, assertIsOneOf, assertIsOneOfOrUndefined, assertIsSubset, assertMultiple, assertOrUndefined, assertPositive, assertRange, assertRangeOrUndefined, backtick, beginMarkedContent, beginText, breakTextIntoLines, byAscendingId, bytesFor, canBeConvertedToUint8Array, charAtIndex, charFromCode, charFromHexCode, charSplit, cleanText, clip, clipEvenOdd, closePath, cmyk, colorString, colorToComponents, componentsToColor, concatTransformationMatrix, copyStringIntoBuffer, createPDFAcroField, createPDFAcroFields, createTypeErrorMsg, createValueErrorMsg, decodeFromBase64, decodeFromBase64DataUri, decodePDFRawStream, defaultButtonAppearanceProvider, defaultCheckBoxAppearanceProvider, defaultDropdownAppearanceProvider, defaultOptionListAppearanceProvider, defaultRadioGroupAppearanceProvider, defaultTextFieldAppearanceProvider, degrees, degreesToRadians, drawButton, drawCheckBox, drawCheckMark, drawEllipse, drawEllipsePath, drawImage, drawLine, drawLinesOfText, drawObject, drawOptionList, drawPage, drawRadioButton, drawRectangle, drawSvgPath, drawText, drawTextField, drawTextLines, encodeToBase64, endMarkedContent, endPath, endText, error, escapeRegExp, escapedNewlineChars, fill, fillAndStroke, fillEvenOdd, findLastMatch, getType, grayscale, hasSurrogates, hasUtf16BOM, highSurrogate, isArrayEqual, isNewlineChar, isStandardFont, isType, isWithinBMP, last, layoutCombedText, layoutMultilineText, layoutSinglelineText, lineSplit, lineTo, lowSurrogate, mergeIntoTypedArray, mergeLines, mergeUint8Arrays, moveText, moveTo, newlineChars, nextLine, normalizeAppearance, numberToString, padStart, parseDate, pdfDocEncodingDecode, pluckIndices, popGraphicsState, pushGraphicsState, radians, radiansToDegrees, range, rectangle, rectanglesAreEqual, reduceRotation, restoreDashPattern, reverseArray, rgb, rotateAndSkewTextDegreesAndTranslate, rotateAndSkewTextRadiansAndTranslate, rotateDegrees, rotateInPlace, rotateRadians, rotateRectangle, scale, setCharacterSpacing, setCharacterSqueeze, setDashPattern, setFillingCmykColor, setFillingColor, setFillingGrayscaleColor, setFillingRgbColor, setFontAndSize, setGraphicsState, setLineCap, setLineHeight, setLineJoin, setLineWidth, setStrokingCmykColor, setStrokingColor, setStrokingGrayscaleColor, setStrokingRgbColor, setTextMatrix, setTextRenderingMode, setTextRise, setWordSpacing, showText, singleQuote, sizeInBytes, skewDegrees, skewRadians, sortedUniq, splitTextIntoShapingRuns, square, stringAsByteArray, stroke, sum, toCharCode, toCodePoint, toDegrees, toHexString, toHexStringOfMinLength, toRadians, toUint8Array, translate, typedArrayFor, utf16Decode, utf16Encode, utf8Encode, values, waitForTick };
|
|
19121
19254
|
|
|
19122
19255
|
//# sourceMappingURL=index.js.map
|