The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

SVG boundaries for ellipses

These changes was commited to the Birdfont repository Wed, 15 Jun 2016 13:15:26 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Wed, 15 Jun 2016 13:15:26 +0000 (15:15 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Wed, 15 Jun 2016 13:15:26 +0000 (15:15 +0200)
commit 2f772845a024ac45eb528a4e3bc241e87c1ab8e0
tree 7bff04e9a9b22157c8333c7bc40cc8d85427db49
parent 47fa1bc857f78392c77814939c3b58cf8b3c2790
SVG boundaries for ellipses

libbirdfont/EmbeddedSvg.vala
libbirdfont/Glyph.vala
libbirdfont/MoveTool.vala
libsvgbird/Ellipse.vala
libsvgbird/Layer.vala
libsvgbird/Object.vala
libsvgbird/SvgDrawing.vala
--- a/libbirdfont/EmbeddedSvg.vala +++ b/libbirdfont/EmbeddedSvg.vala @@ -26,42 +26,42 @@ 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 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) {
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -2459,7 +2459,10 @@ 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 @@ 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; }
--- a/libbirdfont/MoveTool.vala +++ b/libbirdfont/MoveTool.vala @@ -343,7 +343,7 @@ 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) {
--- a/libsvgbird/Ellipse.vala +++ b/libsvgbird/Ellipse.vala @@ -23,7 +23,43 @@ 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 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;
--- a/libsvgbird/Layer.vala +++ b/libsvgbird/Layer.vala @@ -29,6 +29,40 @@ this.name = name; objects = new ObjectGroup (); 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) { @@ -81,14 +115,17 @@ 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 @@ sublayer.remove_layer (layer); } } + + update_boundaries (); } public static void copy_layer (Layer from, Layer to) {
--- a/libsvgbird/Object.vala +++ b/libsvgbird/Object.vala @@ -72,29 +72,33 @@ 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,8 +230,10 @@ object_matrix.multiply (object_matrix, view_matrix); cr.set_matrix (object_matrix); } - + + public virtual void update_boundaries () { + } } }
--- a/libsvgbird/SvgDrawing.vala +++ b/libsvgbird/SvgDrawing.vala @@ -51,7 +51,7 @@ public override double left { get { - return x; + return root_layer.left; } set { @@ -60,7 +60,7 @@ public override double right { get { - return x + width; + return root_layer.right; } set { @@ -69,7 +69,7 @@ public override double top { get { - return y; + return root_layer.top; } set { @@ -78,7 +78,7 @@ public override double bottom { get { - return y + height; + return root_layer.bottom; } set {