Updated Files
dodo.py |
libbirdfont/SvgParser.vala |
libsvgbird/Layer.vala |
libsvgbird/Object.vala |
libsvgbird/PointValue.vala |
libsvgbird/SvgFile.vala |
libsvgbird/point_value.h |
--- a/dodo.py
+++ b/dodo.py
@@ -77,6 +77,7 @@
--enable-experimental \
birdfont/*.vala \
--vapidir=./ \
+ --pkg svgbirdpoint \
--pkg """ + config.GEE + """ \
--pkg gio-2.0 \
--pkg cairo \
@@ -141,6 +142,7 @@
""" + config.VALACFLAGS.get("birdfont-export", "") + """ \
birdfont-export/*.vala \
--vapidir=./ \
+ --pkg svgbirdpoint \
--pkg """ + config.GEE + """ \
--pkg gio-2.0 \
--pkg cairo \
@@ -197,6 +199,7 @@
""" + config.VALACFLAGS.get("birdfont-import", "") + """ \
birdfont-import/*.vala \
--vapidir=./ \
+ --pkg svgbirdpoint \
--pkg """ + config.GEE + """ \
--pkg gio-2.0 \
--pkg cairo \
@@ -252,6 +255,7 @@
""" + config.VALACFLAGS.get("birdfont-autotrace", "") + """ \
birdfont-autotrace/*.vala \
--vapidir=./ \
+ --pkg svgbirdpoint \
--pkg """ + config.GEE + """ \
--pkg gio-2.0 \
--pkg cairo \
@@ -314,6 +318,7 @@
libbirdfont/OpenFontFormat/*.vala \
libbirdfont/TextRendering/*.vala \
--pkg posix \
+ --pkg svgbirdpoint \
--pkg """ + config.GEE + """ \
--pkg gio-2.0 \
--pkg cairo \
@@ -382,6 +387,7 @@
-H build/libsvgbird/svgbird.h \
libsvgbird/*.vala \
--pkg posix \
+ --pkg svgbirdpoint \
--pkg """ + config.GEE + """ \
--pkg gio-2.0 \
--pkg cairo \
@@ -532,6 +538,7 @@
--enable-experimental \
birdfont-test/*.vala \
--vapidir=./ \
+ --pkg svgbirdpoint \
--pkg """ + config.GEE + """ \
--pkg gio-2.0 \
--pkg cairo \
--- a/libbirdfont/SvgParser.vala
+++ b/libbirdfont/SvgParser.vala
@@ -221,8 +221,8 @@
}
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 @@
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,10 +1148,97 @@
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;
}
--- a/libsvgbird/Layer.vala
+++ b/libsvgbird/Layer.vala
@@ -107,7 +107,7 @@
} else {
sublayer.draw_outline (cr);
}
- } else {
+ } else if (object.visible) {
object.apply_transform (cr);
object.draw_outline (cr);
--- a/libsvgbird/Object.vala
+++ b/libsvgbird/Object.vala
@@ -113,6 +113,7 @@
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 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);
--- a/libsvgbird/PointValue.vala
+++ b/libsvgbird/PointValue.vala
@@ -13,12 +13,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;
--- a/libsvgbird/SvgFile.vala
+++ b/libsvgbird/SvgFile.vala
@@ -436,7 +436,7 @@
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 @@
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;
--- a/libsvgbird/point_value.h
+++ b/libsvgbird/point_value.h
@@ -13,10 +13,15 @@
*/
#include<glib.h>
+
+ #ifndef __SVGBIRD_POINT_VALUE_H__
+ #define __SVGBIRD_POINT_VALUE_H__
typedef union {
gdouble value;
guchar type;
} SvgBirdPointValue;
+
+ #endif