pdf-lite 1.7.4-alpha.1 → 1.7.4-alpha.3
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.
|
@@ -26,6 +26,11 @@ export class PdfGraphics {
|
|
|
26
26
|
}
|
|
27
27
|
beginText() {
|
|
28
28
|
this.lines.push('BT');
|
|
29
|
+
// Re-emit font inside text object — some viewers (e.g. pdfjs)
|
|
30
|
+
// require Tf inside BT..ET before any text rendering operator.
|
|
31
|
+
if (this.defaultAppearance) {
|
|
32
|
+
this.lines.push(this.defaultAppearance.toString());
|
|
33
|
+
}
|
|
29
34
|
return this;
|
|
30
35
|
}
|
|
31
36
|
endText() {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PdfString } from '../../core/objects/pdf-string.js';
|
|
2
|
+
import { PdfName } from '../../core/objects/pdf-name.js';
|
|
2
3
|
import { encodeToPDFDocEncoding } from '../../utils/encodeToPDFDocEncoding.js';
|
|
3
4
|
/**
|
|
4
5
|
* Value object that parses and builds DA (Default Appearance) strings.
|
|
@@ -12,7 +13,7 @@ export class PdfDefaultAppearance extends PdfString {
|
|
|
12
13
|
_fontSize;
|
|
13
14
|
_colorOp;
|
|
14
15
|
constructor(fontName, fontSize, colorOp) {
|
|
15
|
-
super(`/${fontName} ${fontSize} Tf ${colorOp}`);
|
|
16
|
+
super(`/${PdfName.escapeName(fontName)} ${fontSize} Tf ${colorOp}`);
|
|
16
17
|
this._fontName = fontName;
|
|
17
18
|
this._fontSize = fontSize;
|
|
18
19
|
this._colorOp = colorOp;
|
|
@@ -43,13 +44,13 @@ export class PdfDefaultAppearance extends PdfString {
|
|
|
43
44
|
this.raw = encodeToPDFDocEncoding(this.toString());
|
|
44
45
|
}
|
|
45
46
|
toString() {
|
|
46
|
-
return `/${this._fontName} ${this._fontSize} Tf ${this._colorOp}`;
|
|
47
|
+
return `/${PdfName.escapeName(this._fontName)} ${this._fontSize} Tf ${this._colorOp}`;
|
|
47
48
|
}
|
|
48
49
|
static parse(da) {
|
|
49
|
-
const fontMatch = da.match(/\/([\
|
|
50
|
+
const fontMatch = da.match(/\/([\S]+)\s+([\d.]+)\s+Tf/);
|
|
50
51
|
if (!fontMatch)
|
|
51
52
|
return null;
|
|
52
|
-
const fontName = fontMatch[1];
|
|
53
|
+
const fontName = PdfName.unescapeName(fontMatch[1]);
|
|
53
54
|
const fontSize = parseFloat(fontMatch[2]) || 0;
|
|
54
55
|
let colorOp = '0 g';
|
|
55
56
|
const rgMatch = da.match(/([\d.]+\s+[\d.]+\s+[\d.]+)\s+rg/);
|
package/dist/fonts/pdf-font.js
CHANGED
|
@@ -42,7 +42,15 @@ export class PdfFont extends PdfIndirectObject {
|
|
|
42
42
|
throw new Error('PdfIndirectObject content must be a PdfDictionary');
|
|
43
43
|
}
|
|
44
44
|
this.content = fontObj.content;
|
|
45
|
-
|
|
45
|
+
// Preserve resourceName from PdfFont sources; fall back to
|
|
46
|
+
// reference key for raw indirect objects already in a document,
|
|
47
|
+
// and finally generate a fresh name for unassigned objects.
|
|
48
|
+
this.resourceName =
|
|
49
|
+
fontObj instanceof PdfFont
|
|
50
|
+
? fontObj.resourceName
|
|
51
|
+
: fontObj.objectNumber >= 0
|
|
52
|
+
? fontObj.reference.key
|
|
53
|
+
: PdfFont.nextResourceName();
|
|
46
54
|
return;
|
|
47
55
|
}
|
|
48
56
|
// Handle string parameter (simple fontName)
|