@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.
Files changed (43) hide show
  1. package/dist/cjs/__tests__/text.test.js +0 -82
  2. package/dist/cjs/__tests__/text.test.js.map +1 -1
  3. package/dist/cjs/src/tables/propPanel.js +1 -1
  4. package/dist/cjs/src/text/constants.js +1 -75
  5. package/dist/cjs/src/text/constants.js.map +1 -1
  6. package/dist/cjs/src/text/extraFormatter.js +1 -2
  7. package/dist/cjs/src/text/extraFormatter.js.map +1 -1
  8. package/dist/cjs/src/text/helper.js +5 -182
  9. package/dist/cjs/src/text/helper.js.map +1 -1
  10. package/dist/cjs/src/text/icons/index.js +1 -2
  11. package/dist/cjs/src/text/icons/index.js.map +1 -1
  12. package/dist/cjs/src/text/pdfRender.js +3 -17
  13. package/dist/cjs/src/text/pdfRender.js.map +1 -1
  14. package/dist/cjs/src/text/propPanel.js +3 -3
  15. package/dist/esm/__tests__/text.test.js +1 -83
  16. package/dist/esm/__tests__/text.test.js.map +1 -1
  17. package/dist/esm/src/tables/propPanel.js +1 -1
  18. package/dist/esm/src/text/constants.js +0 -74
  19. package/dist/esm/src/text/constants.js.map +1 -1
  20. package/dist/esm/src/text/extraFormatter.js +3 -4
  21. package/dist/esm/src/text/extraFormatter.js.map +1 -1
  22. package/dist/esm/src/text/helper.js +5 -180
  23. package/dist/esm/src/text/helper.js.map +1 -1
  24. package/dist/esm/src/text/icons/index.js +1 -2
  25. package/dist/esm/src/text/icons/index.js.map +1 -1
  26. package/dist/esm/src/text/pdfRender.js +3 -17
  27. package/dist/esm/src/text/pdfRender.js.map +1 -1
  28. package/dist/esm/src/text/propPanel.js +3 -3
  29. package/dist/types/src/tables/types.d.ts +1 -1
  30. package/dist/types/src/text/constants.d.ts +0 -3
  31. package/dist/types/src/text/helper.d.ts +0 -2
  32. package/dist/types/src/text/icons/index.d.ts +0 -1
  33. package/dist/types/src/text/types.d.ts +1 -1
  34. package/package.json +1 -1
  35. package/src/tables/propPanel.ts +1 -1
  36. package/src/tables/types.ts +1 -1
  37. package/src/text/constants.ts +0 -81
  38. package/src/text/extraFormatter.ts +1 -4
  39. package/src/text/helper.ts +6 -181
  40. package/src/text/icons/index.ts +0 -3
  41. package/src/text/pdfRender.ts +6 -21
  42. package/src/text/propPanel.ts +3 -3
  43. package/src/text/types.ts +1 -1
@@ -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 trimmed = line.replace('\n', '');
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
- let spacing = characterSpacing;
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,
@@ -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: 8,
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' | 'justify';
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