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 = loadpaths (obj, svg, varargin)
18 here = which ("@svg/loadpaths");
19 here = fileparts (here);
20 script = fullfile (here, 'parsePath.py');
25 [st str]=system (sprintf ('python %s %s', script, svg));
29 [st str]=system (sprintf ('python %s < %s', script, svg));
33 strpath = strsplit (str(1:end-1), '$', true);
35 npaths = numel (strpath);
37 %% Convert path data to polynoms
41 %% FIXME: intialize struct with cell field
42 svgpath2.cmd = svgpath(1).cmd;
43 svgpath2.data = {svgpath.data};
45 nD = length(svgpath2.cmd);
46 pathdata = cell (nD-1,1);
49 %% If the path is closed, last command is Z and we set initial point == final
50 if svgpath2.cmd(end) == 'Z'
52 point_end = svgpath2.data{1};
53 svgpath2.data(end) = [];
57 points(1,:) = svgpath2.data{1};
60 switch svgpath2.cmd(jp)
62 %% Straigth segment to polygon
63 points(2,:) = svgpath2.data{jp};
64 pp = [(points(2,:)-points(1,:))' points(1,:)'];
66 points(1,:) = [polyval(pp(1,:),1) polyval(pp(2,:),1)];
69 %% Cubic bezier to polygon
70 points(2:4,:) = reshape (svgpath2.data{jp}, 2, 3).';
71 pp = cbezier2poly (points);
73 points(1,:) = [polyval(pp(1,:),1) polyval(pp(2,:),1)];
79 if ~isempty(point_end)
80 %% Straight segment to close the path
81 points(2,:) = point_end;
82 pp = [(points(2,:)-points(1,:))' points(1,:)'];
84 if all ( abs(pp(:,1)) < sqrt(eps) )
85 % Final point of last segment is already initial point
93 % pathdata = shapetransform(pathdata);
95 Paths.(svgpathid).data = pathdata;