Commit 2f77284
SVG boundaries for ellipses
Changed files (7)
modifiedlibbirdfont/EmbeddedSvg.valamodifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/MoveTool.valamodifiedlibsvgbird/Ellipse.valamodifiedlibsvgbird/Layer.valamodifiedlibsvgbird/Object.valamodifiedlibsvgbird/SvgDrawing.vala
Diff
@@ -26,42 +26,42 @@ public class EmbeddedSvg : SvgBird.Object { public double x { get; set; } public double y { get; set; } - public override double left {+ public override double left { get {- return x;+ return x + drawing.left; } set { } }-- public override double right {+ + public override double right { get {- return x + drawing.width;+ return x + drawing.right; }-+ set { } }- + public override double top { get {- return y - drawing.height;+ return drawing.top - y; }-+ set { } } public override double bottom { get {- return y;+ return drawing.bottom - y; }-+ set { } }- + public EmbeddedSvg (SvgDrawing drawing) { this.drawing = drawing; }@@ -71,8 +71,8 @@ public class EmbeddedSvg : SvgBird.Object { } public override bool is_over (double x, double y) {- return (this.x <= x <= this.x + drawing.width) - && (this.y - drawing.height <= y <= this.y);+ return (xmin <= x <= xmax) + && (ymin <= y <= ymax); } public void draw_embedded_svg (Context cr) {@@ -2459,7 +2459,10 @@ public class Glyph : FontDisplay { return g2; } - // FIXME: convert everything to the new SvgBird.Object code+ public Gee.ArrayList<SvgBird.Object> get_active_objects () {+ return active_paths;+ }+ public Gee.ArrayList<Path> get_active_paths () { Gee.ArrayList<Path> paths = new Gee.ArrayList<Path> (); @@ -2567,7 +2570,7 @@ public class Glyph : FontDisplay { px2 = CANVAS_MIN; py2 = CANVAS_MIN; - foreach (Path p in get_active_paths ()) {+ foreach (SvgBird.Object p in get_active_objects ()) { if (px > p.xmin) { px = p.xmin; } @@ -343,7 +343,7 @@ public class MoveTool : Tool { PenTool.reset_stroke (); update_selection_boundaries (); objects_moved ();- glyph.redraw_area (0, 0, glyph.allocation.width, glyph.allocation.height);+ GlyphCanvas.redraw (); } static void tie_path_to_ttf_grid (SvgBird.Object p) {@@ -23,7 +23,43 @@ public class Ellipse : Object { public double cy = 0; public double rx = 0; public double ry = 0;++ public override double left {+ get {+ return cx - rx - style.stroke_width / 2;+ }+ + set {+ }+ }++ public override double right {+ get {+ return cx + rx + style.stroke_width / 2;+ }+ + set {+ }+ }+ + public override double top {+ get {+ return cy - ry - style.stroke_width / 2;+ }+ + set {+ }+ } + public override double bottom {+ get {+ return cy + ry + style.stroke_width / 2;+ }+ + set {+ }+ }+ public Ellipse () { } @@ -59,9 +95,6 @@ public class Ellipse : Object { public override Object copy () { Ellipse e = new Ellipse (); Object.copy_attributes (this, e);- - print (@"cy $(cy)\n");- e.cx = cx; e.cy = cy; e.rx = rx;@@ -31,6 +31,40 @@ public class Layer : Object { transforms = new SvgTransforms (); } + public void update_boundaries () {+ top = CANVAS_MAX;+ bottom = CANVAS_MIN;+ left = CANVAS_MAX;+ right = CANVAS_MIN;++ foreach (Object object in objects) {+ if (object is Layer) {+ Layer sublayer = (Layer) object;+ sublayer.update_boundaries ();+ }+ + if (object.boundaries_height > 0.000001 + && object.boundaries_width > 0.000001) {+ + if (object.top < top) {+ top = object.top;+ }++ if (object.bottom > bottom) {+ bottom = object.bottom;+ }+ + if (object.left < left) {+ left = object.left;+ }++ if (object.right > right) {+ right = object.right;+ }+ }+ }+ }+ public void draw (Context cr) { cr.save (); apply_transform (cr);@@ -81,14 +115,17 @@ public class Layer : Object { public void add_layer (Layer layer) { objects.add (layer);+ update_boundaries (); } public void add_object (Object object) { objects.add (object);+ update_boundaries (); } public void remove (Object o) { objects.remove (o);+ update_boundaries (); } public void remove_layer (Layer layer) {@@ -100,6 +137,8 @@ public class Layer : Object { sublayer.remove_layer (layer); } }+ + update_boundaries (); } public static void copy_layer (Layer from, Layer to) {@@ -72,29 +72,33 @@ public abstract class Object : GLib.Object { public double ymin { get {- return top - boundaries_height;+ return -top - boundaries_height; } set {- top = value + boundaries_height;+ top = boundaries_height - value; } } public double ymax { get {- return top;+ return -top; } set {- top = value;+ top = -value; } } + // FIXME: DELETE public virtual double rotation { get; set; } public virtual double stroke { get; set; } public virtual LineCap line_cap { get; set; default = LineCap.BUTT; } public virtual bool fill { get; set; }- + + public const double CANVAS_MAX = 100000;+ public const double CANVAS_MIN = -100000;+ public Object () { } @@ -226,7 +230,9 @@ public abstract class Object : GLib.Object { object_matrix.multiply (object_matrix, view_matrix); cr.set_matrix (object_matrix); }- + + public virtual void update_boundaries () { + } } }@@ -51,7 +51,7 @@ public class SvgDrawing : Object { public override double left { get {- return x;+ return root_layer.left; } set {@@ -60,7 +60,7 @@ public class SvgDrawing : Object { public override double right { get {- return x + width;+ return root_layer.right; } set {@@ -69,7 +69,7 @@ public class SvgDrawing : Object { public override double top { get {- return y;+ return root_layer.top; } set {@@ -78,7 +78,7 @@ public class SvgDrawing : Object { public override double bottom { get {- return y + height;+ return root_layer.bottom; } set {