Commit 75716ee
SVG polyline
Changed files (3)
Diff
@@ -49,6 +49,16 @@ public class Doubles : GLib.Object { 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) { if (unlikely (index < 0)) { warning ("index < 0");new file mode 100644@@ -0,0 +1,75 @@+/*+ 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";+ }+}++}@@ -258,6 +258,24 @@ public class SvgFile : GLib.Object { } 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) {