Clone in a terminal:
Commit 8d55932
Johan Mattsson - 2016-07-07T21:44:56+00:00
8d559323efd1c2e38338700bff65f4ddb6b9c46ejohan.mattsson.m@gmail.com

Apply style without creating a tag

Changed files (8)

Diff

diff --git a/libbirdfont/CircleTool.vala b/libbirdfont/CircleTool.valaindex 656b4f6..0cb8434 100644--- a/libbirdfont/CircleTool.vala+++ b/libbirdfont/CircleTool.vala@@ -184,8 +184,8 @@ public class CircleTool : Tool { 		 		glyph.store_undo_state (); 		-		double px =  Glyph.path_coordinate_x (x);-		double py =  Glyph.path_coordinate_y (y);+		double px = Glyph.path_coordinate_x (x);+		double py = Glyph.path_coordinate_y (y); 		 		path = create_circle (px, py, 2, DrawingTools.point_type); diff --git a/libbirdfont/SvgParser.vala b/libbirdfont/SvgParser.valaindex 2538ad4..b950d49 100644--- a/libbirdfont/SvgParser.vala+++ b/libbirdfont/SvgParser.vala@@ -1263,74 +1263,6 @@ public class SvgParser { 			} 		} 	}-	-	void find_last_handle (int start_index, BezierPoints[] b, int num_b, out double left_x, out double left_y, out PointType last_type) {-		BezierPoints last = new BezierPoints ();-		bool found = false;-		-		left_x = 0;-		left_y = 0;-		last_type = PointType.NONE;-		-		return_if_fail (b.length != 0);-		return_if_fail (b[0].type != 'z');-		return_if_fail (num_b < b.length);--		if (num_b == 2) {-			left_x = b[0].x0 + (b[1].x0 - b[0].x0) / 3.0;-			left_y = b[0].y0 + (b[1].y0 - b[0].y0) / 3.0;-			last_type = PointType.LINE_CUBIC;-			return;-		}-		-		for (int i = start_index; i < num_b; i++) {-			switch (b[i].type) {-				case 'Q':-					break;-				case 'C':-					break;-				case 'z':-					found = true;-					break;-				default:-					break;-			}-			-			if (found || i + 1 == num_b) {-				-				return_if_fail (i >= 1);-				-				if (b[i - 1].type == 'Q') {-					return_if_fail (i >= 1);-					left_x = b[i - 1].x0;-					left_y = b[i - 1].y0;-					last_type = PointType.QUADRATIC;-				} else if (b[i - 1].type == 'C') {-					return_if_fail (i >= 1);-					left_x = b[i - 1].x1;-					left_y = b[i - 1].y1;-					last_type = PointType.CUBIC;-				} else if (b[i - 1].type == 'S') {-					return_if_fail (i >= 1);-					left_x = b[i - 1].x1;-					left_y = b[i - 1].y1;-					last_type = PointType.CUBIC;-				} else if (b[i - 1].type == 'L' || last.type == 'M') {-					return_if_fail (i >= 2); // FIXME: -2 can be C or L-					left_x = b[i - 2].x0 + (b[i - 1].x0 - b[i - 2].x0) / 3.0;-					left_y = b[i - 2].y0 + (b[i - 1].y0 - b[i - 2].y0) / 3.0;-					last_type = PointType.LINE_CUBIC;-				} else {-					warning (@"Unexpected type. $(b[i - 1])\n");-				}-				return;	-			}-			-			last = b[i];-		}-		-		warning ("Last point not found.");-	}  	public static double parse_double (string? s) { 		if (unlikely (is_null (s))) {diff --git a/libsvgbird/Layer.vala b/libsvgbird/Layer.valaindex 19fe358..665f32f 100644--- a/libsvgbird/Layer.vala+++ b/libsvgbird/Layer.vala@@ -53,9 +53,11 @@ public class Layer : Object {  			if (object is Layer) { 				Layer sublayer = (Layer) object;+				object.view_matrix = cr.get_matrix (); 				has_size = sublayer.update_boundaries (cr); 			} else { 				object.apply_transform (cr);+				object.view_matrix = cr.get_matrix (); 				has_size = object.update_boundaries (cr); 			} 			diff --git a/libsvgbird/Object.vala b/libsvgbird/Object.valaindex e71fdc5..90e279e 100644--- a/libsvgbird/Object.vala+++ b/libsvgbird/Object.vala@@ -100,6 +100,8 @@ public abstract class Object : GLib.Object { 	public abstract bool is_empty (); 	public abstract void move (double dx, double dy); 	+	public Matrix view_matrix = Matrix.identity ();+	 	public virtual void move_bounding_box (double dx, double dy) { 		top += dy; 		bottom += dy;@@ -234,6 +236,10 @@ public abstract class Object : GLib.Object { 		return boundaries_width != 0; 	} +	public Matrix get_view_matrix () {+		return view_matrix;+	}+ 	public virtual bool update_boundaries_for_object () { 		ImageSurface surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1); 		Context context = new Cairo.Context (surface);diff --git a/libsvgbird/Points.vala b/libsvgbird/Points.valaindex 4f394f5..eb48c4c 100644--- a/libsvgbird/Points.vala+++ b/libsvgbird/Points.vala@@ -43,6 +43,14 @@ public class Points : GLib.Object { 		p.closed = closed; 		return p; 	}++	public double get_double (int index) {+		return point_data.get_double (index);+	}++	public uchar get_point_type (int index) {+		return point_data.get_point_type (index);+	} }  }diff --git a/libsvgbird/StyleSheet.vala b/libsvgbird/StyleSheet.valaindex fdac481..bbf1d3c 100644--- a/libsvgbird/StyleSheet.vala+++ b/libsvgbird/StyleSheet.vala@@ -47,19 +47,20 @@ public class StyleSheet : GLib.Object { 		return style_sheet; 	} 	-	public void apply_style (XmlElement tag, SvgStyle style, string? pseudo_class) {-		string? id = null;-		string? css_class = null;-		-		foreach (Attribute attribute in tag.get_attributes ()) {-			string name = attribute.get_name ();+	public SvgStyle get_style (string tag_name, string? css_class = null,+		string? id = null, string? pseudo_class = null) { 			-			if (name == "id") {-				id = attribute.get_content ();-			} else if (name == "class") {-				css_class = attribute.get_content ();-			}+		SvgStyle style = new SvgStyle ();++		string xml = @"<$(tag_name) />";+		XmlTree xml_component = new XmlTree (xml);	+		+		if (!xml_component.validate ()) {+			warning (@"Bad tag: $xml");+			warning (xml); 		}+		+		XmlElement tag = xml_component.get_root ();  		foreach (Selector selector in styles) { 			if (selector.match_tag (tag, id, css_class, pseudo_class)) {@@ -92,6 +93,37 @@ public class StyleSheet : GLib.Object { 		} 		 		SvgStyle.set_style_properties (null, style);+		+		return style;+	}+	+	public void apply_style (XmlElement tag, SvgStyle style, string? pseudo_class) {+		string? id = null;+		string? css_class = null;+		string tag_name = tag.get_name ();+		+		if (tag.get_name () == "") {+			warning ("No tag name provided.");+			+			if (pseudo_class != null) {+				warning ((!) pseudo_class);+			}+			return;+		}+		+		foreach (Attribute attribute in tag.get_attributes ()) {+			string name = attribute.get_name ();+			+			if (name == "id") {+				id = attribute.get_content ();+			} else if (name == "class") {+				css_class = attribute.get_content ();+			}+		}++		SvgStyle new_style = get_style (tag_name, css_class, id, pseudo_class);+		style.apply (new_style);+		SvgStyle.set_style_properties (null, style); 	} 	 	public void merge (StyleSheet style_sheet) {diff --git a/libsvgbird/SvgFile.vala b/libsvgbird/SvgFile.valaindex 418383b..e3293b6 100644--- a/libsvgbird/SvgFile.vala+++ b/libsvgbird/SvgFile.vala@@ -796,12 +796,9 @@ public class SvgFile : GLib.Object { 		 		get_bezier_points (data, out bezier_points, out points_size, true); -		print (@"format $format\n");-	 		// all instructions are padded  		for (int i = 0; i < points_size; i++) {-			print (@"$(bezier_points[i])\n"); 			// FIXME: add more types 			if (bezier_points[i].type == 'M') { 				if (i == 0) {diff --git a/libsvgbird/SvgStyle.vala b/libsvgbird/SvgStyle.valaindex 6ab7b2f..6b3d44c 100644--- a/libsvgbird/SvgStyle.vala+++ b/libsvgbird/SvgStyle.vala@@ -108,6 +108,16 @@ public class SvgStyle : GLib.Object { 		return style.get (p); 	} 	+	public double get_double_property (string property) {+		string p = property.down ();+		+		if (!has_css_property (p)) {+			return 0;+		}+		+		return SvgFile.parse_number (style.get (p));+	}+	 	public static bool is_inherited (string property) { 		inheritance_mutex.lock (); 		if (unlikely (inheritance == null)) {

Contact

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