Clone in a terminal:
Commit 75716ee
Johan Mattsson - 2016-01-11T12:00:17+00:00
75716ee5fa3ea7c33f9d80aa6d85e66fd4b1ed68johan.mattsson.m@gmail.com

SVG polyline

Changed files (3)

Diff

diff --git a/libsvgbird/Doubles.vala b/libsvgbird/Doubles.valaindex 43e896e..a4b1c35 100644--- a/libsvgbird/Doubles.vala+++ b/libsvgbird/Doubles.vala@@ -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");diff --git a/libsvgbird/Polyline.vala b/libsvgbird/Polyline.valanew file mode 100644index 0000000..89a2e86--- /dev/null+++ b/libsvgbird/Polyline.vala@@ -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";+	}+}++}diff --git a/libsvgbird/SvgFile.vala b/libsvgbird/SvgFile.valaindex 0f66561..3999b95 100644--- a/libsvgbird/SvgFile.vala+++ b/libsvgbird/SvgFile.vala@@ -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) {

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112