@pdfme/schemas 5.3.3-dev.4 → 5.3.3-dev.5
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__/text.test.js +25 -37
- package/dist/cjs/__tests__/text.test.js.map +1 -1
- package/dist/cjs/src/multiVariableText/uiRender.js +9 -5
- package/dist/cjs/src/multiVariableText/uiRender.js.map +1 -1
- package/dist/cjs/src/text/helper.js +1 -2
- package/dist/cjs/src/text/helper.js.map +1 -1
- package/dist/cjs/src/text/pdfRender.js +4 -4
- package/dist/cjs/src/text/pdfRender.js.map +1 -1
- package/dist/cjs/src/text/uiRender.js +7 -14
- package/dist/cjs/src/text/uiRender.js.map +1 -1
- package/dist/esm/__tests__/text.test.js +25 -37
- package/dist/esm/__tests__/text.test.js.map +1 -1
- package/dist/esm/src/multiVariableText/uiRender.js +6 -2
- package/dist/esm/src/multiVariableText/uiRender.js.map +1 -1
- package/dist/esm/src/text/helper.js +1 -2
- package/dist/esm/src/text/helper.js.map +1 -1
- package/dist/esm/src/text/pdfRender.js +4 -4
- package/dist/esm/src/text/pdfRender.js.map +1 -1
- package/dist/esm/src/text/uiRender.js +7 -14
- package/dist/esm/src/text/uiRender.js.map +1 -1
- package/dist/types/src/text/helper.d.ts +3 -4
- package/dist/types/src/text/uiRender.d.ts +2 -1
- package/package.json +1 -1
- package/src/multiVariableText/uiRender.ts +7 -2
- package/src/text/helper.ts +3 -6
- package/src/text/pdfRender.ts +7 -8
- package/src/text/uiRender.ts +7 -14
package/src/text/helper.ts
CHANGED
@@ -221,18 +221,16 @@ export const getSplittedLines = (textLine: string, calcValues: FontWidthCalcValu
|
|
221
221
|
* Calculating space usage involves splitting lines where they exceed
|
222
222
|
* the box width based on the proposed size.
|
223
223
|
*/
|
224
|
-
export const calculateDynamicFontSize =
|
224
|
+
export const calculateDynamicFontSize = ({
|
225
225
|
textSchema,
|
226
|
-
|
226
|
+
fontKitFont,
|
227
227
|
value,
|
228
228
|
startingFontSize,
|
229
|
-
_cache,
|
230
229
|
}: {
|
231
230
|
textSchema: TextSchema;
|
232
|
-
|
231
|
+
fontKitFont: FontKitFont;
|
233
232
|
value: string;
|
234
233
|
startingFontSize?: number | undefined;
|
235
|
-
_cache: Map<any, any>;
|
236
234
|
}) => {
|
237
235
|
const {
|
238
236
|
fontSize: schemaFontSize,
|
@@ -247,7 +245,6 @@ export const calculateDynamicFontSize = async ({
|
|
247
245
|
if (dynamicFontSizeSetting.max < dynamicFontSizeSetting.min) return fontSize;
|
248
246
|
|
249
247
|
const characterSpacing = schemaCharacterSpacing ?? DEFAULT_CHARACTER_SPACING;
|
250
|
-
const fontKitFont = await getFontKitFont(textSchema.fontName, font, _cache);
|
251
248
|
const paragraphs = value.split('\n');
|
252
249
|
|
253
250
|
let dynamicFontSize = fontSize;
|
package/src/text/pdfRender.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { PDFFont, PDFDocument } from '@pdfme/pdf-lib';
|
2
|
+
import type { Font as FontKitFont } from 'fontkit';
|
2
3
|
import type { TextSchema } from './types';
|
3
4
|
import {
|
4
5
|
PDFRenderProps,
|
@@ -60,21 +61,19 @@ const embedAndGetFontObj = async (arg: {
|
|
60
61
|
return fontObj;
|
61
62
|
};
|
62
63
|
|
63
|
-
const getFontProp =
|
64
|
+
const getFontProp = ({
|
64
65
|
value,
|
65
|
-
|
66
|
+
fontKitFont,
|
66
67
|
schema,
|
67
68
|
colorType,
|
68
|
-
_cache,
|
69
69
|
}: {
|
70
70
|
value: string;
|
71
|
-
|
71
|
+
fontKitFont: FontKitFont;
|
72
72
|
colorType?: ColorType;
|
73
73
|
schema: TextSchema;
|
74
|
-
_cache: Map<any, any>;
|
75
74
|
}) => {
|
76
75
|
const fontSize = schema.dynamicFontSize
|
77
|
-
?
|
76
|
+
? calculateDynamicFontSize({ textSchema: schema, fontKitFont, value })
|
78
77
|
: schema.fontSize ?? DEFAULT_FONT_SIZE;
|
79
78
|
const color = hex2PrintingColor(schema.fontColor || DEFAULT_FONT_COLOR, colorType);
|
80
79
|
|
@@ -94,11 +93,11 @@ export const pdfRender = async (arg: PDFRenderProps<TextSchema>) => {
|
|
94
93
|
|
95
94
|
const { font = getDefaultFont(), colorType } = options;
|
96
95
|
|
97
|
-
const [pdfFontObj, fontKitFont
|
96
|
+
const [pdfFontObj, fontKitFont] = await Promise.all([
|
98
97
|
embedAndGetFontObj({ pdfDoc, font, _cache }),
|
99
98
|
getFontKitFont(schema.fontName, font, _cache),
|
100
|
-
getFontProp({ value, font, schema, _cache, colorType }),
|
101
99
|
]);
|
100
|
+
const fontProp = getFontProp({ value, fontKitFont, schema, colorType });
|
102
101
|
|
103
102
|
const { fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing } = fontProp;
|
104
103
|
|
package/src/text/uiRender.ts
CHANGED
@@ -69,10 +69,8 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
|
69
69
|
return text;
|
70
70
|
};
|
71
71
|
const font = options?.font || getDefaultFont();
|
72
|
-
const
|
73
|
-
|
74
|
-
buildStyledTextContainer(arg, usePlaceholder ? placeholder : value),
|
75
|
-
]);
|
72
|
+
const fontKitFont = await getFontKitFont(schema.fontName, font, _cache);
|
73
|
+
const textBlock = buildStyledTextContainer(arg, fontKitFont, usePlaceholder ? placeholder : value);
|
76
74
|
|
77
75
|
const processedText = replaceUnsupportedChars(value, fontKitFont);
|
78
76
|
|
@@ -100,19 +98,16 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
|
100
98
|
|
101
99
|
if (schema.dynamicFontSize) {
|
102
100
|
let dynamicFontSize: undefined | number = undefined;
|
103
|
-
const font = options?.font || getDefaultFont();
|
104
|
-
const fontKitFont = await getFontKitFont(schema.fontName, font, _cache);
|
105
101
|
|
106
102
|
textBlock.addEventListener('keyup', () => {
|
107
103
|
setTimeout(() => {
|
108
104
|
void (async () => {
|
109
105
|
if (!textBlock.textContent) return;
|
110
|
-
dynamicFontSize =
|
106
|
+
dynamicFontSize = calculateDynamicFontSize({
|
111
107
|
textSchema: schema,
|
112
|
-
|
108
|
+
fontKitFont,
|
113
109
|
value: getText(textBlock),
|
114
110
|
startingFontSize: dynamicFontSize,
|
115
|
-
_cache,
|
116
111
|
});
|
117
112
|
textBlock.style.fontSize = `${dynamicFontSize}pt`;
|
118
113
|
|
@@ -155,23 +150,21 @@ export const uiRender = async (arg: UIRenderProps<TextSchema>) => {
|
|
155
150
|
}
|
156
151
|
};
|
157
152
|
|
158
|
-
export const buildStyledTextContainer =
|
153
|
+
export const buildStyledTextContainer = (arg: UIRenderProps<TextSchema>, fontKitFont: FontKitFont, value: string) => {
|
159
154
|
const { schema, rootElement, mode, options, _cache } = arg;
|
160
155
|
const font = options?.font || getDefaultFont();
|
161
156
|
|
162
157
|
let dynamicFontSize: undefined | number = undefined;
|
163
158
|
|
164
159
|
if (schema.dynamicFontSize && value) {
|
165
|
-
dynamicFontSize =
|
160
|
+
dynamicFontSize = calculateDynamicFontSize({
|
166
161
|
textSchema: schema,
|
167
|
-
|
162
|
+
fontKitFont,
|
168
163
|
value,
|
169
164
|
startingFontSize: dynamicFontSize,
|
170
|
-
_cache,
|
171
165
|
});
|
172
166
|
}
|
173
167
|
|
174
|
-
const fontKitFont = await getFontKitFont(schema.fontName, font, _cache);
|
175
168
|
// Depending on vertical alignment, we need to move the top or bottom of the font to keep
|
176
169
|
// it within it's defined box and align it with the generated pdf.
|
177
170
|
const { topAdj, bottomAdj } = getBrowserVerticalFontAdjustments(
|