Skip to content

Commit 36ede75

Browse files
committed
Add hotfix to scale font size based on transformation matrix
1 parent 8c0ce0c commit 36ede75

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

HOTFIX_README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,18 @@ Filling paths
2525
In certain cases, closing a fill would result in a path resolving to an incorrect point.
2626
The was most likely fixed when we refactored matrix logic. Enabling this hotfix will ignore a most-likely unneeded workaround.
2727

28+
29+
##scale_text
30+
31+
###Applies To
32+
context2d plugin
33+
34+
### Affects
35+
Drawing and Filling Text when a scale transformation is active.
36+
37+
### Description
38+
jsPDF currently has no way to draw scaled text.
39+
This hotfix scales the current font size by the x-axis scale factor.
40+
2841
#Accepted Hotfixes
2942
There a currently no accepted hotfixes.

plugins/context2d.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,22 @@
299299
this.path = origPath;
300300
}
301301

302-
this.pdf.text(text, x, this._getBaseline(y), null, degs);
302+
var scale;
303+
if (this.pdf.hotfix && this.pdf.hotfix.scale_text) {
304+
scale = this._getTransform()[0];
305+
}
306+
else {
307+
scale = 1;
308+
}
309+
if (scale === 1) {
310+
this.pdf.text(text, x, this._getBaseline(y), null, degs);
311+
}
312+
else {
313+
var oldSize = this.pdf.internal.getFontSize();
314+
this.pdf.setFontSize(oldSize * scale);
315+
this.pdf.text(text, x, this._getBaseline(y), null, degs);
316+
this.pdf.setFontSize(oldSize);
317+
}
303318

304319
if (this.ctx._clip_path.length > 0) {
305320
lines.push('Q');
@@ -337,9 +352,26 @@
337352
this.path = origPath;
338353
}
339354

340-
this.pdf.text(text, x, this._getBaseline(y), {
355+
var scale;
356+
if (this.pdf.hotfix && this.pdf.hotfix.scale_text) {
357+
scale = this._getTransform()[0];
358+
}
359+
else {
360+
scale = 1;
361+
}
362+
if (scale === 1) {
363+
this.pdf.text(text, x, this._getBaseline(y), {
341364
stroke: true
342365
}, degs);
366+
}
367+
else {
368+
var oldSize = this.pdf.internal.getFontSize();
369+
this.pdf.setFontSize(oldSize * scale);
370+
this.pdf.text(text, x, this._getBaseline(y), {
371+
stroke: true
372+
}, degs);
373+
this.pdf.setFontSize(oldSize);
374+
}
343375

344376
if (this.ctx._clip_path.length > 0) {
345377
lines.push('Q');

0 commit comments

Comments
 (0)