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/>.
16 function Paths = getSVGPaths_py (svg, varargin)
21 [st str]=system (sprintf ('python parsePath.py %s', svg));
25 [st str]=system (sprintf ('python parsePath.py < %s', svg));
29 strpath = strsplit (str(1:end-1), '$', true);
31 npaths = numel (strpath);
33 %% Convert path data to polygons
37 %% FIXME: intialize struct with cell field
38 svgpath2.cmd = svgpath(1).cmd;
39 svgpath2.data = {svgpath.data};
41 nD = length(svgpath2.cmd);
42 pathdata = cell (nD-1,1);
45 %% If the path is closed, last command is Z and we set initial point == final
46 if svgpath2.cmd(end) == 'Z'
48 point_end = svgpath2.data{1};
52 points(1,:) = svgpath2.data{1};
55 switch svgpath2.cmd(jp)
57 %% Straigth segment to polygon
58 points(2,:) = svgpath2.data{jp};
59 pp = [(points(2,:)-points(1,:))' points(1,:)'];
61 points(1,:) = [polyval(pp(1,:),1) polyval(pp(2,:),1)];
64 %% Cubic bezier to polygon
65 points(2:4,:) = reshape (svgpath2.data{jp}, 2, 3).';
66 pp = cbezier2poly (points);
68 points(1,:) = [polyval(pp(1,:),1) polyval(pp(2,:),1)];
74 if ~isempty(point_end)
75 %% Straight segmet to close the path
76 points(2,:) = point_end;
77 pp = [(points(2,:)-points(1,:))' points(1,:)'];
82 Paths.(svgpathid).data = pathdata;
89 %! paths = getSVGPaths_py ('../drawing.svg');
92 %! ids = fieldnames(paths);
93 %! npath = numel(ids);
95 %! t = linspace (0, 1, 64);
99 %! data = paths.(ids(i)).data;
101 %! for j = 1:numel(data)
102 %! x = cat (2, x, polyval (data{j}(1,:),t));
103 %! y = cat (2, y, polyval (data{j}(2,:),t));
109 %! if strcmpi(input('You should see drawing.svg [y/n] ','s'),'n')
110 %! error ("didn't get what was expected.");