Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix context2d lineWidth scaling #2702

Merged
merged 7 commits into from Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions spec/context2d.pageoverlap.spec.js
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
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