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) {
// Don't use base() for reasons of performance.
// Don't use this.base() for reasons of performance.
Item.prototype._changed.call(this, flags);
if (flags & (ChangeFlag.HIERARCHY | ChangeFlag.CLIPPING)) {
// 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:
// http://dxr.mozilla.org/mozilla-central/dom/interfaces/svg/nsIDOMSVGPathSeg.idl.html
var segment = list.getItem(i),
pathSegType = segment.pathSegType,
relativeSegType = pathSegType % 2 == 1;
if (pathSegType === 0) // SVGPathSeg.PATHSEG_UNKNOWN
segType = segment.pathSegType,
isRelative = segType % 2 == 1;
if (segType === 0) // SVGPathSeg.PATHSEG_UNKNOWN
continue;
if (!path.isEmpty())
lastPoint = path.getLastSegment().getPoint();
var relative = relativeSegType && !path.isEmpty()
var relative = isRelative && !path.isEmpty()
? lastPoint
: Point.create(0, 0);
// Horizontal or vertical lineto:
if (pathSegType >= 12 && pathSegType <= 15) {
// Fill in the missing x or y value:
if (segment.x === undefined)
segment.x = relativeSegType ? 0 : lastPoint.x;
if (segment.y === undefined)
segment.y = relativeSegType ? 0 : lastPoint.y;
}
// Horizontal or vertical lineto commands, so fill in the
// missing x or y value:
var coord =
// SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS
// SVGPathSeg.PATHSEG_LINETO_HORIZONTAL_REL
(segType == 12 || segType == 13) && '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);
switch (segment.pathSegType) {
switch (segType) {
case 1: // SVGPathSeg.PATHSEG_CLOSEPATH:
path.closePath();
break;