1
0
Fork 0

Use new canvas Path rect/SVG support.

This commit is contained in:
James Turner 2016-12-16 19:34:16 +00:00
parent adde60a994
commit 57a2d21ddf
2 changed files with 23 additions and 16 deletions

View file

@ -480,7 +480,7 @@ var Map = {
controller = Map.df_controller;
elsif (typeof(controller) != 'hash')
controller = Map.Controller.get(controller);
if (controller == nil) {
me.controller = nil;
} else {
@ -778,6 +778,12 @@ var Path = {
me._last_coord = size(coords) - 1;
return me;
},
setDataSVG: func(svgPath)
{
me.reset();
me._node.setValues({'svg': svgPath});
return me;
},
# Add a path segment
addSegment: func(cmd, coords...)
{
@ -948,7 +954,7 @@ var Path = {
},
setColor: func me.setStroke(_getColor(arg)),
getColor: func me.getStroke(),
getColor: func me.getStroke(),
setColorFill: func me.setFill(_getColor(arg)),
getColorFill: func me.getColorFill(),

View file

@ -502,13 +502,15 @@ var parsesvg = func(group, path, options = nil)
else if( name == "path" or name == "rect" )
{
pushElement('path', attr['id']);
var p = stack[-1];
if( name == "rect" )
{
var width = evalCSSNum(attr['width']);
var height = evalCSSNum(attr['height']);
var x = evalCSSNum(attr['x']);
var y = evalCSSNum(attr['y']);
p.set('rect/left', evalCSSNum(attr['x']));
p.set('rect/top', evalCSSNum(attr['y']));
p.set('rect/width', evalCSSNum(attr['width']));
p.set('rect/height', evalCSSNum(attr['height']));
var rx = attr['rx'];
var ry = attr['ry'];
@ -517,15 +519,14 @@ var parsesvg = func(group, path, options = nil)
else if( rx == nil )
rx = ry;
var cfg = {};
if( rx != nil )
cfg["border-radius"] = [evalCSSNum(rx), evalCSSNum(ry)];
stack[-1].rect(x, y, width, height, cfg);
if( rx != nil ) {
p.set('border-radius[0]', rx);
p.set('border-radius[1]', ry);
}
} else {
p.setDataSVG(attr['d']);
}
else
parsePath(attr['d']);
var fillOpacity = style['fill-opacity'];
if( fillOpacity != nil)
stack[-1].set('fill', style['fill'] ~ sprintf("%02x", int(style['fill-opacity']*255)));
@ -534,13 +535,13 @@ var parsesvg = func(group, path, options = nil)
var w = style['stroke-width'];
stack[-1].setStrokeLineWidth( w != nil ? evalCSSNum(w) : 1 );
var strokeOpacity = style['stroke-opacity'];
if(strokeOpacity != nil)
stack[-1].set('stroke', (style['stroke'] ~ sprintf("%02x", int(style['stroke-opacity']*255))));
else
stack[-1].set('stroke', style['stroke'] or "none");
var linecap = style['stroke-linecap'];
if( linecap != nil )
stack[-1].setStrokeLineCap(style['stroke-linecap']);