@pdfme/generator 2.2.1 → 3.0.0-beta.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.
Files changed (63) hide show
  1. package/README.md +33 -36
  2. package/dist/cjs/__tests__/assets/templates/index.js +2 -0
  3. package/dist/cjs/__tests__/assets/templates/index.js.map +1 -1
  4. package/dist/cjs/__tests__/generate.test.js +52 -25
  5. package/dist/cjs/__tests__/generate.test.js.map +1 -1
  6. package/dist/cjs/src/builtInRenderer.js +2 -5
  7. package/dist/cjs/src/builtInRenderer.js.map +1 -1
  8. package/dist/cjs/src/generate.js +10 -9
  9. package/dist/cjs/src/generate.js.map +1 -1
  10. package/dist/cjs/src/index.js +1 -13
  11. package/dist/cjs/src/index.js.map +1 -1
  12. package/dist/cjs/src/pdfUtils.js +1 -21
  13. package/dist/cjs/src/pdfUtils.js.map +1 -1
  14. package/dist/esm/__tests__/assets/templates/index.js +2 -0
  15. package/dist/esm/__tests__/assets/templates/index.js.map +1 -1
  16. package/dist/esm/__tests__/generate.test.js +52 -25
  17. package/dist/esm/__tests__/generate.test.js.map +1 -1
  18. package/dist/esm/src/builtInRenderer.js +2 -5
  19. package/dist/esm/src/builtInRenderer.js.map +1 -1
  20. package/dist/esm/src/generate.js +12 -11
  21. package/dist/esm/src/generate.js.map +1 -1
  22. package/dist/esm/src/index.js +1 -2
  23. package/dist/esm/src/index.js.map +1 -1
  24. package/dist/esm/src/pdfUtils.js +0 -19
  25. package/dist/esm/src/pdfUtils.js.map +1 -1
  26. package/dist/types/__tests__/assets/templates/index.d.ts +725 -1936
  27. package/dist/types/src/builtInRenderer.d.ts +2 -2
  28. package/dist/types/src/index.d.ts +1 -4
  29. package/dist/types/src/pdfUtils.d.ts +2 -6
  30. package/dist/types/src/types.d.ts +5 -16
  31. package/package.json +5 -3
  32. package/src/builtInRenderer.ts +4 -13
  33. package/src/generate.ts +22 -14
  34. package/src/index.ts +1 -71
  35. package/src/pdfUtils.ts +34 -62
  36. package/src/types.ts +9 -19
  37. package/tsconfig.cjs.json +3 -2
  38. package/tsconfig.esm.json +3 -2
  39. package/tsconfig.json +3 -0
  40. package/dist/cjs/src/renderUtils.js +0 -65
  41. package/dist/cjs/src/renderUtils.js.map +0 -1
  42. package/dist/cjs/src/renders/barcodes.js +0 -37
  43. package/dist/cjs/src/renders/barcodes.js.map +0 -1
  44. package/dist/cjs/src/renders/image.js +0 -34
  45. package/dist/cjs/src/renders/image.js.map +0 -1
  46. package/dist/cjs/src/renders/text.js +0 -86
  47. package/dist/cjs/src/renders/text.js.map +0 -1
  48. package/dist/esm/src/renderUtils.js +0 -56
  49. package/dist/esm/src/renderUtils.js.map +0 -1
  50. package/dist/esm/src/renders/barcodes.js +0 -33
  51. package/dist/esm/src/renders/barcodes.js.map +0 -1
  52. package/dist/esm/src/renders/image.js +0 -30
  53. package/dist/esm/src/renders/image.js.map +0 -1
  54. package/dist/esm/src/renders/text.js +0 -82
  55. package/dist/esm/src/renders/text.js.map +0 -1
  56. package/dist/types/src/renderUtils.d.ts +0 -16
  57. package/dist/types/src/renders/barcodes.d.ts +0 -2
  58. package/dist/types/src/renders/image.d.ts +0 -2
  59. package/dist/types/src/renders/text.d.ts +0 -2
  60. package/src/renderUtils.ts +0 -68
  61. package/src/renders/barcodes.ts +0 -32
  62. package/src/renders/image.ts +0 -24
  63. package/src/renders/text.ts +0 -114
@@ -1,86 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.renderText = void 0;
13
- const pdf_lib_1 = require("@pdfme/pdf-lib");
14
- const common_1 = require("@pdfme/common");
15
- const pdfUtils_1 = require("../pdfUtils");
16
- const renderUtils_1 = require("../renderUtils");
17
- const getFontProp = ({ value, font, schema }) => __awaiter(void 0, void 0, void 0, function* () {
18
- var _a, _b, _c, _d, _e, _f;
19
- const fontSize = schema.dynamicFontSize ? yield (0, common_1.calculateDynamicFontSize)({ textSchema: schema, font, value }) : (_a = schema.fontSize) !== null && _a !== void 0 ? _a : common_1.DEFAULT_FONT_SIZE;
20
- const color = (0, renderUtils_1.hex2RgbColor)((_b = schema.fontColor) !== null && _b !== void 0 ? _b : common_1.DEFAULT_FONT_COLOR);
21
- const alignment = (_c = schema.alignment) !== null && _c !== void 0 ? _c : common_1.DEFAULT_ALIGNMENT;
22
- const verticalAlignment = (_d = schema.verticalAlignment) !== null && _d !== void 0 ? _d : common_1.DEFAULT_VERTICAL_ALIGNMENT;
23
- const lineHeight = (_e = schema.lineHeight) !== null && _e !== void 0 ? _e : common_1.DEFAULT_LINE_HEIGHT;
24
- const characterSpacing = (_f = schema.characterSpacing) !== null && _f !== void 0 ? _f : common_1.DEFAULT_CHARACTER_SPACING;
25
- return { fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing };
26
- });
27
- const renderText = (arg) => __awaiter(void 0, void 0, void 0, function* () {
28
- const { value, pdfDoc, page, options } = arg;
29
- const schema = arg.schema;
30
- const { font = (0, common_1.getDefaultFont)() } = options;
31
- const [pdfFontObj, fontKitFont, fontProp] = yield Promise.all([
32
- (0, pdfUtils_1.embedAndGetFontObj)({ pdfDoc, font }),
33
- (0, common_1.getFontKitFont)(schema, font),
34
- getFontProp({ value, font, schema: schema })
35
- ]);
36
- const { fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing } = fontProp;
37
- const pdfFontValue = pdfFontObj[schema.fontName ? schema.fontName : (0, common_1.getFallbackFontName)(font)];
38
- const pageHeight = page.getHeight();
39
- (0, renderUtils_1.renderBackgroundColor)({ schema, page, pageHeight });
40
- const { width, height, rotate } = (0, renderUtils_1.convertSchemaDimensionsToPt)(schema);
41
- page.pushOperators((0, pdf_lib_1.setCharacterSpacing)(characterSpacing));
42
- const firstLineTextHeight = (0, common_1.heightOfFontAtSize)(fontKitFont, fontSize);
43
- const descent = (0, common_1.getFontDescentInPt)(fontKitFont, fontSize);
44
- const halfLineHeightAdjustment = lineHeight === 0 ? 0 : ((lineHeight - 1) * fontSize) / 2;
45
- const fontWidthCalcValues = {
46
- font: fontKitFont,
47
- fontSize,
48
- characterSpacing,
49
- boxWidthInPt: width,
50
- };
51
- let lines = [];
52
- value.split(/\r|\n|\r\n/g).forEach((line) => {
53
- lines = lines.concat((0, common_1.getSplittedLines)(line, fontWidthCalcValues));
54
- });
55
- // Text lines are rendered from the bottom upwards, we need to adjust the position down
56
- let yOffset = 0;
57
- if (verticalAlignment === common_1.VERTICAL_ALIGN_TOP) {
58
- yOffset = firstLineTextHeight + halfLineHeightAdjustment;
59
- }
60
- else {
61
- const otherLinesHeight = lineHeight * fontSize * (lines.length - 1);
62
- if (verticalAlignment === common_1.VERTICAL_ALIGN_BOTTOM) {
63
- yOffset = height - otherLinesHeight + descent - halfLineHeightAdjustment;
64
- }
65
- else if (verticalAlignment === common_1.VERTICAL_ALIGN_MIDDLE) {
66
- yOffset = (height - otherLinesHeight - firstLineTextHeight + descent) / 2 + firstLineTextHeight;
67
- }
68
- }
69
- lines.forEach((line, rowIndex) => {
70
- const textWidth = (0, common_1.widthOfTextAtSize)(line, fontKitFont, fontSize, characterSpacing);
71
- const rowYOffset = lineHeight * fontSize * rowIndex;
72
- page.drawText(line, {
73
- x: (0, renderUtils_1.calcX)(schema.position.x, alignment, width, textWidth),
74
- y: (0, renderUtils_1.calcY)(schema.position.y, pageHeight, yOffset) - rowYOffset,
75
- rotate,
76
- size: fontSize,
77
- color,
78
- lineHeight: lineHeight * fontSize,
79
- maxWidth: width,
80
- font: pdfFontValue,
81
- wordBreaks: [''],
82
- });
83
- });
84
- });
85
- exports.renderText = renderText;
86
- //# sourceMappingURL=text.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"text.js","sourceRoot":"","sources":["../../../../src/renders/text.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAsD;AACtD,0CAqBuB;AAEvB,0CAAgD;AAChD,gDAMuB;AAEvB,MAAM,WAAW,GAAG,CAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAqD,EAAE,EAAE;;IACvG,MAAM,QAAQ,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,IAAA,iCAAwB,EAAC,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,MAAA,MAAM,CAAC,QAAQ,mCAAI,0BAAiB,CAAC;IACrJ,MAAM,KAAK,GAAG,IAAA,0BAAY,EAAC,MAAA,MAAM,CAAC,SAAS,mCAAI,2BAAkB,CAAC,CAAC;IACnE,MAAM,SAAS,GAAG,MAAA,MAAM,CAAC,SAAS,mCAAI,0BAAiB,CAAC;IACxD,MAAM,iBAAiB,GAAG,MAAA,MAAM,CAAC,iBAAiB,mCAAI,mCAA0B,CAAC;IACjF,MAAM,UAAU,GAAG,MAAA,MAAM,CAAC,UAAU,mCAAI,4BAAmB,CAAC;IAC5D,MAAM,gBAAgB,GAAG,MAAA,MAAM,CAAC,gBAAgB,mCAAI,kCAAyB,CAAC;IAE9E,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC;AACzF,CAAC,CAAA,CAAC;AAEK,MAAM,UAAU,GAAG,CAAO,GAAgB,EAAE,EAAE;IACnD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;IAC7C,MAAM,MAAM,GAAG,GAAG,C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I,EAAE;YAClB,CAAC,EAAE,IAAA,mBAAK,EAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,CAAC;YACxD,CAAC,EAAE,IAAA,mBAAK,EAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,GAAG,UAAU;YAC7D,MAAM;YACN,IAAI,EAAE,QAAQ;YACd,KAAK;YACL,UAAU,EAAE,UAAU,GAAG,QAAQ;YACjC,QAAQ,EAAE,KAAK;YACf,IAAI,EAAE,YAAY;YAClB,UAAU,EAAE,CAAC,EAAE,CAAC;SACjB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAA,CAAC;AArEW,QAAA,UAAU,cAqErB"}
@@ -1,56 +0,0 @@
1
- import { degrees, rgb, } from '@pdfme/pdf-lib';
2
- import { mm2pt } from '@pdfme/common';
3
- const hex2rgb = (hex) => {
4
- if (hex.slice(0, 1) === '#')
5
- hex = hex.slice(1);
6
- if (hex.length === 3)
7
- hex =
8
- hex.slice(0, 1) +
9
- hex.slice(0, 1) +
10
- hex.slice(1, 2) +
11
- hex.slice(1, 2) +
12
- hex.slice(2, 3) +
13
- hex.slice(2, 3);
14
- return [hex.slice(0, 2), hex.slice(2, 4), hex.slice(4, 6)].map((str) => parseInt(str, 16));
15
- };
16
- export const hex2RgbColor = (hexString) => {
17
- if (hexString) {
18
- const [r, g, b] = hex2rgb(hexString);
19
- return rgb(r / 255, g / 255, b / 255);
20
- }
21
- // eslint-disable-next-line no-undefined
22
- return undefined;
23
- };
24
- export const calcX = (x, alignment, boxWidth, textWidth) => {
25
- let addition = 0;
26
- if (alignment === 'center') {
27
- addition = (boxWidth - textWidth) / 2;
28
- }
29
- else if (alignment === 'right') {
30
- addition = boxWidth - textWidth;
31
- }
32
- return mm2pt(x) + addition;
33
- };
34
- export const calcY = (y, pageHeight, itemHeight) => pageHeight - mm2pt(y) - itemHeight;
35
- export const renderBackgroundColor = (arg) => {
36
- const { schema, page, pageHeight } = arg;
37
- if (!schema.backgroundColor)
38
- return;
39
- const { width, height } = convertSchemaDimensionsToPt(schema);
40
- const color = hex2RgbColor(schema.backgroundColor);
41
- page.drawRectangle({
42
- x: calcX(schema.position.x, 'left', width, width),
43
- y: calcY(schema.position.y, pageHeight, height),
44
- width,
45
- height,
46
- color,
47
- });
48
- };
49
- export const convertSchemaDimensionsToPt = (schema) => {
50
- const width = mm2pt(schema.width);
51
- const height = mm2pt(schema.height);
52
- const rotate = degrees(schema.rotate ? schema.rotate : 0);
53
- return { width, height, rotate };
54
- };
55
- export const getCacheKey = (schema, input) => `${schema.type}${input}`;
56
- //# sourceMappingURL=renderUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"renderUtils.js","sourceRoot":"","sources":["../../../src/renderUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,OAAO,EAAE,GAAG,GAAG,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAiC,KAAK,EAAE,MAAM,eAAe,CAAC;AAErE,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,EAAE;IAC9B,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG;QAAE,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAChD,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAClB,GAAG;YACD,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;gBACf,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;gBACf,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;gBACf,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;gBACf,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;gBACf,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEpB,OAAO,CA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,EAAE,EAAE;IACH,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,GAAG,CAAC;IACzC,IAAI,CAAC,MAAM,CAAC,eAAe;QAAE,OAAO;IACpC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,2BAA2B,CAAC,MAAM,CAAC,CAAC;IAC9D,MAAM,KAAK,GAAG,YAAY,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;IACnD,IAAI,CAAC,aAAa,CAAC;QACjB,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC;QACjD,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC;QAC/C,KAAK;QACL,MAAM;QACN,KAAK;KACN,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,MAAc,EAAE,EAAE;IAC5D,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACpC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE1D,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AACnC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,KAAa,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,IAAI,GAAG,KAAK,EAAE,CAAC"}
@@ -1,33 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { createBarCode, validateBarcodeInput, } from '@pdfme/common';
11
- import { calcX, calcY, convertSchemaDimensionsToPt, getCacheKey } from '../renderUtils';
12
- export const renderBarcode = (arg) => __awaiter(void 0, void 0, void 0, function* () {
13
- const { value, schema, pdfDoc, page, _cache } = arg;
14
- if (!validateBarcodeInput(schema.type, value))
15
- return;
16
- const { width, height, rotate } = convertSchemaDimensionsToPt(schema);
17
- const opt = {
18
- x: calcX(schema.position.x, 'left', width, width),
19
- y: calcY(schema.position.y, page.getHeight(), height),
20
- rotate,
21
- width,
22
- height,
23
- };
24
- const inputBarcodeCacheKey = getCacheKey(schema, value);
25
- let image = _cache.get(inputBarcodeCacheKey);
26
- if (!image) {
27
- const imageBuf = yield createBarCode(Object.assign(schema, { type: schema.type, input: value }));
28
- image = yield pdfDoc.embedPng(imageBuf);
29
- _cache.set(inputBarcodeCacheKey, image);
30
- }
31
- page.drawImage(image, opt);
32
- });
33
- //# sourceMappingURL=barcodes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"barcodes.js","sourceRoot":"","sources":["../../../../src/renders/barcodes.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACH,aAAa,EACb,oBAAoB,GAEvB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,2BAA2B,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAEvF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAO,GAAgB,EAAE,EAAE;IACpD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IACpD,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,IAAmB,EAAE,KAAK,CAAC;QAAE,OAAO;IAErE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,2BAA2B,CAAC,MAAM,CAAC,CAAC;IACtE,MAAM,GAAG,GAAG;QACR,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC;QACjD,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,MAAM,CAAC;QACrD,MAAM;QACN,KAAK;QACL,MAAM;KACT,CAAC;IACF,MAAM,oBAAoB,GAAG,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACxD,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IAC7C,IAAI,CAAC,KAAK,EAAE;QACR,MAAM,QAAQ,GAAG,MAAM,aAAa,CAChC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAmB,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAC5E,CAAC;QACF,KAAK,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACxC,MAAM,CAAC,GAAG,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAA;KAC1C;IAED,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC/B,CAAC,CAAA,CAAA"}
@@ -1,30 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { calcX, calcY, convertSchemaDimensionsToPt, getCacheKey } from '../renderUtils';
11
- export const renderImage = (arg) => __awaiter(void 0, void 0, void 0, function* () {
12
- const { value, schema, pdfDoc, page, _cache } = arg;
13
- const { width, height, rotate } = convertSchemaDimensionsToPt(schema);
14
- const opt = {
15
- x: calcX(schema.position.x, 'left', width, width),
16
- y: calcY(schema.position.y, page.getHeight(), height),
17
- rotate,
18
- width,
19
- height,
20
- };
21
- const inputImageCacheKey = getCacheKey(schema, value);
22
- let image = _cache.get(inputImageCacheKey);
23
- if (!image) {
24
- const isPng = value.startsWith('data:image/png;');
25
- image = yield (isPng ? pdfDoc.embedPng(value) : pdfDoc.embedJpg(value));
26
- _cache.set(inputImageCacheKey, image);
27
- }
28
- page.drawImage(image, opt);
29
- });
30
- //# sourceMappingURL=image.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"image.js","sourceRoot":"","sources":["../../../../src/renders/image.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,2BAA2B,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAGvF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAO,GAAgB,EAAE,EAAE;IAClD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAEpD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,2BAA2B,CAAC,MAAM,CAAC,CAAC;IACtE,MAAM,GAAG,GAAG;QACR,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC;QACjD,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,MAAM,CAAC;QACrD,MAAM;QACN,KAAK;QACL,MAAM;KACT,CAAC;IACF,MAAM,kBAAkB,GAAG,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACtD,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC3C,IAAI,CAAC,KAAK,EAAE;QACR,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;QAClD,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QACxE,MAAM,CAAC,GAAG,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;KACzC;IACD,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC/B,CAAC,CAAA,CAAA"}
@@ -1,82 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { setCharacterSpacing, } from '@pdfme/pdf-lib';
11
- import { DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, DEFAULT_VERTICAL_ALIGNMENT, VERTICAL_ALIGN_TOP, VERTICAL_ALIGN_MIDDLE, VERTICAL_ALIGN_BOTTOM, calculateDynamicFontSize, heightOfFontAtSize, getFontDescentInPt, getFontKitFont, getSplittedLines, widthOfTextAtSize, getDefaultFont, getFallbackFontName, } from '@pdfme/common';
12
- import { embedAndGetFontObj } from '../pdfUtils';
13
- import { hex2RgbColor, calcX, calcY, renderBackgroundColor, convertSchemaDimensionsToPt } from '../renderUtils';
14
- const getFontProp = ({ value, font, schema }) => __awaiter(void 0, void 0, void 0, function* () {
15
- var _a, _b, _c, _d, _e, _f;
16
- const fontSize = schema.dynamicFontSize ? yield calculateDynamicFontSize({ textSchema: schema, font, value }) : (_a = schema.fontSize) !== null && _a !== void 0 ? _a : DEFAULT_FONT_SIZE;
17
- const color = hex2RgbColor((_b = schema.fontColor) !== null && _b !== void 0 ? _b : DEFAULT_FONT_COLOR);
18
- const alignment = (_c = schema.alignment) !== null && _c !== void 0 ? _c : DEFAULT_ALIGNMENT;
19
- const verticalAlignment = (_d = schema.verticalAlignment) !== null && _d !== void 0 ? _d : DEFAULT_VERTICAL_ALIGNMENT;
20
- const lineHeight = (_e = schema.lineHeight) !== null && _e !== void 0 ? _e : DEFAULT_LINE_HEIGHT;
21
- const characterSpacing = (_f = schema.characterSpacing) !== null && _f !== void 0 ? _f : DEFAULT_CHARACTER_SPACING;
22
- return { fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing };
23
- });
24
- export const renderText = (arg) => __awaiter(void 0, void 0, void 0, function* () {
25
- const { value, pdfDoc, page, options } = arg;
26
- const schema = arg.schema;
27
- const { font = getDefaultFont() } = options;
28
- const [pdfFontObj, fontKitFont, fontProp] = yield Promise.all([
29
- embedAndGetFontObj({ pdfDoc, font }),
30
- getFontKitFont(schema, font),
31
- getFontProp({ value, font, schema: schema })
32
- ]);
33
- const { fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing } = fontProp;
34
- const pdfFontValue = pdfFontObj[schema.fontName ? schema.fontName : getFallbackFontName(font)];
35
- const pageHeight = page.getHeight();
36
- renderBackgroundColor({ schema, page, pageHeight });
37
- const { width, height, rotate } = convertSchemaDimensionsToPt(schema);
38
- page.pushOperators(setCharacterSpacing(characterSpacing));
39
- const firstLineTextHeight = heightOfFontAtSize(fontKitFont, fontSize);
40
- const descent = getFontDescentInPt(fontKitFont, fontSize);
41
- const halfLineHeightAdjustment = lineHeight === 0 ? 0 : ((lineHeight - 1) * fontSize) / 2;
42
- const fontWidthCalcValues = {
43
- font: fontKitFont,
44
- fontSize,
45
- characterSpacing,
46
- boxWidthInPt: width,
47
- };
48
- let lines = [];
49
- value.split(/\r|\n|\r\n/g).forEach((line) => {
50
- lines = lines.concat(getSplittedLines(line, fontWidthCalcValues));
51
- });
52
- // Text lines are rendered from the bottom upwards, we need to adjust the position down
53
- let yOffset = 0;
54
- if (verticalAlignment === VERTICAL_ALIGN_TOP) {
55
- yOffset = firstLineTextHeight + halfLineHeightAdjustment;
56
- }
57
- else {
58
- const otherLinesHeight = lineHeight * fontSize * (lines.length - 1);
59
- if (verticalAlignment === VERTICAL_ALIGN_BOTTOM) {
60
- yOffset = height - otherLinesHeight + descent - halfLineHeightAdjustment;
61
- }
62
- else if (verticalAlignment === VERTICAL_ALIGN_MIDDLE) {
63
- yOffset = (height - otherLinesHeight - firstLineTextHeight + descent) / 2 + firstLineTextHeight;
64
- }
65
- }
66
- lines.forEach((line, rowIndex) => {
67
- const textWidth = widthOfTextAtSize(line, fontKitFont, fontSize, characterSpacing);
68
- const rowYOffset = lineHeight * fontSize * rowIndex;
69
- page.drawText(line, {
70
- x: calcX(schema.position.x, alignment, width, textWidth),
71
- y: calcY(schema.position.y, pageHeight, yOffset) - rowYOffset,
72
- rotate,
73
- size: fontSize,
74
- color,
75
- lineHeight: lineHeight * fontSize,
76
- maxWidth: width,
77
- font: pdfFontValue,
78
- wordBreaks: [''],
79
- });
80
- });
81
- });
82
- //# sourceMappingURL=text.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"text.js","sourceRoot":"","sources":["../../../../src/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AC/B,MAAM,SAAS,GAAG,iBAAiB,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QACnF,MAAM,UAAU,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAC;QAEpD,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;YAClB,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,CAAC;YACxD,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,GAAG,UAAU;YAC7D,MAAM;YACN,IAAI,EAAE,QAAQ;YACd,KAAK;YACL,UAAU,EAAE,UAAU,GAAG,QAAQ;YACjC,QAAQ,EAAE,KAAK;YACf,IAAI,EAAE,YAAY;YAClB,UAAU,EAAE,CAAC,EAAE,CAAC;SACjB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAA,CAAC"}
@@ -1,16 +0,0 @@
1
- import { PDFPage } from '@pdfme/pdf-lib';
2
- import { Schema, TextSchema, Alignment } from '@pdfme/common';
3
- export declare const hex2RgbColor: (hexString: string | undefined) => import("@pdfme/pdf-lib").RGB | undefined;
4
- export declare const calcX: (x: number, alignment: Alignment, boxWidth: number, textWidth: number) => number;
5
- export declare const calcY: (y: number, pageHeight: number, itemHeight: number) => number;
6
- export declare const renderBackgroundColor: (arg: {
7
- schema: TextSchema;
8
- page: PDFPage;
9
- pageHeight: number;
10
- }) => void;
11
- export declare const convertSchemaDimensionsToPt: (schema: Schema) => {
12
- width: number;
13
- height: number;
14
- rotate: import("@pdfme/pdf-lib").Degrees;
15
- };
16
- export declare const getCacheKey: (schema: Schema, input: string) => string;
@@ -1,2 +0,0 @@
1
- import type { RenderProps } from "../types";
2
- export declare const renderBarcode: (arg: RenderProps) => Promise<void>;
@@ -1,2 +0,0 @@
1
- import type { RenderProps } from "../types";
2
- export declare const renderImage: (arg: RenderProps) => Promise<void>;
@@ -1,2 +0,0 @@
1
- import type { RenderProps } from "../types";
2
- export declare const renderText: (arg: RenderProps) => Promise<void>;
@@ -1,68 +0,0 @@
1
- import { PDFPage, degrees, rgb, } from '@pdfme/pdf-lib';
2
- import { Schema, TextSchema, Alignment, mm2pt } from '@pdfme/common';
3
-
4
- const hex2rgb = (hex: string) => {
5
- if (hex.slice(0, 1) === '#') hex = hex.slice(1);
6
- if (hex.length === 3)
7
- hex =
8
- hex.slice(0, 1) +
9
- hex.slice(0, 1) +
10
- hex.slice(1, 2) +
11
- hex.slice(1, 2) +
12
- hex.slice(2, 3) +
13
- hex.slice(2, 3);
14
-
15
- return [hex.slice(0, 2), hex.slice(2, 4), hex.slice(4, 6)].map((str) => parseInt(str, 16));
16
- };
17
-
18
- export const hex2RgbColor = (hexString: string | undefined) => {
19
- if (hexString) {
20
- const [r, g, b] = hex2rgb(hexString);
21
-
22
- return rgb(r / 255, g / 255, b / 255);
23
- }
24
-
25
- // eslint-disable-next-line no-undefined
26
- return undefined;
27
- };
28
-
29
- export const calcX = (x: number, alignment: Alignment, boxWidth: number, textWidth: number) => {
30
- let addition = 0;
31
- if (alignment === 'center') {
32
- addition = (boxWidth - textWidth) / 2;
33
- } else if (alignment === 'right') {
34
- addition = boxWidth - textWidth;
35
- }
36
-
37
- return mm2pt(x) + addition;
38
- };
39
-
40
- export const calcY = (y: number, pageHeight: number, itemHeight: number) => pageHeight - mm2pt(y) - itemHeight;
41
-
42
- export const renderBackgroundColor = (arg: {
43
- schema: TextSchema;
44
- page: PDFPage;
45
- pageHeight: number;
46
- }) => {
47
- const { schema, page, pageHeight } = arg;
48
- if (!schema.backgroundColor) return;
49
- const { width, height } = convertSchemaDimensionsToPt(schema);
50
- const color = hex2RgbColor(schema.backgroundColor);
51
- page.drawRectangle({
52
- x: calcX(schema.position.x, 'left', width, width),
53
- y: calcY(schema.position.y, pageHeight, height),
54
- width,
55
- height,
56
- color,
57
- });
58
- };
59
-
60
- export const convertSchemaDimensionsToPt = (schema: Schema) => {
61
- const width = mm2pt(schema.width);
62
- const height = mm2pt(schema.height);
63
- const rotate = degrees(schema.rotate ? schema.rotate : 0);
64
-
65
- return { width, height, rotate };
66
- };
67
-
68
- export const getCacheKey = (schema: Schema, input: string) => `${schema.type}${input}`;
@@ -1,32 +0,0 @@
1
- import {
2
- createBarCode,
3
- validateBarcodeInput,
4
- BarCodeType,
5
- } from '@pdfme/common';
6
- import type { RenderProps } from "../types"
7
- import { calcX, calcY, convertSchemaDimensionsToPt, getCacheKey } from '../renderUtils'
8
-
9
- export const renderBarcode = async (arg: RenderProps) => {
10
- const { value, schema, pdfDoc, page, _cache } = arg;
11
- if (!validateBarcodeInput(schema.type as BarCodeType, value)) return;
12
-
13
- const { width, height, rotate } = convertSchemaDimensionsToPt(schema);
14
- const opt = {
15
- x: calcX(schema.position.x, 'left', width, width),
16
- y: calcY(schema.position.y, page.getHeight(), height),
17
- rotate,
18
- width,
19
- height,
20
- };
21
- const inputBarcodeCacheKey = getCacheKey(schema, value);
22
- let image = _cache.get(inputBarcodeCacheKey);
23
- if (!image) {
24
- const imageBuf = await createBarCode(
25
- Object.assign(schema, { type: schema.type as BarCodeType, input: value })
26
- );
27
- image = await pdfDoc.embedPng(imageBuf);
28
- _cache.set(inputBarcodeCacheKey, image)
29
- }
30
-
31
- page.drawImage(image, opt);
32
- }
@@ -1,24 +0,0 @@
1
- import type { RenderProps } from "../types"
2
- import { calcX, calcY, convertSchemaDimensionsToPt, getCacheKey } from '../renderUtils'
3
-
4
-
5
- export const renderImage = async (arg: RenderProps) => {
6
- const { value, schema, pdfDoc, page, _cache } = arg;
7
-
8
- const { width, height, rotate } = convertSchemaDimensionsToPt(schema);
9
- const opt = {
10
- x: calcX(schema.position.x, 'left', width, width),
11
- y: calcY(schema.position.y, page.getHeight(), height),
12
- rotate,
13
- width,
14
- height,
15
- };
16
- const inputImageCacheKey = getCacheKey(schema, value);
17
- let image = _cache.get(inputImageCacheKey);
18
- if (!image) {
19
- const isPng = value.startsWith('data:image/png;');
20
- image = await (isPng ? pdfDoc.embedPng(value) : pdfDoc.embedJpg(value));
21
- _cache.set(inputImageCacheKey, image);
22
- }
23
- page.drawImage(image, opt);
24
- }
@@ -1,114 +0,0 @@
1
- import { setCharacterSpacing, } from '@pdfme/pdf-lib';
2
- import {
3
- TextSchema,
4
- Font,
5
- DEFAULT_FONT_SIZE,
6
- DEFAULT_ALIGNMENT,
7
- DEFAULT_LINE_HEIGHT,
8
- DEFAULT_CHARACTER_SPACING,
9
- DEFAULT_FONT_COLOR,
10
- DEFAULT_VERTICAL_ALIGNMENT,
11
- VERTICAL_ALIGN_TOP,
12
- VERTICAL_ALIGN_MIDDLE,
13
- VERTICAL_ALIGN_BOTTOM,
14
- calculateDynamicFontSize,
15
- heightOfFontAtSize,
16
- getFontDescentInPt,
17
- getFontKitFont,
18
- getSplittedLines,
19
- widthOfTextAtSize,
20
- FontWidthCalcValues,
21
- getDefaultFont,
22
- getFallbackFontName,
23
- } from '@pdfme/common';
24
- import type { RenderProps } from "../types"
25
- import { embedAndGetFontObj } from '../pdfUtils'
26
- import {
27
- hex2RgbColor,
28
- calcX,
29
- calcY,
30
- renderBackgroundColor,
31
- convertSchemaDimensionsToPt
32
- } from '../renderUtils'
33
-
34
- const getFontProp = async ({ value, font, schema }: { value: string, font: Font, schema: TextSchema }) => {
35
- const fontSize = schema.dynamicFontSize ? await calculateDynamicFontSize({ textSchema: schema, font, value }) : schema.fontSize ?? DEFAULT_FONT_SIZE;
36
- const color = hex2RgbColor(schema.fontColor ?? DEFAULT_FONT_COLOR);
37
- const alignment = schema.alignment ?? DEFAULT_ALIGNMENT;
38
- const verticalAlignment = schema.verticalAlignment ?? DEFAULT_VERTICAL_ALIGNMENT;
39
- const lineHeight = schema.lineHeight ?? DEFAULT_LINE_HEIGHT;
40
- const characterSpacing = schema.characterSpacing ?? DEFAULT_CHARACTER_SPACING;
41
-
42
- return { fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing };
43
- };
44
-
45
- export const renderText = async (arg: RenderProps) => {
46
- const { value, pdfDoc, page, options } = arg;
47
- const schema = arg.schema as TextSchema;
48
-
49
- const { font = getDefaultFont() } = options;
50
-
51
- const [pdfFontObj, fontKitFont, fontProp] = await Promise.all([
52
- embedAndGetFontObj({ pdfDoc, font }),
53
- getFontKitFont(schema, font),
54
- getFontProp({ value, font, schema: schema })
55
- ])
56
-
57
- const { fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing } = fontProp;
58
-
59
- const pdfFontValue = pdfFontObj[schema.fontName ? schema.fontName : getFallbackFontName(font)];
60
-
61
- const pageHeight = page.getHeight();
62
- renderBackgroundColor({ schema, page, pageHeight });
63
-
64
- const { width, height, rotate } = convertSchemaDimensionsToPt(schema);
65
-
66
- page.pushOperators(setCharacterSpacing(characterSpacing));
67
-
68
- const firstLineTextHeight = heightOfFontAtSize(fontKitFont, fontSize);
69
- const descent = getFontDescentInPt(fontKitFont, fontSize);
70
- const halfLineHeightAdjustment = lineHeight === 0 ? 0 : ((lineHeight - 1) * fontSize) / 2;
71
-
72
- const fontWidthCalcValues: FontWidthCalcValues = {
73
- font: fontKitFont,
74
- fontSize,
75
- characterSpacing,
76
- boxWidthInPt: width,
77
- };
78
-
79
- let lines: string[] = [];
80
- value.split(/\r|\n|\r\n/g).forEach((line) => {
81
- lines = lines.concat(getSplittedLines(line, fontWidthCalcValues));
82
- });
83
-
84
- // Text lines are rendered from the bottom upwards, we need to adjust the position down
85
- let yOffset = 0;
86
- if (verticalAlignment === VERTICAL_ALIGN_TOP) {
87
- yOffset = firstLineTextHeight + halfLineHeightAdjustment;
88
- } else {
89
- const otherLinesHeight = lineHeight * fontSize * (lines.length - 1);
90
-
91
- if (verticalAlignment === VERTICAL_ALIGN_BOTTOM) {
92
- yOffset = height - otherLinesHeight + descent - halfLineHeightAdjustment;
93
- } else if (verticalAlignment === VERTICAL_ALIGN_MIDDLE) {
94
- yOffset = (height - otherLinesHeight - firstLineTextHeight + descent) / 2 + firstLineTextHeight;
95
- }
96
- }
97
-
98
- lines.forEach((line, rowIndex) => {
99
- const textWidth = widthOfTextAtSize(line, fontKitFont, fontSize, characterSpacing);
100
- const rowYOffset = lineHeight * fontSize * rowIndex;
101
-
102
- page.drawText(line, {
103
- x: calcX(schema.position.x, alignment, width, textWidth),
104
- y: calcY(schema.position.y, pageHeight, yOffset) - rowYOffset,
105
- rotate,
106
- size: fontSize,
107
- color,
108
- lineHeight: lineHeight * fontSize,
109
- maxWidth: width,
110
- font: pdfFontValue,
111
- wordBreaks: [''],
112
- });
113
- });
114
- };