1 %% Copyright (c) 2011 Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
3 %% This program is free software: you can redistribute it and/or modify
4 %% it under the terms of the GNU General Public License as published by
5 %% the Free Software Foundation, either version 3 of the License, or
8 %% This program is distributed in the hope that it will be useful,
9 %% but WITHOUT ANY WARRANTY; without even the implied warranty of
10 %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 %% GNU General Public License for more details.
13 %% You should have received a copy of the GNU General Public License
14 %% along with this program. If not, see <http://www.gnu.org/licenses/>.
17 %% @deftypefn {Function File} @var{SVG} = loadSVG (@var{filename})
18 %% Reads the plain SVG file @var{filename} and returns an SVG structure.
20 %% In the current version only SVG path elements are parsed and stored in the field
21 %% path of the @var{SVG} structure.
22 %% The coordinates of the path are not modified in anyway. This produces the path
23 %% to be ploted vertically reflected.
25 %% @seealso{svgnormalize, svgpath2polygon}
29 function SVG = svgload (filename)
31 SVG = struct ('height', [], 'width', [], 'path', [], 'normalized', []);
33 SVG.normalized = false;
35 fid = fopen (filename);
36 svg = char (fread (fid, "uchar")');
38 svgF = formatSVGstr (svg);
41 data = getSVGdata (svgF);
42 SVG.height = data.height;
43 SVG.width = data.width;
46 SVGstrPath = getSVGstrPath (svgF);
47 SVGpath = SVGstrPath2SVGpath (SVGstrPath);
53 %! file = 'tmp__.svg';
54 %! fid = fopen (file,'w');
55 %! svgfile = '<html><body><svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="250" width="250"><path d="M150,0 75,200 225,200 Z" /></svg></body></html>';
56 %! fprintf (fid,"%s\n",svgfile);
58 %! SVG = svgload (file);
60 %! plot([SVG.path.coord(:,1); SVG.path.coord(1,1)], ...
61 %! [SVG.path.coord(:,2); SVG.path.coord(1,2)]);