The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Update layer copy code for the new SVG backend

These changes was commited to the Birdfont repository Sat, 14 May 2016 10:54:35 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Sat, 14 May 2016 10:54:35 +0000]

Updated Files

libbirdfont/EmbeddedSvg.vala
libbirdfont/Glyph.vala
libbirdfont/LayerLabel.vala
libbirdfont/Path.vala
libsvgbird/ClipPath.vala
libsvgbird/Layer.vala
libsvgbird/Object.vala
libsvgbird/SvgTransform.vala
libsvgbird/SvgTransforms.vala
--- a/libbirdfont/EmbeddedSvg.vala +++ b/libbirdfont/EmbeddedSvg.vala @@ -84,12 +84,6 @@ } public override void draw_outline (Context cr) { - } - - public override SvgBird.Object copy () { - EmbeddedSvg svg = new EmbeddedSvg (drawing); - svg.svg_data = svg_data; - return svg; } public override void move (double dx, double dy) { @@ -109,7 +103,20 @@ drawing.resize (ratio_x, ratio_y); } + public override SvgBird.Object copy () { + EmbeddedSvg svg = new EmbeddedSvg ((SvgDrawing) drawing.copy ()); + + svg.svg_data = svg_data; + svg.x = x; + svg.y = y; + + return svg; + } + + public override string to_string () { + return "Embedded SVG"; + } } }
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -131,7 +131,7 @@ public static bool show_orientation_arrow = false; public static double orientation_arrow_opacity = 1; - public Layer layers = new Layer (); + public Layer layers = new Layer.with_name ("Root"); public int current_layer = 0; public Gee.ArrayList<SvgBird.Object> active_paths = new Gee.ArrayList<SvgBird.Object> (); @@ -546,6 +546,12 @@ DrawingTools.update_layers (); MainWindow.get_toolbox ().update_expanders (); + + print(@"PRECOPY $(name)\n"); + print_layers (layers); + // layers = (Layer) layers.copy (); // FIXME: DELETE + print("\n"); + print_layers (layers); } void update_zoom_bar () { @@ -1813,9 +1819,43 @@ public void store_undo_state (bool clear_redo = false) { Glyph g = copy (); undo_list.add (g); + + print ("\n\n"); + print_layers (g.layers); if (clear_redo) { redo_list.clear (); + } + } + + public void print_layers (Layer layer, int indent = 0) { + stdout.printf (@"Layer ($indent): $(layer.name)"); + + if (!layer.visible) { + stdout.printf (" hidden"); + } + + stdout.printf (@" $(layer.transforms) $(layer.style)"); + stdout.printf (@"\n"); + + foreach (SvgBird.Object object in layer.objects) { + if (object is Layer) { + Layer sublayer = (Layer) object; + print_layers (sublayer, indent + 1); + } else { + stdout.printf (@"$(object.to_string ()) $(object.transforms) $(object.style)"); + + if (!object.visible) { + stdout.printf (" hidden"); + } + + stdout.printf ("\n"); + + if (object is EmbeddedSvg) { + EmbeddedSvg embedded = (EmbeddedSvg) object; + print_layers (embedded.drawing.root_layer, indent + 1); + } + } } } @@ -1911,7 +1951,11 @@ void set_glyph_data (Glyph g) { current_layer = g.current_layer; + layers = (Layer) g.layers.copy (); + + print ("\n\n"); + print_layers (g.layers); left_limit = g.left_limit; right_limit = g.right_limit;
--- a/libbirdfont/LayerLabel.vala +++ b/libbirdfont/LayerLabel.vala @@ -54,6 +54,10 @@ GlyphCanvas.redraw (); BirdFont.get_current_font ().touch (); MainWindow.get_current_glyph ().clear_active_paths (); + + Glyph g = MainWindow.get_current_glyph (); + print ("\n\n"); + g.print_layers (g.layers); } else { active_layer = true; select_layer ();
--- a/libbirdfont/Path.vala +++ b/libbirdfont/Path.vala @@ -838,8 +838,6 @@ public bool is_over_coordinate (double x, double y) { int insides = 0; Path path; - - print (@"is_over_coordinate_var stroke: $stroke\n"); if (stroke > 0) { foreach (Path p in get_stroke_fast ().paths) {
--- a/libsvgbird/ClipPath.vala +++ b/libsvgbird/ClipPath.vala @@ -32,8 +32,13 @@ public void apply (Context cr) { layer.draw_outline (cr); cr.clip (); + } + + public ClipPath copy () { + ClipPath path = new ClipPath (layer); + return path; } } }
--- a/libsvgbird/Layer.vala +++ b/libsvgbird/Layer.vala @@ -25,6 +25,12 @@ transforms = new SvgTransforms (); } + public Layer.with_name (string name) { + this.name = name; + objects = new ObjectGroup (); + transforms = new SvgTransforms (); + } + public void draw (Context cr) { cr.save (); apply_transform (cr); @@ -105,6 +111,7 @@ Layer layer = new Layer (); copy_layer (this, layer); Object.copy_attributes (this, layer); + stdout.printf (@"Copy $name\n"); return layer; } @@ -152,7 +159,6 @@ } } } - public override bool is_over (double x, double y) { return false;
--- a/libsvgbird/Object.vala +++ b/libsvgbird/Object.vala @@ -70,9 +70,23 @@ public static void copy_attributes (Object from, Object to) { to.open = from.open; - to.color = from.color; - to.stroke_color = from.stroke_color; - to.gradient = from.gradient; + if (from.color != null) { + to.color = ((!) from.color).copy (); + } else { + to.color = null; + } + + if (from.stroke_color != null) { + to.stroke_color = ((!) from.stroke_color).copy (); + } else { + to.stroke_color = null; + } + + if (to.gradient != null) { + to.gradient = ((!) from.gradient).copy (); + } else { + to.gradient = null; + } to.xmax = from.xmax; to.xmin = from.xmin; @@ -82,7 +96,14 @@ to.rotation = from.rotation; to.stroke = from.stroke; to.line_cap = from.line_cap; - to.fill = from.fill; + to.fill = from.fill; + + to.style = from.style.copy (); + to.transforms = from.transforms.copy (); + + if (from.clip_path != null) { + to.clip_path = ((!) from.clip_path).copy (); + } } public virtual string to_string () {
--- a/libsvgbird/SvgTransform.vala +++ b/libsvgbird/SvgTransform.vala @@ -29,6 +29,13 @@ public Doubles arguments = new Doubles.for_capacity (10); public SvgTransform () { + } + + public SvgTransform copy () { + SvgTransform transform = new SvgTransform (); + transform.type = type; + transform.arguments = arguments.copy (); + return transform; } public string to_string () {
--- a/libsvgbird/SvgTransforms.vala +++ b/libsvgbird/SvgTransforms.vala @@ -21,6 +21,16 @@ public SvgTransforms () { transforms = new Gee.ArrayList<SvgTransform> (); + } + + public SvgTransforms copy () { + SvgTransforms copy_transforms = new SvgTransforms (); + + foreach (SvgTransform t in transforms) { + copy_transforms.add (t.copy ()); + } + + return copy_transforms; } public void add (SvgTransform transform) {