Skip to content

Commit b743737

Browse files
authored
Merge pull request #19732 from calixteman/rm_useless_beginpath
Remove few useless beginPaths
2 parents e5fbf52 + a35443f commit b743737

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

src/display/canvas.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,6 @@ class CanvasGraphics {
16051605
const paths = this.pendingTextPaths;
16061606
const ctx = this.ctx;
16071607
if (paths === undefined) {
1608-
ctx.beginPath();
16091608
return;
16101609
}
16111610

@@ -1622,7 +1621,6 @@ class CanvasGraphics {
16221621
}
16231622

16241623
ctx.clip(newPath);
1625-
ctx.beginPath();
16261624
delete this.pendingTextPaths;
16271625
}
16281626

@@ -2127,8 +2125,9 @@ class CanvasGraphics {
21272125
}
21282126

21292127
setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
2130-
this.ctx.rect(llx, lly, urx - llx, ury - lly);
2131-
this.ctx.clip();
2128+
const clip = new Path2D();
2129+
clip.rect(llx, lly, urx - llx, ury - lly);
2130+
this.ctx.clip(clip);
21322131
this.endPath();
21332132
}
21342133

@@ -2271,11 +2270,11 @@ class CanvasGraphics {
22712270
this.baseTransform = getCurrentTransform(this.ctx);
22722271

22732272
if (bbox) {
2274-
const width = bbox[2] - bbox[0];
2275-
const height = bbox[3] - bbox[1];
2276-
this.ctx.rect(bbox[0], bbox[1], width, height);
22772273
this.current.updateRectMinMax(getCurrentTransform(this.ctx), bbox);
2278-
this.clip();
2274+
const [x0, y0, x1, y1] = bbox;
2275+
const clip = new Path2D();
2276+
clip.rect(x0, y0, x1 - x0, y1 - y0);
2277+
this.ctx.clip(clip);
22792278
this.endPath();
22802279
}
22812280
}
@@ -2503,9 +2502,9 @@ class CanvasGraphics {
25032502
// Consume a potential path before clipping.
25042503
this.endPath();
25052504

2506-
this.ctx.rect(rect[0], rect[1], width, height);
2507-
this.ctx.clip();
2508-
this.ctx.beginPath();
2505+
const clip = new Path2D();
2506+
clip.rect(rect[0], rect[1], width, height);
2507+
this.ctx.clip(clip);
25092508
}
25102509
}
25112510

@@ -2902,7 +2901,6 @@ class CanvasGraphics {
29022901
this.pendingClip = null;
29032902
}
29042903
this.current.startNewPathAndClipBox(this.current.clipBox);
2905-
ctx.beginPath();
29062904
}
29072905

29082906
getSinglePixelWidth() {

0 commit comments

Comments
 (0)