]> Creatis software - CreaPhase.git/blob - octave_packages/geometry-1.5.0/io/@svg/svg.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / geometry-1.5.0 / io / @svg / svg.m
1 ## Copyright (C) 2011 CarnĂ« Draug <carandraug+dev@gmail.com>
2 ## Copyright (c) 2011 Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
3 ##
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.
8 ##
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.
13 ##
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/>.
16
17 ## -*- texinfo -*-
18 ## @deftypefn {Function File} {@var{obj} =} svg ()
19 ## @deftypefnx {Function File} {@var{obj} =} svg (@var{str})
20 ## Create object of the svg class.
21 ##
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.
24 ##
25 ## @end deftypefn
26
27 function svg = svg(name='')
28
29   svg = struct;
30
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);
34
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',' ');
38
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.
42   svg.Path = struct();
43
44   svg = class (svg, 'svg');
45
46   if !isempty (name)
47     if exist(name,"file") == 2
48       name = file_in_path(path(), name);
49     else
50       error("svg:BadArguemnt", "File %s doesn't exist",name);
51     end
52     paths = loadpaths(svg, name);
53     svg.Path = paths;
54     data = loadsvgdata(svg, name);
55     svg.Data = data;
56     svg.Data.normalized = false;
57   elseif !ischar(name)
58     print_usage ;
59   endif
60
61
62 endfunction
63
64 %!test
65 %!  dc = svg('drawing5.svg');
66 %!  dc.getpath();
67 %!  dc.pathid();
68 %!  dc.getpath('path3756');
69 %!
70 %!  dc = svg('drawing.svg');
71 %!  ids = dc.pathid();
72 %!  dc.getpath({ids{[1 3]}});
73
74 %!test
75 %!  dc = svg('drawing6.svg');
76 %!  ids = dc.pathid();
77 %!  P = dc.path2polygon(ids{1});
78
79 %!test
80 %! dc = svg('drawing6.svg');
81 %! dc.plot();
82 %! dc.plot('color','r','linewidth',2);