Commit c8bb2a0
Update layer copy code for the new SVG backend
Changed files (9)
modifiedlibbirdfont/EmbeddedSvg.valamodifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/LayerLabel.valamodifiedlibbirdfont/Path.valamodifiedlibsvgbird/ClipPath.valamodifiedlibsvgbird/Layer.valamodifiedlibsvgbird/Object.valamodifiedlibsvgbird/SvgTransform.valamodifiedlibsvgbird/SvgTransforms.vala
Diff
@@ -86,12 +86,6 @@ public class EmbeddedSvg : SvgBird.Object { 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) { x += dx; y += dy;@@ -109,6 +103,19 @@ public class EmbeddedSvg : SvgBird.Object { 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";+ } } }@@ -131,7 +131,7 @@ public class Glyph : FontDisplay { 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 @@ public class Glyph : FontDisplay { 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 () {@@ -1814,11 +1820,45 @@ public class Glyph : FontDisplay { 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);+ }+ }+ }+ }+ public void store_redo_state () { Glyph g = copy (); redo_list.add (g);@@ -1911,8 +1951,12 @@ public class Glyph : FontDisplay { 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; @@ -54,6 +54,10 @@ public class LayerLabel : Tool { 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 ();@@ -839,8 +839,6 @@ public class Path : GLib.Object { int insides = 0; Path path; - print (@"is_over_coordinate_var stroke: $stroke\n");- if (stroke > 0) { foreach (Path p in get_stroke_fast ().paths) { path = p.flatten ();@@ -33,6 +33,11 @@ public class ClipPath : GLib.Object { layer.draw_outline (cr); cr.clip (); }+ + public ClipPath copy () {+ ClipPath path = new ClipPath (layer);+ return path;+ } } }@@ -25,6 +25,12 @@ public class Layer : Object { 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 @@ public class Layer : Object { Layer layer = new Layer (); copy_layer (this, layer); Object.copy_attributes (this, layer);+ stdout.printf (@"Copy $name\n"); return layer; } @@ -153,7 +160,6 @@ public class Layer : Object { } } - public override bool is_over (double x, double y) { return false; }@@ -70,9 +70,23 @@ public abstract class Object : GLib.Object { 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 @@ public abstract class Object : GLib.Object { 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 () {@@ -31,6 +31,13 @@ public class SvgTransform : GLib.Object { public SvgTransform () { } + public SvgTransform copy () {+ SvgTransform transform = new SvgTransform ();+ transform.type = type;+ transform.arguments = arguments.copy ();+ return transform;+ }+ public string to_string () { StringBuilder sb = new StringBuilder (); @@ -23,6 +23,16 @@ public class SvgTransforms : GLib.Object { 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) { transforms.add (transform); }