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

Move svg:clipPath generation from clip to endPath #8542

Merged
merged 1 commit into from
Jun 22, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/display/svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
this.extraStack = [];
this.commonObjs = commonObjs;
this.objs = objs;
this.pendingClip = null;
this.pendingEOFill = false;

this.embedFonts = false;
Expand Down Expand Up @@ -389,6 +390,7 @@ SVGGraphics = (function SVGGraphicsClosure() {
this.transformMatrix = this.transformStack.pop();
this.current = this.extraStack.pop();

this.pendingClip = null;
this.tgrp = null;
},

Expand Down Expand Up @@ -894,9 +896,10 @@ SVGGraphics = (function SVGGraphicsClosure() {
current.setCurrentPoint(x, y);
},

endPath: function SVGGraphics_endPath() {},

clip: function SVGGraphics_clip(type) {
endPath: function SVGGraphics_endPath() {
if (!this.pendingClip) {
return;
}
var current = this.current;
// Add current path to clipping path
var clipId = 'clippath' + clipCount;
Expand All @@ -905,17 +908,18 @@ SVGGraphics = (function SVGGraphicsClosure() {
clipPath.setAttributeNS(null, 'id', clipId);
clipPath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
var clipElement = current.element.cloneNode();
if (type === 'evenodd') {
if (this.pendingClip === 'evenodd') {
clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
} else {
clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
}
this.pendingClip = null;
clipPath.appendChild(clipElement);
this.defs.appendChild(clipPath);

if (current.activeClipUrl) {
// The previous clipping group content can go out of order -- resetting
// cached clipGroup's.
// cached clipGroups.
current.clipGroup = null;
this.extraStack.forEach(function (prev) {
prev.clipGroup = null;
Expand All @@ -926,6 +930,10 @@ SVGGraphics = (function SVGGraphicsClosure() {
this.tgrp = null;
},

clip: function SVGGraphics_clip(type) {
this.pendingClip = type;
},

closePath: function SVGGraphics_closePath() {
var current = this.current;
var d = current.path.getAttributeNS(null, 'd');
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
!issue3879r.pdf
!issue5686.pdf
!issue3928.pdf
!clippath.pdf
!close-path-bug.pdf
!issue6019.pdf
!issue6621.pdf
Expand Down
Binary file added test/pdfs/clippath.pdf
Binary file not shown.
8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2776,6 +2776,14 @@
"type": "eq",
"about": "CFF font that is drawn with clipping."
},
{ "id": "clippath",
"file": "pdfs/clippath.pdf",
"md5": "7ab95c0f106dccd90d6569f241fe8771",
"rounds": 1,
"link": false,
"type": "eq",
"about": "Clipping before a path exists, followed by adding a path and then drawing a rectangle."
},
{ "id": "annotation-tx",
"file": "pdfs/annotation-tx.pdf",
"md5": "56321ea830be9c4f8437ca17ac535b2d",
Expand Down