The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Apply style without creating a tag

These changes was commited to the Birdfont repository Thu, 07 Jul 2016 21:44:56 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Thu, 07 Jul 2016 21:44:56 +0000 (23:44 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Thu, 07 Jul 2016 21:44:56 +0000 (23:44 +0200)
commit 8d559323efd1c2e38338700bff65f4ddb6b9c46e
tree 5f73126fafa589cb81ae34e921846749772be847
parent 52e91ac8f4082289b00bea40d872ba134d11054d
Apply style without creating a tag

libbirdfont/CircleTool.vala
libbirdfont/SvgParser.vala
libsvgbird/Layer.vala
libsvgbird/Object.vala
libsvgbird/Points.vala
libsvgbird/StyleSheet.vala
libsvgbird/SvgFile.vala
libsvgbird/SvgStyle.vala
--- a/libbirdfont/CircleTool.vala +++ b/libbirdfont/CircleTool.vala @@ -184,8 +184,8 @@ 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);
--- a/libbirdfont/SvgParser.vala +++ b/libbirdfont/SvgParser.vala @@ -1262,74 +1262,6 @@ b[i].y2 += font.top_limit; } } - } - - 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) {
--- a/libsvgbird/Layer.vala +++ b/libsvgbird/Layer.vala @@ -53,9 +53,11 @@ 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); }
--- a/libsvgbird/Object.vala +++ b/libsvgbird/Object.vala @@ -99,6 +99,8 @@ public abstract Object copy (); 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; @@ -232,6 +234,10 @@ bottom = y1; return boundaries_width != 0; + } + + public Matrix get_view_matrix () { + return view_matrix; } public virtual bool update_boundaries_for_object () {
--- a/libsvgbird/Points.vala +++ b/libsvgbird/Points.vala @@ -42,9 +42,17 @@ p.y = y; 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); } } }
--- a/libsvgbird/StyleSheet.vala +++ b/libsvgbird/StyleSheet.vala @@ -47,19 +47,20 @@ 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)) { @@ -91,6 +92,37 @@ } } + 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); }
--- a/libsvgbird/SvgFile.vala +++ b/libsvgbird/SvgFile.vala @@ -796,12 +796,9 @@ 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) {
--- a/libsvgbird/SvgStyle.vala +++ b/libsvgbird/SvgStyle.vala @@ -106,6 +106,16 @@ } 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) {