Commit d865fa7
Convert from SVG files to BF files
Changed files (7)
modifieddodo.pymodifiedlibbirdfont/SvgParser.valamodifiedlibsvgbird/Layer.valamodifiedlibsvgbird/Object.valamodifiedlibsvgbird/PointValue.valamodifiedlibsvgbird/SvgFile.valamodifiedlibsvgbird/point_value.h
Diff
@@ -77,6 +77,7 @@ def make_birdfont(target_binary, deps): --enable-experimental \ birdfont/*.vala \ --vapidir=./ \+ --pkg svgbirdpoint \ --pkg """ + config.GEE + """ \ --pkg gio-2.0 \ --pkg cairo \@@ -141,6 +142,7 @@ def make_birdfont_export(target_binary, deps): """ + config.VALACFLAGS.get("birdfont-export", "") + """ \ birdfont-export/*.vala \ --vapidir=./ \+ --pkg svgbirdpoint \ --pkg """ + config.GEE + """ \ --pkg gio-2.0 \ --pkg cairo \@@ -197,6 +199,7 @@ def make_birdfont_import(target_binary, deps): """ + config.VALACFLAGS.get("birdfont-import", "") + """ \ birdfont-import/*.vala \ --vapidir=./ \+ --pkg svgbirdpoint \ --pkg """ + config.GEE + """ \ --pkg gio-2.0 \ --pkg cairo \@@ -252,6 +255,7 @@ def make_birdfont_autotrace(target_binary, deps): """ + config.VALACFLAGS.get("birdfont-autotrace", "") + """ \ birdfont-autotrace/*.vala \ --vapidir=./ \+ --pkg svgbirdpoint \ --pkg """ + config.GEE + """ \ --pkg gio-2.0 \ --pkg cairo \@@ -314,6 +318,7 @@ def make_libbirdfont(target_binary, deps): libbirdfont/OpenFontFormat/*.vala \ libbirdfont/TextRendering/*.vala \ --pkg posix \+ --pkg svgbirdpoint \ --pkg """ + config.GEE + """ \ --pkg gio-2.0 \ --pkg cairo \@@ -382,6 +387,7 @@ def make_libsvgbird(target_binary, deps): -H build/libsvgbird/svgbird.h \ libsvgbird/*.vala \ --pkg posix \+ --pkg svgbirdpoint \ --pkg """ + config.GEE + """ \ --pkg gio-2.0 \ --pkg cairo \@@ -532,6 +538,7 @@ def make_birdfont_test(target_binary, deps): --enable-experimental \ birdfont-test/*.vala \ --vapidir=./ \+ --pkg svgbirdpoint \ --pkg """ + config.GEE + """ \ --pkg gio-2.0 \ --pkg cairo \@@ -221,8 +221,8 @@ public class SvgParser { } private PathList parse_svg_tag (XmlElement tag, Layer pl) {- double width = 1;- double height = 1;+ double width = 0;+ double height = 0; foreach (Attribute attribute in tag.get_attributes ()) { if (attribute.get_name () == "width") {@@ -283,17 +283,8 @@ public class SvgParser { if (box != null) { ViewBox view_box = (!) box; Cairo.Matrix matrix = Cairo.Matrix.identity ();- //- double x = 0;- double y = 0;- to_svg_coordinate (ref x, ref y);- - //matrix.translate (x, y);- Cairo.Matrix view_box_matrix = view_box.get_matrix (width, height); view_box_matrix.multiply (view_box_matrix, matrix);- - //view_box_matrix.scale (1, -1); SvgTransform t = new SvgTransform.for_matrix (view_box_matrix); transform (t.get_xml (), pl); }@@ -1157,12 +1148,99 @@ public class SvgParser { if (format == SvgFormat.ILLUSTRATOR) { path_list = create_paths_illustrator (bezier_points, points); } else {- path_list = create_paths_inkscape (bezier_points, points);+ path_list = create_svg_paths_inkscape (d); } // TODO: Find out if it is possible to tie handles. return path_list; }+ + public PathList create_svg_paths_inkscape (string path_data) {+ Gee.ArrayList<Points> points_set = SvgFile.parse_points (path_data);+ PathList path_list = new PathList ();+ + foreach (Points p in points_set) {+ Path path = new Path ();+ + PointValue* points = p.point_data.data;+ EditPoint next = new EditPoint (p.x, -p.y, PointType.CUBIC);+ EditPointHandle handle;++ if (p.size % 8 != 0) {+ warning ("Points not padded.");+ return path_list;+ }+ + path.add_point (next);+ + for (int i = 0; i < p.size; i += 8) {+ + switch (points[i].type) {+ case POINT_ARC:+ /*+ draw_arc (cr, , points[i + 2].value,+ points[i + 3].value, points[i + 4].value,+ points[i + 5].value, points[i + 6].value,+ points[i + 7].value);+ */+ break;+ case POINT_CUBIC:+ handle = next.get_right_handle ();+ handle.x = points[i + 1].value;+ handle.y = -points[i + 2].value;+ handle.type = PointType.CUBIC;+ + next = new EditPoint (points[i + 5].value, -points[i + 6].value, PointType.CUBIC);+ path.add_point (next);+ + handle = next.get_left_handle ();+ handle.x = points[i + 3].value;+ handle.y = -points[i + 4].value;+ handle.type = PointType.CUBIC;++ handle = next.get_right_handle ();+ handle.x = p.x;+ handle.y = -p.y;+ handle.type = PointType.CUBIC;+ + break;+ case POINT_LINE:+ handle = next.get_right_handle ();+ handle.type = PointType.LINE_CUBIC;+ + next = new EditPoint (points[i + 1].value, -points[i + 2].value, PointType.CUBIC);+ path.add_point (next);+ + handle = next.get_left_handle ();+ handle.type = PointType.LINE_CUBIC;+ + break;+ }+ }+ + if (p.closed) {+ path.close ();+ path.get_first_point ().color = Color.blue ();+ path.get_last_point ().color = Color.green ();+ }++ Font font = BirdFont.get_current_font ();+ Glyph glyph = MainWindow.get_current_glyph ();+ + foreach (EditPoint e in path.points) {+ e.independent_x += glyph.left_limit;+ e.independent_y += font.top_limit;+ e.get_right_handle ().independent_x += glyph.left_limit;+ e.get_right_handle ().independent_y += font.top_limit;+ e.get_left_handle ().independent_x += glyph.left_limit;+ e.get_left_handle ().independent_y += font.top_limit; + }+ + path_list.add (path);+ }+ + return path_list;+ } void to_svg_coordinate (ref double x, ref double y) { Font font = BirdFont.get_current_font ();@@ -107,7 +107,7 @@ public class Layer : Object { } else { sublayer.draw_outline (cr); }- } else {+ } else if (object.visible) { object.apply_transform (cr); object.draw_outline (cr); @@ -113,6 +113,7 @@ public abstract class Object : GLib.Object { to.top = from.top; to.bottom = from.bottom; + to.visible = from.visible; to.style = from.style.copy (); to.transforms = from.transforms.copy (); @@ -127,8 +128,8 @@ public abstract class Object : GLib.Object { public void paint (Context cr) { Color fill, stroke;- bool need_fill = style.fill_gradient != null || style.fill != null;- bool need_stroke = style.stroke_gradient != null || style.stroke != null;+ bool need_fill = (style.fill_gradient != null || style.fill != null);+ bool need_stroke = (style.stroke_gradient != null || style.stroke != null); cr.set_line_width (style.stroke_width); @@ -14,12 +14,6 @@ namespace SvgBird { -[CCode (cheader_filename="point_value.h")]-public extern struct PointValue {- uchar type;- double value;-}- public static const uchar POINT_NONE = 0; public static const uchar POINT_ARC = 1; public static const uchar POINT_CUBIC = 2;@@ -436,7 +436,7 @@ public class SvgFile : GLib.Object { object.clip_path = get_clip_path (attributes); object.transforms = get_transform (attributes); object.style = SvgStyle.parse (drawing.defs, parent_style, tag, null);- object.visible = is_visible (tag); // FIXME: add style fill none+ object.visible = is_visible (tag); } ClipPath? get_clip_path (Attributes attributes) {@@ -773,7 +773,7 @@ public class SvgFile : GLib.Object { layer.add_object (path); } - public Gee.ArrayList<Points> parse_points (string data) {+ public static Gee.ArrayList<Points> parse_points (string data) { Gee.ArrayList<Points> path_data = new Gee.ArrayList<Points> (); Points points = new Points (); BezierPoints[] bezier_points;@@ -14,8 +14,13 @@ #include<glib.h> +#ifndef __SVGBIRD_POINT_VALUE_H__+#define __SVGBIRD_POINT_VALUE_H__+ typedef union { gdouble value; guchar type; } SvgBirdPointValue; +#endif+