Commit abd6de7
Merge ../birdfont-2.x
Changed files (8)
modifiedlibbirdfont/BirdFontFile.valamodifiedlibbirdfont/ExportSettings.valamodifiedlibbirdfont/Font.valamodifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/OpenFontFormat/GlyfData.valamodifiedlibbirdfont/Path.valamodifiedlibbirdfont/PointConverter.valamodifiedlibbirdfont/TestCases.vala
Diff
@@ -343,7 +343,8 @@ class BirdFontFile : GLib.Object { 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 @@ class BirdFontFile : GLib.Object { 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 ()); }@@ -1188,6 +1193,18 @@ class BirdFontFile : GLib.Object { } } + 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) { string file = ""; string data = "";@@ -24,6 +24,7 @@ public class ExportSettings : TableLayout { CheckBox ttf; CheckBox eot; CheckBox svg;+ TextArea tolerance; Button export_action; Button name_tab; @@ -130,6 +131,31 @@ public class ExportSettings : TableLayout { 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) => { MenuTab.show_description ();@@ -125,6 +125,7 @@ public class Font : GLib.Object { public int format_minor = 0; public int units_per_em = 1024;+ public double tolerance = 1.0; public Font () { KerningClasses kerning_classes;@@ -231,7 +231,7 @@ public class Glyph : FontDisplay { 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 @@ public class Glyph : FontDisplay { 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 ()); } }@@ -58,11 +58,12 @@ public class GlyfData : GLib.Object { 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 @@ public class GlyfData : GLib.Object { 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) {@@ -1204,9 +1204,9 @@ public class Path : GLib.Object { /** 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 (); } @@ -22,9 +22,11 @@ public class PointConverter { 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 @@ public class PointConverter { 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@@ -592,7 +592,7 @@ class TestCases { 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 @@ class TestCases { 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 @@ class TestCases { 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);