Commit 46d1bc1
parse quadratic bezier paths
Changed files (5)
modifiedsrc/EditPoint.valamodifiedsrc/ExportTool.valamodifiedsrc/OpenFontFormatWriter.valamodifiedsrc/Path.valamodifiedsrc/Svg.vala
Diff
@@ -23,6 +23,7 @@ using Math; namespace Supplement { enum PointType {+ NONE, NORMAL, LINE, CURVE,@@ -178,7 +178,7 @@ class ExportTool : Tool { @font-face{ font-family: '"""); os.put_string (@"$(name)"); os.put_string ("""';- src: url('"""); os.put_string (@"$(name).svg#$(name)"); os.put_string ("""') format('svg');+ src: url('"""); os.put_string (@"$(name).svg#$(name)"); os.put_string ("""') format('svg'), url('"""); os.put_string (@"$(name).ttf"); os.put_string ("""') format('truetype'); } h1 {@@ -1074,8 +1074,8 @@ class GlyfTable : Table { path.add_point (edit_point); if (prev_is_curve) { - edit_point.get_left_handle ().set_point_type (PointType.CURVE); - edit_point.get_left_handle ().length = 0; + edit_point.get_left_handle ().set_point_type (PointType.NONE); + edit_point.get_left_handle ().length = 0; } else { edit_point.recalculate_linear_handles (); } @@ -1095,7 +1095,7 @@ class GlyfTable : Table { x = xcoordinates[j] * 1000.0 / units_per_em; // in proportion to em width y = ycoordinates[j] * 1000.0 / units_per_em; - edit_point.get_left_handle ().set_point_type (PointType.CURVE); + edit_point.get_left_handle ().set_point_type (PointType.NONE); edit_point.get_left_handle ().length = 0; edit_point.type = PointType.CURVE; @@ -2460,8 +2460,10 @@ class NameTable : Table { text.append (font.get_name ()); type.append (FULL_FONT_NAME); - text.append ("Version 1.0;"); - type.append (VERSION); + // This does for some reason cause an internal error in ms fontvalidatior utility + // put it back when you have figured out how to solve the validation issue. + // text.append ("Version 1.0"); + // type.append (VERSION); num_records = (uint16) text.length (); @@ -180,32 +180,6 @@ class Path { cr.curve_to (xb, yb, xc, yc, xd, yd); } - private static void print_curve (EditPoint e, EditPoint en) {- double xa, ya, xb, yb, xc, yc, xd, yd;- - get_bezier_points (e, en, out xa, out ya, out xb, out yb, out xc, out yc, out xd, out yd);-- stdout.printf ("L");- - stdout.printf ("%s ", round (xa));- stdout.printf ("%s ", round (ya)); - - stdout.printf ("\n");-- stdout.printf ("C");-- stdout.printf ("%s ", round (xb));- stdout.printf ("%s ", round (yb));- - stdout.printf ("%s ", round (xc));- stdout.printf ("%s ", round (yc)); - - stdout.printf ("%s ", round (xd));- stdout.printf ("%s ", round (yd)); - - stdout.printf ("\n");- }- /** Curve relative to window center. */ public static void get_bezier_points (EditPoint e, EditPoint en, out double xa, out double ya, out double xb, out double yb, out double xc, out double yc, out double xd, out double yd) { Glyph g = MainWindow.get_current_glyph ();@@ -85,8 +85,10 @@ class Svg { private static void add_abs_next (EditPoint start, EditPoint end, StringBuilder svg, Glyph g, bool do_glyph, double scale = 1) { if (start.right_handle.type == PointType.LINE && end.left_handle.type == PointType.LINE) { add_abs_line_to (end, start, svg, g, do_glyph, scale);+ } else if (end.get_left_handle ().type == PointType.NONE) {+ add_quadratic_abs_path (end, start, svg, g, do_glyph, scale); } else {- add_abs_path (end, start, svg, g, do_glyph, scale);+ add_cubic_abs_path (end, start, svg, g, do_glyph, scale); } } @@ -141,9 +143,40 @@ class Svg { } } - private static void add_abs_path (EditPoint start, EditPoint end, StringBuilder svg, Glyph g, bool to_glyph, double scale = 1) {- // Just like Path.print_curve (e, m, svg);+ private static void add_quadratic_abs_path (EditPoint start, EditPoint end, StringBuilder svg, Glyph g, bool to_glyph, double scale = 1) {+ double left = g.left_limit;+ double baseline = Supplement.get_current_font ().base_line;+ double height = Supplement.get_current_font ().get_height (); // no probably not + double xa, ya, xb, yb, xc, yc, xd, yd;+ + Path.get_bezier_points (start, end, out xa, out ya, out xb, out yb, out xc, out yc, out xd, out yd);++ double center_x = Glyph.xc ();+ double center_y = Glyph.yc ();+ + // cubic path+ if (!to_glyph) {+ svg.append_printf ("Q");++ svg.append_printf ("%s ", round ((xb - center_x - left) * scale));+ svg.append_printf ("%s ", round ((yb - center_y - baseline + height) * scale));+ + svg.append_printf ("%s ", round ((xc - center_x - left) * scale));+ svg.append_printf ("%s ", round ((yc - center_y - baseline + height) * scale));++ } else { + svg.append_printf ("Q");++ svg.append_printf ("%s ", round ((xb - center_x - left) * scale));+ svg.append_printf ("%s ", round ((-yb + center_y + baseline) * scale));+ + svg.append_printf ("%s ", round ((xc - center_x - left) * scale));+ svg.append_printf ("%s ", round ((-yc + center_y + baseline) * scale)); + }+ }+ + private static void add_cubic_abs_path (EditPoint start, EditPoint end, StringBuilder svg, Glyph g, bool to_glyph, double scale = 1) { double left = g.left_limit; double baseline = Supplement.get_current_font ().base_line; double height = Supplement.get_current_font ().get_height (); // no probably not@@ -155,6 +188,7 @@ class Svg { double center_x = Glyph.xc (); double center_y = Glyph.yc (); + // cubic path if (!to_glyph) { svg.append_printf ("C"); @@ -218,6 +252,23 @@ class Svg { continue; } + if (d[i].index_of ("Q") == 0) {+ x1 = double.parse (d[i].substring (1)) + x;+ y1 = -double.parse (d[i+1]) + y;++ x2 = double.parse (d[i+2]) + x;+ y2 = -double.parse (d[i+3]) + y;++ x1 *= scale;+ y1 *= scale;++ x2 *= scale;+ y2 *= scale;+ + cr.curve_to (x1, y1, x2, y2, x2, y2);+ continue;+ }+ if (d[i].index_of ("C") == 0) { x1 = double.parse (d[i].substring (1)) + x; y1 = -double.parse (d[i+1]) + y;