From 39386a8b128eac2faedd8fc82f2b96393100a1e5 Mon Sep 17 00:00:00 2001 From: Reto Fahrni <82324518+retfah@users.noreply.github.com> Date: Tue, 12 Apr 2022 07:56:49 +0200 Subject: [PATCH 1/7] additional options for drawing text Provide textRenderingMode, horizontalScaling, textRise, charcterSpacing and wordSpacing as an option for drawing text. In operator.ts and PDFOperatorNames.ts those operators were already implementes. The function for the horizontalScaling (as it is called in the pdf standard) was called "setCharacterSqueeze" so far. To keep the standardized terminology, the function was renamed to "setHorizontalSpacing". However, for backward compatibility (if somebody had used setCharacterSqueeze in his own script; in the actual pdf-lib code there was no reference) the original function was kept as well with a deprecated note. In the textOptions, not the standard names were used, but noun forms of it, to match the current options style (e.g. horizontalScale (options) instead of horizontalScaling (pdf standard)). --- apps/node/index.ts | 8 ++--- apps/node/tests/test1.ts | 64 +++++++++++++++++++++++++++++++++++++++ src/api/PDFPage.ts | 12 ++++++++ src/api/PDFPageOptions.ts | 7 ++++- src/api/operations.ts | 21 +++++++++++++ src/api/operators.ts | 10 +++++- 6 files changed, 116 insertions(+), 6 deletions(-) diff --git a/apps/node/index.ts b/apps/node/index.ts index 97b9b47ef..3acaaf0b2 100644 --- a/apps/node/index.ts +++ b/apps/node/index.ts @@ -5,7 +5,7 @@ import { sep } from 'path'; import readline from 'readline'; import test1 from './tests/test1'; -import test2 from './tests/test2'; +/*import test2 from './tests/test2'; import test3 from './tests/test3'; import test4 from './tests/test4'; import test5 from './tests/test5'; @@ -21,7 +21,7 @@ import test14 from './tests/test14'; import test15 from './tests/test15'; import test16 from './tests/test16'; import test17 from './tests/test17'; -import test18 from './tests/test18'; +import test18 from './tests/test18';*/ const cli = readline.createInterface({ input: process.stdin, @@ -162,8 +162,8 @@ const main = async () => { // prettier-ignore const allTests = [ - test1, test2, test3, test4, test5, test6, test7, test8, test9, test10, - test11, test12, test13, test14, test15, test16, test17, test18, + test1//, test2, test3, test4, test5, test6, test7, test8, test9, test10, + //test11, test12, test13, test14, test15, test16, test17, test18, ]; const tests = testIdx ? [allTests[testIdx - 1]] : allTests; diff --git a/apps/node/tests/test1.ts b/apps/node/tests/test1.ts index 1fc9f74db..05cbe1c57 100644 --- a/apps/node/tests/test1.ts +++ b/apps/node/tests/test1.ts @@ -21,6 +21,7 @@ import { StandardFonts, typedArrayFor, AFRelationship, + TextRenderingMode, } from '../../..'; const ipsumLines = [ @@ -644,6 +645,69 @@ export default async (assets: Assets) => { form.removeField(textField); + // This page tests different drawing operations as well as adding custom + // operators to the page content. + + const page6 = pdfDoc.addPage([size, size]); + + // Upper-left Quadrant + page6.moveTo(0, size / 2); + + const text = "These are the test words. " + page6.drawText(text + 'regular', { + y: size - 20, + size: 20, + lineHeight: 20, + //horizontalScale: 50, + //rise: 0, + //wordSpace: 10, + //characterSpace: -2, + }); + page6.drawText(text + '+5 raised and fontsize 12 instead of 20', { + y: size - 20, + x: 325, + size: 12, + lineHeight: 20, + //horizontalScale: 50, + rise: 5, + //wordSpace: 10, + //characterSpace: -2, + }); + page6.drawText(text + '50% horizontal scale', { + y: size - 40, + size: 20, + lineHeight: 20, + horizontalScale: 50, + //rise: 0, + //wordSpace: 10, + //characterSpace: -2, + }); + page6.drawText(text + '+10 word space', { + y: size - 60, + size: 20, + lineHeight: 20, + //horizontalScale: 50, + //rise: 0, + wordSpace: 10, + //characterSpace: -2, + renderingMode: TextRenderingMode.Outline, + }); + page6.drawText(text + '+4 character space', { + y: size - 80, + size: 20, + lineHeight: 20, + //horizontalScale: 50, + //rise: 0, + //wordSpace: 10, + characterSpace: 4, + }); + page6.drawText(text + 'textRenderingMode = outline', { + y: size - 100, + size: 20, + lineHeight: 20, + renderingMode: TextRenderingMode.Outline, + }); + /********************** Print Metadata **********************/ console.log('Title:', pdfDoc.getTitle()); diff --git a/src/api/PDFPage.ts b/src/api/PDFPage.ts index 7333440bd..67fc137ba 100644 --- a/src/api/PDFPage.ts +++ b/src/api/PDFPage.ts @@ -14,6 +14,7 @@ import { translate, LineCapStyle, scale, + TextRenderingMode, } from 'src/api/operators'; import PDFDocument from 'src/api/PDFDocument'; import PDFEmbeddedPage from 'src/api/PDFEmbeddedPage'; @@ -976,6 +977,11 @@ export default class PDFPage { assertOrUndefined(options.lineHeight, 'options.lineHeight', ['number']); assertOrUndefined(options.maxWidth, 'options.maxWidth', ['number']); assertOrUndefined(options.wordBreaks, 'options.wordBreaks', [Array]); + assertOrUndefined(options.horizontalScale, 'options.horizontalScale', ['number']); + assertOrUndefined(options.wordSpace, 'options.wordSpace', ['number']); + assertOrUndefined(options.characterSpace, 'options.characterSpace', ['number']); + assertOrUndefined(options.rise, 'options.rise', ['number']); + assertIsOneOfOrUndefined(options.renderingMode, 'options.renderingMode', TextRenderingMode); assertIsOneOfOrUndefined(options.blendMode, 'options.blendMode', BlendMode); const { oldFont, newFont, newFontKey } = this.setOrEmbedFont(options.font); @@ -1010,7 +1016,13 @@ export default class PDFPage { x: options.x ?? this.x, y: options.y ?? this.y, lineHeight: options.lineHeight ?? this.lineHeight, + // optional: graphicsState: graphicsStateKey, + horizontalScale: options.horizontalScale, // defaults to 100 + wordSpace: options.wordSpace, // defaults to 0 + characterSpace: options.characterSpace, // defaults to 0 + rise: options.rise, // defaults to 0 + renderingMode: options.renderingMode, // defaults to TextRenderingMode.Fill }), ); diff --git a/src/api/PDFPageOptions.ts b/src/api/PDFPageOptions.ts index 6ddd8357f..288ef5162 100644 --- a/src/api/PDFPageOptions.ts +++ b/src/api/PDFPageOptions.ts @@ -1,7 +1,7 @@ import { Color } from 'src/api/colors'; import PDFFont from 'src/api/PDFFont'; import { Rotation } from 'src/api/rotations'; -import { LineCapStyle } from 'src/api/operators'; +import { LineCapStyle,TextRenderingMode } from 'src/api/operators'; export enum BlendMode { Normal = 'Normal', @@ -32,6 +32,11 @@ export interface PDFPageDrawTextOptions { lineHeight?: number; maxWidth?: number; wordBreaks?: string[]; + horizontalScale?: number; + wordSpace?: number; + characterSpace?: number; + rise?: number; + renderingMode?: TextRenderingMode; } export interface PDFPageDrawImageOptions { diff --git a/src/api/operations.ts b/src/api/operations.ts index 0e46e6fdf..c5ff2ca8d 100644 --- a/src/api/operations.ts +++ b/src/api/operations.ts @@ -31,6 +31,12 @@ import { clip, endPath, appendBezierCurve, + TextRenderingMode, + setCharacterSpacing, + setHorizontalScaling, + setTextRenderingMode, + setTextRise, + setWordSpacing, } from 'src/api/operators'; import { Rotation, degrees, toRadians } from 'src/api/rotations'; import { svgPathToOperators } from 'src/api/svgPath'; @@ -47,6 +53,11 @@ export interface DrawTextOptions { x: number | PDFNumber; y: number | PDFNumber; graphicsState?: string | PDFName; + horizontalScale?: number | PDFNumber; + wordSpace?: number | PDFNumber; + characterSpace?: number | PDFNumber; + rise?: number | PDFNumber; + renderingMode?: TextRenderingMode; } export const drawText = ( @@ -66,6 +77,11 @@ export const drawText = ( options.x, options.y, ), + options.horizontalScale && setHorizontalScaling(options.horizontalScale), + options.wordSpace && setWordSpacing(options.wordSpace), + options.characterSpace && setCharacterSpacing(options.characterSpace), + options.rise && setTextRise(options.rise), + options.renderingMode && setTextRenderingMode(options.renderingMode), showText(line), endText(), popGraphicsState(), @@ -86,6 +102,11 @@ export const drawLinesOfText = ( setFillingColor(options.color), setFontAndSize(options.font, options.size), setLineHeight(options.lineHeight), + options.horizontalScale && setHorizontalScaling(options.horizontalScale), + options.wordSpace && setWordSpacing(options.wordSpace), + options.characterSpace && setCharacterSpacing(options.characterSpace), + options.rise && setTextRise(options.rise), + options.renderingMode && setTextRenderingMode(options.renderingMode), rotateAndSkewTextRadiansAndTranslate( toRadians(options.rotate), toRadians(options.xSkew), diff --git a/src/api/operators.ts b/src/api/operators.ts index 62b5e3a24..17c605f2b 100644 --- a/src/api/operators.ts +++ b/src/api/operators.ts @@ -213,16 +213,24 @@ export const setFontAndSize = ( size: number | PDFNumber, ) => PDFOperator.of(Ops.SetFontAndSize, [asPDFName(name), asPDFNumber(size)]); +/** @param characterSpace extra space between characters; in unscaled text sapce units; can also be negative **/ export const setCharacterSpacing = (spacing: number | PDFNumber) => PDFOperator.of(Ops.SetCharacterSpacing, [asPDFNumber(spacing)]); +/**@param wordSpace space "between words" (actually extra space for every ASCII SPACE character); in unscaled text sapce units; can also be negative; NOTE: This only works for fonts that define code 32 (=space) as a single-byte code, according to the standard. (E.g. it works with Helvetica, but not with ubuntuFont.) **/ export const setWordSpacing = (spacing: number | PDFNumber) => PDFOperator.of(Ops.SetWordSpacing, [asPDFNumber(spacing)]); -/** @param squeeze horizontal character spacing */ +/** + * DEPRECATED: use "setHorizontalScaling" instead + * @param squeeze horizontal character spacing */ export const setCharacterSqueeze = (squeeze: number | PDFNumber) => PDFOperator.of(Ops.SetTextHorizontalScaling, [asPDFNumber(squeeze)]); +/** @param horizontalScaling horizontal character spacing; value in %; default = 100 **/ +export const setHorizontalScaling = (horizontalScaling: number | PDFNumber) => + PDFOperator.of(Ops.SetTextHorizontalScaling, [asPDFNumber(horizontalScaling)]); + export const setLineHeight = (lineHeight: number | PDFNumber) => PDFOperator.of(Ops.SetTextLineHeight, [asPDFNumber(lineHeight)]); From ba7741227871c65285b1a26577e22d18cb37045e Mon Sep 17 00:00:00 2001 From: Reto Fahrni <82324518+retfah@users.noreply.github.com> Date: Tue, 12 Apr 2022 08:06:02 +0200 Subject: [PATCH 2/7] Revert "additional options for drawing text" This reverts commit 39386a8b128eac2faedd8fc82f2b96393100a1e5. --- apps/node/index.ts | 8 ++--- apps/node/tests/test1.ts | 64 --------------------------------------- src/api/PDFPage.ts | 12 -------- src/api/PDFPageOptions.ts | 7 +---- src/api/operations.ts | 21 ------------- src/api/operators.ts | 10 +----- 6 files changed, 6 insertions(+), 116 deletions(-) diff --git a/apps/node/index.ts b/apps/node/index.ts index 3acaaf0b2..97b9b47ef 100644 --- a/apps/node/index.ts +++ b/apps/node/index.ts @@ -5,7 +5,7 @@ import { sep } from 'path'; import readline from 'readline'; import test1 from './tests/test1'; -/*import test2 from './tests/test2'; +import test2 from './tests/test2'; import test3 from './tests/test3'; import test4 from './tests/test4'; import test5 from './tests/test5'; @@ -21,7 +21,7 @@ import test14 from './tests/test14'; import test15 from './tests/test15'; import test16 from './tests/test16'; import test17 from './tests/test17'; -import test18 from './tests/test18';*/ +import test18 from './tests/test18'; const cli = readline.createInterface({ input: process.stdin, @@ -162,8 +162,8 @@ const main = async () => { // prettier-ignore const allTests = [ - test1//, test2, test3, test4, test5, test6, test7, test8, test9, test10, - //test11, test12, test13, test14, test15, test16, test17, test18, + test1, test2, test3, test4, test5, test6, test7, test8, test9, test10, + test11, test12, test13, test14, test15, test16, test17, test18, ]; const tests = testIdx ? [allTests[testIdx - 1]] : allTests; diff --git a/apps/node/tests/test1.ts b/apps/node/tests/test1.ts index 05cbe1c57..1fc9f74db 100644 --- a/apps/node/tests/test1.ts +++ b/apps/node/tests/test1.ts @@ -21,7 +21,6 @@ import { StandardFonts, typedArrayFor, AFRelationship, - TextRenderingMode, } from '../../..'; const ipsumLines = [ @@ -645,69 +644,6 @@ export default async (assets: Assets) => { form.removeField(textField); - // This page tests different drawing operations as well as adding custom - // operators to the page content. - - const page6 = pdfDoc.addPage([size, size]); - - // Upper-left Quadrant - page6.moveTo(0, size / 2); - - const text = "These are the test words. " - page6.drawText(text + 'regular', { - y: size - 20, - size: 20, - lineHeight: 20, - //horizontalScale: 50, - //rise: 0, - //wordSpace: 10, - //characterSpace: -2, - }); - page6.drawText(text + '+5 raised and fontsize 12 instead of 20', { - y: size - 20, - x: 325, - size: 12, - lineHeight: 20, - //horizontalScale: 50, - rise: 5, - //wordSpace: 10, - //characterSpace: -2, - }); - page6.drawText(text + '50% horizontal scale', { - y: size - 40, - size: 20, - lineHeight: 20, - horizontalScale: 50, - //rise: 0, - //wordSpace: 10, - //characterSpace: -2, - }); - page6.drawText(text + '+10 word space', { - y: size - 60, - size: 20, - lineHeight: 20, - //horizontalScale: 50, - //rise: 0, - wordSpace: 10, - //characterSpace: -2, - renderingMode: TextRenderingMode.Outline, - }); - page6.drawText(text + '+4 character space', { - y: size - 80, - size: 20, - lineHeight: 20, - //horizontalScale: 50, - //rise: 0, - //wordSpace: 10, - characterSpace: 4, - }); - page6.drawText(text + 'textRenderingMode = outline', { - y: size - 100, - size: 20, - lineHeight: 20, - renderingMode: TextRenderingMode.Outline, - }); - /********************** Print Metadata **********************/ console.log('Title:', pdfDoc.getTitle()); diff --git a/src/api/PDFPage.ts b/src/api/PDFPage.ts index 67fc137ba..7333440bd 100644 --- a/src/api/PDFPage.ts +++ b/src/api/PDFPage.ts @@ -14,7 +14,6 @@ import { translate, LineCapStyle, scale, - TextRenderingMode, } from 'src/api/operators'; import PDFDocument from 'src/api/PDFDocument'; import PDFEmbeddedPage from 'src/api/PDFEmbeddedPage'; @@ -977,11 +976,6 @@ export default class PDFPage { assertOrUndefined(options.lineHeight, 'options.lineHeight', ['number']); assertOrUndefined(options.maxWidth, 'options.maxWidth', ['number']); assertOrUndefined(options.wordBreaks, 'options.wordBreaks', [Array]); - assertOrUndefined(options.horizontalScale, 'options.horizontalScale', ['number']); - assertOrUndefined(options.wordSpace, 'options.wordSpace', ['number']); - assertOrUndefined(options.characterSpace, 'options.characterSpace', ['number']); - assertOrUndefined(options.rise, 'options.rise', ['number']); - assertIsOneOfOrUndefined(options.renderingMode, 'options.renderingMode', TextRenderingMode); assertIsOneOfOrUndefined(options.blendMode, 'options.blendMode', BlendMode); const { oldFont, newFont, newFontKey } = this.setOrEmbedFont(options.font); @@ -1016,13 +1010,7 @@ export default class PDFPage { x: options.x ?? this.x, y: options.y ?? this.y, lineHeight: options.lineHeight ?? this.lineHeight, - // optional: graphicsState: graphicsStateKey, - horizontalScale: options.horizontalScale, // defaults to 100 - wordSpace: options.wordSpace, // defaults to 0 - characterSpace: options.characterSpace, // defaults to 0 - rise: options.rise, // defaults to 0 - renderingMode: options.renderingMode, // defaults to TextRenderingMode.Fill }), ); diff --git a/src/api/PDFPageOptions.ts b/src/api/PDFPageOptions.ts index 288ef5162..6ddd8357f 100644 --- a/src/api/PDFPageOptions.ts +++ b/src/api/PDFPageOptions.ts @@ -1,7 +1,7 @@ import { Color } from 'src/api/colors'; import PDFFont from 'src/api/PDFFont'; import { Rotation } from 'src/api/rotations'; -import { LineCapStyle,TextRenderingMode } from 'src/api/operators'; +import { LineCapStyle } from 'src/api/operators'; export enum BlendMode { Normal = 'Normal', @@ -32,11 +32,6 @@ export interface PDFPageDrawTextOptions { lineHeight?: number; maxWidth?: number; wordBreaks?: string[]; - horizontalScale?: number; - wordSpace?: number; - characterSpace?: number; - rise?: number; - renderingMode?: TextRenderingMode; } export interface PDFPageDrawImageOptions { diff --git a/src/api/operations.ts b/src/api/operations.ts index c5ff2ca8d..0e46e6fdf 100644 --- a/src/api/operations.ts +++ b/src/api/operations.ts @@ -31,12 +31,6 @@ import { clip, endPath, appendBezierCurve, - TextRenderingMode, - setCharacterSpacing, - setHorizontalScaling, - setTextRenderingMode, - setTextRise, - setWordSpacing, } from 'src/api/operators'; import { Rotation, degrees, toRadians } from 'src/api/rotations'; import { svgPathToOperators } from 'src/api/svgPath'; @@ -53,11 +47,6 @@ export interface DrawTextOptions { x: number | PDFNumber; y: number | PDFNumber; graphicsState?: string | PDFName; - horizontalScale?: number | PDFNumber; - wordSpace?: number | PDFNumber; - characterSpace?: number | PDFNumber; - rise?: number | PDFNumber; - renderingMode?: TextRenderingMode; } export const drawText = ( @@ -77,11 +66,6 @@ export const drawText = ( options.x, options.y, ), - options.horizontalScale && setHorizontalScaling(options.horizontalScale), - options.wordSpace && setWordSpacing(options.wordSpace), - options.characterSpace && setCharacterSpacing(options.characterSpace), - options.rise && setTextRise(options.rise), - options.renderingMode && setTextRenderingMode(options.renderingMode), showText(line), endText(), popGraphicsState(), @@ -102,11 +86,6 @@ export const drawLinesOfText = ( setFillingColor(options.color), setFontAndSize(options.font, options.size), setLineHeight(options.lineHeight), - options.horizontalScale && setHorizontalScaling(options.horizontalScale), - options.wordSpace && setWordSpacing(options.wordSpace), - options.characterSpace && setCharacterSpacing(options.characterSpace), - options.rise && setTextRise(options.rise), - options.renderingMode && setTextRenderingMode(options.renderingMode), rotateAndSkewTextRadiansAndTranslate( toRadians(options.rotate), toRadians(options.xSkew), diff --git a/src/api/operators.ts b/src/api/operators.ts index 17c605f2b..62b5e3a24 100644 --- a/src/api/operators.ts +++ b/src/api/operators.ts @@ -213,24 +213,16 @@ export const setFontAndSize = ( size: number | PDFNumber, ) => PDFOperator.of(Ops.SetFontAndSize, [asPDFName(name), asPDFNumber(size)]); -/** @param characterSpace extra space between characters; in unscaled text sapce units; can also be negative **/ export const setCharacterSpacing = (spacing: number | PDFNumber) => PDFOperator.of(Ops.SetCharacterSpacing, [asPDFNumber(spacing)]); -/**@param wordSpace space "between words" (actually extra space for every ASCII SPACE character); in unscaled text sapce units; can also be negative; NOTE: This only works for fonts that define code 32 (=space) as a single-byte code, according to the standard. (E.g. it works with Helvetica, but not with ubuntuFont.) **/ export const setWordSpacing = (spacing: number | PDFNumber) => PDFOperator.of(Ops.SetWordSpacing, [asPDFNumber(spacing)]); -/** - * DEPRECATED: use "setHorizontalScaling" instead - * @param squeeze horizontal character spacing */ +/** @param squeeze horizontal character spacing */ export const setCharacterSqueeze = (squeeze: number | PDFNumber) => PDFOperator.of(Ops.SetTextHorizontalScaling, [asPDFNumber(squeeze)]); -/** @param horizontalScaling horizontal character spacing; value in %; default = 100 **/ -export const setHorizontalScaling = (horizontalScaling: number | PDFNumber) => - PDFOperator.of(Ops.SetTextHorizontalScaling, [asPDFNumber(horizontalScaling)]); - export const setLineHeight = (lineHeight: number | PDFNumber) => PDFOperator.of(Ops.SetTextLineHeight, [asPDFNumber(lineHeight)]); From 79a48684229467c68e31257a11c8a9e00bca2cbc Mon Sep 17 00:00:00 2001 From: Reto Fahrni <82324518+retfah@users.noreply.github.com> Date: Tue, 12 Apr 2022 08:11:17 +0200 Subject: [PATCH 3/7] Update index.ts revert temporary test removal --- apps/node/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/node/index.ts b/apps/node/index.ts index 3acaaf0b2..97b9b47ef 100644 --- a/apps/node/index.ts +++ b/apps/node/index.ts @@ -5,7 +5,7 @@ import { sep } from 'path'; import readline from 'readline'; import test1 from './tests/test1'; -/*import test2 from './tests/test2'; +import test2 from './tests/test2'; import test3 from './tests/test3'; import test4 from './tests/test4'; import test5 from './tests/test5'; @@ -21,7 +21,7 @@ import test14 from './tests/test14'; import test15 from './tests/test15'; import test16 from './tests/test16'; import test17 from './tests/test17'; -import test18 from './tests/test18';*/ +import test18 from './tests/test18'; const cli = readline.createInterface({ input: process.stdin, @@ -162,8 +162,8 @@ const main = async () => { // prettier-ignore const allTests = [ - test1//, test2, test3, test4, test5, test6, test7, test8, test9, test10, - //test11, test12, test13, test14, test15, test16, test17, test18, + test1, test2, test3, test4, test5, test6, test7, test8, test9, test10, + test11, test12, test13, test14, test15, test16, test17, test18, ]; const tests = testIdx ? [allTests[testIdx - 1]] : allTests; From 42c97397b33302333276703235d20dbb540d4f05 Mon Sep 17 00:00:00 2001 From: Reto Fahrni <82324518+retfah@users.noreply.github.com> Date: Tue, 12 Apr 2022 08:18:30 +0200 Subject: [PATCH 4/7] tests finalized --- apps/deno/tests/test1.ts | 61 ++++++++++++++++++++++++++++++++++++++ apps/node/tests/test1.ts | 4 +-- apps/rn/src/tests/test1.js | 61 ++++++++++++++++++++++++++++++++++++++ apps/web/test1.html | 61 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 184 insertions(+), 3 deletions(-) diff --git a/apps/deno/tests/test1.ts b/apps/deno/tests/test1.ts index fe71ed5c7..a12861782 100644 --- a/apps/deno/tests/test1.ts +++ b/apps/deno/tests/test1.ts @@ -646,6 +646,67 @@ export default async (assets: Assets) => { form.removeField(textField); + /********************** Page 6 **********************/ + // This page tests different drawing operations as well as adding custom + // operators to the page content. + + const page6 = pdfDoc.addPage([size, size]); + + const text = "These are the test words. " + page6.drawText(text + 'regular', { + y: size - 20, + size: 20, + lineHeight: 20, + //horizontalScale: 50, + //rise: 0, + //wordSpace: 10, + //characterSpace: -2, + }); + page6.drawText(text + '+5 raised and fontsize 12 instead of 20', { + y: size - 20, + x: 325, + size: 12, + lineHeight: 20, + //horizontalScale: 50, + rise: 5, + //wordSpace: 10, + //characterSpace: -2, + }); + page6.drawText(text + '50% horizontal scale', { + y: size - 40, + size: 20, + lineHeight: 20, + horizontalScale: 50, + //rise: 0, + //wordSpace: 10, + //characterSpace: -2, + }); + page6.drawText(text + '+10 word space', { + y: size - 60, + size: 20, + lineHeight: 20, + //horizontalScale: 50, + //rise: 0, + wordSpace: 10, + //characterSpace: -2, + renderingMode: TextRenderingMode.Outline, + }); + page6.drawText(text + '+4 character space', { + y: size - 80, + size: 20, + lineHeight: 20, + //horizontalScale: 50, + //rise: 0, + //wordSpace: 10, + characterSpace: 4, + }); + page6.drawText(text + 'textRenderingMode = outline', { + y: size - 100, + size: 20, + lineHeight: 20, + renderingMode: TextRenderingMode.Outline, + }); + /********************** Print Metadata **********************/ console.log('Title:', pdfDoc.getTitle()); diff --git a/apps/node/tests/test1.ts b/apps/node/tests/test1.ts index 05cbe1c57..727700c84 100644 --- a/apps/node/tests/test1.ts +++ b/apps/node/tests/test1.ts @@ -645,14 +645,12 @@ export default async (assets: Assets) => { form.removeField(textField); + /********************** Page 6 **********************/ // This page tests different drawing operations as well as adding custom // operators to the page content. const page6 = pdfDoc.addPage([size, size]); - // Upper-left Quadrant - page6.moveTo(0, size / 2); - const text = "These are the test words. " page6.drawText(text + 'regular', { y: size - 20, diff --git a/apps/rn/src/tests/test1.js b/apps/rn/src/tests/test1.js index e7ebd36b3..5a51eb739 100644 --- a/apps/rn/src/tests/test1.js +++ b/apps/rn/src/tests/test1.js @@ -679,6 +679,67 @@ export default async () => { form.removeField(textField); + /********************** Page 6 **********************/ + // This page tests different drawing operations as well as adding custom + // operators to the page content. + + const page6 = pdfDoc.addPage([size, size]); + + const text = "These are the test words. " + page6.drawText(text + 'regular', { + y: size - 20, + size: 20, + lineHeight: 20, + //horizontalScale: 50, + //rise: 0, + //wordSpace: 10, + //characterSpace: -2, + }); + page6.drawText(text + '+5 raised and fontsize 12 instead of 20', { + y: size - 20, + x: 325, + size: 12, + lineHeight: 20, + //horizontalScale: 50, + rise: 5, + //wordSpace: 10, + //characterSpace: -2, + }); + page6.drawText(text + '50% horizontal scale', { + y: size - 40, + size: 20, + lineHeight: 20, + horizontalScale: 50, + //rise: 0, + //wordSpace: 10, + //characterSpace: -2, + }); + page6.drawText(text + '+10 word space', { + y: size - 60, + size: 20, + lineHeight: 20, + //horizontalScale: 50, + //rise: 0, + wordSpace: 10, + //characterSpace: -2, + renderingMode: TextRenderingMode.Outline, + }); + page6.drawText(text + '+4 character space', { + y: size - 80, + size: 20, + lineHeight: 20, + //horizontalScale: 50, + //rise: 0, + //wordSpace: 10, + characterSpace: 4, + }); + page6.drawText(text + 'textRenderingMode = outline', { + y: size - 100, + size: 20, + lineHeight: 20, + renderingMode: TextRenderingMode.Outline, + }); + /********************** Print Metadata **********************/ console.log('Title:', pdfDoc.getTitle()); diff --git a/apps/web/test1.html b/apps/web/test1.html index 5b881326d..6e26519bb 100644 --- a/apps/web/test1.html +++ b/apps/web/test1.html @@ -758,6 +758,67 @@ }); form.removeField(textField); + + /********************** Page 6 **********************/ + // This page tests different drawing operations as well as adding custom + // operators to the page content. + + const page6 = pdfDoc.addPage([size, size]); + + const text = "These are the test words. " + page6.drawText(text + 'regular', { + y: size - 20, + size: 20, + lineHeight: 20, + //horizontalScale: 50, + //rise: 0, + //wordSpace: 10, + //characterSpace: -2, + }); + page6.drawText(text + '+5 raised and fontsize 12 instead of 20', { + y: size - 20, + x: 325, + size: 12, + lineHeight: 20, + //horizontalScale: 50, + rise: 5, + //wordSpace: 10, + //characterSpace: -2, + }); + page6.drawText(text + '50% horizontal scale', { + y: size - 40, + size: 20, + lineHeight: 20, + horizontalScale: 50, + //rise: 0, + //wordSpace: 10, + //characterSpace: -2, + }); + page6.drawText(text + '+10 word space', { + y: size - 60, + size: 20, + lineHeight: 20, + //horizontalScale: 50, + //rise: 0, + wordSpace: 10, + //characterSpace: -2, + renderingMode: TextRenderingMode.Outline, + }); + page6.drawText(text + '+4 character space', { + y: size - 80, + size: 20, + lineHeight: 20, + //horizontalScale: 50, + //rise: 0, + //wordSpace: 10, + characterSpace: 4, + }); + page6.drawText(text + 'textRenderingMode = outline', { + y: size - 100, + size: 20, + lineHeight: 20, + renderingMode: TextRenderingMode.Outline, + }); /********************** Print Metadata **********************/ From 50699e96b62efe5c94f713270007d8608e606dab Mon Sep 17 00:00:00 2001 From: Reto Fahrni <82324518+retfah@users.noreply.github.com> Date: Tue, 12 Apr 2022 08:58:06 +0200 Subject: [PATCH 5/7] redo the actual changes the first commit in master had to be reverted, since the tests were still in a temporary modified state. A new branch (textOptions) was then created on the basis of the meanwhile reverted commit. In this branch, the tests were cleaned up and the branch finally got merged with tha master. However, the actual changes, which were reverted in the master, were not merged, despiute the fact they were present in the brach. Finally, I manually added the actual changes directly in the master. --- apps/node/tests/test1.ts | 1 + src/api/PDFPage.ts | 12 ++++++++++++ src/api/PDFPageOptions.ts | 7 ++++++- src/api/operations.ts | 21 +++++++++++++++++++++ src/api/operators.ts | 10 +++++++++- 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/apps/node/tests/test1.ts b/apps/node/tests/test1.ts index 7176bfa20..727700c84 100644 --- a/apps/node/tests/test1.ts +++ b/apps/node/tests/test1.ts @@ -21,6 +21,7 @@ import { StandardFonts, typedArrayFor, AFRelationship, + TextRenderingMode, } from '../../..'; const ipsumLines = [ diff --git a/src/api/PDFPage.ts b/src/api/PDFPage.ts index 7333440bd..67fc137ba 100644 --- a/src/api/PDFPage.ts +++ b/src/api/PDFPage.ts @@ -14,6 +14,7 @@ import { translate, LineCapStyle, scale, + TextRenderingMode, } from 'src/api/operators'; import PDFDocument from 'src/api/PDFDocument'; import PDFEmbeddedPage from 'src/api/PDFEmbeddedPage'; @@ -976,6 +977,11 @@ export default class PDFPage { assertOrUndefined(options.lineHeight, 'options.lineHeight', ['number']); assertOrUndefined(options.maxWidth, 'options.maxWidth', ['number']); assertOrUndefined(options.wordBreaks, 'options.wordBreaks', [Array]); + assertOrUndefined(options.horizontalScale, 'options.horizontalScale', ['number']); + assertOrUndefined(options.wordSpace, 'options.wordSpace', ['number']); + assertOrUndefined(options.characterSpace, 'options.characterSpace', ['number']); + assertOrUndefined(options.rise, 'options.rise', ['number']); + assertIsOneOfOrUndefined(options.renderingMode, 'options.renderingMode', TextRenderingMode); assertIsOneOfOrUndefined(options.blendMode, 'options.blendMode', BlendMode); const { oldFont, newFont, newFontKey } = this.setOrEmbedFont(options.font); @@ -1010,7 +1016,13 @@ export default class PDFPage { x: options.x ?? this.x, y: options.y ?? this.y, lineHeight: options.lineHeight ?? this.lineHeight, + // optional: graphicsState: graphicsStateKey, + horizontalScale: options.horizontalScale, // defaults to 100 + wordSpace: options.wordSpace, // defaults to 0 + characterSpace: options.characterSpace, // defaults to 0 + rise: options.rise, // defaults to 0 + renderingMode: options.renderingMode, // defaults to TextRenderingMode.Fill }), ); diff --git a/src/api/PDFPageOptions.ts b/src/api/PDFPageOptions.ts index 6ddd8357f..288ef5162 100644 --- a/src/api/PDFPageOptions.ts +++ b/src/api/PDFPageOptions.ts @@ -1,7 +1,7 @@ import { Color } from 'src/api/colors'; import PDFFont from 'src/api/PDFFont'; import { Rotation } from 'src/api/rotations'; -import { LineCapStyle } from 'src/api/operators'; +import { LineCapStyle,TextRenderingMode } from 'src/api/operators'; export enum BlendMode { Normal = 'Normal', @@ -32,6 +32,11 @@ export interface PDFPageDrawTextOptions { lineHeight?: number; maxWidth?: number; wordBreaks?: string[]; + horizontalScale?: number; + wordSpace?: number; + characterSpace?: number; + rise?: number; + renderingMode?: TextRenderingMode; } export interface PDFPageDrawImageOptions { diff --git a/src/api/operations.ts b/src/api/operations.ts index 0e46e6fdf..c5ff2ca8d 100644 --- a/src/api/operations.ts +++ b/src/api/operations.ts @@ -31,6 +31,12 @@ import { clip, endPath, appendBezierCurve, + TextRenderingMode, + setCharacterSpacing, + setHorizontalScaling, + setTextRenderingMode, + setTextRise, + setWordSpacing, } from 'src/api/operators'; import { Rotation, degrees, toRadians } from 'src/api/rotations'; import { svgPathToOperators } from 'src/api/svgPath'; @@ -47,6 +53,11 @@ export interface DrawTextOptions { x: number | PDFNumber; y: number | PDFNumber; graphicsState?: string | PDFName; + horizontalScale?: number | PDFNumber; + wordSpace?: number | PDFNumber; + characterSpace?: number | PDFNumber; + rise?: number | PDFNumber; + renderingMode?: TextRenderingMode; } export const drawText = ( @@ -66,6 +77,11 @@ export const drawText = ( options.x, options.y, ), + options.horizontalScale && setHorizontalScaling(options.horizontalScale), + options.wordSpace && setWordSpacing(options.wordSpace), + options.characterSpace && setCharacterSpacing(options.characterSpace), + options.rise && setTextRise(options.rise), + options.renderingMode && setTextRenderingMode(options.renderingMode), showText(line), endText(), popGraphicsState(), @@ -86,6 +102,11 @@ export const drawLinesOfText = ( setFillingColor(options.color), setFontAndSize(options.font, options.size), setLineHeight(options.lineHeight), + options.horizontalScale && setHorizontalScaling(options.horizontalScale), + options.wordSpace && setWordSpacing(options.wordSpace), + options.characterSpace && setCharacterSpacing(options.characterSpace), + options.rise && setTextRise(options.rise), + options.renderingMode && setTextRenderingMode(options.renderingMode), rotateAndSkewTextRadiansAndTranslate( toRadians(options.rotate), toRadians(options.xSkew), diff --git a/src/api/operators.ts b/src/api/operators.ts index 62b5e3a24..17c605f2b 100644 --- a/src/api/operators.ts +++ b/src/api/operators.ts @@ -213,16 +213,24 @@ export const setFontAndSize = ( size: number | PDFNumber, ) => PDFOperator.of(Ops.SetFontAndSize, [asPDFName(name), asPDFNumber(size)]); +/** @param characterSpace extra space between characters; in unscaled text sapce units; can also be negative **/ export const setCharacterSpacing = (spacing: number | PDFNumber) => PDFOperator.of(Ops.SetCharacterSpacing, [asPDFNumber(spacing)]); +/**@param wordSpace space "between words" (actually extra space for every ASCII SPACE character); in unscaled text sapce units; can also be negative; NOTE: This only works for fonts that define code 32 (=space) as a single-byte code, according to the standard. (E.g. it works with Helvetica, but not with ubuntuFont.) **/ export const setWordSpacing = (spacing: number | PDFNumber) => PDFOperator.of(Ops.SetWordSpacing, [asPDFNumber(spacing)]); -/** @param squeeze horizontal character spacing */ +/** + * DEPRECATED: use "setHorizontalScaling" instead + * @param squeeze horizontal character spacing */ export const setCharacterSqueeze = (squeeze: number | PDFNumber) => PDFOperator.of(Ops.SetTextHorizontalScaling, [asPDFNumber(squeeze)]); +/** @param horizontalScaling horizontal character spacing; value in %; default = 100 **/ +export const setHorizontalScaling = (horizontalScaling: number | PDFNumber) => + PDFOperator.of(Ops.SetTextHorizontalScaling, [asPDFNumber(horizontalScaling)]); + export const setLineHeight = (lineHeight: number | PDFNumber) => PDFOperator.of(Ops.SetTextLineHeight, [asPDFNumber(lineHeight)]); From aed4aac716a9d4c0295d7043395aa2ce1a6e7629 Mon Sep 17 00:00:00 2001 From: Reto Fahrni <82324518+retfah@users.noreply.github.com> Date: Sun, 17 Apr 2022 08:21:31 +0200 Subject: [PATCH 6/7] corrected tests + linting harmonization of tests + linting --- apps/deno/tests/test1.ts | 18 +----------------- apps/node/tests/test1.ts | 19 +------------------ apps/rn/src/tests/test1.js | 20 ++------------------ apps/web/test1.html | 22 +++------------------- src/api/PDFPageOptions.ts | 2 +- src/api/operations.ts | 8 ++++---- src/api/operators.ts | 16 ++++++++++------ 7 files changed, 22 insertions(+), 83 deletions(-) diff --git a/apps/deno/tests/test1.ts b/apps/deno/tests/test1.ts index a12861782..f125166fe 100644 --- a/apps/deno/tests/test1.ts +++ b/apps/deno/tests/test1.ts @@ -23,6 +23,7 @@ import { setLineJoin, StandardFonts, AFRelationship, + TextRenderingMode, } from '../../../dist/pdf-lib.esm.js'; const ipsumLines = [ @@ -657,47 +658,30 @@ export default async (assets: Assets) => { y: size - 20, size: 20, lineHeight: 20, - //horizontalScale: 50, - //rise: 0, - //wordSpace: 10, - //characterSpace: -2, }); page6.drawText(text + '+5 raised and fontsize 12 instead of 20', { y: size - 20, x: 325, size: 12, lineHeight: 20, - //horizontalScale: 50, rise: 5, - //wordSpace: 10, - //characterSpace: -2, }); page6.drawText(text + '50% horizontal scale', { y: size - 40, size: 20, lineHeight: 20, horizontalScale: 50, - //rise: 0, - //wordSpace: 10, - //characterSpace: -2, }); page6.drawText(text + '+10 word space', { y: size - 60, size: 20, lineHeight: 20, - //horizontalScale: 50, - //rise: 0, wordSpace: 10, - //characterSpace: -2, - renderingMode: TextRenderingMode.Outline, }); page6.drawText(text + '+4 character space', { y: size - 80, size: 20, lineHeight: 20, - //horizontalScale: 50, - //rise: 0, - //wordSpace: 10, characterSpace: 4, }); page6.drawText(text + 'textRenderingMode = outline', { diff --git a/apps/node/tests/test1.ts b/apps/node/tests/test1.ts index 727700c84..068362432 100644 --- a/apps/node/tests/test1.ts +++ b/apps/node/tests/test1.ts @@ -651,52 +651,35 @@ export default async (assets: Assets) => { const page6 = pdfDoc.addPage([size, size]); - const text = "These are the test words. " + const text = 'These are the test words. '; page6.drawText(text + 'regular', { y: size - 20, size: 20, lineHeight: 20, - //horizontalScale: 50, - //rise: 0, - //wordSpace: 10, - //characterSpace: -2, }); page6.drawText(text + '+5 raised and fontsize 12 instead of 20', { y: size - 20, x: 325, size: 12, lineHeight: 20, - //horizontalScale: 50, rise: 5, - //wordSpace: 10, - //characterSpace: -2, }); page6.drawText(text + '50% horizontal scale', { y: size - 40, size: 20, lineHeight: 20, horizontalScale: 50, - //rise: 0, - //wordSpace: 10, - //characterSpace: -2, }); page6.drawText(text + '+10 word space', { y: size - 60, size: 20, lineHeight: 20, - //horizontalScale: 50, - //rise: 0, wordSpace: 10, - //characterSpace: -2, - renderingMode: TextRenderingMode.Outline, }); page6.drawText(text + '+4 character space', { y: size - 80, size: 20, lineHeight: 20, - //horizontalScale: 50, - //rise: 0, - //wordSpace: 10, characterSpace: 4, }); page6.drawText(text + 'textRenderingMode = outline', { diff --git a/apps/rn/src/tests/test1.js b/apps/rn/src/tests/test1.js index 5a51eb739..5ff110c0a 100644 --- a/apps/rn/src/tests/test1.js +++ b/apps/rn/src/tests/test1.js @@ -20,6 +20,7 @@ import { setLineJoin, StandardFonts, AFRelationship, + TextRenderingMode, } from 'pdf-lib'; import { fetchAsset } from './assets'; @@ -685,52 +686,35 @@ export default async () => { const page6 = pdfDoc.addPage([size, size]); - const text = "These are the test words. " + const text = 'These are the test words. '; page6.drawText(text + 'regular', { y: size - 20, size: 20, lineHeight: 20, - //horizontalScale: 50, - //rise: 0, - //wordSpace: 10, - //characterSpace: -2, }); page6.drawText(text + '+5 raised and fontsize 12 instead of 20', { y: size - 20, x: 325, size: 12, lineHeight: 20, - //horizontalScale: 50, rise: 5, - //wordSpace: 10, - //characterSpace: -2, }); page6.drawText(text + '50% horizontal scale', { y: size - 40, size: 20, lineHeight: 20, horizontalScale: 50, - //rise: 0, - //wordSpace: 10, - //characterSpace: -2, }); page6.drawText(text + '+10 word space', { y: size - 60, size: 20, lineHeight: 20, - //horizontalScale: 50, - //rise: 0, wordSpace: 10, - //characterSpace: -2, - renderingMode: TextRenderingMode.Outline, }); page6.drawText(text + '+4 character space', { y: size - 80, size: 20, lineHeight: 20, - //horizontalScale: 50, - //rise: 0, - //wordSpace: 10, characterSpace: 4, }); page6.drawText(text + 'textRenderingMode = outline', { diff --git a/apps/web/test1.html b/apps/web/test1.html index 6e26519bb..30a28ef4c 100644 --- a/apps/web/test1.html +++ b/apps/web/test1.html @@ -79,6 +79,7 @@ rgb, StandardFonts, AFRelationship, + TextRenderingMode, } = PDFLib; const pdfDoc = await PDFDocument.create(); @@ -758,59 +759,42 @@ }); form.removeField(textField); - + /********************** Page 6 **********************/ // This page tests different drawing operations as well as adding custom // operators to the page content. const page6 = pdfDoc.addPage([size, size]); - const text = "These are the test words. " + const text = 'These are the test words. '; page6.drawText(text + 'regular', { y: size - 20, size: 20, lineHeight: 20, - //horizontalScale: 50, - //rise: 0, - //wordSpace: 10, - //characterSpace: -2, }); page6.drawText(text + '+5 raised and fontsize 12 instead of 20', { y: size - 20, x: 325, size: 12, lineHeight: 20, - //horizontalScale: 50, rise: 5, - //wordSpace: 10, - //characterSpace: -2, }); page6.drawText(text + '50% horizontal scale', { y: size - 40, size: 20, lineHeight: 20, horizontalScale: 50, - //rise: 0, - //wordSpace: 10, - //characterSpace: -2, }); page6.drawText(text + '+10 word space', { y: size - 60, size: 20, lineHeight: 20, - //horizontalScale: 50, - //rise: 0, wordSpace: 10, - //characterSpace: -2, - renderingMode: TextRenderingMode.Outline, }); page6.drawText(text + '+4 character space', { y: size - 80, size: 20, lineHeight: 20, - //horizontalScale: 50, - //rise: 0, - //wordSpace: 10, characterSpace: 4, }); page6.drawText(text + 'textRenderingMode = outline', { diff --git a/src/api/PDFPageOptions.ts b/src/api/PDFPageOptions.ts index 288ef5162..73918409c 100644 --- a/src/api/PDFPageOptions.ts +++ b/src/api/PDFPageOptions.ts @@ -1,7 +1,7 @@ import { Color } from 'src/api/colors'; import PDFFont from 'src/api/PDFFont'; import { Rotation } from 'src/api/rotations'; -import { LineCapStyle,TextRenderingMode } from 'src/api/operators'; +import { LineCapStyle, TextRenderingMode } from 'src/api/operators'; export enum BlendMode { Normal = 'Normal', diff --git a/src/api/operations.ts b/src/api/operations.ts index c5ff2ca8d..155b601b3 100644 --- a/src/api/operations.ts +++ b/src/api/operations.ts @@ -32,10 +32,10 @@ import { endPath, appendBezierCurve, TextRenderingMode, - setCharacterSpacing, - setHorizontalScaling, - setTextRenderingMode, - setTextRise, + setCharacterSpacing, + setHorizontalScaling, + setTextRenderingMode, + setTextRise, setWordSpacing, } from 'src/api/operators'; import { Rotation, degrees, toRadians } from 'src/api/rotations'; diff --git a/src/api/operators.ts b/src/api/operators.ts index 17c605f2b..141b576c4 100644 --- a/src/api/operators.ts +++ b/src/api/operators.ts @@ -213,23 +213,27 @@ export const setFontAndSize = ( size: number | PDFNumber, ) => PDFOperator.of(Ops.SetFontAndSize, [asPDFName(name), asPDFNumber(size)]); -/** @param characterSpace extra space between characters; in unscaled text sapce units; can also be negative **/ +/** @param characterSpace extra space between characters; in unscaled text sapce units; can also be negative */ export const setCharacterSpacing = (spacing: number | PDFNumber) => PDFOperator.of(Ops.SetCharacterSpacing, [asPDFNumber(spacing)]); -/**@param wordSpace space "between words" (actually extra space for every ASCII SPACE character); in unscaled text sapce units; can also be negative; NOTE: This only works for fonts that define code 32 (=space) as a single-byte code, according to the standard. (E.g. it works with Helvetica, but not with ubuntuFont.) **/ +/** @param wordSpace space "between words" (actually extra space for every ASCII SPACE character); in unscaled text sapce units; can also be negative; NOTE: This only works for fonts that define code 32 (=space) as a single-byte code, according to the standard. (E.g. it works with Helvetica, but not with ubuntuFont.) */ export const setWordSpacing = (spacing: number | PDFNumber) => PDFOperator.of(Ops.SetWordSpacing, [asPDFNumber(spacing)]); /** - * DEPRECATED: use "setHorizontalScaling" instead - * @param squeeze horizontal character spacing */ + * DEPRECATED: use "setHorizontalScaling" instead + * + * @param squeeze horizontal character spacing + */ export const setCharacterSqueeze = (squeeze: number | PDFNumber) => PDFOperator.of(Ops.SetTextHorizontalScaling, [asPDFNumber(squeeze)]); -/** @param horizontalScaling horizontal character spacing; value in %; default = 100 **/ +/** @param horizontalScaling horizontal character spacing; value in %; default = 100 */ export const setHorizontalScaling = (horizontalScaling: number | PDFNumber) => - PDFOperator.of(Ops.SetTextHorizontalScaling, [asPDFNumber(horizontalScaling)]); + PDFOperator.of(Ops.SetTextHorizontalScaling, [ + asPDFNumber(horizontalScaling), + ]); export const setLineHeight = (lineHeight: number | PDFNumber) => PDFOperator.of(Ops.SetTextLineHeight, [asPDFNumber(lineHeight)]); From 7829e2bd1a21cea493bf1424594ad68f8f020fde Mon Sep 17 00:00:00 2001 From: Reto Fahrni <82324518+retfah@users.noreply.github.com> Date: Sun, 17 Apr 2022 08:46:19 +0200 Subject: [PATCH 7/7] latest linting --- apps/deno/tests/test1.ts | 2 +- src/api/PDFPage.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/deno/tests/test1.ts b/apps/deno/tests/test1.ts index f125166fe..4adc14984 100644 --- a/apps/deno/tests/test1.ts +++ b/apps/deno/tests/test1.ts @@ -653,7 +653,7 @@ export default async (assets: Assets) => { const page6 = pdfDoc.addPage([size, size]); - const text = "These are the test words. " + const text = 'These are the test words. '; page6.drawText(text + 'regular', { y: size - 20, size: 20, diff --git a/src/api/PDFPage.ts b/src/api/PDFPage.ts index 67fc137ba..558d544b9 100644 --- a/src/api/PDFPage.ts +++ b/src/api/PDFPage.ts @@ -977,11 +977,19 @@ export default class PDFPage { assertOrUndefined(options.lineHeight, 'options.lineHeight', ['number']); assertOrUndefined(options.maxWidth, 'options.maxWidth', ['number']); assertOrUndefined(options.wordBreaks, 'options.wordBreaks', [Array]); - assertOrUndefined(options.horizontalScale, 'options.horizontalScale', ['number']); + assertOrUndefined(options.horizontalScale, 'options.horizontalScale', [ + 'number', + ]); assertOrUndefined(options.wordSpace, 'options.wordSpace', ['number']); - assertOrUndefined(options.characterSpace, 'options.characterSpace', ['number']); + assertOrUndefined(options.characterSpace, 'options.characterSpace', [ + 'number', + ]); assertOrUndefined(options.rise, 'options.rise', ['number']); - assertIsOneOfOrUndefined(options.renderingMode, 'options.renderingMode', TextRenderingMode); + assertIsOneOfOrUndefined( + options.renderingMode, + 'options.renderingMode', + TextRenderingMode, + ); assertIsOneOfOrUndefined(options.blendMode, 'options.blendMode', BlendMode); const { oldFont, newFont, newFontKey } = this.setOrEmbedFont(options.font);