@pdfme/schemas 5.3.4-dev.2 → 5.3.4
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 +0 -82
- package/dist/cjs/__tests__/text.test.js.map +1 -1
- package/dist/cjs/src/tables/propPanel.js +1 -1
- package/dist/cjs/src/text/constants.js +1 -75
- package/dist/cjs/src/text/constants.js.map +1 -1
- package/dist/cjs/src/text/extraFormatter.js +1 -2
- package/dist/cjs/src/text/extraFormatter.js.map +1 -1
- package/dist/cjs/src/text/helper.js +5 -182
- package/dist/cjs/src/text/helper.js.map +1 -1
- package/dist/cjs/src/text/icons/index.js +1 -2
- package/dist/cjs/src/text/icons/index.js.map +1 -1
- package/dist/cjs/src/text/pdfRender.js +3 -17
- package/dist/cjs/src/text/pdfRender.js.map +1 -1
- package/dist/cjs/src/text/propPanel.js +3 -3
- package/dist/esm/__tests__/text.test.js +1 -83
- package/dist/esm/__tests__/text.test.js.map +1 -1
- package/dist/esm/src/tables/propPanel.js +1 -1
- package/dist/esm/src/text/constants.js +0 -74
- package/dist/esm/src/text/constants.js.map +1 -1
- package/dist/esm/src/text/extraFormatter.js +3 -4
- package/dist/esm/src/text/extraFormatter.js.map +1 -1
- package/dist/esm/src/text/helper.js +5 -180
- package/dist/esm/src/text/helper.js.map +1 -1
- package/dist/esm/src/text/icons/index.js +1 -2
- package/dist/esm/src/text/icons/index.js.map +1 -1
- package/dist/esm/src/text/pdfRender.js +3 -17
- package/dist/esm/src/text/pdfRender.js.map +1 -1
- package/dist/esm/src/text/propPanel.js +3 -3
- package/dist/types/src/tables/types.d.ts +1 -1
- package/dist/types/src/text/constants.d.ts +0 -3
- package/dist/types/src/text/helper.d.ts +0 -2
- package/dist/types/src/text/icons/index.d.ts +0 -1
- package/dist/types/src/text/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/tables/propPanel.ts +1 -1
- package/src/tables/types.ts +1 -1
- package/src/text/constants.ts +0 -81
- package/src/text/extraFormatter.ts +1 -4
- package/src/text/helper.ts +6 -181
- package/src/text/icons/index.ts +0 -3
- package/src/text/pdfRender.ts +6 -21
- package/src/text/propPanel.ts +3 -3
- package/src/text/types.ts +1 -1
package/src/text/pdfRender.ts
CHANGED
@@ -120,6 +120,8 @@ export const pdfRender = async (arg: PDFRenderProps<TextSchema>) => {
|
|
120
120
|
page.drawRectangle({ x, y, width, height, rotate, color });
|
121
121
|
}
|
122
122
|
|
123
|
+
page.pushOperators(pdfLib.setCharacterSpacing(characterSpacing ?? DEFAULT_CHARACTER_SPACING));
|
124
|
+
|
123
125
|
const firstLineTextHeight = heightOfFontAtSize(fontKitFont, fontSize);
|
124
126
|
const descent = getFontDescentInPt(fontKitFont, fontSize);
|
125
127
|
const halfLineHeightAdjustment = lineHeight === 0 ? 0 : ((lineHeight - 1) * fontSize) / 2;
|
@@ -148,20 +150,12 @@ export const pdfRender = async (arg: PDFRenderProps<TextSchema>) => {
|
|
148
150
|
}
|
149
151
|
|
150
152
|
const pivotPoint = { x: x + width / 2, y: pageHeight - mm2pt(schema.position.y) - height / 2 };
|
151
|
-
const segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
|
152
153
|
|
153
154
|
lines.forEach((line, rowIndex) => {
|
154
|
-
const
|
155
|
-
const textWidth = widthOfTextAtSize(trimmed, fontKitFont, fontSize, characterSpacing);
|
155
|
+
const textWidth = widthOfTextAtSize(line, fontKitFont, fontSize, characterSpacing);
|
156
156
|
const textHeight = heightOfFontAtSize(fontKitFont, fontSize);
|
157
157
|
const rowYOffset = lineHeight * fontSize * rowIndex;
|
158
158
|
|
159
|
-
// Adobe Acrobat Reader shows an error if `drawText` is called with an empty text
|
160
|
-
if (line === '') {
|
161
|
-
// return; // this also works
|
162
|
-
line = '\r\n';
|
163
|
-
}
|
164
|
-
|
165
159
|
let xLine = x;
|
166
160
|
if (alignment === 'center') {
|
167
161
|
xLine += (width - textWidth) / 2;
|
@@ -173,7 +167,7 @@ export const pdfRender = async (arg: PDFRenderProps<TextSchema>) => {
|
|
173
167
|
|
174
168
|
// draw strikethrough
|
175
169
|
if (schema.strikethrough && textWidth > 0) {
|
176
|
-
const _x = xLine + textWidth + 1
|
170
|
+
const _x = xLine + textWidth + 1
|
177
171
|
const _y = yLine + textHeight / 3;
|
178
172
|
page.drawLine({
|
179
173
|
start: rotatePoint({ x: xLine, y: _y }, pivotPoint, rotate.angle),
|
@@ -186,7 +180,7 @@ export const pdfRender = async (arg: PDFRenderProps<TextSchema>) => {
|
|
186
180
|
|
187
181
|
// draw underline
|
188
182
|
if (schema.underline && textWidth > 0) {
|
189
|
-
const _x = xLine + textWidth + 1
|
183
|
+
const _x = xLine + textWidth + 1
|
190
184
|
const _y = yLine - textHeight / 12;
|
191
185
|
page.drawLine({
|
192
186
|
start: rotatePoint({ x: xLine, y: _y }, pivotPoint, rotate.angle),
|
@@ -205,16 +199,7 @@ export const pdfRender = async (arg: PDFRenderProps<TextSchema>) => {
|
|
205
199
|
yLine = rotatedPoint.y;
|
206
200
|
}
|
207
201
|
|
208
|
-
|
209
|
-
if (alignment === 'justify' && line.slice(-1) !== '\n') {
|
210
|
-
// if alignment is `justify` but the end of line is not newline, then adjust the spacing
|
211
|
-
const iterator = segmenter.segment(trimmed)[Symbol.iterator]();
|
212
|
-
const len = Array.from(iterator).length;
|
213
|
-
spacing += (width - textWidth) / len;
|
214
|
-
}
|
215
|
-
page.pushOperators(pdfLib.setCharacterSpacing(spacing));
|
216
|
-
|
217
|
-
page.drawText(trimmed, {
|
202
|
+
page.drawText(line, {
|
218
203
|
x: xLine,
|
219
204
|
y: yLine,
|
220
205
|
rotate,
|
package/src/text/propPanel.ts
CHANGED
@@ -87,7 +87,7 @@ export const propPanel: PropPanel<TextSchema> = {
|
|
87
87
|
type: 'number',
|
88
88
|
widget: 'inputNumber',
|
89
89
|
props: { step: 0.1, min: 0 },
|
90
|
-
span:
|
90
|
+
span: 7,
|
91
91
|
},
|
92
92
|
useDynamicFontSize: { type: 'boolean', widget: 'UseDynamicFontSize', bind: false, span: 16 },
|
93
93
|
dynamicFontSize: {
|
@@ -128,7 +128,7 @@ export const propPanel: PropPanel<TextSchema> = {
|
|
128
128
|
type: 'string',
|
129
129
|
widget: 'color',
|
130
130
|
props: {
|
131
|
-
disabledAlpha: true
|
131
|
+
disabledAlpha: true
|
132
132
|
},
|
133
133
|
rules: [
|
134
134
|
{
|
@@ -142,7 +142,7 @@ export const propPanel: PropPanel<TextSchema> = {
|
|
142
142
|
type: 'string',
|
143
143
|
widget: 'color',
|
144
144
|
props: {
|
145
|
-
disabledAlpha: true
|
145
|
+
disabledAlpha: true
|
146
146
|
},
|
147
147
|
rules: [
|
148
148
|
{
|
package/src/text/types.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { Schema } from '@pdfme/common';
|
2
2
|
import type { Font as FontKitFont } from 'fontkit';
|
3
3
|
|
4
|
-
export type ALIGNMENT = 'left' | 'center' | 'right'
|
4
|
+
export type ALIGNMENT = 'left' | 'center' | 'right';
|
5
5
|
export type VERTICAL_ALIGNMENT = 'top' | 'middle' | 'bottom';
|
6
6
|
export type DYNAMIC_FONT_SIZE_FIT = 'horizontal' | 'vertical';
|
7
7
|
|