pols-pdf 1.0.2 → 1.1.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/index.d.ts +10 -5
- package/dist/index.js +14 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -74,6 +74,10 @@ export type PFont = {
|
|
|
74
74
|
size: number;
|
|
75
75
|
color: string;
|
|
76
76
|
};
|
|
77
|
+
export type PFontSize = number | `${number}%`;
|
|
78
|
+
export type PFontParams = Omit<PFont, 'size'> & {
|
|
79
|
+
size: PFontSize;
|
|
80
|
+
};
|
|
77
81
|
export type PImage = {
|
|
78
82
|
filePath: string | Buffer;
|
|
79
83
|
left?: number;
|
|
@@ -113,7 +117,7 @@ export type PRectangle = {
|
|
|
113
117
|
};
|
|
114
118
|
export type PTextParams = {
|
|
115
119
|
chars: string;
|
|
116
|
-
font?: Partial<
|
|
120
|
+
font?: Partial<PFontParams>;
|
|
117
121
|
};
|
|
118
122
|
type PLetter = {
|
|
119
123
|
char: string;
|
|
@@ -145,7 +149,7 @@ export type PCellParams = {
|
|
|
145
149
|
left?: number;
|
|
146
150
|
top?: number;
|
|
147
151
|
width?: 'auto' | number;
|
|
148
|
-
font?: Partial<
|
|
152
|
+
font?: Partial<PFontParams>;
|
|
149
153
|
fillColor?: string;
|
|
150
154
|
padding?: PBoundParams;
|
|
151
155
|
border?: PBorderParams;
|
|
@@ -191,7 +195,7 @@ export type PRowParams = {
|
|
|
191
195
|
padding?: PBoundParams;
|
|
192
196
|
border?: PBorderParams;
|
|
193
197
|
radius?: PRadiusParams;
|
|
194
|
-
font?: Partial<
|
|
198
|
+
font?: Partial<PFontParams>;
|
|
195
199
|
stroke?: {
|
|
196
200
|
width?: number;
|
|
197
201
|
color?: PBorderColorParams;
|
|
@@ -209,7 +213,7 @@ export type PTableParams = {
|
|
|
209
213
|
padding?: PBoundParams;
|
|
210
214
|
border?: PBorderParams;
|
|
211
215
|
radius?: PRadiusParams;
|
|
212
|
-
font?: Partial<
|
|
216
|
+
font?: Partial<PFontParams>;
|
|
213
217
|
stroke?: {
|
|
214
218
|
width?: number;
|
|
215
219
|
color?: PBorderColorParams;
|
|
@@ -251,7 +255,8 @@ export declare class PPdf {
|
|
|
251
255
|
private capturedFont?;
|
|
252
256
|
private captureFont;
|
|
253
257
|
private restoreFont;
|
|
254
|
-
|
|
258
|
+
private resolveFontSize;
|
|
259
|
+
setFont(font: Partial<PFontParams>): void;
|
|
255
260
|
constructor(params?: {
|
|
256
261
|
title?: string;
|
|
257
262
|
page?: Partial<PPage>;
|
package/dist/index.js
CHANGED
|
@@ -47,13 +47,25 @@ class PPdf {
|
|
|
47
47
|
if (this.capturedFont)
|
|
48
48
|
this.currentFont = this.capturedFont;
|
|
49
49
|
}
|
|
50
|
+
/* Resuelve un PFontSize a un número absoluto. Un porcentaje ('x%') se calcula sobre `base`,
|
|
51
|
+
que es siempre el tamaño de fuente activo (this.currentFont.size) antes de aplicar este tamaño. */
|
|
52
|
+
resolveFontSize(size, base) {
|
|
53
|
+
if (size == null)
|
|
54
|
+
return undefined;
|
|
55
|
+
if (typeof size == 'number')
|
|
56
|
+
return size;
|
|
57
|
+
const match = /^(\d+(?:\.\d+)?)%$/.exec(size);
|
|
58
|
+
if (!match)
|
|
59
|
+
throw new Error(`Formato de tamaño de fuente inválido: "${size}"`);
|
|
60
|
+
return base * (Number(match[1]) / 100);
|
|
61
|
+
}
|
|
50
62
|
/* Establece en el engine la fuente especificada en currentFont */
|
|
51
63
|
setFont(font) {
|
|
52
64
|
const finalFont = {
|
|
53
65
|
name: font.name ?? this.currentFont.name,
|
|
54
66
|
bold: font.bold ?? this.currentFont.bold,
|
|
55
67
|
oblique: font.oblique ?? this.currentFont.oblique,
|
|
56
|
-
size: font.size ?? this.currentFont.size,
|
|
68
|
+
size: this.resolveFontSize(font.size, this.currentFont.size) ?? this.currentFont.size,
|
|
57
69
|
color: font.color ?? this.currentFont.color,
|
|
58
70
|
};
|
|
59
71
|
let fontName = this.currentFont.name;
|
|
@@ -451,7 +463,7 @@ class PPdf {
|
|
|
451
463
|
name: t.font?.name ?? params.font?.name ?? this.currentFont.name,
|
|
452
464
|
bold: t.font?.bold ?? params.font?.bold ?? this.currentFont.bold,
|
|
453
465
|
oblique: t.font?.oblique ?? params.font?.oblique ?? this.currentFont.oblique,
|
|
454
|
-
size: t.font?.size ?? params.font?.size ?? this.currentFont.size,
|
|
466
|
+
size: this.resolveFontSize(t.font?.size, this.currentFont.size) ?? this.resolveFontSize(params.font?.size, this.currentFont.size) ?? this.currentFont.size,
|
|
455
467
|
color: t.font?.color ?? params.font?.color ?? this.currentFont.color,
|
|
456
468
|
};
|
|
457
469
|
this.setFont(font);
|