@libpdf/core 0.0.1-beta.11 → 0.0.1-beta.13
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/index.d.mts +146 -23
- package/dist/index.mjs +450 -151
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { createCMSECDSASignature } from "pkijs";
|
|
|
9
9
|
import { base64 } from "@scure/base";
|
|
10
10
|
|
|
11
11
|
//#region package.json
|
|
12
|
-
var version = "0.0.1-beta.
|
|
12
|
+
var version = "0.0.1-beta.13";
|
|
13
13
|
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/objects/pdf-array.ts
|
|
@@ -13525,6 +13525,12 @@ function getBaseFontName(name) {
|
|
|
13525
13525
|
return name.includes("+") ? name.split("+")[1] : name;
|
|
13526
13526
|
}
|
|
13527
13527
|
/**
|
|
13528
|
+
* Get basic metrics (ascent, descent, etc.) for a Standard 14 font.
|
|
13529
|
+
*/
|
|
13530
|
+
function getStandard14BasicMetrics(name) {
|
|
13531
|
+
return FONT_BASIC_METRICS[getBaseFontName(name)];
|
|
13532
|
+
}
|
|
13533
|
+
/**
|
|
13528
13534
|
* Get width for a glyph in a Standard 14 font.
|
|
13529
13535
|
* Returns undefined if font or glyph not found.
|
|
13530
13536
|
*/
|
|
@@ -13546,6 +13552,116 @@ function getStandard14DefaultWidth(fontName) {
|
|
|
13546
13552
|
if (baseName === "ZapfDingbats") return 278;
|
|
13547
13553
|
return 250;
|
|
13548
13554
|
}
|
|
13555
|
+
/**
|
|
13556
|
+
* Map common Unicode code points to glyph names.
|
|
13557
|
+
* This is a subset of the Adobe Glyph List.
|
|
13558
|
+
*/
|
|
13559
|
+
const CHAR_TO_GLYPH = {
|
|
13560
|
+
32: "space",
|
|
13561
|
+
33: "exclam",
|
|
13562
|
+
34: "quotedbl",
|
|
13563
|
+
35: "numbersign",
|
|
13564
|
+
36: "dollar",
|
|
13565
|
+
37: "percent",
|
|
13566
|
+
38: "ampersand",
|
|
13567
|
+
39: "quotesingle",
|
|
13568
|
+
40: "parenleft",
|
|
13569
|
+
41: "parenright",
|
|
13570
|
+
42: "asterisk",
|
|
13571
|
+
43: "plus",
|
|
13572
|
+
44: "comma",
|
|
13573
|
+
45: "hyphen",
|
|
13574
|
+
46: "period",
|
|
13575
|
+
47: "slash",
|
|
13576
|
+
48: "zero",
|
|
13577
|
+
49: "one",
|
|
13578
|
+
50: "two",
|
|
13579
|
+
51: "three",
|
|
13580
|
+
52: "four",
|
|
13581
|
+
53: "five",
|
|
13582
|
+
54: "six",
|
|
13583
|
+
55: "seven",
|
|
13584
|
+
56: "eight",
|
|
13585
|
+
57: "nine",
|
|
13586
|
+
58: "colon",
|
|
13587
|
+
59: "semicolon",
|
|
13588
|
+
60: "less",
|
|
13589
|
+
61: "equal",
|
|
13590
|
+
62: "greater",
|
|
13591
|
+
63: "question",
|
|
13592
|
+
64: "at",
|
|
13593
|
+
65: "A",
|
|
13594
|
+
66: "B",
|
|
13595
|
+
67: "C",
|
|
13596
|
+
68: "D",
|
|
13597
|
+
69: "E",
|
|
13598
|
+
70: "F",
|
|
13599
|
+
71: "G",
|
|
13600
|
+
72: "H",
|
|
13601
|
+
73: "I",
|
|
13602
|
+
74: "J",
|
|
13603
|
+
75: "K",
|
|
13604
|
+
76: "L",
|
|
13605
|
+
77: "M",
|
|
13606
|
+
78: "N",
|
|
13607
|
+
79: "O",
|
|
13608
|
+
80: "P",
|
|
13609
|
+
81: "Q",
|
|
13610
|
+
82: "R",
|
|
13611
|
+
83: "S",
|
|
13612
|
+
84: "T",
|
|
13613
|
+
85: "U",
|
|
13614
|
+
86: "V",
|
|
13615
|
+
87: "W",
|
|
13616
|
+
88: "X",
|
|
13617
|
+
89: "Y",
|
|
13618
|
+
90: "Z",
|
|
13619
|
+
91: "bracketleft",
|
|
13620
|
+
92: "backslash",
|
|
13621
|
+
93: "bracketright",
|
|
13622
|
+
94: "asciicircum",
|
|
13623
|
+
95: "underscore",
|
|
13624
|
+
96: "grave",
|
|
13625
|
+
97: "a",
|
|
13626
|
+
98: "b",
|
|
13627
|
+
99: "c",
|
|
13628
|
+
100: "d",
|
|
13629
|
+
101: "e",
|
|
13630
|
+
102: "f",
|
|
13631
|
+
103: "g",
|
|
13632
|
+
104: "h",
|
|
13633
|
+
105: "i",
|
|
13634
|
+
106: "j",
|
|
13635
|
+
107: "k",
|
|
13636
|
+
108: "l",
|
|
13637
|
+
109: "m",
|
|
13638
|
+
110: "n",
|
|
13639
|
+
111: "o",
|
|
13640
|
+
112: "p",
|
|
13641
|
+
113: "q",
|
|
13642
|
+
114: "r",
|
|
13643
|
+
115: "s",
|
|
13644
|
+
116: "t",
|
|
13645
|
+
117: "u",
|
|
13646
|
+
118: "v",
|
|
13647
|
+
119: "w",
|
|
13648
|
+
120: "x",
|
|
13649
|
+
121: "y",
|
|
13650
|
+
122: "z",
|
|
13651
|
+
123: "braceleft",
|
|
13652
|
+
124: "bar",
|
|
13653
|
+
125: "braceright",
|
|
13654
|
+
126: "asciitilde"
|
|
13655
|
+
};
|
|
13656
|
+
/**
|
|
13657
|
+
* Get glyph name for a character (for Standard 14 font width lookup).
|
|
13658
|
+
*/
|
|
13659
|
+
function getGlyphName(char) {
|
|
13660
|
+
const code = char.codePointAt(0);
|
|
13661
|
+
if (code !== void 0 && CHAR_TO_GLYPH[code]) return CHAR_TO_GLYPH[code];
|
|
13662
|
+
if (char.length === 1 && /[a-zA-Z]/.test(char)) return char;
|
|
13663
|
+
return "space";
|
|
13664
|
+
}
|
|
13549
13665
|
const FONT_BASIC_METRICS = {
|
|
13550
13666
|
Courier: {
|
|
13551
13667
|
ascent: 629,
|
|
@@ -20612,6 +20728,58 @@ var EmbeddedFont = class EmbeddedFont extends PdfFont {
|
|
|
20612
20728
|
return !this._usedInForm;
|
|
20613
20729
|
}
|
|
20614
20730
|
/**
|
|
20731
|
+
* Get width of text in points at a given font size.
|
|
20732
|
+
*
|
|
20733
|
+
* Alias for getTextWidth() to match Standard14Font API.
|
|
20734
|
+
*
|
|
20735
|
+
* @param text - The text to measure
|
|
20736
|
+
* @param size - Font size in points
|
|
20737
|
+
* @returns Width in points
|
|
20738
|
+
*/
|
|
20739
|
+
widthOfTextAtSize(text, size) {
|
|
20740
|
+
return this.getTextWidth(text, size);
|
|
20741
|
+
}
|
|
20742
|
+
/**
|
|
20743
|
+
* Get the height of the font at a given size.
|
|
20744
|
+
*
|
|
20745
|
+
* This returns the full height from descender to ascender.
|
|
20746
|
+
*
|
|
20747
|
+
* @param size - Font size in points
|
|
20748
|
+
* @returns Height in points
|
|
20749
|
+
*/
|
|
20750
|
+
heightAtSize(size) {
|
|
20751
|
+
const desc = this.descriptor;
|
|
20752
|
+
if (!desc) return size;
|
|
20753
|
+
return (desc.ascent - desc.descent) * size / 1e3;
|
|
20754
|
+
}
|
|
20755
|
+
/**
|
|
20756
|
+
* Calculate font size needed to achieve a specific text height.
|
|
20757
|
+
*
|
|
20758
|
+
* @param height - Desired height in points
|
|
20759
|
+
* @returns Font size in points
|
|
20760
|
+
*/
|
|
20761
|
+
sizeAtHeight(height) {
|
|
20762
|
+
const desc = this.descriptor;
|
|
20763
|
+
if (!desc) return height;
|
|
20764
|
+
const unitsHeight = desc.ascent - desc.descent;
|
|
20765
|
+
return height * 1e3 / unitsHeight;
|
|
20766
|
+
}
|
|
20767
|
+
/**
|
|
20768
|
+
* Calculate font size needed for text to fit a specific width.
|
|
20769
|
+
*
|
|
20770
|
+
* @param text - The text to measure
|
|
20771
|
+
* @param width - Desired width in points
|
|
20772
|
+
* @returns Font size in points
|
|
20773
|
+
*/
|
|
20774
|
+
sizeAtWidth(text, width) {
|
|
20775
|
+
if (text.length === 0) return 0;
|
|
20776
|
+
const codes = this.encodeText(text);
|
|
20777
|
+
let totalWidth = 0;
|
|
20778
|
+
for (const code of codes) totalWidth += this.getWidth(code);
|
|
20779
|
+
if (totalWidth === 0) return 0;
|
|
20780
|
+
return width * 1e3 / totalWidth;
|
|
20781
|
+
}
|
|
20782
|
+
/**
|
|
20615
20783
|
* Build a FontDescriptor from the font program.
|
|
20616
20784
|
*/
|
|
20617
20785
|
buildDescriptor() {
|
|
@@ -23428,6 +23596,57 @@ function isWordBoundary(char) {
|
|
|
23428
23596
|
//#endregion
|
|
23429
23597
|
//#region src/api/drawing/types.ts
|
|
23430
23598
|
/**
|
|
23599
|
+
* Resolve a rotation origin to explicit coordinates.
|
|
23600
|
+
*
|
|
23601
|
+
* @param origin - The origin specification (coordinates or named position)
|
|
23602
|
+
* @param bounds - The bounding box of the object
|
|
23603
|
+
* @param defaultOrigin - Default origin if none specified (as coordinates)
|
|
23604
|
+
* @returns Explicit { x, y } coordinates
|
|
23605
|
+
*/
|
|
23606
|
+
function resolveRotationOrigin(origin, bounds, defaultOrigin) {
|
|
23607
|
+
if (origin === void 0) return defaultOrigin;
|
|
23608
|
+
if (typeof origin === "object") return origin;
|
|
23609
|
+
const { x, y, width, height } = bounds;
|
|
23610
|
+
switch (origin) {
|
|
23611
|
+
case "top-left": return {
|
|
23612
|
+
x,
|
|
23613
|
+
y: y + height
|
|
23614
|
+
};
|
|
23615
|
+
case "top-center": return {
|
|
23616
|
+
x: x + width / 2,
|
|
23617
|
+
y: y + height
|
|
23618
|
+
};
|
|
23619
|
+
case "top-right": return {
|
|
23620
|
+
x: x + width,
|
|
23621
|
+
y: y + height
|
|
23622
|
+
};
|
|
23623
|
+
case "center-left": return {
|
|
23624
|
+
x,
|
|
23625
|
+
y: y + height / 2
|
|
23626
|
+
};
|
|
23627
|
+
case "center": return {
|
|
23628
|
+
x: x + width / 2,
|
|
23629
|
+
y: y + height / 2
|
|
23630
|
+
};
|
|
23631
|
+
case "center-right": return {
|
|
23632
|
+
x: x + width,
|
|
23633
|
+
y: y + height / 2
|
|
23634
|
+
};
|
|
23635
|
+
case "bottom-left": return {
|
|
23636
|
+
x,
|
|
23637
|
+
y
|
|
23638
|
+
};
|
|
23639
|
+
case "bottom-center": return {
|
|
23640
|
+
x: x + width / 2,
|
|
23641
|
+
y
|
|
23642
|
+
};
|
|
23643
|
+
case "bottom-right": return {
|
|
23644
|
+
x: x + width,
|
|
23645
|
+
y
|
|
23646
|
+
};
|
|
23647
|
+
}
|
|
23648
|
+
}
|
|
23649
|
+
/**
|
|
23431
23650
|
* Convert LineCap to PDF numeric value.
|
|
23432
23651
|
*/
|
|
23433
23652
|
function lineCapToNumber(cap) {
|
|
@@ -23840,116 +24059,6 @@ var PathBuilder = class {
|
|
|
23840
24059
|
* Text layout utilities for measuring and wrapping text.
|
|
23841
24060
|
*/
|
|
23842
24061
|
/**
|
|
23843
|
-
* Map common Unicode code points to glyph names.
|
|
23844
|
-
* This is a subset of the Adobe Glyph List.
|
|
23845
|
-
*/
|
|
23846
|
-
const CHAR_TO_GLYPH = {
|
|
23847
|
-
32: "space",
|
|
23848
|
-
33: "exclam",
|
|
23849
|
-
34: "quotedbl",
|
|
23850
|
-
35: "numbersign",
|
|
23851
|
-
36: "dollar",
|
|
23852
|
-
37: "percent",
|
|
23853
|
-
38: "ampersand",
|
|
23854
|
-
39: "quotesingle",
|
|
23855
|
-
40: "parenleft",
|
|
23856
|
-
41: "parenright",
|
|
23857
|
-
42: "asterisk",
|
|
23858
|
-
43: "plus",
|
|
23859
|
-
44: "comma",
|
|
23860
|
-
45: "hyphen",
|
|
23861
|
-
46: "period",
|
|
23862
|
-
47: "slash",
|
|
23863
|
-
48: "zero",
|
|
23864
|
-
49: "one",
|
|
23865
|
-
50: "two",
|
|
23866
|
-
51: "three",
|
|
23867
|
-
52: "four",
|
|
23868
|
-
53: "five",
|
|
23869
|
-
54: "six",
|
|
23870
|
-
55: "seven",
|
|
23871
|
-
56: "eight",
|
|
23872
|
-
57: "nine",
|
|
23873
|
-
58: "colon",
|
|
23874
|
-
59: "semicolon",
|
|
23875
|
-
60: "less",
|
|
23876
|
-
61: "equal",
|
|
23877
|
-
62: "greater",
|
|
23878
|
-
63: "question",
|
|
23879
|
-
64: "at",
|
|
23880
|
-
65: "A",
|
|
23881
|
-
66: "B",
|
|
23882
|
-
67: "C",
|
|
23883
|
-
68: "D",
|
|
23884
|
-
69: "E",
|
|
23885
|
-
70: "F",
|
|
23886
|
-
71: "G",
|
|
23887
|
-
72: "H",
|
|
23888
|
-
73: "I",
|
|
23889
|
-
74: "J",
|
|
23890
|
-
75: "K",
|
|
23891
|
-
76: "L",
|
|
23892
|
-
77: "M",
|
|
23893
|
-
78: "N",
|
|
23894
|
-
79: "O",
|
|
23895
|
-
80: "P",
|
|
23896
|
-
81: "Q",
|
|
23897
|
-
82: "R",
|
|
23898
|
-
83: "S",
|
|
23899
|
-
84: "T",
|
|
23900
|
-
85: "U",
|
|
23901
|
-
86: "V",
|
|
23902
|
-
87: "W",
|
|
23903
|
-
88: "X",
|
|
23904
|
-
89: "Y",
|
|
23905
|
-
90: "Z",
|
|
23906
|
-
91: "bracketleft",
|
|
23907
|
-
92: "backslash",
|
|
23908
|
-
93: "bracketright",
|
|
23909
|
-
94: "asciicircum",
|
|
23910
|
-
95: "underscore",
|
|
23911
|
-
96: "grave",
|
|
23912
|
-
97: "a",
|
|
23913
|
-
98: "b",
|
|
23914
|
-
99: "c",
|
|
23915
|
-
100: "d",
|
|
23916
|
-
101: "e",
|
|
23917
|
-
102: "f",
|
|
23918
|
-
103: "g",
|
|
23919
|
-
104: "h",
|
|
23920
|
-
105: "i",
|
|
23921
|
-
106: "j",
|
|
23922
|
-
107: "k",
|
|
23923
|
-
108: "l",
|
|
23924
|
-
109: "m",
|
|
23925
|
-
110: "n",
|
|
23926
|
-
111: "o",
|
|
23927
|
-
112: "p",
|
|
23928
|
-
113: "q",
|
|
23929
|
-
114: "r",
|
|
23930
|
-
115: "s",
|
|
23931
|
-
116: "t",
|
|
23932
|
-
117: "u",
|
|
23933
|
-
118: "v",
|
|
23934
|
-
119: "w",
|
|
23935
|
-
120: "x",
|
|
23936
|
-
121: "y",
|
|
23937
|
-
122: "z",
|
|
23938
|
-
123: "braceleft",
|
|
23939
|
-
124: "bar",
|
|
23940
|
-
125: "braceright",
|
|
23941
|
-
126: "asciitilde"
|
|
23942
|
-
};
|
|
23943
|
-
/**
|
|
23944
|
-
* Get glyph name for a character.
|
|
23945
|
-
*/
|
|
23946
|
-
function getGlyphName(char) {
|
|
23947
|
-
const code = char.codePointAt(0);
|
|
23948
|
-
if (code !== void 0 && CHAR_TO_GLYPH[code]) return CHAR_TO_GLYPH[code];
|
|
23949
|
-
if (char.length === 1 && /[a-zA-Z]/.test(char)) return char;
|
|
23950
|
-
return "space";
|
|
23951
|
-
}
|
|
23952
|
-
/**
|
|
23953
24062
|
* Measure the width of text at a given font size.
|
|
23954
24063
|
*
|
|
23955
24064
|
* @param text - The text to measure
|
|
@@ -24459,12 +24568,21 @@ var PDFPage = class PDFPage {
|
|
|
24459
24568
|
if (options.opacity !== void 0 || options.borderOpacity !== void 0) gsName = this.registerGraphicsStateForOpacity(options.opacity, options.borderOpacity);
|
|
24460
24569
|
let rotate;
|
|
24461
24570
|
if (options.rotate) {
|
|
24462
|
-
const
|
|
24463
|
-
|
|
24571
|
+
const bounds = {
|
|
24572
|
+
x: options.x,
|
|
24573
|
+
y: options.y,
|
|
24574
|
+
width: options.width,
|
|
24575
|
+
height: options.height
|
|
24576
|
+
};
|
|
24577
|
+
const defaultOrigin = {
|
|
24578
|
+
x: options.x + options.width / 2,
|
|
24579
|
+
y: options.y + options.height / 2
|
|
24580
|
+
};
|
|
24581
|
+
const origin = resolveRotationOrigin(options.rotate.origin, bounds, defaultOrigin);
|
|
24464
24582
|
rotate = {
|
|
24465
24583
|
angle: options.rotate.angle,
|
|
24466
|
-
originX,
|
|
24467
|
-
originY
|
|
24584
|
+
originX: origin.x,
|
|
24585
|
+
originY: origin.y
|
|
24468
24586
|
};
|
|
24469
24587
|
}
|
|
24470
24588
|
const ops = drawRectangleOps({
|
|
@@ -24567,12 +24685,21 @@ var PDFPage = class PDFPage {
|
|
|
24567
24685
|
if (options.opacity !== void 0 || options.borderOpacity !== void 0) gsName = this.registerGraphicsStateForOpacity(options.opacity, options.borderOpacity);
|
|
24568
24686
|
let rotate;
|
|
24569
24687
|
if (options.rotate) {
|
|
24570
|
-
const
|
|
24571
|
-
|
|
24688
|
+
const bounds = {
|
|
24689
|
+
x: options.x - options.xRadius,
|
|
24690
|
+
y: options.y - options.yRadius,
|
|
24691
|
+
width: options.xRadius * 2,
|
|
24692
|
+
height: options.yRadius * 2
|
|
24693
|
+
};
|
|
24694
|
+
const defaultOrigin = {
|
|
24695
|
+
x: options.x,
|
|
24696
|
+
y: options.y
|
|
24697
|
+
};
|
|
24698
|
+
const origin = resolveRotationOrigin(options.rotate.origin, bounds, defaultOrigin);
|
|
24572
24699
|
rotate = {
|
|
24573
24700
|
angle: options.rotate.angle,
|
|
24574
|
-
originX,
|
|
24575
|
-
originY
|
|
24701
|
+
originX: origin.x,
|
|
24702
|
+
originY: origin.y
|
|
24576
24703
|
};
|
|
24577
24704
|
}
|
|
24578
24705
|
const ops = drawEllipseOps({
|
|
@@ -24642,14 +24769,37 @@ var PDFPage = class PDFPage {
|
|
|
24642
24769
|
const ops = [pushGraphicsState()];
|
|
24643
24770
|
if (gsName) ops.push(setGraphicsState(gsName));
|
|
24644
24771
|
if (options.rotate) {
|
|
24645
|
-
const
|
|
24646
|
-
|
|
24772
|
+
const textWidth = options.maxWidth ?? Math.max(...lines.map((l) => l.width));
|
|
24773
|
+
let ascent;
|
|
24774
|
+
let descent;
|
|
24775
|
+
if (typeof font === "string") {
|
|
24776
|
+
const metrics = getStandard14BasicMetrics(font);
|
|
24777
|
+
ascent = metrics ? metrics.ascent * fontSize / 1e3 : fontSize * .8;
|
|
24778
|
+
descent = metrics ? Math.abs(metrics.descent) * fontSize / 1e3 : fontSize * .2;
|
|
24779
|
+
} else {
|
|
24780
|
+
const desc = font.descriptor;
|
|
24781
|
+
ascent = desc ? desc.ascent * fontSize / 1e3 : fontSize * .8;
|
|
24782
|
+
descent = desc ? Math.abs(desc.descent) * fontSize / 1e3 : fontSize * .2;
|
|
24783
|
+
}
|
|
24784
|
+
const firstLineTop = y + ascent;
|
|
24785
|
+
const lastLineBottom = y - (lines.length - 1) * lineHeight - descent;
|
|
24786
|
+
const bounds = {
|
|
24787
|
+
x,
|
|
24788
|
+
y: lastLineBottom,
|
|
24789
|
+
width: textWidth,
|
|
24790
|
+
height: firstLineTop - lastLineBottom
|
|
24791
|
+
};
|
|
24792
|
+
const defaultOrigin = {
|
|
24793
|
+
x,
|
|
24794
|
+
y
|
|
24795
|
+
};
|
|
24796
|
+
const origin = resolveRotationOrigin(options.rotate.origin, bounds, defaultOrigin);
|
|
24647
24797
|
const rad = options.rotate.angle * Math.PI / 180;
|
|
24648
24798
|
const cos = Math.cos(rad);
|
|
24649
24799
|
const sin = Math.sin(rad);
|
|
24650
|
-
ops.push(concatMatrix(1, 0, 0, 1,
|
|
24800
|
+
ops.push(concatMatrix(1, 0, 0, 1, origin.x, origin.y));
|
|
24651
24801
|
ops.push(concatMatrix(cos, sin, -sin, cos, 0, 0));
|
|
24652
|
-
ops.push(concatMatrix(1, 0, 0, 1, -
|
|
24802
|
+
ops.push(concatMatrix(1, 0, 0, 1, -origin.x, -origin.y));
|
|
24653
24803
|
}
|
|
24654
24804
|
ops.push(setFillColor(color));
|
|
24655
24805
|
ops.push(beginText());
|
|
@@ -24732,14 +24882,23 @@ var PDFPage = class PDFPage {
|
|
|
24732
24882
|
ops.push(`/${gsName} gs`);
|
|
24733
24883
|
}
|
|
24734
24884
|
if (options.rotate) {
|
|
24735
|
-
const
|
|
24736
|
-
|
|
24885
|
+
const bounds = {
|
|
24886
|
+
x,
|
|
24887
|
+
y,
|
|
24888
|
+
width,
|
|
24889
|
+
height
|
|
24890
|
+
};
|
|
24891
|
+
const defaultOrigin = {
|
|
24892
|
+
x: x + width / 2,
|
|
24893
|
+
y: y + height / 2
|
|
24894
|
+
};
|
|
24895
|
+
const origin = resolveRotationOrigin(options.rotate.origin, bounds, defaultOrigin);
|
|
24737
24896
|
const rad = options.rotate.angle * Math.PI / 180;
|
|
24738
24897
|
const cos = Math.cos(rad);
|
|
24739
24898
|
const sin = Math.sin(rad);
|
|
24740
|
-
ops.push(`1 0 0 1 ${this.formatNumber(
|
|
24899
|
+
ops.push(`1 0 0 1 ${this.formatNumber(origin.x)} ${this.formatNumber(origin.y)} cm`);
|
|
24741
24900
|
ops.push(`${this.formatNumber(cos)} ${this.formatNumber(sin)} ${this.formatNumber(-sin)} ${this.formatNumber(cos)} 0 0 cm`);
|
|
24742
|
-
ops.push(`1 0 0 1 ${this.formatNumber(-
|
|
24901
|
+
ops.push(`1 0 0 1 ${this.formatNumber(-origin.x)} ${this.formatNumber(-origin.y)} cm`);
|
|
24743
24902
|
}
|
|
24744
24903
|
ops.push(`${this.formatNumber(width)} 0 0 ${this.formatNumber(height)} ${this.formatNumber(x)} ${this.formatNumber(y)} cm`);
|
|
24745
24904
|
ops.push(`/${imageName} Do`);
|
|
@@ -26323,8 +26482,7 @@ var AnnotationFlattener = class {
|
|
|
26323
26482
|
* Wrap existing page content in q...Q and append new content.
|
|
26324
26483
|
*/
|
|
26325
26484
|
wrapAndAppendContent(page, newContent) {
|
|
26326
|
-
|
|
26327
|
-
if (existing instanceof PdfRef) existing = this.registry.resolve(existing) ?? void 0;
|
|
26485
|
+
const existing = page.get("Contents");
|
|
26328
26486
|
const prefixBytes = new Uint8Array([113, 10]);
|
|
26329
26487
|
const prefixStream = new PdfStream(new PdfDict(), prefixBytes);
|
|
26330
26488
|
const prefixRef = this.registry.register(prefixStream);
|
|
@@ -26338,10 +26496,12 @@ var AnnotationFlattener = class {
|
|
|
26338
26496
|
page.set("Contents", suffixRef);
|
|
26339
26497
|
return;
|
|
26340
26498
|
}
|
|
26341
|
-
|
|
26499
|
+
let resolved = existing;
|
|
26500
|
+
if (existing instanceof PdfRef) resolved = this.registry.resolve(existing) ?? existing;
|
|
26501
|
+
if (resolved instanceof PdfArray) {
|
|
26342
26502
|
const items = [];
|
|
26343
|
-
for (let i = 0; i <
|
|
26344
|
-
const item =
|
|
26503
|
+
for (let i = 0; i < resolved.length; i++) {
|
|
26504
|
+
const item = resolved.at(i);
|
|
26345
26505
|
if (item instanceof PdfRef) items.push(item);
|
|
26346
26506
|
}
|
|
26347
26507
|
const newArray = PdfArray.of(prefixRef, ...items, suffixRef);
|
|
@@ -39247,6 +39407,15 @@ function derToPem(der, label) {
|
|
|
39247
39407
|
return `-----BEGIN ${label}-----\n${(base64.encode(der).match(/.{1,64}/g) ?? []).join("\n")}\n-----END ${label}-----\n`;
|
|
39248
39408
|
}
|
|
39249
39409
|
/**
|
|
39410
|
+
* Check if a string is in PEM format.
|
|
39411
|
+
*
|
|
39412
|
+
* @param data - The string to check
|
|
39413
|
+
* @returns True if the string appears to be PEM-encoded
|
|
39414
|
+
*/
|
|
39415
|
+
function isPem(data) {
|
|
39416
|
+
return /-----BEGIN [A-Z0-9 ]+-----/.test(data) && /-----END [A-Z0-9 ]+-----/.test(data);
|
|
39417
|
+
}
|
|
39418
|
+
/**
|
|
39250
39419
|
* Normalize a PEM string for comparison by removing headers, footers, and whitespace.
|
|
39251
39420
|
*
|
|
39252
39421
|
* @param pem - The PEM-encoded string
|
|
@@ -39543,31 +39712,43 @@ var GoogleKmsSigner = class GoogleKmsSigner {
|
|
|
39543
39712
|
}
|
|
39544
39713
|
}
|
|
39545
39714
|
/**
|
|
39546
|
-
*
|
|
39715
|
+
* Loads a signing certificate from Google Secret Manager for use with KMS-based signing.
|
|
39716
|
+
*
|
|
39717
|
+
* This helper retrieves certificate material securely stored in Secret Manager, supporting
|
|
39718
|
+
* both PEM and DER formats:
|
|
39719
|
+
* - If the secret contains PEM-encoded data, all certificates will be parsed.
|
|
39720
|
+
* The first is used as the signing cert (`cert`), and the remainder returned as
|
|
39721
|
+
* the optional `chain` (intermediates).
|
|
39722
|
+
* - If the secret contains raw DER data, it is returned as the signing cert (`cert`).
|
|
39547
39723
|
*
|
|
39548
|
-
*
|
|
39549
|
-
* convert to DER before storing in Secret Manager.
|
|
39724
|
+
* Supports cross-project use: the secret may be in a different GCP project than the KMS key.
|
|
39550
39725
|
*
|
|
39551
|
-
*
|
|
39552
|
-
*
|
|
39726
|
+
* - The secret should contain the certificate in binary DER (recommended) or PEM format.
|
|
39727
|
+
* - Private keys must never be stored in Secret Manager.
|
|
39553
39728
|
*
|
|
39554
|
-
* @param secretVersionName
|
|
39555
|
-
* "projects/my-project/secrets/my-cert/versions/latest"
|
|
39556
|
-
* @param options
|
|
39557
|
-
* @
|
|
39729
|
+
* @param secretVersionName Full resource name for the secret version,
|
|
39730
|
+
* e.g. "projects/my-project/secrets/my-cert/versions/latest"
|
|
39731
|
+
* @param options Optional client configuration, including a SecretManagerServiceClient instance.
|
|
39732
|
+
* @returns An object with `cert` (main certificate bytes) and optional `chain` (intermediates).
|
|
39733
|
+
* @throws {KmsSignerError} if @google-cloud/secret-manager is not installed or retrieval fails.
|
|
39558
39734
|
*
|
|
39559
39735
|
* @example
|
|
39560
|
-
*
|
|
39561
|
-
*
|
|
39562
|
-
* const cert = await GoogleKmsSigner.getCertificateFromSecretManager(
|
|
39736
|
+
* // Load a certificate from the same project
|
|
39737
|
+
* const { cert } = await GoogleKmsSigner.getCertificateFromSecretManager(
|
|
39563
39738
|
* "projects/my-project/secrets/signing-cert/versions/latest"
|
|
39564
39739
|
* );
|
|
39565
39740
|
*
|
|
39566
|
-
* //
|
|
39567
|
-
* const cert = await GoogleKmsSigner.getCertificateFromSecretManager(
|
|
39568
|
-
* "projects/shared-certs-project/secrets/
|
|
39741
|
+
* // Load from a different project (cross-project access)
|
|
39742
|
+
* const { cert, chain } = await GoogleKmsSigner.getCertificateFromSecretManager(
|
|
39743
|
+
* "projects/shared-certs-project/secrets/org-ca-cert/versions/1"
|
|
39569
39744
|
* );
|
|
39570
|
-
*
|
|
39745
|
+
*
|
|
39746
|
+
* // Use the result with KMS-based signing
|
|
39747
|
+
* const signer = await GoogleKmsSigner.create({
|
|
39748
|
+
* keyVersionName: "...",
|
|
39749
|
+
* certificate: cert,
|
|
39750
|
+
* chain,
|
|
39751
|
+
* });
|
|
39571
39752
|
*/
|
|
39572
39753
|
static async getCertificateFromSecretManager(secretVersionName, options) {
|
|
39573
39754
|
const secretManager = await importSecretManager();
|
|
@@ -39575,8 +39756,15 @@ var GoogleKmsSigner = class GoogleKmsSigner {
|
|
|
39575
39756
|
try {
|
|
39576
39757
|
const [version$1] = await client.accessSecretVersion({ name: secretVersionName });
|
|
39577
39758
|
if (!version$1.payload?.data) throw new KmsSignerError(`Secret is empty: ${secretVersionName}`);
|
|
39578
|
-
|
|
39579
|
-
|
|
39759
|
+
let data = typeof version$1.payload.data === "string" ? version$1.payload.data : new TextDecoder().decode(version$1.payload.data);
|
|
39760
|
+
if (isPem(data)) {
|
|
39761
|
+
const [first, ...rest] = parsePem(data).map((block) => block.der);
|
|
39762
|
+
return {
|
|
39763
|
+
cert: first,
|
|
39764
|
+
chain: rest
|
|
39765
|
+
};
|
|
39766
|
+
}
|
|
39767
|
+
return { cert: new TextEncoder().encode(data) };
|
|
39580
39768
|
} catch (error) {
|
|
39581
39769
|
if (error instanceof KmsSignerError) throw error;
|
|
39582
39770
|
if (isGrpcError(error)) switch (error.code) {
|
|
@@ -41721,5 +41909,116 @@ var HttpTimestampAuthority = class {
|
|
|
41721
41909
|
};
|
|
41722
41910
|
|
|
41723
41911
|
//#endregion
|
|
41724
|
-
|
|
41912
|
+
//#region src/fonts/standard-14-font.ts
|
|
41913
|
+
/**
|
|
41914
|
+
* Standard14Font - A font wrapper for Standard 14 PDF fonts.
|
|
41915
|
+
*
|
|
41916
|
+
* This class provides width/height measurement for text using Standard 14 fonts,
|
|
41917
|
+
* which are built into every PDF reader and don't need embedding.
|
|
41918
|
+
*
|
|
41919
|
+
* Usage:
|
|
41920
|
+
* ```typescript
|
|
41921
|
+
* const font = Standard14Font.of("Helvetica-Bold");
|
|
41922
|
+
*
|
|
41923
|
+
* // Measure text
|
|
41924
|
+
* const width = font.widthOfTextAtSize("Hello", 12);
|
|
41925
|
+
* const height = font.heightAtSize(12);
|
|
41926
|
+
* ```
|
|
41927
|
+
*/
|
|
41928
|
+
/**
|
|
41929
|
+
* A wrapper class for Standard 14 fonts that provides measurement methods.
|
|
41930
|
+
*
|
|
41931
|
+
* Standard 14 fonts don't need to be embedded - they're built into PDF readers.
|
|
41932
|
+
* This class provides the same measurement API as EmbeddedFont.
|
|
41933
|
+
*/
|
|
41934
|
+
var Standard14Font = class Standard14Font {
|
|
41935
|
+
/** The Standard 14 font name */
|
|
41936
|
+
name;
|
|
41937
|
+
/** Cached metrics */
|
|
41938
|
+
metrics;
|
|
41939
|
+
constructor(name) {
|
|
41940
|
+
this.name = name;
|
|
41941
|
+
const basicMetrics = getStandard14BasicMetrics(name);
|
|
41942
|
+
if (!basicMetrics) throw new Error(`Unknown Standard 14 font: ${name}`);
|
|
41943
|
+
this.metrics = {
|
|
41944
|
+
ascent: basicMetrics.ascent,
|
|
41945
|
+
descent: basicMetrics.descent
|
|
41946
|
+
};
|
|
41947
|
+
}
|
|
41948
|
+
/**
|
|
41949
|
+
* Create a Standard14Font instance.
|
|
41950
|
+
*
|
|
41951
|
+
* @param name - The Standard 14 font name (e.g., "Helvetica", "Times-Bold")
|
|
41952
|
+
* @returns Standard14Font instance
|
|
41953
|
+
* @throws {Error} if name is not a valid Standard 14 font
|
|
41954
|
+
*
|
|
41955
|
+
* @example
|
|
41956
|
+
* ```typescript
|
|
41957
|
+
* const helvetica = Standard14Font.of("Helvetica");
|
|
41958
|
+
* const timesBold = Standard14Font.of("Times-Bold");
|
|
41959
|
+
* ```
|
|
41960
|
+
*/
|
|
41961
|
+
static of(name) {
|
|
41962
|
+
if (!isStandard14Font(name)) throw new Error(`"${name}" is not a Standard 14 font. Valid names: Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique, Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic, Courier, Courier-Bold, Courier-Oblique, Courier-BoldOblique, Symbol, ZapfDingbats`);
|
|
41963
|
+
return new Standard14Font(name);
|
|
41964
|
+
}
|
|
41965
|
+
/**
|
|
41966
|
+
* Get width of text in points at a given font size.
|
|
41967
|
+
*
|
|
41968
|
+
* @param text - The text to measure
|
|
41969
|
+
* @param size - Font size in points
|
|
41970
|
+
* @returns Width in points
|
|
41971
|
+
*/
|
|
41972
|
+
widthOfTextAtSize(text, size) {
|
|
41973
|
+
let totalWidth = 0;
|
|
41974
|
+
for (const char of text) {
|
|
41975
|
+
const glyphName = getGlyphName(char);
|
|
41976
|
+
const width = getStandard14GlyphWidth(this.name, glyphName) ?? getStandard14DefaultWidth(this.name);
|
|
41977
|
+
totalWidth += width;
|
|
41978
|
+
}
|
|
41979
|
+
return totalWidth * size / 1e3;
|
|
41980
|
+
}
|
|
41981
|
+
/**
|
|
41982
|
+
* Get the height of the font at a given size.
|
|
41983
|
+
*
|
|
41984
|
+
* This returns the full height from descender to ascender.
|
|
41985
|
+
*
|
|
41986
|
+
* @param size - Font size in points
|
|
41987
|
+
* @returns Height in points
|
|
41988
|
+
*/
|
|
41989
|
+
heightAtSize(size) {
|
|
41990
|
+
return (this.metrics.ascent - this.metrics.descent) * size / 1e3;
|
|
41991
|
+
}
|
|
41992
|
+
/**
|
|
41993
|
+
* Calculate font size needed to achieve a specific text height.
|
|
41994
|
+
*
|
|
41995
|
+
* @param height - Desired height in points
|
|
41996
|
+
* @returns Font size in points
|
|
41997
|
+
*/
|
|
41998
|
+
sizeAtHeight(height) {
|
|
41999
|
+
const unitsHeight = this.metrics.ascent - this.metrics.descent;
|
|
42000
|
+
return height * 1e3 / unitsHeight;
|
|
42001
|
+
}
|
|
42002
|
+
/**
|
|
42003
|
+
* Calculate font size needed for text to fit a specific width.
|
|
42004
|
+
*
|
|
42005
|
+
* @param text - The text to measure
|
|
42006
|
+
* @param width - Desired width in points
|
|
42007
|
+
* @returns Font size in points
|
|
42008
|
+
*/
|
|
42009
|
+
sizeAtWidth(text, width) {
|
|
42010
|
+
if (text.length === 0) return 0;
|
|
42011
|
+
let totalWidth = 0;
|
|
42012
|
+
for (const char of text) {
|
|
42013
|
+
const glyphName = getGlyphName(char);
|
|
42014
|
+
const charWidth = getStandard14GlyphWidth(this.name, glyphName) ?? getStandard14DefaultWidth(this.name);
|
|
42015
|
+
totalWidth += charWidth;
|
|
42016
|
+
}
|
|
42017
|
+
if (totalWidth === 0) return 0;
|
|
42018
|
+
return width * 1e3 / totalWidth;
|
|
42019
|
+
}
|
|
42020
|
+
};
|
|
42021
|
+
|
|
42022
|
+
//#endregion
|
|
42023
|
+
export { AnnotationFlags, CertificateChainError, CryptoKeySigner, GoogleKmsSigner, HttpTimestampAuthority, KmsSignerError, P12Signer, PDF, PDFAnnotation, PDFCaretAnnotation, PDFCircleAnnotation, PDFEmbeddedPage, PDFFileAttachmentAnnotation, PDFForm, PDFFreeTextAnnotation, PDFHighlightAnnotation, PDFImage, PDFInkAnnotation, PDFLineAnnotation, PDFLinkAnnotation, PDFMarkupAnnotation, PDFPage, PDFPolygonAnnotation, PDFPolylineAnnotation, PDFPopupAnnotation, PDFSquareAnnotation, PDFSquigglyAnnotation, PDFStampAnnotation, PDFStrikeOutAnnotation, PDFTextAnnotation, PDFTextMarkupAnnotation, PDFUnderlineAnnotation, PDFUnknownAnnotation, PathBuilder, PdfArray, PdfBool, PdfDict, PdfName, PdfNull, PdfNumber, PdfRef, PdfStream, PdfString, PermissionDeniedError, PlaceholderError, RevocationError, STANDARD_STAMPS, SecurityError, SignatureError, SignerError, Standard14Font, StandardFonts, TextAlignment, TimestampError, black, blue, cmyk, createAnnotation, degrees, grayscale, green, isPopupAnnotation, isWidgetAnnotation, layoutJustifiedLine, layoutText, lineCapToNumber, lineJoinToNumber, measureText, parsePem, rectToQuadPoints, rectsToQuadPoints, red, rgb, version, white };
|
|
41725
42024
|
//# sourceMappingURL=index.mjs.map
|