From 52e8e9b059e682dfecfa762957d3ffcccacbeddb Mon Sep 17 00:00:00 2001 From: Jani Pehkonen Date: Tue, 26 Feb 2019 20:00:35 +0200 Subject: [PATCH] Fix missing moveTos in SVG paths --- src/display/svg.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/display/svg.js b/src/display/svg.js index 755c87b9f..03b5175e2 100644 --- a/src/display/svg.js +++ b/src/display/svg.js @@ -940,7 +940,6 @@ SVGGraphics = (function SVGGraphicsClosure() { constructPath: function SVGGraphics_constructPath(ops, args) { var current = this.current; var x = current.x, y = current.y; - current.path = this.svgFactory.createElement('svg:path'); var d = []; var opLength = ops.length; @@ -992,10 +991,22 @@ SVGGraphics = (function SVGGraphicsClosure() { break; } } - current.path.setAttributeNS(null, 'd', d.join(' ')); - current.path.setAttributeNS(null, 'fill', 'none'); - this._ensureTransformGroup().appendChild(current.path); + d = d.join(' '); + + if (current.path && opLength > 0 && ops[0] !== OPS.rectangle && + ops[0] !== OPS.moveTo) { + // If a path does not start with an OPS.rectangle or OPS.moveTo, it has + // probably been divided into two OPS.constructPath operators by + // OperatorList. Append the commands to the previous path element. + d = current.path.getAttributeNS(null, 'd') + d; + } else { + current.path = this.svgFactory.createElement('svg:path'); + this._ensureTransformGroup().appendChild(current.path); + } + + current.path.setAttributeNS(null, 'd', d); + current.path.setAttributeNS(null, 'fill', 'none'); // Saving a reference in current.element so that it can be addressed // in 'fill' and 'stroke' @@ -1004,6 +1015,9 @@ SVGGraphics = (function SVGGraphicsClosure() { }, endPath: function SVGGraphics_endPath() { + // Painting operators end a path. + this.current.path = null; + if (!this.pendingClip) { return; }