From 51e2ddc8ba4a9e60623a5881470f1fb043aa5c6a Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 23 Jan 2017 17:51:39 +0000 Subject: [PATCH] Revert "Use new canvas Path rect/SVG support." Don't use the built-in SVG/rect parser, since this bypasses creating coordinate / command properties which some Canvas users rely upon. This reverts commit 57a2d21ddf5117551d0193d79771d34a7cf99945. --- Nasal/canvas/api.nas | 10 ++-------- Nasal/canvas/svg.nas | 29 ++++++++++++++--------------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/Nasal/canvas/api.nas b/Nasal/canvas/api.nas index 72794195b..ea67217fa 100644 --- a/Nasal/canvas/api.nas +++ b/Nasal/canvas/api.nas @@ -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,12 +778,6 @@ 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...) { @@ -954,7 +948,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(), diff --git a/Nasal/canvas/svg.nas b/Nasal/canvas/svg.nas index 081c114a3..d7fe570a3 100644 --- a/Nasal/canvas/svg.nas +++ b/Nasal/canvas/svg.nas @@ -502,15 +502,13 @@ 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" ) { - 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 width = evalCSSNum(attr['width']); + var height = evalCSSNum(attr['height']); + var x = evalCSSNum(attr['x']); + var y = evalCSSNum(attr['y']); var rx = attr['rx']; var ry = attr['ry']; @@ -519,14 +517,15 @@ var parsesvg = func(group, path, options = nil) else if( rx == nil ) rx = ry; - if( rx != nil ) { - p.set('border-radius[0]', rx); - p.set('border-radius[1]', ry); - } - } else { - p.setDataSVG(attr['d']); - } + var cfg = {}; + if( rx != nil ) + cfg["border-radius"] = [evalCSSNum(rx), evalCSSNum(ry)]; + stack[-1].rect(x, y, width, height, cfg); + } + 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))); @@ -535,13 +534,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']);