1
0
Fork 0

parsesvg: rename canvas.num to canvas.evalCSSNum

This commit is contained in:
Thomas Geymayer 2013-12-01 14:03:19 +01:00
parent 2e6ba5f8c0
commit 748f1d4d29

View file

@ -34,7 +34,7 @@ var parsesvg = func(group, path, options = nil)
}; };
# Helper to get number without unit (eg. px) # Helper to get number without unit (eg. px)
var num = func(css_num) var evalCSSNum = func(css_num)
{ {
if( css_num.ends_with("px") ) if( css_num.ends_with("px") )
return substr(css_num, 0, size(css_num) - 2); return substr(css_num, 0, size(css_num) - 2);
@ -292,11 +292,11 @@ var parsesvg = func(group, path, options = nil)
var font_size = style["font-size"]; var font_size = style["font-size"];
if( font_size != nil ) if( font_size != nil )
stack[-1].setDouble("character-size", num(font_size)); stack[-1].setDouble("character-size", evalCSSNum(font_size));
var line_height = style["line-height"]; var line_height = style["line-height"];
if( line_height != nil ) if( line_height != nil )
stack[-1].setDouble("line-height", num(line_height)); stack[-1].setDouble("line-height", evalCSSNum(line_height));
} }
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
@ -399,10 +399,10 @@ var parsesvg = func(group, path, options = nil)
if( name == "rect" ) if( name == "rect" )
{ {
var width = attr['width']; var width = evalCSSNum(attr['width']);
var height = attr['height']; var height = evalCSSNum(attr['height']);
var x = attr['x']; var x = evalCSSNum(attr['x']);
var y = attr['y']; var y = evalCSSNum(attr['y']);
var rx = attr['rx']; var rx = attr['rx'];
var ry = attr['ry']; var ry = attr['ry'];
@ -413,9 +413,9 @@ var parsesvg = func(group, path, options = nil)
var cfg = {}; var cfg = {};
if( rx != nil ) if( rx != nil )
cfg["border-radius"] = [num(rx), num(ry)]; cfg["border-radius"] = [evalCSSNum(rx), evalCSSNum(ry)];
stack[-1].rect(num(x), num(y), num(width), num(height), cfg); stack[-1].rect(x, y, width, height, cfg);
} }
else else
parsePath(attr['d']); parsePath(attr['d']);
@ -423,7 +423,7 @@ var parsesvg = func(group, path, options = nil)
stack[-1].set('fill', style['fill']); stack[-1].set('fill', style['fill']);
var w = style['stroke-width']; var w = style['stroke-width'];
stack[-1].setStrokeLineWidth( w != nil ? num(w) : 1 ); stack[-1].setStrokeLineWidth( w != nil ? evalCSSNum(w) : 1 );
stack[-1].set('stroke', style['stroke'] or "none"); stack[-1].set('stroke', style['stroke'] or "none");
var linecap = style['stroke-linecap']; var linecap = style['stroke-linecap'];
@ -464,11 +464,11 @@ var parsesvg = func(group, path, options = nil)
var cx = attr['inkscape:transform-center-x']; var cx = attr['inkscape:transform-center-x'];
if( cx != nil and cx != 0 ) if( cx != nil and cx != 0 )
stack[-1].setDouble("center-offset-x", num(cx)); stack[-1].setDouble("center-offset-x", evalCSSNum(cx));
var cy = attr['inkscape:transform-center-y']; var cy = attr['inkscape:transform-center-y'];
if( cy != nil and cy != 0 ) if( cy != nil and cy != 0 )
stack[-1].setDouble("center-offset-y", -num(cy)); stack[-1].setDouble("center-offset-y", -evalCSSNum(cy));
if( cx != nil or cy != nil ) if( cx != nil or cy != nil )
stack[-1].updateCenter(); stack[-1].updateCenter();