Skip to content

Commit babeb35

Browse files
authored
Add horizontal scale option for text (#3294)
1 parent 57120de commit babeb35

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

src/jspdf.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3404,6 +3404,7 @@ function jsPDF(options) {
34043404
* @param {number|Matrix} [options.angle=0] - Rotate the text clockwise or counterclockwise. Expects the angle in degree.
34053405
* @param {number} [options.rotationDirection=1] - Direction of the rotation. 0 = clockwise, 1 = counterclockwise.
34063406
* @param {number} [options.charSpace=0] - The space between each letter.
3407+
* @param {number} [options.horizontalScale=1] - Horizontal scale of the text as a factor of the regular size.
34073408
* @param {number} [options.lineHeightFactor=1.15] - The lineheight of each line.
34083409
* @param {Object} [options.flags] - Flags for to8bitStream.
34093410
* @param {boolean} [options.flags.noBOM=true] - Don't add BOM to Unicode-text.
@@ -3440,7 +3441,7 @@ function jsPDF(options) {
34403441
*/
34413442
options = options || {};
34423443
var scope = options.scope || this;
3443-
var payload, da, angle, align, charSpace, maxWidth, flags;
3444+
var payload, da, angle, align, charSpace, maxWidth, flags, horizontalScale;
34443445

34453446
// Pre-August-2012 the order of arguments was function(x, y, text, flags)
34463447
// in effort to make all calls have similar signature like
@@ -3707,6 +3708,11 @@ function jsPDF(options) {
37073708
this.setCharSpace(this.getCharSpace() || 0);
37083709
}
37093710

3711+
horizontalScale = options.horizontalScale;
3712+
if (typeof horizontalScale !== "undefined") {
3713+
xtra += hpf(horizontalScale * 100) + " Tz\n";
3714+
}
3715+
37103716
//lang
37113717

37123718
var lang = options.lang;
3.19 KB
Binary file not shown.

test/specs/text.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,15 @@ break`
211211
comparePdf(doc.output(), "letter-spacing.pdf", "text");
212212
});
213213

214+
it("should render horizontally scaled text", () => {
215+
const doc = jsPDF({ floatPrecision: 2 });
216+
doc.text("hello", 10, 10, { horizontalScale: 0.5 });
217+
doc.text("hello", 10, 20, { horizontalScale: 0.75 });
218+
doc.text("hello", 10, 30, { horizontalScale: 1 });
219+
doc.text("hello", 10, 40, { horizontalScale: 1.5 });
220+
comparePdf(doc.output(), "text-horizontal-scaling.pdf", "text");
221+
});
222+
214223
it("should respect autoencode and noBOM flags", () => {
215224
const doc = jsPDF({ floatPrecision: 2 });
216225

types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ declare module "jspdf" {
549549
};
550550
rotationDirection?: 0 | 1;
551551
charSpace?: number;
552+
horizontalScale?: number;
552553
lineHeightFactor?: number;
553554
maxWidth?: number;
554555
renderingMode?:

0 commit comments

Comments
 (0)