The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

SVG polyline

These changes was commited to the Birdfont repository Mon, 11 Jan 2016 12:00:17 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Mon, 11 Jan 2016 12:00:17 +0000]

Updated Files

libsvgbird/Doubles.vala
libsvgbird/Polyline.vala
libsvgbird/SvgFile.vala
--- a/libsvgbird/Doubles.vala +++ b/libsvgbird/Doubles.vala @@ -47,6 +47,16 @@ data[size] = d; size++; + } + + public Doubles copy () { + Doubles d = new Doubles (); + delete d.data; + d.data = new double[capacity]; + d.capacity = capacity; + d.size = size; + Posix.memcpy (d.data, data, sizeof (double) * size); + return d; } public double get_double (int index) {
diff --git libsvgbird/Polyline.vala(new)
--- /dev/null +++ b/libsvgbird/Polyline.vala @@ -1,1 +1,76 @@ + /* + 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 Polyline : Object { + + public Doubles points = new Doubles (); + + public Polyline () { + } + + 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]); + } + } + + 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 () { + Polyline p = new Polyline (); + p.points = points.copy (); + Object.copy_attributes (this, p); + return p; + } + + public override string to_string () { + return "Polyline"; + } + } + + }
--- a/libsvgbird/SvgFile.vala +++ b/libsvgbird/SvgFile.vala @@ -258,6 +258,24 @@ } private void parse_polyline (Layer layer, SvgStyle parent_style, Tag tag) { + Polyline polyline = new Polyline (); + + 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) { + polyline.points.add (parse_number (number)); + } + } + } + + polyline.transforms = get_transform (tag.get_attributes ()); + polyline.style = SvgStyle.parse (drawing.defs, parent_style, tag.get_attributes ()); + polyline.visible = is_visible (tag); + + layer.add_object (polyline); } private void parse_rect (Layer layer, SvgStyle parent_style, Tag tag) {