Skip to content
This repository has been archived by the owner on Dec 21, 2019. It is now read-only.

Commit

Permalink
Smarter path concatenation
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Jan 19, 2011
1 parent 8487e7a commit edfa604
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions Source/ART.SVG.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,16 +411,16 @@ var fontAnchors = { left: 'start', center: 'middle', right: 'end' },
var splitPaths, splitPath;

function splitMove(sx, sy, x, y){
if (splitPath.length > 4) splitPaths.push(splitPath);
splitPath = ['M', x, ',', y];
if (splitPath.length > 3) splitPaths.push(splitPath);
splitPath = ['M', x, y];
};

function splitLine(sx, sy, x, y){
splitPath.push('L', x, ',', y);
splitPath.push('L', x, y);
};

function splitCurve(sx, sy, p1x, p1y, p2x, p2y, x, y){
splitPath.push('C', p1x, ',', p1y, ',', p2x, ',', p2y, ',', x, ',', y);
splitPath.push('C', p1x, p1y, p2x, p2y, x, y);
};

ART.SVG.Text = new Class({
Expand Down Expand Up @@ -557,14 +557,14 @@ ART.SVG.Text = new Class({
this._ejectPaths();
var id = 'p' + String.uniqueID() + '-';

splitPaths = []; splitPath = ['M', 0, ',', 0];
splitPaths = []; splitPath = ['M', 0, 0];
path.visit(splitLine, splitCurve, null, splitMove);
splitPaths.push(splitPath);

var result = [];
for (var i = 0, l = splitPaths.length; i < l; i++){
var p = createElement('path');
p.setAttribute('d', splitPaths[i].join(''));
p.setAttribute('d', splitPaths[i].join(' '));
p.setAttribute('id', id + i);
result.push(p);
}
Expand Down
20 changes: 10 additions & 10 deletions Source/ART.VML.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,18 +724,18 @@ ART.VML.Text = new Class({
var path, p, round = Math.round;

function moveTo(sx, sy, x, y){
path.push('m', round(x * p), ',', round(y * p));
path.push('m', round(x * p), round(y * p));
};

function lineTo(sx, sy, x, y){
path.push('l', round(x * p), ',', round(y * p));
path.push('l', round(x * p), round(y * p));
};

function curveTo(sx, sy, p1x, p1y, p2x, p2y, x, y){
path.push('c',
round(p1x * p), ',', round(p1y * p), ',',
round(p2x * p), ',', round(p2y * p), ',',
round(x * p), ',', round(y * p)
round(p1x * p), round(p1y * p),
round(p2x * p), round(p2y * p),
round(x * p), round(y * p)
);
};

Expand All @@ -744,10 +744,10 @@ function arcTo(sx, sy, ex, ey, cx, cy, r, sa, ea, ccw){
cy *= p;
r *= p;
path.push(ccw ? 'at' : 'wa',
round(cx - r), ',', round(cy - r), ',',
round(cx + r), ',', round(cy + r), ',',
round(sx * p), ',', round(sy * p), ',',
round(ex * p), ',', round(ey * p)
round(cx - r), round(cy - r),
round(cx + r), round(cy + r),
round(sx * p), round(sy * p),
round(ex * p), round(ey * p)
);
};

Expand All @@ -762,7 +762,7 @@ ART.Path.implement({
path = [];
p = precision;
this.visit(lineTo, curveTo, arcTo, moveTo, close);
this.cache.vml = path.join('');
this.cache.vml = path.join(' ');
}
return this.cache.vml;
}
Expand Down

0 comments on commit edfa604

Please sign in to comment.