@pdfme/schemas 6.0.3 → 6.0.5-dev.1
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/barcodes/constants.d.ts +4 -0
- package/dist/barcodes/helper.d.ts +21 -0
- package/dist/barcodes/index.d.ts +4 -0
- package/dist/barcodes/pdfRender.d.ts +3 -0
- package/dist/barcodes/propPanel.d.ts +3 -0
- package/{src/barcodes/types.ts → dist/barcodes/types.d.ts} +5 -7
- package/dist/barcodes/uiRender.d.ts +3 -0
- package/dist/builtins-CgaZ0UX3.js +613 -0
- package/dist/builtins-CgaZ0UX3.js.map +1 -0
- package/dist/builtins.d.ts +4 -0
- package/dist/builtins.js +2 -0
- package/dist/checkbox/index.d.ts +6 -0
- package/dist/constants.d.ts +2 -0
- package/dist/date/date.d.ts +2 -0
- package/dist/date/dateTime.d.ts +2 -0
- package/dist/date/helper.d.ts +20 -0
- package/dist/date/time.d.ts +2 -0
- package/dist/date/types.d.ts +17 -0
- package/dist/dynamicTemplate-D_DHR3-X.js +1128 -0
- package/dist/dynamicTemplate-D_DHR3-X.js.map +1 -0
- package/dist/graphics/image.d.ts +5 -0
- package/dist/graphics/imagehelper.d.ts +4 -0
- package/dist/graphics/signature.d.ts +4 -0
- package/dist/graphics/svg.d.ts +4 -0
- package/{src/index.ts → dist/index.d.ts} +1 -22
- package/dist/index.js +5383 -0
- package/dist/index.js.map +1 -0
- package/dist/multiVariableText/helper.d.ts +3 -0
- package/dist/multiVariableText/index.d.ts +4 -0
- package/dist/multiVariableText/pdfRender.d.ts +3 -0
- package/dist/multiVariableText/propPanel.d.ts +3 -0
- package/{src/multiVariableText/types.ts → dist/multiVariableText/types.d.ts} +2 -3
- package/dist/multiVariableText/uiRender.d.ts +3 -0
- package/dist/multiVariableText/variables.d.ts +10 -0
- package/dist/radioGroup/index.d.ts +7 -0
- package/dist/sanitize.d.ts +1 -0
- package/dist/select/index.d.ts +7 -0
- package/dist/shapes/line.d.ts +6 -0
- package/dist/shapes/rectAndEllipse.d.ts +11 -0
- package/dist/tables/cell.d.ts +4 -0
- package/dist/tables/classes.d.ts +69 -0
- package/dist/tables/dynamicTemplate.d.ts +7 -0
- package/dist/tables/helper.d.ts +265 -0
- package/dist/tables/index.d.ts +4 -0
- package/dist/tables/pdfRender.d.ts +3 -0
- package/dist/tables/propPanel.d.ts +3 -0
- package/dist/tables/tableHelper.d.ts +10 -0
- package/dist/tables/types.d.ts +88 -0
- package/dist/tables/uiRender.d.ts +3 -0
- package/dist/tables.js +2 -0
- package/dist/text/constants.d.ts +23 -0
- package/dist/text/extraFormatter.d.ts +25 -0
- package/dist/text/helper.d.ts +40 -0
- package/dist/text/icons/index.d.ts +9 -0
- package/dist/text/index.d.ts +4 -0
- package/dist/text/pdfRender.d.ts +3 -0
- package/dist/text/propPanel.d.ts +3 -0
- package/dist/text/types.d.ts +28 -0
- package/dist/text/uiRender.d.ts +11 -0
- package/dist/utils.d.ts +40 -0
- package/dist/utils.js +215 -0
- package/dist/utils.js.map +1 -0
- package/package.json +5 -1
- package/src/barcodes/constants.ts +0 -20
- package/src/barcodes/helper.ts +0 -187
- package/src/barcodes/index.ts +0 -23
- package/src/barcodes/pdfRender.ts +0 -37
- package/src/barcodes/propPanel.ts +0 -249
- package/src/barcodes/uiRender.ts +0 -94
- package/src/builtins.ts +0 -8
- package/src/checkbox/index.ts +0 -70
- package/src/constants.ts +0 -2
- package/src/date/date.ts +0 -9
- package/src/date/dateTime.ts +0 -9
- package/src/date/helper.ts +0 -544
- package/src/date/time.ts +0 -9
- package/src/date/types.ts +0 -19
- package/src/graphics/image.ts +0 -201
- package/src/graphics/imagehelper.ts +0 -156
- package/src/graphics/signature.ts +0 -136
- package/src/graphics/svg.ts +0 -121
- package/src/multiVariableText/helper.ts +0 -65
- package/src/multiVariableText/index.ts +0 -16
- package/src/multiVariableText/pdfRender.ts +0 -21
- package/src/multiVariableText/propPanel.ts +0 -169
- package/src/multiVariableText/uiRender.ts +0 -157
- package/src/multiVariableText/variables.ts +0 -63
- package/src/radioGroup/index.ts +0 -115
- package/src/sanitize.ts +0 -50
- package/src/select/index.ts +0 -205
- package/src/shapes/line.ts +0 -94
- package/src/shapes/rectAndEllipse.ts +0 -152
- package/src/tables/cell.ts +0 -152
- package/src/tables/classes.ts +0 -402
- package/src/tables/dynamicTemplate.ts +0 -88
- package/src/tables/helper.ts +0 -216
- package/src/tables/index.ts +0 -15
- package/src/tables/pdfRender.ts +0 -144
- package/src/tables/propPanel.ts +0 -111
- package/src/tables/tableHelper.ts +0 -289
- package/src/tables/types.ts +0 -87
- package/src/tables/uiRender.ts +0 -436
- package/src/text/constants.ts +0 -104
- package/src/text/extraFormatter.ts +0 -83
- package/src/text/helper.ts +0 -573
- package/src/text/icons/index.ts +0 -30
- package/src/text/index.ts +0 -16
- package/src/text/pdfRender.ts +0 -240
- package/src/text/propPanel.ts +0 -184
- package/src/text/types.ts +0 -30
- package/src/text/uiRender.ts +0 -292
- package/src/utils.ts +0 -354
- package/tsconfig.build.json +0 -14
- package/tsconfig.json +0 -16
- package/vite.config.mts +0 -51
- /package/{src/tables.ts → dist/tables.d.ts} +0 -0
package/src/text/pdfRender.ts
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { PDFFont, PDFDocument } from '@pdfme/pdf-lib';
|
|
2
|
-
import type { Font as FontKitFont } from 'fontkit';
|
|
3
|
-
import type { TextSchema } from './types.js';
|
|
4
|
-
import {
|
|
5
|
-
PDFRenderProps,
|
|
6
|
-
ColorType,
|
|
7
|
-
Font,
|
|
8
|
-
getDefaultFont,
|
|
9
|
-
getFallbackFontName,
|
|
10
|
-
mm2pt,
|
|
11
|
-
} from '@pdfme/common';
|
|
12
|
-
import {
|
|
13
|
-
VERTICAL_ALIGN_TOP,
|
|
14
|
-
VERTICAL_ALIGN_MIDDLE,
|
|
15
|
-
VERTICAL_ALIGN_BOTTOM,
|
|
16
|
-
DEFAULT_FONT_SIZE,
|
|
17
|
-
DEFAULT_ALIGNMENT,
|
|
18
|
-
DEFAULT_VERTICAL_ALIGNMENT,
|
|
19
|
-
DEFAULT_LINE_HEIGHT,
|
|
20
|
-
DEFAULT_CHARACTER_SPACING,
|
|
21
|
-
DEFAULT_FONT_COLOR,
|
|
22
|
-
} from './constants.js';
|
|
23
|
-
import {
|
|
24
|
-
calculateDynamicFontSize,
|
|
25
|
-
heightOfFontAtSize,
|
|
26
|
-
getFontDescentInPt,
|
|
27
|
-
getFontKitFont,
|
|
28
|
-
fetchRemoteFontData,
|
|
29
|
-
widthOfTextAtSize,
|
|
30
|
-
splitTextToSize,
|
|
31
|
-
} from './helper.js';
|
|
32
|
-
import { convertForPdfLayoutProps, rotatePoint, hex2PrintingColor } from '../utils.js';
|
|
33
|
-
|
|
34
|
-
const embedAndGetFontObj = async (arg: {
|
|
35
|
-
pdfDoc: PDFDocument;
|
|
36
|
-
font: Font;
|
|
37
|
-
_cache: Map<PDFDocument, { [key: string]: PDFFont }>;
|
|
38
|
-
}) => {
|
|
39
|
-
const { pdfDoc, font, _cache } = arg;
|
|
40
|
-
if (_cache.has(pdfDoc)) {
|
|
41
|
-
return _cache.get(pdfDoc) as { [key: string]: PDFFont };
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const fontValues = await Promise.all(
|
|
45
|
-
Object.values(font).map(async (v) => {
|
|
46
|
-
let fontData = v.data;
|
|
47
|
-
if (typeof fontData === 'string' && fontData.startsWith('http')) {
|
|
48
|
-
fontData = await fetchRemoteFontData(fontData);
|
|
49
|
-
}
|
|
50
|
-
return pdfDoc.embedFont(fontData, {
|
|
51
|
-
subset: typeof v.subset === 'undefined' ? true : v.subset,
|
|
52
|
-
});
|
|
53
|
-
}),
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
const fontObj = Object.keys(font).reduce(
|
|
57
|
-
(acc, cur, i) => Object.assign(acc, { [cur]: fontValues[i] }),
|
|
58
|
-
{} as { [key: string]: PDFFont },
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
_cache.set(pdfDoc, fontObj);
|
|
62
|
-
return fontObj;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const getFontProp = ({
|
|
66
|
-
value,
|
|
67
|
-
fontKitFont,
|
|
68
|
-
schema,
|
|
69
|
-
colorType,
|
|
70
|
-
}: {
|
|
71
|
-
value: string;
|
|
72
|
-
fontKitFont: FontKitFont;
|
|
73
|
-
colorType?: ColorType;
|
|
74
|
-
schema: TextSchema;
|
|
75
|
-
}) => {
|
|
76
|
-
const fontSize = schema.dynamicFontSize
|
|
77
|
-
? calculateDynamicFontSize({ textSchema: schema, fontKitFont, value })
|
|
78
|
-
: (schema.fontSize ?? DEFAULT_FONT_SIZE);
|
|
79
|
-
const color = hex2PrintingColor(schema.fontColor || DEFAULT_FONT_COLOR, colorType);
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
alignment: schema.alignment ?? DEFAULT_ALIGNMENT,
|
|
83
|
-
verticalAlignment: schema.verticalAlignment ?? DEFAULT_VERTICAL_ALIGNMENT,
|
|
84
|
-
lineHeight: schema.lineHeight ?? DEFAULT_LINE_HEIGHT,
|
|
85
|
-
characterSpacing: schema.characterSpacing ?? DEFAULT_CHARACTER_SPACING,
|
|
86
|
-
fontSize,
|
|
87
|
-
color,
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export const pdfRender = async (arg: PDFRenderProps<TextSchema>) => {
|
|
92
|
-
const { value, pdfDoc, pdfLib, page, options, schema, _cache } = arg;
|
|
93
|
-
if (!value) return;
|
|
94
|
-
|
|
95
|
-
const { font = getDefaultFont(), colorType } = options;
|
|
96
|
-
|
|
97
|
-
const [pdfFontObj, fontKitFont] = await Promise.all([
|
|
98
|
-
embedAndGetFontObj({
|
|
99
|
-
pdfDoc,
|
|
100
|
-
font,
|
|
101
|
-
_cache: _cache as unknown as Map<PDFDocument, { [key: string]: PDFFont }>,
|
|
102
|
-
}),
|
|
103
|
-
getFontKitFont(schema.fontName, font, _cache as Map<string, FontKitFont>),
|
|
104
|
-
]);
|
|
105
|
-
const fontProp = getFontProp({ value, fontKitFont, schema, colorType });
|
|
106
|
-
|
|
107
|
-
const { fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing } = fontProp;
|
|
108
|
-
|
|
109
|
-
const fontName = (
|
|
110
|
-
schema.fontName ? schema.fontName : getFallbackFontName(font)
|
|
111
|
-
) as keyof typeof pdfFontObj;
|
|
112
|
-
const pdfFontValue = pdfFontObj && pdfFontObj[fontName];
|
|
113
|
-
|
|
114
|
-
const pageHeight = page.getHeight();
|
|
115
|
-
const {
|
|
116
|
-
width,
|
|
117
|
-
height,
|
|
118
|
-
rotate,
|
|
119
|
-
position: { x, y },
|
|
120
|
-
opacity,
|
|
121
|
-
} = convertForPdfLayoutProps({ schema, pageHeight, applyRotateTranslate: false });
|
|
122
|
-
|
|
123
|
-
const pivotPoint = { x: x + width / 2, y: pageHeight - mm2pt(schema.position.y) - height / 2 };
|
|
124
|
-
|
|
125
|
-
if (schema.backgroundColor) {
|
|
126
|
-
const color = hex2PrintingColor(schema.backgroundColor, colorType);
|
|
127
|
-
if (rotate.angle !== 0) {
|
|
128
|
-
// Apply the same rotation logic as text rendering to match UI behavior
|
|
129
|
-
const rotatedPoint = rotatePoint({ x, y }, pivotPoint, rotate.angle);
|
|
130
|
-
page.drawRectangle({ x: rotatedPoint.x, y: rotatedPoint.y, width, height, rotate, color });
|
|
131
|
-
} else {
|
|
132
|
-
page.drawRectangle({ x, y, width, height, rotate, color });
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const firstLineTextHeight = heightOfFontAtSize(fontKitFont, fontSize);
|
|
137
|
-
const descent = getFontDescentInPt(fontKitFont, fontSize);
|
|
138
|
-
const halfLineHeightAdjustment = lineHeight === 0 ? 0 : ((lineHeight - 1) * fontSize) / 2;
|
|
139
|
-
|
|
140
|
-
const lines = splitTextToSize({
|
|
141
|
-
value,
|
|
142
|
-
characterSpacing,
|
|
143
|
-
fontSize,
|
|
144
|
-
fontKitFont,
|
|
145
|
-
boxWidthInPt: width,
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// Text lines are rendered from the bottom upwards, we need to adjust the position down
|
|
149
|
-
let yOffset = 0;
|
|
150
|
-
if (verticalAlignment === VERTICAL_ALIGN_TOP) {
|
|
151
|
-
yOffset = firstLineTextHeight + halfLineHeightAdjustment;
|
|
152
|
-
} else {
|
|
153
|
-
const otherLinesHeight = lineHeight * fontSize * (lines.length - 1);
|
|
154
|
-
|
|
155
|
-
if (verticalAlignment === VERTICAL_ALIGN_BOTTOM) {
|
|
156
|
-
yOffset = height - otherLinesHeight + descent - halfLineHeightAdjustment;
|
|
157
|
-
} else if (verticalAlignment === VERTICAL_ALIGN_MIDDLE) {
|
|
158
|
-
yOffset =
|
|
159
|
-
(height - otherLinesHeight - firstLineTextHeight + descent) / 2 + firstLineTextHeight;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
|
|
164
|
-
|
|
165
|
-
lines.forEach((line, rowIndex) => {
|
|
166
|
-
const trimmed = line.replace('\n', '');
|
|
167
|
-
const textWidth = widthOfTextAtSize(trimmed, fontKitFont, fontSize, characterSpacing);
|
|
168
|
-
const textHeight = heightOfFontAtSize(fontKitFont, fontSize);
|
|
169
|
-
const rowYOffset = lineHeight * fontSize * rowIndex;
|
|
170
|
-
|
|
171
|
-
// Adobe Acrobat Reader shows an error if `drawText` is called with an empty text
|
|
172
|
-
if (line === '') {
|
|
173
|
-
// return; // this also works
|
|
174
|
-
line = '\r\n';
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
let xLine = x;
|
|
178
|
-
if (alignment === 'center') {
|
|
179
|
-
xLine += (width - textWidth) / 2;
|
|
180
|
-
} else if (alignment === 'right') {
|
|
181
|
-
xLine += width - textWidth;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
let yLine = pageHeight - mm2pt(schema.position.y) - yOffset - rowYOffset;
|
|
185
|
-
|
|
186
|
-
// draw strikethrough
|
|
187
|
-
if (schema.strikethrough && textWidth > 0) {
|
|
188
|
-
const _x = xLine + textWidth + 1;
|
|
189
|
-
const _y = yLine + textHeight / 3;
|
|
190
|
-
page.drawLine({
|
|
191
|
-
start: rotatePoint({ x: xLine, y: _y }, pivotPoint, rotate.angle),
|
|
192
|
-
end: rotatePoint({ x: _x, y: _y }, pivotPoint, rotate.angle),
|
|
193
|
-
thickness: (1 / 12) * fontSize,
|
|
194
|
-
color: color,
|
|
195
|
-
opacity,
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// draw underline
|
|
200
|
-
if (schema.underline && textWidth > 0) {
|
|
201
|
-
const _x = xLine + textWidth + 1;
|
|
202
|
-
const _y = yLine - textHeight / 12;
|
|
203
|
-
page.drawLine({
|
|
204
|
-
start: rotatePoint({ x: xLine, y: _y }, pivotPoint, rotate.angle),
|
|
205
|
-
end: rotatePoint({ x: _x, y: _y }, pivotPoint, rotate.angle),
|
|
206
|
-
thickness: (1 / 12) * fontSize,
|
|
207
|
-
color: color,
|
|
208
|
-
opacity,
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (rotate.angle !== 0) {
|
|
213
|
-
// As we draw each line individually from different points, we must translate each lines position
|
|
214
|
-
// relative to the UI rotation pivot point. see comments in convertForPdfLayoutProps() for more info.
|
|
215
|
-
const rotatedPoint = rotatePoint({ x: xLine, y: yLine }, pivotPoint, rotate.angle);
|
|
216
|
-
xLine = rotatedPoint.x;
|
|
217
|
-
yLine = rotatedPoint.y;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
let spacing = characterSpacing;
|
|
221
|
-
if (alignment === 'justify' && line.slice(-1) !== '\n') {
|
|
222
|
-
// if alignment is `justify` but the end of line is not newline, then adjust the spacing
|
|
223
|
-
const iterator = segmenter.segment(trimmed)[Symbol.iterator]();
|
|
224
|
-
const len = Array.from(iterator).length;
|
|
225
|
-
spacing += (width - textWidth) / len;
|
|
226
|
-
}
|
|
227
|
-
page.pushOperators(pdfLib.setCharacterSpacing(spacing));
|
|
228
|
-
|
|
229
|
-
page.drawText(trimmed, {
|
|
230
|
-
x: xLine,
|
|
231
|
-
y: yLine,
|
|
232
|
-
rotate,
|
|
233
|
-
size: fontSize,
|
|
234
|
-
color,
|
|
235
|
-
lineHeight: lineHeight * fontSize,
|
|
236
|
-
font: pdfFontValue,
|
|
237
|
-
opacity,
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
};
|
package/src/text/propPanel.ts
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DEFAULT_FONT_NAME,
|
|
3
|
-
PropPanel,
|
|
4
|
-
PropPanelWidgetProps,
|
|
5
|
-
PropPanelSchema,
|
|
6
|
-
getFallbackFontName,
|
|
7
|
-
} from '@pdfme/common';
|
|
8
|
-
import type { TextSchema } from './types.js';
|
|
9
|
-
import {
|
|
10
|
-
DEFAULT_FONT_SIZE,
|
|
11
|
-
DEFAULT_ALIGNMENT,
|
|
12
|
-
DEFAULT_VERTICAL_ALIGNMENT,
|
|
13
|
-
DEFAULT_CHARACTER_SPACING,
|
|
14
|
-
DEFAULT_LINE_HEIGHT,
|
|
15
|
-
DEFAULT_FONT_COLOR,
|
|
16
|
-
DYNAMIC_FIT_VERTICAL,
|
|
17
|
-
DYNAMIC_FIT_HORIZONTAL,
|
|
18
|
-
DEFAULT_DYNAMIC_FIT,
|
|
19
|
-
DEFAULT_DYNAMIC_MIN_FONT_SIZE,
|
|
20
|
-
DEFAULT_DYNAMIC_MAX_FONT_SIZE,
|
|
21
|
-
} from './constants.js';
|
|
22
|
-
import { DEFAULT_OPACITY, HEX_COLOR_PATTERN } from '../constants.js';
|
|
23
|
-
import { getExtraFormatterSchema } from './extraFormatter.js';
|
|
24
|
-
|
|
25
|
-
const UseDynamicFontSize = (props: PropPanelWidgetProps) => {
|
|
26
|
-
const { rootElement, changeSchemas, activeSchema, i18n } = props;
|
|
27
|
-
|
|
28
|
-
const checkbox = document.createElement('input');
|
|
29
|
-
checkbox.type = 'checkbox';
|
|
30
|
-
checkbox.checked = Boolean((activeSchema as { dynamicFontSize?: unknown })?.dynamicFontSize);
|
|
31
|
-
checkbox.onchange = (e: Event) => {
|
|
32
|
-
const val = (e.target as HTMLInputElement).checked
|
|
33
|
-
? {
|
|
34
|
-
min: DEFAULT_DYNAMIC_MIN_FONT_SIZE,
|
|
35
|
-
max: DEFAULT_DYNAMIC_MAX_FONT_SIZE,
|
|
36
|
-
fit: DEFAULT_DYNAMIC_FIT,
|
|
37
|
-
}
|
|
38
|
-
: undefined;
|
|
39
|
-
changeSchemas([{ key: 'dynamicFontSize', value: val, schemaId: activeSchema.id }]);
|
|
40
|
-
};
|
|
41
|
-
const label = document.createElement('label');
|
|
42
|
-
const span = document.createElement('span');
|
|
43
|
-
span.innerText = i18n('schemas.text.dynamicFontSize') || '';
|
|
44
|
-
span.style.cssText = 'margin-left: 0.5rem';
|
|
45
|
-
label.style.cssText = 'display: flex; width: 100%;';
|
|
46
|
-
label.appendChild(checkbox);
|
|
47
|
-
label.appendChild(span);
|
|
48
|
-
rootElement.appendChild(label);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const propPanel: PropPanel<TextSchema> = {
|
|
52
|
-
schema: ({ options, activeSchema, i18n }) => {
|
|
53
|
-
const font = options.font || { [DEFAULT_FONT_NAME]: { data: '', fallback: true } };
|
|
54
|
-
const fontNames = Object.keys(font);
|
|
55
|
-
const fallbackFontName = getFallbackFontName(font);
|
|
56
|
-
|
|
57
|
-
const enableDynamicFont = Boolean(
|
|
58
|
-
(activeSchema as { dynamicFontSize?: unknown })?.dynamicFontSize,
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
const textSchema: Record<string, PropPanelSchema> = {
|
|
62
|
-
fontName: {
|
|
63
|
-
title: i18n('schemas.text.fontName'),
|
|
64
|
-
type: 'string',
|
|
65
|
-
widget: 'select',
|
|
66
|
-
default: fallbackFontName,
|
|
67
|
-
placeholder: fallbackFontName,
|
|
68
|
-
props: { options: fontNames.map((name) => ({ label: name, value: name })) },
|
|
69
|
-
span: 12,
|
|
70
|
-
},
|
|
71
|
-
fontSize: {
|
|
72
|
-
title: i18n('schemas.text.size'),
|
|
73
|
-
type: 'number',
|
|
74
|
-
widget: 'inputNumber',
|
|
75
|
-
span: 6,
|
|
76
|
-
disabled: enableDynamicFont,
|
|
77
|
-
props: { min: 0 },
|
|
78
|
-
},
|
|
79
|
-
characterSpacing: {
|
|
80
|
-
title: i18n('schemas.text.spacing'),
|
|
81
|
-
type: 'number',
|
|
82
|
-
widget: 'inputNumber',
|
|
83
|
-
span: 6,
|
|
84
|
-
props: { min: 0 },
|
|
85
|
-
},
|
|
86
|
-
formatter: getExtraFormatterSchema(i18n),
|
|
87
|
-
lineHeight: {
|
|
88
|
-
title: i18n('schemas.text.lineHeight'),
|
|
89
|
-
type: 'number',
|
|
90
|
-
widget: 'inputNumber',
|
|
91
|
-
props: { step: 0.1, min: 0 },
|
|
92
|
-
span: 8,
|
|
93
|
-
},
|
|
94
|
-
useDynamicFontSize: { type: 'boolean', widget: 'UseDynamicFontSize', bind: false, span: 16 },
|
|
95
|
-
dynamicFontSize: {
|
|
96
|
-
type: 'object',
|
|
97
|
-
widget: 'card',
|
|
98
|
-
column: 3,
|
|
99
|
-
properties: {
|
|
100
|
-
min: {
|
|
101
|
-
title: i18n('schemas.text.min'),
|
|
102
|
-
type: 'number',
|
|
103
|
-
widget: 'inputNumber',
|
|
104
|
-
hidden: !enableDynamicFont,
|
|
105
|
-
props: { min: 0 },
|
|
106
|
-
},
|
|
107
|
-
max: {
|
|
108
|
-
title: i18n('schemas.text.max'),
|
|
109
|
-
type: 'number',
|
|
110
|
-
widget: 'inputNumber',
|
|
111
|
-
hidden: !enableDynamicFont,
|
|
112
|
-
props: { min: 0 },
|
|
113
|
-
},
|
|
114
|
-
fit: {
|
|
115
|
-
title: i18n('schemas.text.fit'),
|
|
116
|
-
type: 'string',
|
|
117
|
-
widget: 'select',
|
|
118
|
-
hidden: !enableDynamicFont,
|
|
119
|
-
props: {
|
|
120
|
-
options: [
|
|
121
|
-
{ label: i18n('schemas.horizontal'), value: DYNAMIC_FIT_HORIZONTAL },
|
|
122
|
-
{ label: i18n('schemas.vertical'), value: DYNAMIC_FIT_VERTICAL },
|
|
123
|
-
],
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
fontColor: {
|
|
129
|
-
title: i18n('schemas.textColor'),
|
|
130
|
-
type: 'string',
|
|
131
|
-
widget: 'color',
|
|
132
|
-
props: {
|
|
133
|
-
disabledAlpha: true,
|
|
134
|
-
},
|
|
135
|
-
rules: [
|
|
136
|
-
{
|
|
137
|
-
pattern: HEX_COLOR_PATTERN,
|
|
138
|
-
message: i18n('validation.hexColor'),
|
|
139
|
-
},
|
|
140
|
-
],
|
|
141
|
-
},
|
|
142
|
-
backgroundColor: {
|
|
143
|
-
title: i18n('schemas.bgColor'),
|
|
144
|
-
type: 'string',
|
|
145
|
-
widget: 'color',
|
|
146
|
-
props: {
|
|
147
|
-
disabledAlpha: true,
|
|
148
|
-
},
|
|
149
|
-
rules: [
|
|
150
|
-
{
|
|
151
|
-
pattern: HEX_COLOR_PATTERN,
|
|
152
|
-
message: i18n('validation.hexColor'),
|
|
153
|
-
},
|
|
154
|
-
],
|
|
155
|
-
},
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
return textSchema;
|
|
159
|
-
},
|
|
160
|
-
widgets: { UseDynamicFontSize },
|
|
161
|
-
defaultSchema: {
|
|
162
|
-
name: '',
|
|
163
|
-
type: 'text',
|
|
164
|
-
content: 'Type Something...',
|
|
165
|
-
position: { x: 0, y: 0 },
|
|
166
|
-
width: 45,
|
|
167
|
-
height: 10,
|
|
168
|
-
// If the value of "rotate" is set to undefined or not set at all, rotation will be disabled in the UI.
|
|
169
|
-
// Check this document: https://pdfme.com//docs/custom-schemas#learning-how-to-create-from-pdfmeschemas-code
|
|
170
|
-
rotate: 0,
|
|
171
|
-
alignment: DEFAULT_ALIGNMENT,
|
|
172
|
-
verticalAlignment: DEFAULT_VERTICAL_ALIGNMENT,
|
|
173
|
-
fontSize: DEFAULT_FONT_SIZE,
|
|
174
|
-
lineHeight: DEFAULT_LINE_HEIGHT,
|
|
175
|
-
characterSpacing: DEFAULT_CHARACTER_SPACING,
|
|
176
|
-
dynamicFontSize: undefined,
|
|
177
|
-
fontColor: DEFAULT_FONT_COLOR,
|
|
178
|
-
fontName: undefined,
|
|
179
|
-
backgroundColor: '',
|
|
180
|
-
opacity: DEFAULT_OPACITY,
|
|
181
|
-
strikethrough: false,
|
|
182
|
-
underline: false,
|
|
183
|
-
},
|
|
184
|
-
};
|
package/src/text/types.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Schema } from '@pdfme/common';
|
|
2
|
-
import type { Font as FontKitFont } from 'fontkit';
|
|
3
|
-
|
|
4
|
-
export type ALIGNMENT = 'left' | 'center' | 'right' | 'justify';
|
|
5
|
-
export type VERTICAL_ALIGNMENT = 'top' | 'middle' | 'bottom';
|
|
6
|
-
export type DYNAMIC_FONT_SIZE_FIT = 'horizontal' | 'vertical';
|
|
7
|
-
|
|
8
|
-
export type FontWidthCalcValues = {
|
|
9
|
-
font: FontKitFont;
|
|
10
|
-
fontSize: number;
|
|
11
|
-
characterSpacing: number;
|
|
12
|
-
boxWidthInPt: number;
|
|
13
|
-
};
|
|
14
|
-
export type TextSchema = Schema & {
|
|
15
|
-
fontName?: string;
|
|
16
|
-
alignment: ALIGNMENT;
|
|
17
|
-
verticalAlignment: VERTICAL_ALIGNMENT;
|
|
18
|
-
fontSize: number;
|
|
19
|
-
lineHeight: number;
|
|
20
|
-
strikethrough?: boolean;
|
|
21
|
-
underline?: boolean;
|
|
22
|
-
characterSpacing: number;
|
|
23
|
-
dynamicFontSize?: {
|
|
24
|
-
min: number;
|
|
25
|
-
max: number;
|
|
26
|
-
fit: DYNAMIC_FONT_SIZE_FIT;
|
|
27
|
-
};
|
|
28
|
-
fontColor: string;
|
|
29
|
-
backgroundColor: string;
|
|
30
|
-
};
|