Clone in a terminal:
Commit 4431915
Johan Mattsson - 2016-01-11T12:25:07+00:00
4431915b0597afe81bdef75bdae99aa45c30582ejohan.mattsson.m@gmail.com

SVG polygon

Changed files (2)

Diff

diff --git a/libsvgbird/Polygon.vala b/libsvgbird/Polygon.valanew file mode 100644index 0000000..dd82120--- /dev/null+++ b/libsvgbird/Polygon.vala@@ -0,0 +1,77 @@+/*+	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";+	}+}++}diff --git a/libsvgbird/SvgFile.vala b/libsvgbird/SvgFile.valaindex 3999b95..42bee53 100644--- a/libsvgbird/SvgFile.vala+++ b/libsvgbird/SvgFile.vala@@ -255,6 +255,25 @@ public class SvgFile : GLib.Object { 	}  	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) {

Contact

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