@pdfme/common
Advanced tools
Comparing version
@@ -420,2 +420,46 @@ "use strict"; | ||
}); | ||
describe('getFontDescentInPt test', () => { | ||
test('it gets a descent size relative to the font size', () => { | ||
expect((0, font_1.getFontDescentInPt)({ descent: -400, unitsPerEm: 1000 }, 12)).toBe(-4.800000000000001); | ||
expect((0, font_1.getFontDescentInPt)({ descent: 54, unitsPerEm: 1000 }, 20)).toBe(1.08); | ||
expect((0, font_1.getFontDescentInPt)({ descent: -512, unitsPerEm: 2048 }, 54)).toBe(-13.5); | ||
}); | ||
}); | ||
describe('getBrowserVerticalFontAdjustments test', () => { | ||
// Font with a base line-height of 1.349 | ||
const font = { ascent: 1037, descent: -312, unitsPerEm: 1000 }; | ||
test('it gets a top adjustment when vertically aligning top', () => { | ||
expect((0, font_1.getBrowserVerticalFontAdjustments)(font, 12, 1.0, 'top')).toEqual({ | ||
topAdj: 2.791301999999999, | ||
bottomAdj: 0, | ||
}); | ||
expect((0, font_1.getBrowserVerticalFontAdjustments)(font, 36, 2.0, 'top')).toEqual({ | ||
topAdj: 8.373906, | ||
bottomAdj: 0, | ||
}); | ||
}); | ||
test('it gets a bottom adjustment when vertically aligning middle or bottom', () => { | ||
expect((0, font_1.getBrowserVerticalFontAdjustments)(font, 12, 1.0, 'bottom')).toEqual({ | ||
topAdj: 0, | ||
bottomAdj: 2.791302, | ||
}); | ||
expect((0, font_1.getBrowserVerticalFontAdjustments)(font, 12, 1.15, 'middle')).toEqual({ | ||
topAdj: 0, | ||
bottomAdj: 1.5916020000000004, | ||
}); | ||
}); | ||
test('it does not get a bottom adjustment if the line height exceeds that of the font', () => { | ||
expect((0, font_1.getBrowserVerticalFontAdjustments)(font, 12, 1.35, 'bottom')).toEqual({ | ||
topAdj: 0, | ||
bottomAdj: 0, | ||
}); | ||
}); | ||
test('it does not get a bottom adjustment if the font base line-height is 1.0 or less', () => { | ||
const thisFont = { ascent: 900, descent: -50, unitsPerEm: 1000 }; | ||
expect((0, font_1.getBrowserVerticalFontAdjustments)(thisFont, 20, 1.0, 'bottom')).toEqual({ | ||
topAdj: 0, | ||
bottomAdj: 0, | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=font.test.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const helper_1 = require("../src/helper"); | ||
const src_1 = require("../src"); | ||
describe('validateBarcodeInput test', () => { | ||
@@ -251,2 +252,11 @@ test('qrcode', () => { | ||
}); | ||
describe('pt2px test', () => { | ||
it('converts points to pixels', () => { | ||
expect((0, helper_1.pt2px)(1)).toEqual(src_1.PT_TO_PX_RATIO); | ||
expect((0, helper_1.pt2px)(1)).toEqual(1.333); | ||
expect((0, helper_1.pt2px)(2.8346)).toEqual(3.7785218); | ||
expect((0, helper_1.pt2px)(10)).toEqual(13.33); | ||
expect((0, helper_1.pt2px)(5322.98)).toEqual(7095.532339999999); | ||
}); | ||
}); | ||
//# sourceMappingURL=helper.test.js.map |
@@ -35,3 +35,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.calculateDynamicFontSize = exports.getSplittedLines = exports.getFontKitFont = exports.widthOfTextAtSize = exports.heightOfFontAtSize = exports.getFontAlignmentValue = exports.checkFont = exports.getDefaultFont = exports.getFallbackFontName = void 0; | ||
exports.calculateDynamicFontSize = exports.getSplittedLines = exports.getFontKitFont = exports.widthOfTextAtSize = exports.heightOfFontAtSize = exports.getFontDescentInPt = exports.getBrowserVerticalFontAdjustments = exports.checkFont = exports.getDefaultFont = exports.getFallbackFontName = void 0; | ||
const fontkit = __importStar(require("fontkit")); | ||
@@ -87,14 +87,37 @@ const type_1 = require("./type"); | ||
exports.checkFont = checkFont; | ||
const getFontAlignmentValue = (fontKitFont, fontSize) => { | ||
const getBrowserVerticalFontAdjustments = (fontKitFont, fontSize, lineHeight, verticalAlignment) => { | ||
const { ascent, descent, unitsPerEm } = fontKitFont; | ||
const fontSizeInPx = fontSize * constants_1.PT_TO_PX_RATIO; | ||
// Convert ascent and descent to px values | ||
const ascentInPixels = (ascent / unitsPerEm) * fontSizeInPx; | ||
const descentInPixels = (descent / unitsPerEm) * fontSizeInPx; | ||
// Calculate the single line height in px | ||
const singleLineHeight = ((ascentInPixels + Math.abs(descentInPixels)) / fontSizeInPx); | ||
// Calculate the top margin/padding in px | ||
return ((singleLineHeight * fontSizeInPx) - fontSizeInPx) / 2; | ||
// Fonts have a designed line height that the browser renders when using `line-height: normal` | ||
const fontBaseLineHeight = (ascent - descent) / unitsPerEm; | ||
// For vertical alignment top | ||
// To achieve consistent positioning between browser and PDF, we apply the difference between | ||
// the font's actual height and the font size in pixels. | ||
// Browsers middle the font within this height, so we only need half of it to apply to the top. | ||
// This means the font renders a bit lower in the browser, but achieves PDF alignment | ||
const topAdjustment = (fontBaseLineHeight * fontSize - fontSize) / 2; | ||
if (verticalAlignment === constants_1.VERTICAL_ALIGN_TOP) { | ||
return { topAdj: (0, helper_1.pt2px)(topAdjustment), bottomAdj: 0 }; | ||
} | ||
// For vertical alignment bottom and middle | ||
// When browsers render text in a non-form element (such as a <div>), some of the text may be | ||
// lowered below and outside the containing element if the line height used is less than | ||
// the base line-height of the font. | ||
// This behaviour does not happen in a <textarea> though, so we need to adjust the positioning | ||
// for consistency between editing and viewing to stop text jumping up and down. | ||
// This portion of text is half of the difference between the base line height and the used | ||
// line height. If using the same or higher line-height than the base font, then line-height | ||
// takes over in the browser and this adjustment is not needed. | ||
// Unlike the top adjustment - this is only driven by browser behaviour, not PDF alignment. | ||
let bottomAdjustment = 0; | ||
if (lineHeight < fontBaseLineHeight) { | ||
bottomAdjustment = ((fontBaseLineHeight - lineHeight) * fontSize) / 2; | ||
} | ||
return { topAdj: 0, bottomAdj: (0, helper_1.pt2px)(bottomAdjustment) }; | ||
}; | ||
exports.getFontAlignmentValue = getFontAlignmentValue; | ||
exports.getBrowserVerticalFontAdjustments = getBrowserVerticalFontAdjustments; | ||
const getFontDescentInPt = (fontKitFont, fontSize) => { | ||
const { descent, unitsPerEm } = fontKitFont; | ||
return (descent / unitsPerEm) * fontSize; | ||
}; | ||
exports.getFontDescentInPt = getFontDescentInPt; | ||
const heightOfFontAtSize = (fontKitFont, fontSize) => { | ||
@@ -101,0 +124,0 @@ const { ascent, descent, bbox, unitsPerEm } = fontKitFont; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.validateBarcodeInput = exports.checkGenerateProps = exports.checkDesignerProps = exports.checkPreviewProps = exports.checkUIProps = exports.checkTemplate = exports.checkUIOptions = exports.checkInputs = exports.b64toUint8Array = exports.getB64BasePdf = exports.pt2mm = exports.mm2pt = void 0; | ||
exports.validateBarcodeInput = exports.checkGenerateProps = exports.checkDesignerProps = exports.checkPreviewProps = exports.checkUIProps = exports.checkTemplate = exports.checkUIOptions = exports.checkInputs = exports.b64toUint8Array = exports.getB64BasePdf = exports.pt2px = exports.pt2mm = exports.mm2pt = void 0; | ||
const zod_1 = require("zod"); | ||
@@ -17,2 +17,6 @@ const buffer_1 = require("buffer"); | ||
exports.pt2mm = pt2mm; | ||
const pt2px = (pt) => { | ||
return pt * constants_1.PT_TO_PX_RATIO; | ||
}; | ||
exports.pt2px = pt2px; | ||
const blob2Base64Pdf = (blob) => { | ||
@@ -19,0 +23,0 @@ return new Promise((resolve, reject) => { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.calculateDynamicFontSize = exports.validateBarcodeInput = exports.checkGenerateProps = exports.checkDesignerProps = exports.checkPreviewProps = exports.checkUIProps = exports.checkTemplate = exports.checkUIOptions = exports.checkInputs = exports.getFontAlignmentValue = exports.getFontKitFont = exports.checkFont = exports.mm2pt = exports.widthOfTextAtSize = exports.heightOfFontAtSize = exports.getSplittedLines = exports.getDefaultFont = exports.getFallbackFontName = exports.b64toUint8Array = exports.getB64BasePdf = exports.isBarcodeSchema = exports.isImageSchema = exports.isTextSchema = exports.schemaTypes = exports.DEFAULT_FONT_VALUE = exports.BLANK_PDF = exports.PT_TO_PX_RATIO = exports.PT_TO_MM_RATIO = exports.MM_TO_PT_RATIO = exports.FONT_SIZE_ADJUSTMENT = exports.DEFAULT_DYNAMIC_FIT = exports.DYNAMIC_FIT_HORIZONTAL = exports.DYNAMIC_FIT_VERTICAL = exports.DEFAULT_FONT_COLOR = exports.DEFAULT_CHARACTER_SPACING = exports.DEFAULT_LINE_HEIGHT = exports.DEFAULT_ALIGNMENT = exports.DEFAULT_FONT_SIZE = exports.DEFAULT_FONT_NAME = void 0; | ||
exports.calculateDynamicFontSize = exports.validateBarcodeInput = exports.checkGenerateProps = exports.checkDesignerProps = exports.checkPreviewProps = exports.checkUIProps = exports.checkTemplate = exports.checkUIOptions = exports.checkInputs = exports.getFontKitFont = exports.getFontDescentInPt = exports.getBrowserVerticalFontAdjustments = exports.checkFont = exports.pt2px = exports.mm2pt = exports.widthOfTextAtSize = exports.heightOfFontAtSize = exports.getSplittedLines = exports.getDefaultFont = exports.getFallbackFontName = exports.b64toUint8Array = exports.getB64BasePdf = exports.isBarcodeSchema = exports.isImageSchema = exports.isTextSchema = exports.schemaTypes = exports.DEFAULT_FONT_VALUE = exports.BLANK_PDF = exports.PT_TO_PX_RATIO = exports.PT_TO_MM_RATIO = exports.MM_TO_PT_RATIO = exports.FONT_SIZE_ADJUSTMENT = exports.DEFAULT_DYNAMIC_FIT = exports.DYNAMIC_FIT_HORIZONTAL = exports.DYNAMIC_FIT_VERTICAL = exports.DEFAULT_FONT_COLOR = exports.DEFAULT_CHARACTER_SPACING = exports.DEFAULT_LINE_HEIGHT = exports.DEFAULT_VERTICAL_ALIGNMENT = exports.VERTICAL_ALIGN_BOTTOM = exports.VERTICAL_ALIGN_MIDDLE = exports.VERTICAL_ALIGN_TOP = exports.DEFAULT_ALIGNMENT = exports.DEFAULT_FONT_SIZE = exports.DEFAULT_FONT_NAME = void 0; | ||
const constants_js_1 = require("./constants.js"); | ||
@@ -8,2 +8,6 @@ Object.defineProperty(exports, "DEFAULT_FONT_NAME", { enumerable: true, get: function () { return constants_js_1.DEFAULT_FONT_NAME; } }); | ||
Object.defineProperty(exports, "DEFAULT_ALIGNMENT", { enumerable: true, get: function () { return constants_js_1.DEFAULT_ALIGNMENT; } }); | ||
Object.defineProperty(exports, "VERTICAL_ALIGN_TOP", { enumerable: true, get: function () { return constants_js_1.VERTICAL_ALIGN_TOP; } }); | ||
Object.defineProperty(exports, "VERTICAL_ALIGN_MIDDLE", { enumerable: true, get: function () { return constants_js_1.VERTICAL_ALIGN_MIDDLE; } }); | ||
Object.defineProperty(exports, "VERTICAL_ALIGN_BOTTOM", { enumerable: true, get: function () { return constants_js_1.VERTICAL_ALIGN_BOTTOM; } }); | ||
Object.defineProperty(exports, "DEFAULT_VERTICAL_ALIGNMENT", { enumerable: true, get: function () { return constants_js_1.DEFAULT_VERTICAL_ALIGNMENT; } }); | ||
Object.defineProperty(exports, "DEFAULT_LINE_HEIGHT", { enumerable: true, get: function () { return constants_js_1.DEFAULT_LINE_HEIGHT; } }); | ||
@@ -37,2 +41,3 @@ Object.defineProperty(exports, "DEFAULT_CHARACTER_SPACING", { enumerable: true, get: function () { return constants_js_1.DEFAULT_CHARACTER_SPACING; } }); | ||
Object.defineProperty(exports, "mm2pt", { enumerable: true, get: function () { return helper_js_1.mm2pt; } }); | ||
Object.defineProperty(exports, "pt2px", { enumerable: true, get: function () { return helper_js_1.pt2px; } }); | ||
Object.defineProperty(exports, "validateBarcodeInput", { enumerable: true, get: function () { return helper_js_1.validateBarcodeInput; } }); | ||
@@ -47,4 +52,5 @@ const font_js_1 = require("./font.js"); | ||
Object.defineProperty(exports, "getFontKitFont", { enumerable: true, get: function () { return font_js_1.getFontKitFont; } }); | ||
Object.defineProperty(exports, "getFontAlignmentValue", { enumerable: true, get: function () { return font_js_1.getFontAlignmentValue; } }); | ||
Object.defineProperty(exports, "getBrowserVerticalFontAdjustments", { enumerable: true, get: function () { return font_js_1.getBrowserVerticalFontAdjustments; } }); | ||
Object.defineProperty(exports, "getFontDescentInPt", { enumerable: true, get: function () { return font_js_1.getFontDescentInPt; } }); | ||
Object.defineProperty(exports, "getSplittedLines", { enumerable: true, get: function () { return font_js_1.getSplittedLines; } }); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DesignerReactProps = exports.DesignerProps = exports.PreviewReactProps = exports.PreviewProps = exports.UIProps = exports.UIOptions = exports.SchemaInputs = exports.GenerateProps = exports.GeneratorOptions = exports.CommonProps = exports.Inputs = exports.Template = exports.BasePdf = exports.Font = exports.SchemaForUI = exports.Schema = exports.BarcodeSchema = exports.ImageSchema = exports.TextSchema = exports.CommonSchema = exports.SchemaType = exports.BarcodeSchemaType = exports.schemaTypes = exports.barcodeSchemaTypes = exports.Alignment = exports.Size = exports.Lang = void 0; | ||
exports.DesignerReactProps = exports.DesignerProps = exports.PreviewReactProps = exports.PreviewProps = exports.UIProps = exports.UIOptions = exports.SchemaInputs = exports.GenerateProps = exports.GeneratorOptions = exports.CommonProps = exports.Inputs = exports.Template = exports.BasePdf = exports.Font = exports.SchemaForUI = exports.Schema = exports.BarcodeSchema = exports.ImageSchema = exports.TextSchema = exports.CommonSchema = exports.SchemaType = exports.BarcodeSchemaType = exports.schemaTypes = exports.barcodeSchemaTypes = exports.VerticalAlignment = exports.Alignment = exports.Size = exports.Lang = void 0; | ||
/* eslint dot-notation: "off"*/ | ||
const zod_1 = require("zod"); | ||
const constants_1 = require("./constants"); | ||
const langs = ['en', 'ja', 'ar', 'th', 'pl']; | ||
@@ -11,2 +12,8 @@ exports.Lang = zod_1.z.enum(langs); | ||
exports.Alignment = zod_1.z.enum(alignments); | ||
const verticalAlignments = [ | ||
constants_1.VERTICAL_ALIGN_TOP, | ||
constants_1.VERTICAL_ALIGN_MIDDLE, | ||
constants_1.VERTICAL_ALIGN_BOTTOM, | ||
]; | ||
exports.VerticalAlignment = zod_1.z.enum(verticalAlignments); | ||
// prettier-ignore | ||
@@ -28,2 +35,3 @@ exports.barcodeSchemaTypes = ['qrcode', 'japanpost', 'ean13', 'ean8', 'code39', 'code128', 'nw7', 'itf14', 'upca', 'upce', 'gs1datamatrix']; | ||
alignment: exports.Alignment.optional(), | ||
verticalAlignment: exports.VerticalAlignment.optional(), | ||
fontSize: zod_1.z.number().optional(), | ||
@@ -30,0 +38,0 @@ fontName: zod_1.z.string().optional(), |
@@ -12,3 +12,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import * as path from 'path'; | ||
import { calculateDynamicFontSize, checkFont, getDefaultFont, getFontKitFont, getSplittedLines, } from '../src/font'; | ||
import { calculateDynamicFontSize, checkFont, getBrowserVerticalFontAdjustments, getDefaultFont, getFontDescentInPt, getFontKitFont, getSplittedLines, } from '../src/font'; | ||
import { BLANK_PDF } from '../src'; | ||
@@ -396,2 +396,46 @@ const sansData = readFileSync(path.join(__dirname, `/assets/fonts/SauceHanSansJP.ttf`)); | ||
}); | ||
describe('getFontDescentInPt test', () => { | ||
test('it gets a descent size relative to the font size', () => { | ||
expect(getFontDescentInPt({ descent: -400, unitsPerEm: 1000 }, 12)).toBe(-4.800000000000001); | ||
expect(getFontDescentInPt({ descent: 54, unitsPerEm: 1000 }, 20)).toBe(1.08); | ||
expect(getFontDescentInPt({ descent: -512, unitsPerEm: 2048 }, 54)).toBe(-13.5); | ||
}); | ||
}); | ||
describe('getBrowserVerticalFontAdjustments test', () => { | ||
// Font with a base line-height of 1.349 | ||
const font = { ascent: 1037, descent: -312, unitsPerEm: 1000 }; | ||
test('it gets a top adjustment when vertically aligning top', () => { | ||
expect(getBrowserVerticalFontAdjustments(font, 12, 1.0, 'top')).toEqual({ | ||
topAdj: 2.791301999999999, | ||
bottomAdj: 0, | ||
}); | ||
expect(getBrowserVerticalFontAdjustments(font, 36, 2.0, 'top')).toEqual({ | ||
topAdj: 8.373906, | ||
bottomAdj: 0, | ||
}); | ||
}); | ||
test('it gets a bottom adjustment when vertically aligning middle or bottom', () => { | ||
expect(getBrowserVerticalFontAdjustments(font, 12, 1.0, 'bottom')).toEqual({ | ||
topAdj: 0, | ||
bottomAdj: 2.791302, | ||
}); | ||
expect(getBrowserVerticalFontAdjustments(font, 12, 1.15, 'middle')).toEqual({ | ||
topAdj: 0, | ||
bottomAdj: 1.5916020000000004, | ||
}); | ||
}); | ||
test('it does not get a bottom adjustment if the line height exceeds that of the font', () => { | ||
expect(getBrowserVerticalFontAdjustments(font, 12, 1.35, 'bottom')).toEqual({ | ||
topAdj: 0, | ||
bottomAdj: 0, | ||
}); | ||
}); | ||
test('it does not get a bottom adjustment if the font base line-height is 1.0 or less', () => { | ||
const thisFont = { ascent: 900, descent: -50, unitsPerEm: 1000 }; | ||
expect(getBrowserVerticalFontAdjustments(thisFont, 20, 1.0, 'bottom')).toEqual({ | ||
topAdj: 0, | ||
bottomAdj: 0, | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=font.test.js.map |
@@ -1,2 +0,3 @@ | ||
import { validateBarcodeInput, mm2pt, pt2mm } from '../src/helper'; | ||
import { validateBarcodeInput, mm2pt, pt2mm, pt2px } from '../src/helper'; | ||
import { PT_TO_PX_RATIO } from "../src"; | ||
describe('validateBarcodeInput test', () => { | ||
@@ -249,2 +250,11 @@ test('qrcode', () => { | ||
}); | ||
describe('pt2px test', () => { | ||
it('converts points to pixels', () => { | ||
expect(pt2px(1)).toEqual(PT_TO_PX_RATIO); | ||
expect(pt2px(1)).toEqual(1.333); | ||
expect(pt2px(2.8346)).toEqual(3.7785218); | ||
expect(pt2px(10)).toEqual(13.33); | ||
expect(pt2px(5322.98)).toEqual(7095.532339999999); | ||
}); | ||
}); | ||
//# sourceMappingURL=helper.test.js.map |
@@ -13,4 +13,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { Buffer } from 'buffer'; | ||
import { DEFAULT_FONT_VALUE, DEFAULT_FONT_NAME, DEFAULT_FONT_SIZE, DEFAULT_CHARACTER_SPACING, DEFAULT_LINE_HEIGHT, FONT_SIZE_ADJUSTMENT, PT_TO_PX_RATIO, DEFAULT_DYNAMIC_FIT, DYNAMIC_FIT_HORIZONTAL, DYNAMIC_FIT_VERTICAL, } from './constants'; | ||
import { mm2pt, pt2mm } from './helper'; | ||
import { DEFAULT_FONT_VALUE, DEFAULT_FONT_NAME, DEFAULT_FONT_SIZE, DEFAULT_CHARACTER_SPACING, DEFAULT_LINE_HEIGHT, FONT_SIZE_ADJUSTMENT, DEFAULT_DYNAMIC_FIT, DYNAMIC_FIT_HORIZONTAL, DYNAMIC_FIT_VERTICAL, VERTICAL_ALIGN_TOP, } from './constants'; | ||
import { mm2pt, pt2mm, pt2px } from './helper'; | ||
import { b64toUint8Array } from "."; | ||
@@ -58,13 +58,35 @@ export const getFallbackFontName = (font) => { | ||
}; | ||
export const getFontAlignmentValue = (fontKitFont, fontSize) => { | ||
export const getBrowserVerticalFontAdjustments = (fontKitFont, fontSize, lineHeight, verticalAlignment) => { | ||
const { ascent, descent, unitsPerEm } = fontKitFont; | ||
const fontSizeInPx = fontSize * PT_TO_PX_RATIO; | ||
// Convert ascent and descent to px values | ||
const ascentInPixels = (ascent / unitsPerEm) * fontSizeInPx; | ||
const descentInPixels = (descent / unitsPerEm) * fontSizeInPx; | ||
// Calculate the single line height in px | ||
const singleLineHeight = ((ascentInPixels + Math.abs(descentInPixels)) / fontSizeInPx); | ||
// Calculate the top margin/padding in px | ||
return ((singleLineHeight * fontSizeInPx) - fontSizeInPx) / 2; | ||
// Fonts have a designed line height that the browser renders when using `line-height: normal` | ||
const fontBaseLineHeight = (ascent - descent) / unitsPerEm; | ||
// For vertical alignment top | ||
// To achieve consistent positioning between browser and PDF, we apply the difference between | ||
// the font's actual height and the font size in pixels. | ||
// Browsers middle the font within this height, so we only need half of it to apply to the top. | ||
// This means the font renders a bit lower in the browser, but achieves PDF alignment | ||
const topAdjustment = (fontBaseLineHeight * fontSize - fontSize) / 2; | ||
if (verticalAlignment === VERTICAL_ALIGN_TOP) { | ||
return { topAdj: pt2px(topAdjustment), bottomAdj: 0 }; | ||
} | ||
// For vertical alignment bottom and middle | ||
// When browsers render text in a non-form element (such as a <div>), some of the text may be | ||
// lowered below and outside the containing element if the line height used is less than | ||
// the base line-height of the font. | ||
// This behaviour does not happen in a <textarea> though, so we need to adjust the positioning | ||
// for consistency between editing and viewing to stop text jumping up and down. | ||
// This portion of text is half of the difference between the base line height and the used | ||
// line height. If using the same or higher line-height than the base font, then line-height | ||
// takes over in the browser and this adjustment is not needed. | ||
// Unlike the top adjustment - this is only driven by browser behaviour, not PDF alignment. | ||
let bottomAdjustment = 0; | ||
if (lineHeight < fontBaseLineHeight) { | ||
bottomAdjustment = ((fontBaseLineHeight - lineHeight) * fontSize) / 2; | ||
} | ||
return { topAdj: 0, bottomAdj: pt2px(bottomAdjustment) }; | ||
}; | ||
export const getFontDescentInPt = (fontKitFont, fontSize) => { | ||
const { descent, unitsPerEm } = fontKitFont; | ||
return (descent / unitsPerEm) * fontSize; | ||
}; | ||
export const heightOfFontAtSize = (fontKitFont, fontSize) => { | ||
@@ -71,0 +93,0 @@ const { ascent, descent, bbox, unitsPerEm } = fontKitFont; |
import { z } from 'zod'; | ||
import { Buffer } from 'buffer'; | ||
import { Inputs as InputsSchema, UIOptions as UIOptionsSchema, Template as TemplateSchema, PreviewProps as PreviewPropsSchema, DesignerProps as DesignerPropsSchema, GenerateProps as GeneratePropsSchema, UIProps as UIPropsSchema, } from './schema'; | ||
import { MM_TO_PT_RATIO, PT_TO_MM_RATIO } from './constants'; | ||
import { MM_TO_PT_RATIO, PT_TO_MM_RATIO, PT_TO_PX_RATIO } from './constants'; | ||
import { checkFont } from './font'; | ||
@@ -12,2 +12,5 @@ export const mm2pt = (mm) => { | ||
}; | ||
export const pt2px = (pt) => { | ||
return pt * PT_TO_PX_RATIO; | ||
}; | ||
const blob2Base64Pdf = (blob) => { | ||
@@ -14,0 +17,0 @@ return new Promise((resolve, reject) => { |
@@ -1,6 +0,6 @@ | ||
import { DEFAULT_FONT_NAME, DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, DYNAMIC_FIT_VERTICAL, DYNAMIC_FIT_HORIZONTAL, DEFAULT_DYNAMIC_FIT, FONT_SIZE_ADJUSTMENT, MM_TO_PT_RATIO, PT_TO_MM_RATIO, PT_TO_PX_RATIO, BLANK_PDF, DEFAULT_FONT_VALUE, } from './constants.js'; | ||
import { DEFAULT_FONT_NAME, DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, VERTICAL_ALIGN_TOP, VERTICAL_ALIGN_MIDDLE, VERTICAL_ALIGN_BOTTOM, DEFAULT_VERTICAL_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, DYNAMIC_FIT_VERTICAL, DYNAMIC_FIT_HORIZONTAL, DEFAULT_DYNAMIC_FIT, FONT_SIZE_ADJUSTMENT, MM_TO_PT_RATIO, PT_TO_MM_RATIO, PT_TO_PX_RATIO, BLANK_PDF, DEFAULT_FONT_VALUE, } from './constants.js'; | ||
import { schemaTypes, isImageSchema, isBarcodeSchema, isTextSchema } from './type.js'; | ||
import { getB64BasePdf, b64toUint8Array, checkInputs, checkUIOptions, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, mm2pt, validateBarcodeInput, } from './helper.js'; | ||
import { calculateDynamicFontSize, getFallbackFontName, getDefaultFont, heightOfFontAtSize, widthOfTextAtSize, checkFont, getFontKitFont, getFontAlignmentValue, getSplittedLines, } from './font.js'; | ||
export { DEFAULT_FONT_NAME, DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, DYNAMIC_FIT_VERTICAL, DYNAMIC_FIT_HORIZONTAL, DEFAULT_DYNAMIC_FIT, FONT_SIZE_ADJUSTMENT, MM_TO_PT_RATIO, PT_TO_MM_RATIO, PT_TO_PX_RATIO, BLANK_PDF, DEFAULT_FONT_VALUE, schemaTypes, isTextSchema, isImageSchema, isBarcodeSchema, getB64BasePdf, b64toUint8Array, getFallbackFontName, getDefaultFont, getSplittedLines, heightOfFontAtSize, widthOfTextAtSize, mm2pt, checkFont, getFontKitFont, getFontAlignmentValue, checkInputs, checkUIOptions, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, validateBarcodeInput, calculateDynamicFontSize, }; | ||
import { getB64BasePdf, b64toUint8Array, checkInputs, checkUIOptions, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, mm2pt, pt2px, validateBarcodeInput, } from './helper.js'; | ||
import { calculateDynamicFontSize, getFallbackFontName, getDefaultFont, heightOfFontAtSize, widthOfTextAtSize, checkFont, getFontKitFont, getBrowserVerticalFontAdjustments, getFontDescentInPt, getSplittedLines, } from './font.js'; | ||
export { DEFAULT_FONT_NAME, DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, VERTICAL_ALIGN_TOP, VERTICAL_ALIGN_MIDDLE, VERTICAL_ALIGN_BOTTOM, DEFAULT_VERTICAL_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, DYNAMIC_FIT_VERTICAL, DYNAMIC_FIT_HORIZONTAL, DEFAULT_DYNAMIC_FIT, FONT_SIZE_ADJUSTMENT, MM_TO_PT_RATIO, PT_TO_MM_RATIO, PT_TO_PX_RATIO, BLANK_PDF, DEFAULT_FONT_VALUE, schemaTypes, isTextSchema, isImageSchema, isBarcodeSchema, getB64BasePdf, b64toUint8Array, getFallbackFontName, getDefaultFont, getSplittedLines, heightOfFontAtSize, widthOfTextAtSize, mm2pt, pt2px, checkFont, getBrowserVerticalFontAdjustments, getFontDescentInPt, getFontKitFont, checkInputs, checkUIOptions, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, validateBarcodeInput, calculateDynamicFontSize, }; | ||
//# sourceMappingURL=index.js.map |
/* eslint dot-notation: "off"*/ | ||
import { z } from 'zod'; | ||
import { VERTICAL_ALIGN_TOP, VERTICAL_ALIGN_MIDDLE, VERTICAL_ALIGN_BOTTOM } from "./constants"; | ||
const langs = ['en', 'ja', 'ar', 'th', 'pl']; | ||
@@ -8,2 +9,8 @@ export const Lang = z.enum(langs); | ||
export const Alignment = z.enum(alignments); | ||
const verticalAlignments = [ | ||
VERTICAL_ALIGN_TOP, | ||
VERTICAL_ALIGN_MIDDLE, | ||
VERTICAL_ALIGN_BOTTOM, | ||
]; | ||
export const VerticalAlignment = z.enum(verticalAlignments); | ||
// prettier-ignore | ||
@@ -25,2 +32,3 @@ export const barcodeSchemaTypes = ['qrcode', 'japanpost', 'ean13', 'ean8', 'code39', 'code128', 'nw7', 'itf14', 'upca', 'upce', 'gs1datamatrix']; | ||
alignment: Alignment.optional(), | ||
verticalAlignment: VerticalAlignment.optional(), | ||
fontSize: z.number().optional(), | ||
@@ -27,0 +35,0 @@ fontName: z.string().optional(), |
import * as fontkit from 'fontkit'; | ||
import type { Font as FontKitFont } from 'fontkit'; | ||
import { Template, Font, TextSchema } from './type'; | ||
import { FontWidthCalcValues, Template, Font, TextSchema } from './type'; | ||
export declare const getFallbackFontName: (font: Font) => string; | ||
@@ -10,12 +10,10 @@ export declare const getDefaultFont: () => Font; | ||
}) => void; | ||
export declare const getFontAlignmentValue: (fontKitFont: FontKitFont, fontSize: number) => number; | ||
export declare const getBrowserVerticalFontAdjustments: (fontKitFont: FontKitFont, fontSize: number, lineHeight: number, verticalAlignment: string) => { | ||
topAdj: number; | ||
bottomAdj: number; | ||
}; | ||
export declare const getFontDescentInPt: (fontKitFont: FontKitFont, fontSize: number) => number; | ||
export declare const heightOfFontAtSize: (fontKitFont: FontKitFont, fontSize: number) => number; | ||
export declare const widthOfTextAtSize: (text: string, fontKitFont: FontKitFont, fontSize: number, characterSpacing: number) => number; | ||
export declare const getFontKitFont: (textSchema: TextSchema, font: Font) => Promise<fontkit.Font>; | ||
export declare type FontWidthCalcValues = { | ||
font: FontKitFont; | ||
fontSize: number; | ||
characterSpacing: number; | ||
boxWidthInPt: number; | ||
}; | ||
/** | ||
@@ -22,0 +20,0 @@ * Recursively splits the line at getSplitPosition. |
import { BasePdf, BarCodeType } from './type'; | ||
export declare const mm2pt: (mm: number) => number; | ||
export declare const pt2mm: (pt: number) => number; | ||
export declare const pt2px: (pt: number) => number; | ||
export declare const getB64BasePdf: (basePdf: BasePdf) => string | Promise<string>; | ||
@@ -5,0 +6,0 @@ export declare const b64toUint8Array: (base64: string) => Uint8Array; |
@@ -1,7 +0,7 @@ | ||
import { DEFAULT_FONT_NAME, DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, DYNAMIC_FIT_VERTICAL, DYNAMIC_FIT_HORIZONTAL, DEFAULT_DYNAMIC_FIT, FONT_SIZE_ADJUSTMENT, MM_TO_PT_RATIO, PT_TO_MM_RATIO, PT_TO_PX_RATIO, BLANK_PDF, DEFAULT_FONT_VALUE } from './constants.js'; | ||
import { DEFAULT_FONT_NAME, DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, VERTICAL_ALIGN_TOP, VERTICAL_ALIGN_MIDDLE, VERTICAL_ALIGN_BOTTOM, DEFAULT_VERTICAL_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, DYNAMIC_FIT_VERTICAL, DYNAMIC_FIT_HORIZONTAL, DEFAULT_DYNAMIC_FIT, FONT_SIZE_ADJUSTMENT, MM_TO_PT_RATIO, PT_TO_MM_RATIO, PT_TO_PX_RATIO, BLANK_PDF, DEFAULT_FONT_VALUE } from './constants.js'; | ||
import { schemaTypes, isImageSchema, isBarcodeSchema, isTextSchema } from './type.js'; | ||
import type { Lang, Size, Alignment, SchemaType, BarCodeType, TextSchema, ImageSchema, BarcodeSchema, Schema, SchemaInputs, SchemaForUI, Font, BasePdf, Template, CommonProps, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, PreviewReactProps, DesignerProps, DesignerReactProps } from './type.js'; | ||
import { getB64BasePdf, b64toUint8Array, checkInputs, checkUIOptions, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, mm2pt, validateBarcodeInput } from './helper.js'; | ||
import { calculateDynamicFontSize, getFallbackFontName, getDefaultFont, heightOfFontAtSize, widthOfTextAtSize, checkFont, getFontKitFont, getFontAlignmentValue, getSplittedLines, FontWidthCalcValues } from './font.js'; | ||
export { DEFAULT_FONT_NAME, DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, DYNAMIC_FIT_VERTICAL, DYNAMIC_FIT_HORIZONTAL, DEFAULT_DYNAMIC_FIT, FONT_SIZE_ADJUSTMENT, MM_TO_PT_RATIO, PT_TO_MM_RATIO, PT_TO_PX_RATIO, BLANK_PDF, DEFAULT_FONT_VALUE, schemaTypes, isTextSchema, isImageSchema, isBarcodeSchema, getB64BasePdf, b64toUint8Array, getFallbackFontName, getDefaultFont, getSplittedLines, heightOfFontAtSize, widthOfTextAtSize, mm2pt, checkFont, getFontKitFont, getFontAlignmentValue, checkInputs, checkUIOptions, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, validateBarcodeInput, calculateDynamicFontSize, }; | ||
import type { FontWidthCalcValues, Lang, Size, Alignment, SchemaType, BarCodeType, TextSchema, ImageSchema, BarcodeSchema, Schema, SchemaInputs, SchemaForUI, Font, BasePdf, Template, CommonProps, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, PreviewReactProps, DesignerProps, DesignerReactProps } from './type.js'; | ||
import { getB64BasePdf, b64toUint8Array, checkInputs, checkUIOptions, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, mm2pt, pt2px, validateBarcodeInput } from './helper.js'; | ||
import { calculateDynamicFontSize, getFallbackFontName, getDefaultFont, heightOfFontAtSize, widthOfTextAtSize, checkFont, getFontKitFont, getBrowserVerticalFontAdjustments, getFontDescentInPt, getSplittedLines } from './font.js'; | ||
export { DEFAULT_FONT_NAME, DEFAULT_FONT_SIZE, DEFAULT_ALIGNMENT, VERTICAL_ALIGN_TOP, VERTICAL_ALIGN_MIDDLE, VERTICAL_ALIGN_BOTTOM, DEFAULT_VERTICAL_ALIGNMENT, DEFAULT_LINE_HEIGHT, DEFAULT_CHARACTER_SPACING, DEFAULT_FONT_COLOR, DYNAMIC_FIT_VERTICAL, DYNAMIC_FIT_HORIZONTAL, DEFAULT_DYNAMIC_FIT, FONT_SIZE_ADJUSTMENT, MM_TO_PT_RATIO, PT_TO_MM_RATIO, PT_TO_PX_RATIO, BLANK_PDF, DEFAULT_FONT_VALUE, schemaTypes, isTextSchema, isImageSchema, isBarcodeSchema, getB64BasePdf, b64toUint8Array, getFallbackFontName, getDefaultFont, getSplittedLines, heightOfFontAtSize, widthOfTextAtSize, mm2pt, pt2px, checkFont, getBrowserVerticalFontAdjustments, getFontDescentInPt, getFontKitFont, checkInputs, checkUIOptions, checkTemplate, checkUIProps, checkPreviewProps, checkDesignerProps, checkGenerateProps, validateBarcodeInput, calculateDynamicFontSize, }; | ||
export type { Lang, Size, Alignment, SchemaType, BarCodeType, TextSchema, ImageSchema, BarcodeSchema, Schema, SchemaInputs, SchemaForUI, Font, BasePdf, Template, CommonProps, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, PreviewReactProps, DesignerProps, DesignerReactProps, FontWidthCalcValues, }; |
import { z } from 'zod'; | ||
import type { Font as FontKitFont } from 'fontkit'; | ||
import { Lang, Size, Alignment, BarcodeSchemaType, SchemaType, CommonSchema as _CommonSchema, TextSchema, ImageSchema, BarcodeSchema, Schema, SchemaInputs, SchemaForUI, Font, BasePdf, Template, CommonProps, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, PreviewReactProps, DesignerProps, DesignerReactProps } from './schema.js'; | ||
export declare type FontWidthCalcValues = { | ||
font: FontKitFont; | ||
fontSize: number; | ||
characterSpacing: number; | ||
boxWidthInPt: number; | ||
}; | ||
declare type CommonSchema = z.infer<typeof _CommonSchema>; | ||
@@ -15,2 +22,3 @@ export declare const schemaTypes: readonly ["text", "image", "qrcode", "japanpost", "ean13", "ean8", "code39", "code128", "nw7", "itf14", "upca", "upce", "gs1datamatrix"]; | ||
alignment?: "center" | "left" | "right" | undefined; | ||
verticalAlignment?: "top" | "bottom" | "middle" | undefined; | ||
fontSize?: number | undefined; | ||
@@ -17,0 +25,0 @@ fontName?: string | undefined; |
{ | ||
"name": "@pdfme/common", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"sideEffects": false, | ||
@@ -5,0 +5,0 @@ "author": "hand-dot", |
import * as fontkit from 'fontkit'; | ||
import type { Font as FontKitFont } from 'fontkit'; | ||
import { Template, Schema, Font, isTextSchema, TextSchema } from './type'; | ||
import { FontWidthCalcValues, Template, Schema, Font, isTextSchema, TextSchema } from './type'; | ||
import { Buffer } from 'buffer'; | ||
@@ -12,8 +12,8 @@ import { | ||
FONT_SIZE_ADJUSTMENT, | ||
PT_TO_PX_RATIO, | ||
DEFAULT_DYNAMIC_FIT, | ||
DYNAMIC_FIT_HORIZONTAL, | ||
DYNAMIC_FIT_VERTICAL, | ||
VERTICAL_ALIGN_TOP, | ||
} from './constants'; | ||
import { mm2pt, pt2mm } from './helper'; | ||
import { mm2pt, pt2mm, pt2px } from './helper'; | ||
import { b64toUint8Array } from "." | ||
@@ -81,18 +81,48 @@ | ||
export const getFontAlignmentValue = (fontKitFont: FontKitFont, fontSize: number) => { | ||
export const getBrowserVerticalFontAdjustments = ( | ||
fontKitFont: FontKitFont, | ||
fontSize: number, | ||
lineHeight: number, | ||
verticalAlignment: string | ||
) => { | ||
const { ascent, descent, unitsPerEm } = fontKitFont; | ||
const fontSizeInPx = fontSize * PT_TO_PX_RATIO; | ||
// Fonts have a designed line height that the browser renders when using `line-height: normal` | ||
const fontBaseLineHeight = (ascent - descent) / unitsPerEm; | ||
// Convert ascent and descent to px values | ||
const ascentInPixels = (ascent / unitsPerEm) * fontSizeInPx; | ||
const descentInPixels = (descent / unitsPerEm) * fontSizeInPx; | ||
// For vertical alignment top | ||
// To achieve consistent positioning between browser and PDF, we apply the difference between | ||
// the font's actual height and the font size in pixels. | ||
// Browsers middle the font within this height, so we only need half of it to apply to the top. | ||
// This means the font renders a bit lower in the browser, but achieves PDF alignment | ||
const topAdjustment = (fontBaseLineHeight * fontSize - fontSize) / 2; | ||
// Calculate the single line height in px | ||
const singleLineHeight = ((ascentInPixels + Math.abs(descentInPixels)) / fontSizeInPx); | ||
if (verticalAlignment === VERTICAL_ALIGN_TOP) { | ||
return { topAdj: pt2px(topAdjustment), bottomAdj: 0 }; | ||
} | ||
// Calculate the top margin/padding in px | ||
return ((singleLineHeight * fontSizeInPx) - fontSizeInPx) / 2 | ||
// For vertical alignment bottom and middle | ||
// When browsers render text in a non-form element (such as a <div>), some of the text may be | ||
// lowered below and outside the containing element if the line height used is less than | ||
// the base line-height of the font. | ||
// This behaviour does not happen in a <textarea> though, so we need to adjust the positioning | ||
// for consistency between editing and viewing to stop text jumping up and down. | ||
// This portion of text is half of the difference between the base line height and the used | ||
// line height. If using the same or higher line-height than the base font, then line-height | ||
// takes over in the browser and this adjustment is not needed. | ||
// Unlike the top adjustment - this is only driven by browser behaviour, not PDF alignment. | ||
let bottomAdjustment = 0; | ||
if (lineHeight < fontBaseLineHeight) { | ||
bottomAdjustment = ((fontBaseLineHeight - lineHeight) * fontSize) / 2; | ||
} | ||
return { topAdj: 0, bottomAdj: pt2px(bottomAdjustment) }; | ||
}; | ||
export const getFontDescentInPt = (fontKitFont: FontKitFont, fontSize: number) => { | ||
const { descent, unitsPerEm } = fontKitFont; | ||
return (descent / unitsPerEm) * fontSize; | ||
}; | ||
export const heightOfFontAtSize = (fontKitFont: FontKitFont, fontSize: number) => { | ||
@@ -143,8 +173,2 @@ const { ascent, descent, bbox, unitsPerEm } = fontKitFont; | ||
export type FontWidthCalcValues = { | ||
font: FontKitFont; | ||
fontSize: number; | ||
characterSpacing: number; | ||
boxWidthInPt: number; | ||
}; | ||
@@ -151,0 +175,0 @@ const isTextExceedingBoxWidth = (text: string, calcValues: FontWidthCalcValues) => { |
@@ -13,3 +13,3 @@ import { z } from 'zod'; | ||
} from './schema'; | ||
import { MM_TO_PT_RATIO, PT_TO_MM_RATIO } from './constants'; | ||
import { MM_TO_PT_RATIO, PT_TO_MM_RATIO, PT_TO_PX_RATIO } from './constants'; | ||
import { checkFont } from './font'; | ||
@@ -25,2 +25,6 @@ | ||
export const pt2px = (pt: number): number => { | ||
return pt * PT_TO_PX_RATIO; | ||
}; | ||
const blob2Base64Pdf = (blob: Blob) => { | ||
@@ -27,0 +31,0 @@ return new Promise<string>((resolve, reject) => { |
@@ -5,2 +5,6 @@ import { | ||
DEFAULT_ALIGNMENT, | ||
VERTICAL_ALIGN_TOP, | ||
VERTICAL_ALIGN_MIDDLE, | ||
VERTICAL_ALIGN_BOTTOM, | ||
DEFAULT_VERTICAL_ALIGNMENT, | ||
DEFAULT_LINE_HEIGHT, | ||
@@ -21,2 +25,3 @@ DEFAULT_CHARACTER_SPACING, | ||
import type { | ||
FontWidthCalcValues, | ||
Lang, | ||
@@ -57,2 +62,3 @@ Size, | ||
mm2pt, | ||
pt2px, | ||
validateBarcodeInput, | ||
@@ -68,5 +74,5 @@ } from './helper.js'; | ||
getFontKitFont, | ||
getFontAlignmentValue, | ||
getBrowserVerticalFontAdjustments, | ||
getFontDescentInPt, | ||
getSplittedLines, | ||
FontWidthCalcValues, | ||
} from './font.js'; | ||
@@ -78,2 +84,6 @@ | ||
DEFAULT_ALIGNMENT, | ||
VERTICAL_ALIGN_TOP, | ||
VERTICAL_ALIGN_MIDDLE, | ||
VERTICAL_ALIGN_BOTTOM, | ||
DEFAULT_VERTICAL_ALIGNMENT, | ||
DEFAULT_LINE_HEIGHT, | ||
@@ -103,5 +113,7 @@ DEFAULT_CHARACTER_SPACING, | ||
mm2pt, | ||
pt2px, | ||
checkFont, | ||
getBrowserVerticalFontAdjustments, | ||
getFontDescentInPt, | ||
getFontKitFont, | ||
getFontAlignmentValue, | ||
checkInputs, | ||
@@ -108,0 +120,0 @@ checkUIOptions, |
/* eslint dot-notation: "off"*/ | ||
import { z } from 'zod'; | ||
import { VERTICAL_ALIGN_TOP, VERTICAL_ALIGN_MIDDLE, VERTICAL_ALIGN_BOTTOM } from "./constants"; | ||
@@ -12,2 +13,9 @@ const langs = ['en', 'ja', 'ar', 'th', 'pl'] as const; | ||
const verticalAlignments = [ | ||
VERTICAL_ALIGN_TOP, | ||
VERTICAL_ALIGN_MIDDLE, | ||
VERTICAL_ALIGN_BOTTOM, | ||
] as const; | ||
export const VerticalAlignment = z.enum(verticalAlignments); | ||
// prettier-ignore | ||
@@ -32,2 +40,3 @@ export const barcodeSchemaTypes = ['qrcode', 'japanpost', 'ean13', 'ean8', 'code39', 'code128', 'nw7', 'itf14', 'upca', 'upce', 'gs1datamatrix'] as const; | ||
alignment: Alignment.optional(), | ||
verticalAlignment: VerticalAlignment.optional(), | ||
fontSize: z.number().optional(), | ||
@@ -34,0 +43,0 @@ fontName: z.string().optional(), |
import { z } from 'zod'; | ||
import type { Font as FontKitFont } from 'fontkit'; | ||
import { | ||
@@ -31,2 +33,9 @@ Lang, | ||
export type FontWidthCalcValues = { | ||
font: FontKitFont; | ||
fontSize: number; | ||
characterSpacing: number; | ||
boxWidthInPt: number; | ||
}; | ||
type CommonSchema = z.infer<typeof _CommonSchema>; | ||
@@ -33,0 +42,0 @@ export const schemaTypes = _schemaTypes; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1129115
2.41%10363
3.31%