@pdfme/schemas 3.1.2 → 3.1.3-dev.2
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/cjs/__tests__/renderUtils.test.js +9 -3
- package/dist/cjs/__tests__/renderUtils.test.js.map +1 -1
- package/dist/cjs/__tests__/text.test.js +47 -25
- package/dist/cjs/__tests__/text.test.js.map +1 -1
- package/dist/cjs/src/barcodes/constants.js +2 -1
- package/dist/cjs/src/barcodes/constants.js.map +1 -1
- package/dist/cjs/src/barcodes/pdfRender.js +2 -2
- package/dist/cjs/src/barcodes/pdfRender.js.map +1 -1
- package/dist/cjs/src/barcodes/propPanel.js +11 -0
- package/dist/cjs/src/barcodes/propPanel.js.map +1 -1
- package/dist/cjs/src/barcodes/uiRender.js +1 -0
- package/dist/cjs/src/barcodes/uiRender.js.map +1 -1
- package/dist/cjs/src/image/constants.js +2 -0
- package/dist/cjs/src/image/constants.js.map +1 -1
- package/dist/cjs/src/image/pdfRender.js +2 -2
- package/dist/cjs/src/image/pdfRender.js.map +1 -1
- package/dist/cjs/src/image/propPanel.js +2 -0
- package/dist/cjs/src/image/propPanel.js.map +1 -1
- package/dist/cjs/src/image/uiRender.js +1 -0
- package/dist/cjs/src/image/uiRender.js.map +1 -1
- package/dist/cjs/src/renderUtils.js +2 -1
- package/dist/cjs/src/renderUtils.js.map +1 -1
- package/dist/cjs/src/text/constants.js +2 -1
- package/dist/cjs/src/text/constants.js.map +1 -1
- package/dist/cjs/src/text/helper.js +8 -7
- package/dist/cjs/src/text/helper.js.map +1 -1
- package/dist/cjs/src/text/pdfRender.js +12 -12
- package/dist/cjs/src/text/pdfRender.js.map +1 -1
- package/dist/cjs/src/text/propPanel.js +4 -0
- package/dist/cjs/src/text/propPanel.js.map +1 -1
- package/dist/cjs/src/text/uiRender.js +4 -2
- package/dist/cjs/src/text/uiRender.js.map +1 -1
- package/dist/esm/__tests__/renderUtils.test.js +9 -3
- package/dist/esm/__tests__/renderUtils.test.js.map +1 -1
- package/dist/esm/__tests__/text.test.js +47 -25
- package/dist/esm/__tests__/text.test.js.map +1 -1
- package/dist/esm/src/barcodes/constants.js +1 -0
- package/dist/esm/src/barcodes/constants.js.map +1 -1
- package/dist/esm/src/barcodes/pdfRender.js +2 -2
- package/dist/esm/src/barcodes/pdfRender.js.map +1 -1
- package/dist/esm/src/barcodes/propPanel.js +12 -1
- package/dist/esm/src/barcodes/propPanel.js.map +1 -1
- package/dist/esm/src/barcodes/uiRender.js +1 -0
- package/dist/esm/src/barcodes/uiRender.js.map +1 -1
- package/dist/esm/src/image/constants.js +1 -1
- package/dist/esm/src/image/constants.js.map +1 -1
- package/dist/esm/src/image/pdfRender.js +2 -2
- package/dist/esm/src/image/pdfRender.js.map +1 -1
- package/dist/esm/src/image/propPanel.js +2 -0
- package/dist/esm/src/image/propPanel.js.map +1 -1
- package/dist/esm/src/image/uiRender.js +1 -0
- package/dist/esm/src/image/uiRender.js.map +1 -1
- package/dist/esm/src/renderUtils.js +2 -1
- package/dist/esm/src/renderUtils.js.map +1 -1
- package/dist/esm/src/text/constants.js +1 -0
- package/dist/esm/src/text/constants.js.map +1 -1
- package/dist/esm/src/text/helper.js +8 -7
- package/dist/esm/src/text/helper.js.map +1 -1
- package/dist/esm/src/text/pdfRender.js +12 -12
- package/dist/esm/src/text/pdfRender.js.map +1 -1
- package/dist/esm/src/text/propPanel.js +5 -1
- package/dist/esm/src/text/propPanel.js.map +1 -1
- package/dist/esm/src/text/uiRender.js +4 -2
- package/dist/esm/src/text/uiRender.js.map +1 -1
- package/dist/types/src/barcodes/constants.d.ts +1 -0
- package/dist/types/src/image/constants.d.ts +1 -1
- package/dist/types/src/renderUtils.d.ts +1 -0
- package/dist/types/src/text/constants.d.ts +1 -0
- package/dist/types/src/text/helper.d.ts +4 -3
- package/package.json +1 -1
- package/src/barcodes/constants.ts +2 -0
- package/src/barcodes/pdfRender.ts +2 -1
- package/src/barcodes/propPanel.ts +12 -1
- package/src/barcodes/uiRender.ts +1 -0
- package/src/image/constants.ts +1 -1
- package/src/image/pdfRender.ts +2 -1
- package/src/image/propPanel.ts +3 -0
- package/src/image/uiRender.ts +1 -0
- package/src/renderUtils.ts +2 -1
- package/src/text/constants.ts +1 -0
- package/src/text/helper.ts +11 -7
- package/src/text/pdfRender.ts +19 -12
- package/src/text/propPanel.ts +5 -0
- package/src/text/uiRender.ts +5 -1
@@ -25,7 +25,7 @@ const getBackgroundColor = (mode, value, schema, defaultBackgroundColor) => {
|
|
25
25
|
}
|
26
26
|
};
|
27
27
|
export const uiRender = async (arg) => {
|
28
|
-
const { value, schema, rootElement, mode, onChange, stopEditing, tabIndex, placeholder, options, theme, } = arg;
|
28
|
+
const { value, schema, rootElement, mode, onChange, stopEditing, tabIndex, placeholder, options, theme, _cache, } = arg;
|
29
29
|
const font = options?.font || getDefaultFont();
|
30
30
|
let dynamicFontSize = undefined;
|
31
31
|
if (schema.dynamicFontSize && value) {
|
@@ -34,9 +34,10 @@ export const uiRender = async (arg) => {
|
|
34
34
|
font,
|
35
35
|
value,
|
36
36
|
startingFontSize: dynamicFontSize,
|
37
|
+
_cache,
|
37
38
|
});
|
38
39
|
}
|
39
|
-
const fontKitFont = await getFontKitFont(schema, font);
|
40
|
+
const fontKitFont = await getFontKitFont(schema, font, _cache);
|
40
41
|
// Depending on vertical alignment, we need to move the top or bottom of the font to keep
|
41
42
|
// it within it's defined box and align it with the generated pdf.
|
42
43
|
const { topAdj, bottomAdj } = getBrowserVerticalFontAdjustments(fontKitFont, dynamicFontSize ?? schema.fontSize ?? DEFAULT_FONT_SIZE, schema.lineHeight ?? DEFAULT_LINE_HEIGHT, schema.verticalAlignment ?? DEFAULT_VERTICAL_ALIGNMENT);
|
@@ -53,6 +54,7 @@ export const uiRender = async (arg) => {
|
|
53
54
|
justifyContent: mapVerticalAlignToFlex(schema.verticalAlignment),
|
54
55
|
width: '100%',
|
55
56
|
height: '100%',
|
57
|
+
opacity: schema.opacity,
|
56
58
|
};
|
57
59
|
Object.assign(container.style, containerStyle);
|
58
60
|
rootElement.innerHTML = '';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"uiRender.js","sourceRoot":"","sources":["../../../../src/text/uiRender.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,cAAc,EAAE,MAAM,eAAe,CAAC;AAEtE,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,EACnB,yBAAyB,EACzB,kBAAkB,
|
1
|
+
{"version":3,"file":"uiRender.js","sourceRoot":"","sources":["../../../../src/text/uiRender.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,cAAc,EAAE,MAAM,eAAe,CAAC;AAEtE,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,EACnB,yBAAyB,EACzB,kBAAkB,GAEnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,wBAAwB,EACxB,cAAc,EACd,iCAAiC,GAClC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,sBAAsB,GAAG,CAAC,sBAA0C,EAAE,EAAE;IAC5E,QAAQ,sBAAsB,EAAE;QAC9B,KAAK,kBAAkB;YACrB,OAAO,YAAY,CAAC;QACtB,KAAK,qBAAqB;YACxB,OAAO,QAAQ,CAAC;QAClB,KAAK,qBAAqB;YACxB,OAAO,UAAU,CAAC;KACrB;IACD,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CACzB,IAAoC,EACpC,KAAa,EACb,MAAc,EACd,sBAA8B,EAC9B,EAAE;IACF,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,UAAU,CAAC,IAAI,KAAK,IAAI,MAAM,CAAC,eAAe,EAA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C,KAAK,EAAE,QAAQ,CAAC,CAAC;QACnC,GAAG,CAAC,SAAS,GAAG,KAAK;aAClB,KAAK,CAAC,EAAE,CAAC;aACT,GAAG,CACF,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CACvB,+BACE,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SACvC,MAAM,CAAC,SAAS,CACnB;aACA,IAAI,CAAC,EAAE,CAAC,CAAC;QAEZ,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;KAC5B;AACH,CAAC,CAAC"}
|
@@ -1,3 +1,4 @@
|
|
1
1
|
export declare const BARCODE_TYPES: readonly ["qrcode", "japanpost", "ean13", "ean8", "code39", "code128", "nw7", "itf14", "upca", "upce", "gs1datamatrix"];
|
2
2
|
export declare const DEFAULT_BARCODE_BG_COLOR = "#ffffff";
|
3
3
|
export declare const DEFAULT_BARCODE_COLOR = "#000000";
|
4
|
+
export declare const DEFAULT_OPACITY = 1;
|
@@ -1 +1 @@
|
|
1
|
-
export
|
1
|
+
export declare const DEFAULT_OPACITY = 1;
|
@@ -17,3 +17,4 @@ export declare const DEFAULT_DYNAMIC_FIT: DYNAMIC_FONT_SIZE_FIT;
|
|
17
17
|
export declare const DEFAULT_DYNAMIC_MIN_FONT_SIZE = 4;
|
18
18
|
export declare const DEFAULT_DYNAMIC_MAX_FONT_SIZE = 72;
|
19
19
|
export declare const FONT_SIZE_ADJUSTMENT = 0.25;
|
20
|
+
export declare const DEFAULT_OPACITY = 1;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import * as fontkit from 'fontkit';
|
2
2
|
import type { Font as FontKitFont } from 'fontkit';
|
3
|
-
import {
|
3
|
+
import { Font } from '@pdfme/common';
|
4
4
|
import type { TextSchema, FontWidthCalcValues } from './types';
|
5
5
|
export declare const getBrowserVerticalFontAdjustments: (fontKitFont: FontKitFont, fontSize: number, lineHeight: number, verticalAlignment: string) => {
|
6
6
|
topAdj: number;
|
@@ -9,7 +9,7 @@ export declare const getBrowserVerticalFontAdjustments: (fontKitFont: FontKitFon
|
|
9
9
|
export declare const getFontDescentInPt: (fontKitFont: FontKitFont, fontSize: number) => number;
|
10
10
|
export declare const heightOfFontAtSize: (fontKitFont: FontKitFont, fontSize: number) => number;
|
11
11
|
export declare const widthOfTextAtSize: (text: string, fontKitFont: FontKitFont, fontSize: number, characterSpacing: number) => number;
|
12
|
-
export declare const getFontKitFont: (textSchema:
|
12
|
+
export declare const getFontKitFont: (textSchema: TextSchema, font: Font, _cache: Map<any, any>) => Promise<fontkit.Font>;
|
13
13
|
/**
|
14
14
|
* Recursively splits the line at getSplitPosition.
|
15
15
|
* If there is some leftover, split the rest again in the same manner.
|
@@ -21,9 +21,10 @@ export declare const getSplittedLines: (textLine: string, calcValues: FontWidthC
|
|
21
21
|
* Calculating space usage involves splitting lines where they exceed
|
22
22
|
* the box width based on the proposed size.
|
23
23
|
*/
|
24
|
-
export declare const calculateDynamicFontSize: ({ textSchema, font, value, startingFontSize, }: {
|
24
|
+
export declare const calculateDynamicFontSize: ({ textSchema, font, value, startingFontSize, _cache, }: {
|
25
25
|
textSchema: TextSchema;
|
26
26
|
font: Font;
|
27
27
|
value: string;
|
28
28
|
startingFontSize?: number | undefined;
|
29
|
+
_cache: Map<any, any>;
|
29
30
|
}) => Promise<number>;
|
package/package.json
CHANGED
@@ -27,7 +27,8 @@ export const pdfRender = async (arg: PDFRenderProps<BarcodeSchema>) => {
|
|
27
27
|
height,
|
28
28
|
rotate,
|
29
29
|
position: { x, y },
|
30
|
+
opacity,
|
30
31
|
} = convertForPdfLayoutProps({ schema, pageHeight });
|
31
32
|
|
32
|
-
page.drawImage(image, { x, y, rotate, width, height });
|
33
|
+
page.drawImage(image, { x, y, rotate, width, height, opacity });
|
33
34
|
};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { PropPanel } from '@pdfme/common';
|
2
2
|
import type { BarcodeSchema } from './types';
|
3
|
-
import { DEFAULT_BARCODE_COLOR, DEFAULT_BARCODE_BG_COLOR } from './constants.js';
|
3
|
+
import { DEFAULT_BARCODE_COLOR, DEFAULT_BARCODE_BG_COLOR, DEFAULT_OPACITY } from './constants.js';
|
4
4
|
|
5
5
|
const defaultColors = {
|
6
6
|
backgroundColor: DEFAULT_BARCODE_BG_COLOR,
|
@@ -20,6 +20,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
20
20
|
width: 30,
|
21
21
|
height: 30,
|
22
22
|
rotate: 0,
|
23
|
+
opacity: DEFAULT_OPACITY,
|
23
24
|
},
|
24
25
|
},
|
25
26
|
{
|
@@ -32,6 +33,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
32
33
|
width: 80,
|
33
34
|
height: 7.2,
|
34
35
|
rotate: 0,
|
36
|
+
opacity: DEFAULT_OPACITY,
|
35
37
|
},
|
36
38
|
},
|
37
39
|
{
|
@@ -44,6 +46,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
44
46
|
...default40x20,
|
45
47
|
height: 16,
|
46
48
|
rotate: 0,
|
49
|
+
opacity: DEFAULT_OPACITY,
|
47
50
|
},
|
48
51
|
},
|
49
52
|
{
|
@@ -55,6 +58,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
55
58
|
...defaultTextColors,
|
56
59
|
...default40x20,
|
57
60
|
rotate: 0,
|
61
|
+
opacity: DEFAULT_OPACITY,
|
58
62
|
},
|
59
63
|
},
|
60
64
|
{
|
@@ -65,6 +69,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
65
69
|
...defaultColors,
|
66
70
|
...defaultTextColors,
|
67
71
|
...default40x20,
|
72
|
+
opacity: DEFAULT_OPACITY,
|
68
73
|
},
|
69
74
|
},
|
70
75
|
{
|
@@ -76,6 +81,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
76
81
|
...defaultTextColors,
|
77
82
|
...default40x20,
|
78
83
|
rotate: 0,
|
84
|
+
opacity: DEFAULT_OPACITY,
|
79
85
|
},
|
80
86
|
},
|
81
87
|
{
|
@@ -87,6 +93,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
87
93
|
...defaultTextColors,
|
88
94
|
...default40x20,
|
89
95
|
rotate: 0,
|
96
|
+
opacity: DEFAULT_OPACITY,
|
90
97
|
},
|
91
98
|
},
|
92
99
|
{
|
@@ -99,6 +106,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
99
106
|
...default40x20,
|
100
107
|
height: 12,
|
101
108
|
rotate: 0,
|
109
|
+
opacity: DEFAULT_OPACITY,
|
102
110
|
},
|
103
111
|
},
|
104
112
|
{
|
@@ -111,6 +119,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
111
119
|
...default40x20,
|
112
120
|
height: 16,
|
113
121
|
rotate: 0,
|
122
|
+
opacity: DEFAULT_OPACITY,
|
114
123
|
},
|
115
124
|
},
|
116
125
|
{
|
@@ -122,6 +131,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
122
131
|
...defaultTextColors,
|
123
132
|
...default40x20,
|
124
133
|
rotate: 0,
|
134
|
+
opacity: DEFAULT_OPACITY,
|
125
135
|
},
|
126
136
|
},
|
127
137
|
{
|
@@ -133,6 +143,7 @@ const barcodeDefaults: { defaultValue: string; defaultSchema: BarcodeSchema }[]
|
|
133
143
|
width: 30,
|
134
144
|
height: 30,
|
135
145
|
rotate: 0,
|
146
|
+
opacity: DEFAULT_OPACITY,
|
136
147
|
},
|
137
148
|
},
|
138
149
|
];
|
package/src/barcodes/uiRender.ts
CHANGED
@@ -71,6 +71,7 @@ export const uiRender = async (arg: UIRenderProps<BarcodeSchema>) => {
|
|
71
71
|
alignItems: 'center',
|
72
72
|
justifyContent: 'center',
|
73
73
|
fontFamily: "'Open Sans', sans-serif",
|
74
|
+
opacity: schema.opacity,
|
74
75
|
};
|
75
76
|
Object.assign(container.style, containerStyle);
|
76
77
|
rootElement.appendChild(container);
|
package/src/image/constants.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export
|
1
|
+
export const DEFAULT_OPACITY = 1;
|
package/src/image/pdfRender.ts
CHANGED
@@ -21,7 +21,8 @@ export const pdfRender = async (arg: PDFRenderProps<ImageSchema>) => {
|
|
21
21
|
height,
|
22
22
|
rotate,
|
23
23
|
position: { x, y },
|
24
|
+
opacity,
|
24
25
|
} = convertForPdfLayoutProps({ schema, pageHeight });
|
25
26
|
|
26
|
-
page.drawImage(image, { x, y, rotate, width, height });
|
27
|
+
page.drawImage(image, { x, y, rotate, width, height, opacity });
|
27
28
|
};
|
package/src/image/propPanel.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
import { PropPanel } from '@pdfme/common';
|
2
2
|
import type { ImageSchema } from './types';
|
3
|
+
import { DEFAULT_OPACITY } from '../image/constants';
|
4
|
+
|
3
5
|
export const propPanel: PropPanel<ImageSchema> = {
|
4
6
|
schema: {},
|
5
7
|
defaultValue:
|
@@ -12,5 +14,6 @@ export const propPanel: PropPanel<ImageSchema> = {
|
|
12
14
|
// If the value of "rotate" is set to undefined or not set at all, rotation will be disabled in the UI.
|
13
15
|
// Check this document: https://pdfme.com//docs/custom-schemas#learning-how-to-create-from-pdfmeschemas-code
|
14
16
|
rotate: 0,
|
17
|
+
opacity: DEFAULT_OPACITY,
|
15
18
|
},
|
16
19
|
};
|
package/src/image/uiRender.ts
CHANGED
@@ -46,6 +46,7 @@ export const uiRender = async (arg: UIRenderProps<ImageSchema>) => {
|
|
46
46
|
...fullSize,
|
47
47
|
backgroundImage: value ? 'none' : `url(${placeholder})`,
|
48
48
|
backgroundSize: `${size.width}px ${size.height}px`,
|
49
|
+
opacity: schema.opacity,
|
49
50
|
};
|
50
51
|
Object.assign(container.style, containerStyle);
|
51
52
|
container.addEventListener('click', (e) => {
|
package/src/renderUtils.ts
CHANGED
@@ -10,7 +10,7 @@ export const convertForPdfLayoutProps = ({
|
|
10
10
|
pageHeight: number;
|
11
11
|
applyRotateTranslate?: boolean;
|
12
12
|
}) => {
|
13
|
-
const { width: mmWidth, height: mmHeight, position, rotate } = schema;
|
13
|
+
const { width: mmWidth, height: mmHeight, position, rotate, opacity } = schema;
|
14
14
|
const { x: mmX, y: mmY } = position;
|
15
15
|
|
16
16
|
const rotateDegrees = rotate ? -rotate : 0;
|
@@ -39,6 +39,7 @@ export const convertForPdfLayoutProps = ({
|
|
39
39
|
height: height,
|
40
40
|
width: width,
|
41
41
|
rotate: degrees(rotateDegrees),
|
42
|
+
opacity,
|
42
43
|
};
|
43
44
|
};
|
44
45
|
|
package/src/text/constants.ts
CHANGED
package/src/text/helper.ts
CHANGED
@@ -106,11 +106,13 @@ const getFallbackFont = (font: Font) => {
|
|
106
106
|
return font[fallbackFontName];
|
107
107
|
};
|
108
108
|
|
109
|
-
const
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
109
|
+
const getCacheKey = (fontName: string) => `getFontKitFont-${fontName}`;
|
110
|
+
|
111
|
+
export const getFontKitFont = async (textSchema: TextSchema, font: Font, _cache: Map<any, any>) => {
|
112
|
+
const fontName = textSchema.fontName || getFallbackFontName(font);
|
113
|
+
const cacheKey = getCacheKey(fontName);
|
114
|
+
if (_cache.has(cacheKey)) {
|
115
|
+
return _cache.get(cacheKey) as fontkit.Font;
|
114
116
|
}
|
115
117
|
|
116
118
|
const currentFont =
|
@@ -125,7 +127,7 @@ export const getFontKitFont = async (textSchema: Schema, font: Font) => {
|
|
125
127
|
const fontKitFont = fontkit.create(
|
126
128
|
fontData instanceof Buffer ? fontData : Buffer.from(fontData as ArrayBuffer)
|
127
129
|
);
|
128
|
-
|
130
|
+
_cache.set(cacheKey, fontKitFont);
|
129
131
|
|
130
132
|
return fontKitFont;
|
131
133
|
};
|
@@ -202,11 +204,13 @@ export const calculateDynamicFontSize = async ({
|
|
202
204
|
font,
|
203
205
|
value,
|
204
206
|
startingFontSize,
|
207
|
+
_cache,
|
205
208
|
}: {
|
206
209
|
textSchema: TextSchema;
|
207
210
|
font: Font;
|
208
211
|
value: string;
|
209
212
|
startingFontSize?: number | undefined;
|
213
|
+
_cache: Map<any, any>;
|
210
214
|
}) => {
|
211
215
|
const {
|
212
216
|
fontSize: schemaFontSize,
|
@@ -221,7 +225,7 @@ export const calculateDynamicFontSize = async ({
|
|
221
225
|
if (dynamicFontSizeSetting.max < dynamicFontSizeSetting.min) return fontSize;
|
222
226
|
|
223
227
|
const characterSpacing = schemaCharacterSpacing ?? DEFAULT_CHARACTER_SPACING;
|
224
|
-
const fontKitFont = await getFontKitFont(textSchema, font);
|
228
|
+
const fontKitFont = await getFontKitFont(textSchema, font, _cache);
|
225
229
|
const paragraphs = value.split('\n');
|
226
230
|
|
227
231
|
let dynamicFontSize = fontSize;
|
package/src/text/pdfRender.ts
CHANGED
@@ -46,11 +46,14 @@ const hex2RgbColor = (hexString: string | undefined) => {
|
|
46
46
|
return undefined;
|
47
47
|
};
|
48
48
|
|
49
|
-
const
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
const embedAndGetFontObj = async (arg: {
|
50
|
+
pdfDoc: PDFDocument;
|
51
|
+
font: Font;
|
52
|
+
_cache: Map<any, any>;
|
53
|
+
}) => {
|
54
|
+
const { pdfDoc, font, _cache } = arg;
|
55
|
+
if (_cache.has(pdfDoc)) {
|
56
|
+
return _cache.get(pdfDoc) as { [key: string]: PDFFont };
|
54
57
|
}
|
55
58
|
|
56
59
|
const fontValues = await Promise.all(
|
@@ -70,7 +73,7 @@ const embedAndGetFontObj = async (arg: { pdfDoc: PDFDocument; font: Font }) => {
|
|
70
73
|
{} as { [key: string]: PDFFont }
|
71
74
|
);
|
72
75
|
|
73
|
-
|
76
|
+
_cache.set(pdfDoc, fontObj);
|
74
77
|
return fontObj;
|
75
78
|
};
|
76
79
|
|
@@ -78,13 +81,15 @@ const getFontProp = async ({
|
|
78
81
|
value,
|
79
82
|
font,
|
80
83
|
schema,
|
84
|
+
_cache,
|
81
85
|
}: {
|
82
86
|
value: string;
|
83
87
|
font: Font;
|
84
88
|
schema: TextSchema;
|
89
|
+
_cache: Map<any, any>;
|
85
90
|
}) => {
|
86
91
|
const fontSize = schema.dynamicFontSize
|
87
|
-
? await calculateDynamicFontSize({ textSchema: schema, font, value })
|
92
|
+
? await calculateDynamicFontSize({ textSchema: schema, font, value, _cache })
|
88
93
|
: schema.fontSize ?? DEFAULT_FONT_SIZE;
|
89
94
|
const color = hex2RgbColor(schema.fontColor || DEFAULT_FONT_COLOR);
|
90
95
|
|
@@ -99,14 +104,14 @@ const getFontProp = async ({
|
|
99
104
|
};
|
100
105
|
|
101
106
|
export const pdfRender = async (arg: PDFRenderProps<TextSchema>) => {
|
102
|
-
const { value, pdfDoc, pdfLib, page, options, schema } = arg;
|
107
|
+
const { value, pdfDoc, pdfLib, page, options, schema, _cache } = arg;
|
103
108
|
|
104
109
|
const { font = getDefaultFont() } = options;
|
105
110
|
|
106
111
|
const [pdfFontObj, fontKitFont, fontProp] = await Promise.all([
|
107
|
-
embedAndGetFontObj({ pdfDoc, font }),
|
108
|
-
getFontKitFont(schema, font),
|
109
|
-
getFontProp({ value, font, schema }),
|
112
|
+
embedAndGetFontObj({ pdfDoc, font, _cache }),
|
113
|
+
getFontKitFont(schema, font, _cache),
|
114
|
+
getFontProp({ value, font, schema, _cache }),
|
110
115
|
]);
|
111
116
|
|
112
117
|
const { fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing } = fontProp;
|
@@ -122,10 +127,11 @@ export const pdfRender = async (arg: PDFRenderProps<TextSchema>) => {
|
|
122
127
|
height,
|
123
128
|
rotate,
|
124
129
|
position: { x, y },
|
130
|
+
opacity,
|
125
131
|
} = convertForPdfLayoutProps({ schema, pageHeight, applyRotateTranslate: false });
|
126
132
|
|
127
133
|
if (schema.backgroundColor) {
|
128
|
-
const color = hex2RgbColor(schema.backgroundColor
|
134
|
+
const color = hex2RgbColor(schema.backgroundColor);
|
129
135
|
page.drawRectangle({ x, y, width, height, rotate, color });
|
130
136
|
}
|
131
137
|
|
@@ -195,6 +201,7 @@ export const pdfRender = async (arg: PDFRenderProps<TextSchema>) => {
|
|
195
201
|
maxWidth: width,
|
196
202
|
font: pdfFontValue,
|
197
203
|
wordBreaks: [''],
|
204
|
+
opacity,
|
198
205
|
});
|
199
206
|
});
|
200
207
|
};
|
package/src/text/propPanel.ts
CHANGED
@@ -23,6 +23,7 @@ import {
|
|
23
23
|
DEFAULT_DYNAMIC_MAX_FONT_SIZE,
|
24
24
|
ALIGN_RIGHT,
|
25
25
|
ALIGN_CENTER,
|
26
|
+
DEFAULT_OPACITY,
|
26
27
|
} from './constants.js';
|
27
28
|
|
28
29
|
const UseDynamicFontSize = (props: PropPanelWidgetProps) => {
|
@@ -108,6 +109,9 @@ export const propPanel: PropPanel<TextSchema> = {
|
|
108
109
|
title: i18n('schemas.text.lineHeight'),
|
109
110
|
type: 'number',
|
110
111
|
widget: 'inputNumber',
|
112
|
+
props: {
|
113
|
+
step: 0.1,
|
114
|
+
},
|
111
115
|
span: 8,
|
112
116
|
},
|
113
117
|
useDynamicFontSize: { type: 'boolean', widget: 'UseDynamicFontSize', bind: false, span: 16 },
|
@@ -167,5 +171,6 @@ export const propPanel: PropPanel<TextSchema> = {
|
|
167
171
|
fontColor: DEFAULT_FONT_COLOR,
|
168
172
|
fontName: undefined,
|
169
173
|
backgroundColor: '',
|
174
|
+
opacity: DEFAULT_OPACITY,
|
170
175
|
},
|
171
176
|
};
|
package/src/text/uiRender.ts
CHANGED
@@ -11,6 +11,7 @@ import {
|
|
11
11
|
DEFAULT_LINE_HEIGHT,
|
12
12
|
DEFAULT_CHARACTER_SPACING,
|
13
13
|
DEFAULT_FONT_COLOR,
|
14
|
+
DEFAULT_OPACITY,
|
14
15
|
} from './constants.js';
|
15
16
|
import {
|
16
17
|
calculateDynamicFontSize,
|
@@ -58,6 +59,7 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
|
58
59
|
placeholder,
|
59
60
|
options,
|
60
61
|
theme,
|
62
|
+
_cache,
|
61
63
|
} = arg;
|
62
64
|
const font = options?.font || getDefaultFont();
|
63
65
|
|
@@ -68,10 +70,11 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
|
68
70
|
font,
|
69
71
|
value,
|
70
72
|
startingFontSize: dynamicFontSize,
|
73
|
+
_cache,
|
71
74
|
});
|
72
75
|
}
|
73
76
|
|
74
|
-
const fontKitFont = await getFontKitFont(schema, font);
|
77
|
+
const fontKitFont = await getFontKitFont(schema, font, _cache);
|
75
78
|
// Depending on vertical alignment, we need to move the top or bottom of the font to keep
|
76
79
|
// it within it's defined box and align it with the generated pdf.
|
77
80
|
const { topAdj, bottomAdj } = getBrowserVerticalFontAdjustments(
|
@@ -101,6 +104,7 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
|
101
104
|
justifyContent: mapVerticalAlignToFlex(schema.verticalAlignment),
|
102
105
|
width: '100%',
|
103
106
|
height: '100%',
|
107
|
+
opacity: schema.opacity,
|
104
108
|
};
|
105
109
|
Object.assign(container.style, containerStyle);
|
106
110
|
rootElement.innerHTML = '';
|