Skip to content

Commit

Permalink
Fix context2d lineWidth scaling (#2702)
Browse files Browse the repository at this point in the history
* scale lineWidth using transform.scaleX

* update spec/reference pdf

* update pageoverlaps spec writeArray

* update autoPaging10Pages reference

Co-authored-by: Lukas Hollaender <lukas.hollaender@yworks.com>
  • Loading branch information
tompng and HackbrettXXX authored Jul 17, 2020
1 parent 96a582e commit 91cecee
Show file tree
Hide file tree
Showing 41 changed files with 24 additions and 5 deletions.
15 changes: 12 additions & 3 deletions spec/context2d.pageoverlap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe("Module: Context2D autoPaging", () => {
"170. 821.89 l",
"20. 821.89 l",
"S",
"1. w",
"0. 0. 0. rg",
"1. 0. 0. RG",
"0 J",
Expand All @@ -66,6 +67,7 @@ describe("Module: Context2D autoPaging", () => {
"170. 1663.78 l",
"20. 1663.78 l",
"S",
"1. w",
"0. 0. 0. rg",
"1. 0. 0. RG",
"0 J",
Expand All @@ -79,6 +81,7 @@ describe("Module: Context2D autoPaging", () => {
"170. 2505.67 l",
"20. 2505.67 l",
"S",
"1. w",
"0. 0. 0. rg",
"1. 0. 0. RG",
"0 J",
Expand All @@ -92,6 +95,7 @@ describe("Module: Context2D autoPaging", () => {
"170. 3347.56 l",
"20. 3347.56 l",
"S",
"1. w",
"0. G",
"0. 0. 0. rg",
"0. G",
Expand All @@ -106,6 +110,7 @@ describe("Module: Context2D autoPaging", () => {
"330. 821.89 l",
"180. 821.89 l",
"S",
"1. w",
"0. 0. 0. rg",
"0. G",
"0 J",
Expand All @@ -119,6 +124,7 @@ describe("Module: Context2D autoPaging", () => {
"330. 1663.78 l",
"180. 1663.78 l",
"S",
"1. w",
"0. 0. 0. rg",
"0. G",
"0 J",
Expand All @@ -132,6 +138,7 @@ describe("Module: Context2D autoPaging", () => {
"330. 2505.67 l",
"180. 2505.67 l",
"S",
"1. w",
"0. 0. 0. rg",
"0. G",
"0 J",
Expand All @@ -144,7 +151,8 @@ describe("Module: Context2D autoPaging", () => {
"180. 3347.56 l",
"330. 3347.56 l",
"180. 3347.56 l",
"S"
"S",
"1. w"
]);
});

Expand All @@ -160,7 +168,6 @@ describe("Module: Context2D autoPaging", () => {

var writeArray = [];
doc.__private__.setCustomOutputDestination(writeArray);

ctx.fillText("test", 0, 1000);

expect(writeArray).toEqual([
Expand All @@ -171,7 +178,9 @@ describe("Module: Context2D autoPaging", () => {
"0 J",
"1. w",
"0 j",
"BT\n/F1 10 Tf\n11.5 TL\n0. 0. 0. rg\n0. 683.78 Td\n(test) Tj\nET"
"1. w",
"BT\n/F1 10 Tf\n11.5 TL\n0. 0. 0. rg\n0. 683.78 Td\n(test) Tj\nET",
"1. w"
]);
});
});
Binary file modified spec/reference/autoPaging10Pages.pdf
Binary file not shown.
Binary file modified spec/reference/bar_graph_with_text_and_lines.pdf
Binary file not shown.
Binary file modified spec/reference/csscolornames.pdf
Binary file not shown.
Binary file modified spec/reference/curves.pdf
Binary file not shown.
Binary file modified spec/reference/fillRect_strokeRect.pdf
Binary file not shown.
Binary file modified spec/reference/fillStyle_strokeStyle.pdf
Binary file not shown.
Binary file modified spec/reference/fonts.pdf
Binary file not shown.
Binary file modified spec/reference/moveTo_lineTo_stroke_fill.pdf
Binary file not shown.
Binary file modified spec/reference/paths.pdf
Binary file not shown.
Binary file modified spec/reference/piechart.pdf
Binary file not shown.
Binary file modified spec/reference/sierpinski.pdf
Binary file not shown.
Binary file modified spec/reference/smiley.pdf
Binary file not shown.
Binary file modified spec/reference/textBaseline.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_arc.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_bezierCurveTo.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_clip.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_closePath_v1.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_closePath_v2.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_fillStyle.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_fillText.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_font.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_lineCap_butt.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_lineCap_round.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_lineCap_square.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_lineJoin_bevel.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_lineJoin_miter.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_lineJoin_round.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_lineTo.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_quadraticCurveTo.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_rotate.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_scale.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_setTransform.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_strokeStyle.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_strokeText.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_textAlign.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_textBaseline.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_transform.pdf
Binary file not shown.
Binary file modified spec/reference/w3s_translate.pdf
Binary file not shown.
Binary file modified spec/reference/warnsign.pdf
Binary file not shown.
14 changes: 12 additions & 2 deletions src/modules/context2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,8 @@
var fillStyle = this.fillStyle;
var strokeStyle = this.strokeStyle;
var lineCap = this.lineCap;
var lineWidth = this.lineWidth;
var oldLineWidth = this.lineWidth;
var lineWidth = oldLineWidth * this.ctx.transform.scaleX;
var lineJoin = this.lineJoin;

var origPath = JSON.parse(JSON.stringify(this.path));
Expand Down Expand Up @@ -1665,9 +1666,12 @@
if (isClip === false || k === 0) {
drawPaths.call(this, rule, isClip);
}
this.lineWidth = oldLineWidth;
}
} else {
this.lineWidth = lineWidth;
drawPaths.call(this, rule, isClip);
this.lineWidth = oldLineWidth;
}
this.path = origPath;
};
Expand Down Expand Up @@ -1995,7 +1999,7 @@

sortPages(pages);

var clipPath, oldSize;
var clipPath, oldSize, oldLineWidth;
if (this.autoPaging === true) {
var min = pages[0];
var max = pages[pages.length - 1];
Expand Down Expand Up @@ -2023,6 +2027,8 @@
if (options.scale >= 0.01) {
oldSize = this.pdf.internal.getFontSize();
this.pdf.setFontSize(oldSize * options.scale);
oldLineWidth = this.lineWidth;
this.lineWidth = oldLineWidth * options.scale;
}
this.pdf.text(options.text, tmpRect.x, tmpRect.y, {
angle: options.angle,
Expand All @@ -2033,12 +2039,15 @@

if (options.scale >= 0.01) {
this.pdf.setFontSize(oldSize);
this.lineWidth = oldLineWidth;
}
}
} else {
if (options.scale >= 0.01) {
oldSize = this.pdf.internal.getFontSize();
this.pdf.setFontSize(oldSize * options.scale);
oldLineWidth = this.lineWidth;
this.lineWidth = oldLineWidth * options.scale;
}
this.pdf.text(options.text, pt.x + this.posX, pt.y + this.posY, {
angle: options.angle,
Expand All @@ -2049,6 +2058,7 @@

if (options.scale >= 0.01) {
this.pdf.setFontSize(oldSize);
this.lineWidth = oldLineWidth;
}
}
};
Expand Down

0 comments on commit 91cecee

Please sign in to comment.