]> Creatis software - CreaPhase.git/blob - octave_packages/geometry-1.5.0/io/deprecated/svgload.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / geometry-1.5.0 / io / deprecated / svgload.m
1 %% Copyright (c) 2011 Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
2 %% 
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
6 %%    any later version.
7 %%
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.
12 %%
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/>.
15
16 %% -*- texinfo -*-
17 %% @deftypefn {Function File} @var{SVG} = loadSVG (@var{filename})
18 %% Reads the plain SVG file @var{filename} and returns an SVG structure.
19 %% 
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.
24 %%
25 %% @seealso{svgnormalize, svgpath2polygon}
26 %% @end deftypefn
27
28
29 function SVG = svgload (filename)
30
31     SVG = struct ('height', [], 'width', [], 'path', [], 'normalized', []);
32
33     SVG.normalized = false;
34
35     fid = fopen (filename);
36     svg = char (fread (fid, "uchar")');
37     fclose (fid);
38     svgF = formatSVGstr (svg);
39
40     % Get SVG Data
41     data        = getSVGdata (svgF);
42     SVG.height  = data.height;
43     SVG.width   = data.width;
44
45     % Get SVG Paths
46     SVGstrPath  = getSVGstrPath (svgF);
47     SVGpath     = SVGstrPath2SVGpath (SVGstrPath);
48     SVG.path    = SVGpath;
49
50 end
51
52 %!demo
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);
57 %! fclose (fid);
58 %! SVG     = svgload (file);
59 %! SVG
60 %! plot([SVG.path.coord(:,1); SVG.path.coord(1,1)], ...
61 %!      [SVG.path.coord(:,2); SVG.path.coord(1,2)]);
62 %! delete (file);