1 ## Copyright (C) 2011 Carnë Draug <carandraug+dev@gmail.com>
2 ## Copyright (c) 2011 Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
4 ## This program is free software; you can redistribute it and/or modify
5 ## it under the terms of the GNU General Public License as published by
6 ## the Free Software Foundation; either version 3 of the License, or
7 ## (at your option) any later version.
9 ## This program is distributed in the hope that it will be useful,
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details.
14 ## You should have received a copy of the GNU General Public License
15 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
18 ## @deftypefn {Function File} {@var{obj} =} svg ()
19 ## @deftypefnx {Function File} {@var{obj} =} svg (@var{str})
20 ## Create object of the svg class.
22 ## If no input argument is provided the object is empty. @var{str} can be a filename
23 ## or a string defining an inline SVG.
27 function svg = svg(name='')
31 ## SVG data. All the attributes of the <svg> node.
32 ## The field unparsed contains all the attributes that are not being parsed.
33 svg.Data = struct('height',[],'width',[],'id','null','normalized',false);
35 ## SVG metadata. All the attributes of the <metadata> node.
36 ## The field unparsed contains all the attributes that are not being parsed.
37 svg.Metadata = struct('unparsed',' ');
39 ## SVG paths. It is a vector of path structs. Maybe path can be a object too?
40 ## Order of Path.Data is important so we store in a cell (could be a matrix padded with zeros).
41 ## All the paths stored in polyval compatible format. Straigth segments are also stored as a polynomial.
44 svg = class (svg, 'svg');
47 if exist(name,"file") == 2
48 name = file_in_path(path(), name);
50 error("svg:BadArguemnt", "File %s doesn't exist",name);
52 paths = loadpaths(svg, name);
54 data = loadsvgdata(svg, name);
56 svg.Data.normalized = false;
65 %! dc = svg('drawing5.svg');
68 %! dc.getpath('path3756');
70 %! dc = svg('drawing.svg');
72 %! dc.getpath({ids{[1 3]}});
75 %! dc = svg('drawing6.svg');
77 %! P = dc.path2polygon(ids{1});
80 %! dc = svg('drawing6.svg');
82 %! dc.plot('color','r','linewidth',2);