Commit 8d55932
Apply style without creating a tag
Changed files (8)
modifiedlibbirdfont/CircleTool.valamodifiedlibbirdfont/SvgParser.valamodifiedlibsvgbird/Layer.valamodifiedlibsvgbird/Object.valamodifiedlibsvgbird/Points.valamodifiedlibsvgbird/StyleSheet.valamodifiedlibsvgbird/SvgFile.valamodifiedlibsvgbird/SvgStyle.vala
Diff
@@ -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); @@ -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))) {@@ -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); } @@ -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);@@ -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);+ } } }@@ -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) {@@ -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) {@@ -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)) {