@pdfme/schemas 5.3.3-dev.3 → 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.
@@ -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 = async ({
224
+ export const calculateDynamicFontSize = ({
225
225
  textSchema,
226
- font,
226
+ fontKitFont,
227
227
  value,
228
228
  startingFontSize,
229
- _cache,
230
229
  }: {
231
230
  textSchema: TextSchema;
232
- font: Font;
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;
@@ -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 = async ({
64
+ const getFontProp = ({
64
65
  value,
65
- font,
66
+ fontKitFont,
66
67
  schema,
67
68
  colorType,
68
- _cache,
69
69
  }: {
70
70
  value: string;
71
- font: Font;
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
- ? await calculateDynamicFontSize({ textSchema: schema, font, value, _cache })
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, fontProp] = await Promise.all([
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
 
@@ -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 [fontKitFont, textBlock] = await Promise.all([
73
- getFontKitFont(schema.fontName, font, _cache),
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 = await calculateDynamicFontSize({
106
+ dynamicFontSize = calculateDynamicFontSize({
111
107
  textSchema: schema,
112
- font,
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 = async (arg: UIRenderProps<TextSchema>, value: string) => {
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 = await calculateDynamicFontSize({
160
+ dynamicFontSize = calculateDynamicFontSize({
166
161
  textSchema: schema,
167
- font,
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(