The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Merge ../birdfont-2.x

These changes was commited to the Birdfont repository Sat, 04 Jun 2016 16:04:22 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Sat, 04 Jun 2016 16:04:22 +0000]

Updated Files

libbirdfont/BirdFontFile.vala
libbirdfont/ExportSettings.vala
libbirdfont/Font.vala
libbirdfont/Glyph.vala
libbirdfont/OpenFontFormat/GlyfData.vala
libbirdfont/Path.vala
libbirdfont/PointConverter.vala
libbirdfont/TestCases.vala
--- a/libbirdfont/BirdFontFile.vala +++ b/libbirdfont/BirdFontFile.vala @@ -343,7 +343,8 @@ os.put_string ("\n"); } - os.put_string (@"<background scale=\"$(font.background_scale)\" />\n"); + os.put_string (@"<background scale=\"$(font.background_scale)\" />\n"); + os.put_string (@"<conversion tolerance=\"$(font.tolerance)\" />\n"); } public void write_description (DataOutputStream os) throws GLib.Error { @@ -818,6 +819,10 @@ parse_background (t); } + if (t.get_name () == "conversion") { + parse_cubic_conversion (t); + } + if (t.get_name () == "postscript_name") { font.postscript_name = XmlParser.decode (t.get_content ()); } @@ -1186,6 +1191,18 @@ } catch (MarkupError e) { warning (e.message); } + } + + private void parse_cubic_conversion (Tag tag) { + string tolerance = "1"; + + foreach (Attribute attr in tag.get_attributes ()) { + if (attr.get_name () == "tolerance") { + tolerance = attr.get_content (); + } + } + + font.tolerance = parse_double (tolerance); } private void parse_background_image (Tag tag) {
--- a/libbirdfont/ExportSettings.vala +++ b/libbirdfont/ExportSettings.vala @@ -24,6 +24,7 @@ CheckBox ttf; CheckBox eot; CheckBox svg; + TextArea tolerance; Button export_action; Button name_tab; @@ -129,6 +130,31 @@ focus_ring.add (svg); svg.margin_bottom = 20 * MainWindow.units; + + widgets.add (new Text (t_("Conversion Tolerance"), label_size, label_margin)); + + tolerance = new LineTextArea (label_size); + tolerance.margin_bottom = 20 * MainWindow.units; + + tolerance.set_text (@"$(font.tolerance * 100.0)%"); + tolerance.text_changed.connect ((t) => { + Font f = BirdFont.get_current_font (); + string tolerance_percent = t.replace ("%", ""); + tolerance_percent = t.replace (",", "."); + tolerance_percent = t.replace (" ", ""); + double error_tolerance = double.parse (tolerance_percent); + + if (error_tolerance >= 100.0) { + f.tolerance = 1; + } else if (error_tolerance <= 0) { + f.tolerance = 0; + } else { + f.tolerance = error_tolerance / 100.0; + } + }); + + widgets.add (tolerance); + focus_ring.add (tolerance); name_tab = new Button (t_("Name and Description"), margin); name_tab.action.connect ((c) => {
--- a/libbirdfont/Font.vala +++ b/libbirdfont/Font.vala @@ -125,6 +125,7 @@ public int format_minor = 0; public int units_per_em = 1024; + public double tolerance = 1.0; public Font () { KerningClasses kerning_classes;
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -231,7 +231,7 @@ return (!) ttf_data; } - public PathList get_quadratic_paths () { + public PathList get_quadratic_paths (double tolerance) { PointConverter pc; PathList pl; PathList stroke; @@ -242,11 +242,11 @@ if (p.stroke > 0) { stroke = p.get_completed_stroke (); foreach (Path stroke_part in stroke.paths) { - pc = new PointConverter (stroke_part); + pc = new PointConverter (stroke_part, tolerance); pl.add (pc.get_quadratic_path ()); } } else { - pc = new PointConverter (p); + pc = new PointConverter (p, tolerance); pl.add (pc.get_quadratic_path ()); } }
--- a/libbirdfont/OpenFontFormat/GlyfData.vala +++ b/libbirdfont/OpenFontFormat/GlyfData.vala @@ -58,11 +58,12 @@ public GlyfData (Glyph g) { bool process; - PathList qp = g.get_quadratic_paths (); + Font font = OpenFontFormatWriter.get_current_font (); + PathList quadratic_path = g.get_quadratic_paths (font.tolerance); glyph = g; - foreach (Path p in qp.paths) { + foreach (Path p in quadratic_path.paths) { if (p.points.size > 0) { if (!is_empty (p)) { // Add points at extrema @@ -76,7 +77,7 @@ while (process) { points.clear (); paths.clear (); - foreach (Path p in qp.paths) { + foreach (Path p in quadratic_path.paths) { if (!is_empty (p)) { paths.add (p); foreach (EditPoint ep in p.points) {
--- a/libbirdfont/Path.vala +++ b/libbirdfont/Path.vala @@ -1204,9 +1204,9 @@ /** Convert quadratic bezier points to cubic representation of the glyph * for ttf-export. */ - public Path get_quadratic_points () { + public Path get_quadratic_points (double tolerance) { PointConverter converter; - converter = new PointConverter (this); + converter = new PointConverter (this, tolerance); return converter.get_quadratic_path (); }
--- a/libbirdfont/PointConverter.vala +++ b/libbirdfont/PointConverter.vala @@ -22,9 +22,11 @@ Path original_path; Path quadratic_path; + double error_tolerance = 1; - public PointConverter (Path path) { + public PointConverter (Path path, double tolerance) { original_path = path; + error_tolerance = tolerance; } public Path get_quadratic_path () { @@ -106,7 +108,7 @@ out distance, out e, out step); } - if (distance > 0.2) { // range 0.1 - 0.4, + if (distance > 0.1 + 0.1 * error_tolerance) { // range 0.1 - 0.4, quadratic_path.insert_new_point_on_path (e); points_in_segment++; size += 2; // the new point + segment start
--- a/libbirdfont/TestCases.vala +++ b/libbirdfont/TestCases.vala @@ -592,7 +592,7 @@ g = MainWindow.get_current_glyph (); foreach (Path path in g.get_all_paths ()) { - paths.append (path.get_quadratic_points ()); + paths.append (path.get_quadratic_points (1.0)); paths.append (path.copy ()); } @@ -610,7 +610,7 @@ p.add (-10, -10); p.close (); g.add_path (p); - g.add_path (p1.get_quadratic_points ()); + g.add_path (p1.get_quadratic_points (1.0)); e0 = new EditPoint (20, 40); e1 = new EditPoint (40, 40); @@ -634,7 +634,7 @@ e3.process_tied_handle (); g.add_path (p1); - g.add_path (p1.get_quadratic_points ()); + g.add_path (p1.get_quadratic_points (1.0)); foreach (Path path in paths) { g.add_path (path);