The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Transform paths in SVG to BF conversion

These changes was commited to the Birdfont repository Tue, 29 Nov 2016 19:07:59 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Tue, 29 Nov 2016 19:07:59 +0000 (20:07 +0100)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Tue, 29 Nov 2016 19:07:59 +0000 (20:07 +0100)
commit 982c80b242a2627ee7d38e48ed533247e11e8c9f
tree c84d89175d949bcf8a9013b132cce930d608ddd9
parent 7ea3c155f507511ee910deaa7c5ee8446f648a8a
Transform paths in SVG to BF conversion

libbirdfont/EmbeddedSvg.vala
libbirdfont/SvgParser.vala
libsvgbird/SvgFile.vala
libsvgbird/SvgTransforms.vala
--- a/libbirdfont/EmbeddedSvg.vala +++ b/libbirdfont/EmbeddedSvg.vala @@ -90,7 +90,7 @@ svg.append ("""<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">"""); svg.append ("\n"); - string transforms = transforms.get_xml (); + string transforms = drawing.transforms.get_xml (); if (transforms != "") { svg.append ("<g");
--- a/libbirdfont/SvgParser.vala +++ b/libbirdfont/SvgParser.vala @@ -162,6 +162,7 @@ // parse the file if (!has_format) { + parser.set_format (SvgFormat.ILLUSTRATOR); warn_if_test ("No format identifier found in SVG parser.\n"); } @@ -226,7 +227,6 @@ } foreach (XmlElement t in tag) { - if (t.get_name () == "g") { parse_layer (t, pl); } @@ -269,13 +269,11 @@ } PathList paths = LayerUtils.get_all_paths (pl); - ViewBox? box = SvgFile.parse_view_box (tag); + if (box != null) { ViewBox view_box = (!) box; - Cairo.Matrix matrix = Cairo.Matrix.identity (); - Cairo.Matrix view_box_matrix = view_box.get_matrix (width, height); - view_box_matrix.multiply (view_box_matrix, matrix); + Matrix view_box_matrix = view_box.get_matrix (width, height); SvgTransform t = new SvgTransform.for_matrix (view_box_matrix); SvgTransforms transforms = new SvgTransforms (); transforms.add (t); @@ -347,14 +345,7 @@ } } - PathList paths = new PathList (); - - foreach (SvgBird.Object object in pl.objects) { - if (object is Path) { - paths.add ((Path) object); - } - } - + PathList paths = LayerUtils.get_all_paths (pl); SvgTransforms transforms = SvgFile.get_transform (tag.get_attributes ()); transform_paths (transforms, paths); }
--- a/libsvgbird/SvgFile.vala +++ b/libsvgbird/SvgFile.vala @@ -100,9 +100,15 @@ string aspect_ratio = ""; bool slice = true; bool preserve_aspect_ratio = true; + + if (tag.get_name () != "svg") { + warning (@"viewBox is not the svg tag: $(tag.get_name ())"); + return null; + } foreach (Attribute attribute in tag.get_attributes ()) { if (attribute.get_name () == "viewBox") { + print (@"$(attribute.get_name ()): $(attribute.get_content ())\n"); parameters = attribute.get_content (); } @@ -123,6 +129,7 @@ } } + print (@"parameters: $parameters\n"); arguments = parameters.replace (",", " "); while (arguments.index_of (" ") > -1) { @@ -131,8 +138,9 @@ string[] view_box_parameters = arguments.split (" "); - if (view_box_parameters.length != 4) { + if (unlikely (view_box_parameters.length != 4)) { warning ("Expecting four arguments in view box."); + warning (@"Content: $arguments ($parameters)"); return null; }
--- a/libsvgbird/SvgTransforms.vala +++ b/libsvgbird/SvgTransforms.vala @@ -132,6 +132,10 @@ } return copy_transforms; + } + + public void insert (int position, SvgTransform transform) { + transforms.insert (position, transform); } public void add (SvgTransform transform) {