The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

SVG polygon

These changes was commited to the Birdfont repository Mon, 11 Jan 2016 12:25:07 +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>
Mon, 11 Jan 2016 12:25:07 +0000 (13:25 +0100)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Mon, 11 Jan 2016 12:25:07 +0000 (13:25 +0100)
commit 4431915b0597afe81bdef75bdae99aa45c30582e
tree 44de6211cd8555437b8640678d019e42049b18a0
parent 75716ee5fa3ea7c33f9d80aa6d85e66fd4b1ed68
SVG polygon

libsvgbird/Polygon.vala [new ]
libsvgbird/SvgFile.vala
diff --git libsvgbird/Polygon.vala(new)
--- /dev/null +++ b/libsvgbird/Polygon.vala @@ -1,1 +1,78 @@ + /* + Copyright (C) 2016 Johan Mattsson + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + */ + + using Cairo; + using Math; + + namespace SvgBird { + + public class Polygon : Object { + + public Doubles points = new Doubles (); + + public Polygon () { + } + + public override bool is_over (double x, double y) { + return false; + } + + public override void draw (Context cr) { + cr.save (); + apply_transform (cr); + + if (points.size > 2) { + cr.move_to (points.data[0], points.data[1]); + + for (int i = 2; i < points.size - 1; i += 2) { + cr.line_to (points.data[i], points.data[i + 1]); + } + + cr.close_path (); + } + + paint (cr); + cr.restore (); + } + + public override void move (double dx, double dy) { + } + + public override void update_region_boundaries () { + } + + public override void rotate (double theta, double xc, double yc) { + } + + public override bool is_empty () { + return false; + } + + public override void resize (double ratio_x, double ratio_y) { + } + + public override Object copy () { + Polygon p = new Polygon (); + p.points = points.copy (); + Object.copy_attributes (this, p); + return p; + } + + public override string to_string () { + return "Polygon"; + } + } + + }
--- a/libsvgbird/SvgFile.vala +++ b/libsvgbird/SvgFile.vala @@ -255,6 +255,25 @@ } private void parse_polygon (Layer layer, SvgStyle parent_style, Tag tag) { + Polygon polygon = new Polygon (); + + foreach (Attribute attr in tag.get_attributes ()) { + if (attr.get_name () == "points") { + string data = add_separators (attr.get_content ()); + string[] point_data = data.split (" "); + + foreach (string number in point_data) { + polygon.points.add (parse_number (number)); + } + } + } + + polygon.transforms = get_transform (tag.get_attributes ()); + polygon.style = SvgStyle.parse (drawing.defs, parent_style, tag.get_attributes ()); + polygon.visible = is_visible (tag); + + layer.add_object (polygon); + } private void parse_polyline (Layer layer, SvgStyle parent_style, Tag tag) {