The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Store line cap in bf fonts

These changes was commited to the Birdfont repository Tue, 12 May 2015 07:39:34 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Tue, 12 May 2015 07:39:34 +0000]

Updated Files

libbirdfont/BirdFontFile.vala
libbirdfont/SvgParser.vala
libbirdfont/SvgStyle.vala
--- a/libbirdfont/BirdFontFile.vala +++ b/libbirdfont/BirdFontFile.vala @@ -389,7 +389,22 @@ foreach (Path p in g.path_list) { data = get_point_data (p); if (data != "") { - os.put_string (@"\t\t<path stroke=\"$(double_to_string (p.stroke))\" skew=\"$(double_to_string (p.skew))\" data=\"$(data)\" />\n"); + os.put_string (@"\t\t<path "); + os.put_string (@"stroke=\"$(double_to_string (p.stroke))\" "); + + if (p.line_cap != LineCap.BUTT) { + if (p.line_cap == LineCap.ROUND) { + os.put_string (@"cap=\"round\" "); + } else if (p.line_cap == LineCap.SQUARE) { + os.put_string (@"cap=\"square\" "); + } + } + + if (p.skew != 0) { + os.put_string (@"skew=\"$(double_to_string (p.skew))\" "); + } + + os.put_string (@"data=\"$(data)\" />\n"); } } write_glyph_background (g, os); @@ -1211,7 +1226,15 @@ if (attr.get_name () == "skew") { path.skew = double.parse (attr.get_content ()); - } + } + + if (attr.get_name () == "cap") { + if (attr.get_content () == "round") { + path.line_cap = LineCap.ROUND; + } else if (attr.get_content () == "square") { + path.line_cap = LineCap.SQUARE; + } + } } return path;
--- a/libbirdfont/SvgParser.vala +++ b/libbirdfont/SvgParser.vala @@ -456,12 +456,13 @@ } } - foreach (Path p1 in pl.paths.paths) { - p1.stroke = style.get_stroke_width (); - p1.reset_stroke (); - p1.update_region_boundaries (); + foreach (Path p in path_list.paths) { + p.stroke = style.get_stroke_width (); + p.line_cap = style.get_line_cap (); + p.reset_stroke (); + p.update_region_boundaries (); } - + // assume the even odd rule is applied and convert the path // to a path using the non-zero rule int inside_count;
--- a/libbirdfont/SvgStyle.vala +++ b/libbirdfont/SvgStyle.vala @@ -23,6 +23,24 @@ public SvgStyle () { style = new Gee.HashMap<string, string> (); + } + + public LineCap get_line_cap () { + string l; + + if (!style.has_key ("stroke-linecap")) { + return LineCap.BUTT; + } + + l = style.get ("stroke-linecap"); + + if (l == "round") { + return LineCap.ROUND; + } else if (l == "square") { + return LineCap.SQUARE; + } + + return LineCap.BUTT; } public double get_stroke_width () {