Skip to content

Commit

Permalink
Added endPath, endText. fixes extra <g> elements
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodhkp committed Jul 25, 2014
1 parent 2380b38 commit 6e4dd83
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions src/display/svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ var SVGGraphics = (function SVGGraphicsClosure(ctx) {
this.tgrp = document.createElementNS(NS, 'svg:g');
this.tgrp.setAttributeNS(null, 'transform',
'matrix(' + this.transformMatrix + ')');
this.pgrp.appendChild(this.tgrp);
},

beginDrawing: function SVGGraphics_beginDrawing(viewport, pageNum,
Expand Down Expand Up @@ -266,7 +265,7 @@ var SVGGraphics = (function SVGGraphicsClosure(ctx) {
this.showText(args[0]);
break;
case OPS.endText:
this.endText(args);
this.endText();
break;
case OPS.moveText:
this.moveText(args[0], args[1]);
Expand Down Expand Up @@ -351,6 +350,9 @@ var SVGGraphics = (function SVGGraphicsClosure(ctx) {
case OPS.constructPath:
this.constructPath(args[0], args[1]);
break;
case OPS.endPath:
this.endPath();
break;
case 92:
this.group(opTree[x].items);
break;
Expand Down Expand Up @@ -477,7 +479,7 @@ var SVGGraphics = (function SVGGraphicsClosure(ctx) {
this.tgrp.appendChild(current.txtElement);

},

setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
this.setLeading(-y);
this.moveText(x, y);
Expand Down Expand Up @@ -515,7 +517,14 @@ var SVGGraphics = (function SVGGraphicsClosure(ctx) {
},

endText: function SVGGraphics_endText(args) {
// Empty for now. Not sure how to break showText into this.
if (this.current.pendingClip) {
this.pgrp.appendChild(this.cgrp);
} else {
this.pgrp.appendChild(this.tgrp);
}
this.tgrp = document.createElementNS(NS, 'svg:g');
this.tgrp.setAttributeNS(null, 'transform',
'matrix(' + this.transformMatrix + ')');
},

// Path properties
Expand Down Expand Up @@ -608,17 +617,33 @@ var SVGGraphics = (function SVGGraphicsClosure(ctx) {
current.path.setAttributeNS(null, 'stroke-dasharray', current.dashArray);
current.path.setAttributeNS(null, 'stroke-dashoffset',
current.dashPhase + 'px');
current.path.setAttributeNS(null, 'fill', 'none');

this.tgrp.appendChild(current.path);
if (current.pendingClip) {
this.cgrp.appendChild(this.tgrp);
this.pgrp.appendChild(this.cgrp);
} else {
this.pgrp.appendChild(this.tgrp);
}
current.path.setAttributeNS(null, 'fill', 'none');
this.tgrp.appendChild(current.path);
// Saving a reference in current.element so that it can be addressed
// in 'fill' and 'stroke'
current.element = current.path;
current.setCurrentPoint(x, y);
},

endPath: function SVGGraphics_endPath() {
var current = this.current;
if (current.pendingClip) {
this.pgrp.appendChild(this.cgrp);
} else {
this.pgrp.appendChild(this.tgrp);
}
this.tgrp = document.createElementNS(NS, 'svg:g');
this.tgrp.setAttributeNS(null, 'transform',
'matrix(' + this.transformMatrix + ')');
},

clip: function SVGGraphics_clip(type) {
var current = this.current;
// Add current path to clipping path
Expand Down Expand Up @@ -766,10 +791,14 @@ var SVGGraphics = (function SVGGraphicsClosure(ctx) {
imgEl.setAttributeNS(null, 'y', -h);
imgEl.setAttributeNS(null, 'transform', 'scale(' + 1 / w +
' ' + -1 / h + ')');

this.tgrp.appendChild(imgEl);
if (current.pendingClip) {
this.cgrp.appendChild(this.tgrp);
this.pgrp.appendChild(this.cgrp);
} else {
this.pgrp.appendChild(this.tgrp);
}
this.tgrp.appendChild(imgEl);
},
};
return SVGGraphics;
Expand Down

0 comments on commit 6e4dd83

Please sign in to comment.