Rework horizontal / vertical lineto command code a bit.

This commit is contained in:
Jürg Lehni 2012-11-05 08:54:10 -08:00
parent 6f19f64233
commit 61531949b0
2 changed files with 17 additions and 14 deletions

View file

@ -78,7 +78,7 @@ var Group = this.Group = Item.extend(/** @lends Group# */{
}, },
_changed: function(flags) { _changed: function(flags) {
// Don't use base() for reasons of performance. // Don't use this.base() for reasons of performance.
Item.prototype._changed.call(this, flags); Item.prototype._changed.call(this, flags);
if (flags & (ChangeFlag.HIERARCHY | ChangeFlag.CLIPPING)) { if (flags & (ChangeFlag.HIERARCHY | ChangeFlag.CLIPPING)) {
// Clear cached clip item whenever hierarchy changes // Clear cached clip item whenever hierarchy changes

View file

@ -129,25 +129,28 @@ var SvgImporter = this.SvgImporter = new function() {
// to the original constants. Values were taken from: // to the original constants. Values were taken from:
// http://dxr.mozilla.org/mozilla-central/dom/interfaces/svg/nsIDOMSVGPathSeg.idl.html // http://dxr.mozilla.org/mozilla-central/dom/interfaces/svg/nsIDOMSVGPathSeg.idl.html
var segment = list.getItem(i), var segment = list.getItem(i),
pathSegType = segment.pathSegType, segType = segment.pathSegType,
relativeSegType = pathSegType % 2 == 1; isRelative = segType % 2 == 1;
if (pathSegType === 0) // SVGPathSeg.PATHSEG_UNKNOWN if (segType === 0) // SVGPathSeg.PATHSEG_UNKNOWN
continue; continue;
if (!path.isEmpty()) if (!path.isEmpty())
lastPoint = path.getLastSegment().getPoint(); lastPoint = path.getLastSegment().getPoint();
var relative = relativeSegType && !path.isEmpty() var relative = isRelative && !path.isEmpty()
? lastPoint ? lastPoint
: Point.create(0, 0); : Point.create(0, 0);
// Horizontal or vertical lineto: // Horizontal or vertical lineto commands, so fill in the
if (pathSegType >= 12 && pathSegType <= 15) { // missing x or y value:
// Fill in the missing x or y value: var coord =
if (segment.x === undefined) // SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS
segment.x = relativeSegType ? 0 : lastPoint.x; // SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_REL
if (segment.y === undefined) (segType == 12 || segType == 13) && 'y'
segment.y = relativeSegType ? 0 : lastPoint.y; // SVGPathSeg.PATHSEG_LINETO_VERTICAL_ABS
} // SVGPathSeg.PATHSEG_LINETO_VERTICAL_REL
|| (segType == 14 || segType == 15) && 'x';
if (coord)
segment[coord] = isRelative ? 0 : lastPoint[coord];
var point = Point.create(segment.x, segment.y).add(relative); var point = Point.create(segment.x, segment.y).add(relative);
switch (segment.pathSegType) { switch (segType) {
case 1: // SVGPathSeg.PATHSEG_CLOSEPATH: case 1: // SVGPathSeg.PATHSEG_CLOSEPATH:
path.closePath(); path.closePath();
break; break;