Commit d833952
remove SCALE parameter
Changed files (7)
modifiedlibbirdfont/Birdfont.valamodifiedlibbirdfont/ExportTool.valamodifiedlibbirdfont/Font.valamodifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/GridTool.valamodifiedlibbirdfont/OverView.valamodifiedlibbirdfont/Svg.vala
Diff
@@ -94,7 +94,6 @@ public static int run_export (string[] arg) { Log.set_handler (null, levels, Supplement.Supplement.fatal_warning); } - Preferences preferences = new Preferences (); Preferences.load (); Supplement.Supplement.args = new Argument ("");@@ -42,7 +42,6 @@ public class ExportTool : Tool { public static string export_current_glyph_to_string () { Glyph glyph = MainWindow.get_current_glyph (); Font font = Supplement.get_current_font ();- string glyph_svg; string name; StringBuilder s; double baseline;@@ -56,8 +55,8 @@ public class ExportTool : Tool { s.append ("xmlns=\"http://www.w3.org/2000/svg\"\n"); s.append ("\txmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\"\n");- s.append (@"\twidth=\"$(glyph.get_width () / Glyph.SCALE)\"\n");- s.append (@"\theight=\"$(glyph.get_height () / Glyph.SCALE)\"\n");+ s.append (@"\twidth=\"$(glyph.get_width ())\"\n");+ s.append (@"\theight=\"$(glyph.get_height ())\"\n"); s.append (@"\tid=\"glyph_$(name)\"\n"); s.append (@"\tversion=\"1.1\">\n"); s.append (@"\n");@@ -71,12 +71,12 @@ public class Font : GLib.Object { public Font () { // positions in pixels at first zoom level // default x-height should be 60 in 1:1- top_limit = -66 * Glyph.SCALE;- top_position = -54 * Glyph.SCALE;- xheight_position = -38 * Glyph.SCALE;- base_line = 18 * Glyph.SCALE;- bottom_position = 38 * Glyph.SCALE;- bottom_limit = 45 * Glyph.SCALE;+ top_limit = -66 ;+ top_position = -54;+ xheight_position = -38;+ base_line = 18;+ bottom_position = 38;+ bottom_limit = 45; } public void touch () {@@ -21,9 +21,6 @@ using Math; namespace Supplement { public class Glyph : FontDisplay {-- public static const double SCALE = 1.0;- // Background image GlyphBackgroundImage? background_image = null; bool background_image_visible = true;@@ -96,8 +93,8 @@ public class Glyph : FontDisplay { add_help_lines (); - left_limit = -28 * SCALE;- right_limit = 28 * SCALE;+ left_limit = -28;+ right_limit = 28; } public Glyph.no_lines (string name, unichar unichar_code = 0) {@@ -413,7 +410,7 @@ public class Glyph : FontDisplay { } public string get_svg_data () {- return Svg.to_svg_glyph (this, 1 / SCALE);+ return Svg.to_svg_glyph (this); } public int get_height () @@ -422,11 +419,11 @@ public class Glyph : FontDisplay { unowned List<Line> a = horizontal_help_lines.first (); unowned List<Line> b = horizontal_help_lines.last (); - return (int) Math.fabs (a.data.pos / SCALE - b.data.pos / SCALE); + return (int) Math.fabs (a.data.pos - b.data.pos); } public double get_width () {- return Math.fabs (right_limit / SCALE - left_limit / SCALE);+ return Math.fabs (right_limit - left_limit); } public unichar get_unichar () {@@ -1289,7 +1286,7 @@ public class Glyph : FontDisplay { left = get_line ("left").pos; if (!is_open ()) {- Svg.draw_svg_path (cr, get_svg_data (), Glyph.xc () + left, Glyph.yc () + baseline, SCALE);+ Svg.draw_svg_path (cr, get_svg_data (), Glyph.xc () + left, Glyph.yc () + baseline); } if (is_open ()) {@@ -1530,7 +1527,7 @@ public class Glyph : FontDisplay { cr = new Context (img); - Svg.draw_svg_path (cr, get_svg_data (), gx, gy, 1.0); + Svg.draw_svg_path (cr, get_svg_data (), gx, gy); return img; }@@ -1677,7 +1674,7 @@ public class Glyph : FontDisplay { cr.save (); cr.scale (glyph.view_zoom, glyph.view_zoom); cr.translate (-glyph.view_offset_x, -glyph.view_offset_y);- Svg.draw_svg_path (cr, juxtaposed.get_svg_data (), Glyph.xc () + left + x + kern, Glyph.yc () + baseline, Glyph.SCALE);+ Svg.draw_svg_path (cr, juxtaposed.get_svg_data (), Glyph.xc () + left + x + kern, Glyph.yc () + baseline); cr.restore (); } @@ -1706,7 +1703,7 @@ public class Glyph : FontDisplay { cr.scale (glyph.view_zoom, glyph.view_zoom); cr.translate (-glyph.view_offset_x, -glyph.view_offset_y); - Svg.draw_svg_path (cr, juxtaposed.get_svg_data (), Glyph.xc () + left + x, Glyph.yc () + baseline, Glyph.SCALE);+ Svg.draw_svg_path (cr, juxtaposed.get_svg_data (), Glyph.xc () + left + x, Glyph.yc () + baseline); cr.restore (); } @@ -84,7 +84,7 @@ class GridTool : Tool { private static void updata_lines () { Glyph g = MainWindow.get_current_glyph ();- double step = size_y * Glyph.SCALE;+ double step = size_y; double i; int max_lines = 400; int n;@@ -406,7 +406,7 @@ public class OverView : FontDisplay { c.fill (); */ c.scale (scale, scale); - Svg.draw_svg_path (c, g.get_svg_data (), gx, gy, 1.0);+ Svg.draw_svg_path (c, g.get_svg_data (), gx, gy); cr.save (); cr.set_source_surface (s, x - 6, y);@@ -22,29 +22,29 @@ namespace Supplement { class Svg { /** Export to svg glyph data. */- public static string to_svg_glyph (Glyph g, double scale = 1) { + public static string to_svg_glyph (Glyph g) { StringBuilder svg = new StringBuilder (); foreach (Path pl in g.path_list) {- write_path_as_glyph (pl, svg, g, scale);+ write_path_as_glyph (pl, svg, g); } return svg.str; } /** Export to svg-font data. */- public static string to_svg_path (Path pl, Glyph g, double scale = 1) { + public static string to_svg_path (Path pl, Glyph g) { StringBuilder svg = new StringBuilder (); pl.create_list ();- write_path (pl, svg, g, false, scale);+ write_path (pl, svg, g, false); return svg.str; } - private static void write_path_as_glyph (Path pl, StringBuilder svg, Glyph g, double scale = 1) {- write_path (pl, svg, g, true, scale);+ private static void write_path_as_glyph (Path pl, StringBuilder svg, Glyph g) {+ write_path (pl, svg, g, true); } - private static void write_path (Path pl, StringBuilder svg, Glyph g, bool do_glyph, double scale = 1) {+ private static void write_path (Path pl, StringBuilder svg, Glyph g, bool do_glyph) { int i = 0; EditPoint? n = null; EditPoint m;@@ -57,7 +57,7 @@ class Svg { foreach (var e in pl.points) { if (i == 0) {- add_abs_start (e, svg, g, do_glyph, scale);+ add_abs_start (e, svg, g, do_glyph); i++; n = e; continue;@@ -65,28 +65,28 @@ class Svg { m = (!) n; - add_abs_next (m, e, svg, g, do_glyph, scale);+ add_abs_next (m, e, svg, g, do_glyph); n = e; i++; } m = pl.points.first ().data; - add_abs_next ((!) n, m, svg, g, do_glyph, scale);+ add_abs_next ((!) n, m, svg, g, do_glyph); close_path (svg); } - private static void add_abs_next (EditPoint start, EditPoint end, StringBuilder svg, Glyph g, bool do_glyph, double scale = 1) {+ private static void add_abs_next (EditPoint start, EditPoint end, StringBuilder svg, Glyph g, bool do_glyph) { if (start.right_handle.type == PointType.LINE && end.left_handle.type == PointType.LINE) {- add_abs_line_to (end, start, svg, g, do_glyph, scale);+ add_abs_line_to (end, start, svg, g, do_glyph); } else if (end.get_left_handle ().type == PointType.NONE) {- add_quadratic_abs_path (end, start, svg, g, do_glyph, scale);+ add_quadratic_abs_path (end, start, svg, g, do_glyph); } else {- add_cubic_abs_path (end, start, svg, g, do_glyph, scale);+ add_cubic_abs_path (end, start, svg, g, do_glyph); } } - private static void add_abs_start (EditPoint ep, StringBuilder svg, Glyph g, bool to_glyph, double scale = 1) { + private static void add_abs_start (EditPoint ep, StringBuilder svg, Glyph g, bool to_glyph) { double left = g.left_limit; double baseline = Supplement.get_current_font ().base_line; double height = Supplement.get_current_font ().get_height ();@@ -94,11 +94,11 @@ class Svg { svg.append_printf ("M"); if (!to_glyph) {- svg.append_printf ("%s ", round ((ep.x - left) * scale));- svg.append_printf ("%s ", round ((-ep.y - baseline + height) * scale));+ svg.append_printf ("%s ", round (ep.x - left));+ svg.append_printf ("%s ", round (-ep.y - baseline + height)); } else {- svg.append_printf ("%s ", round ((ep.x - left) * scale));- svg.append_printf ("%s ", round ((ep.y + baseline) * scale));+ svg.append_printf ("%s ", round (ep.x - left));+ svg.append_printf ("%s ", round (ep.y + baseline)); } } @@ -106,7 +106,7 @@ class Svg { svg.append ("z"); } - private static void add_abs_line_to (EditPoint start, EditPoint stop, StringBuilder svg, Glyph g, bool to_glyph, double scale = 1) {+ private static void add_abs_line_to (EditPoint start, EditPoint stop, StringBuilder svg, Glyph g, bool to_glyph) { double baseline = Supplement.get_current_font ().base_line; double left = g.left_limit; @@ -122,15 +122,15 @@ class Svg { svg.append ("L"); if (!to_glyph) {- 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 (xb - center_x - left));+ svg.append_printf ("%s ", round (yb - center_y - baseline + height)); } else {- 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 (xb - center_x - left));+ svg.append_printf ("%s ", round (-yb + center_y + baseline)); } } - private static void add_quadratic_abs_path (EditPoint start, EditPoint end, StringBuilder svg, Glyph g, bool to_glyph, double scale = 1) {+ private static void add_quadratic_abs_path (EditPoint start, EditPoint end, StringBuilder svg, Glyph g, bool to_glyph) { double left = g.left_limit; double baseline = Supplement.get_current_font ().base_line; double height = Supplement.get_current_font ().get_height (); // no probably not@@ -146,24 +146,24 @@ class Svg { 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 (xb - center_x - left));+ svg.append_printf ("%s ", round (yb - center_y - baseline + height)); - svg.append_printf ("%s ", round ((xc - center_x - left) * scale));- svg.append_printf ("%s ", round ((yc - center_y - baseline + height) * scale));+ svg.append_printf ("%s ", round (xc - center_x - left));+ svg.append_printf ("%s ", round (yc - center_y - baseline + height)); } 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 (xb - center_x - left));+ svg.append_printf ("%s ", round (-yb + center_y + baseline)); - svg.append_printf ("%s ", round ((xc - center_x - left) * scale));- svg.append_printf ("%s ", round ((-yc + center_y + baseline) * scale)); + svg.append_printf ("%s ", round (xc - center_x - left));+ svg.append_printf ("%s ", round (-yc + center_y + baseline)); } } - private static void add_cubic_abs_path (EditPoint start, EditPoint end, StringBuilder svg, Glyph g, bool to_glyph, double scale = 1) {+ private static void add_cubic_abs_path (EditPoint start, EditPoint end, StringBuilder svg, Glyph g, bool to_glyph) { double left = g.left_limit; double baseline = Supplement.get_current_font ().base_line; double height = Supplement.get_current_font ().get_height (); // no probably not@@ -179,38 +179,35 @@ class Svg { if (!to_glyph) { svg.append_printf ("C"); - 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 (xb - center_x - left));+ svg.append_printf ("%s ", round (yb - center_y - baseline + height)); - svg.append_printf ("%s ", round ((xc - center_x - left) * scale));- svg.append_printf ("%s ", round ((yc - center_y - baseline + height) * scale));+ svg.append_printf ("%s ", round (xc - center_x - left));+ svg.append_printf ("%s ", round (yc - center_y - baseline + height)); - svg.append_printf ("%s ", round ((xd - center_x - left) * scale));- svg.append_printf ("%s ", round ((yd - center_y - baseline + height) * scale)); + svg.append_printf ("%s ", round (xd - center_x - left));+ svg.append_printf ("%s ", round (yd - center_y - baseline + height)); } else { svg.append_printf ("C"); - 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 (xb - center_x - left));+ svg.append_printf ("%s ", round (-yb + center_y + baseline)); - svg.append_printf ("%s ", round ((xc - center_x - left) * scale));- svg.append_printf ("%s ", round ((-yc + center_y + baseline) * scale)); + svg.append_printf ("%s ", round (xc - center_x - left));+ svg.append_printf ("%s ", round (-yc + center_y + baseline)); - svg.append_printf ("%s ", round ((xd - center_x - left) * scale));- svg.append_printf ("%s ", round ((-yd + center_y + baseline) * scale)); + svg.append_printf ("%s ", round (xd - center_x - left));+ svg.append_printf ("%s ", round (-yd + center_y + baseline)); } } /** Draw path from svg font data. */- public static void draw_svg_path (Context cr, string svg, double x, double y, double scale = 1) {+ public static void draw_svg_path (Context cr, string svg, double x, double y) { double x1, x2, x3; double y1, y2, y3; string[] d = svg.split (" ");- - x /= scale;- y /= scale; if (d.length == 0) { return;@@ -235,10 +232,6 @@ class Svg { if (d[i].index_of ("L") == 0) { x1 = double.parse (d[i].substring (1)) + x; y1 = -double.parse (d[i+1]) + y;- - x1 *= scale;- y1 *= scale;- cr.line_to (x1, y1); continue; }@@ -249,12 +242,6 @@ class Svg { 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;@@ -269,15 +256,6 @@ class Svg { x3 = double.parse (d[i+4]) + x; y3 = -double.parse (d[i+5]) + y;-- x1 *= scale;- y1 *= scale;-- x2 *= scale;- y2 *= scale;- - x3 *= scale;- y3 *= scale; cr.curve_to (x1, y1, x2, y2, x3, y3); continue;@@ -287,9 +265,6 @@ class Svg { x1 = double.parse (d[i].substring (1)) + x; y1 = -double.parse (d[i+1]) + y; - x1 *= scale;- y1 *= scale;- cr.move_to (x1, y1); continue; }@@ -300,9 +275,6 @@ class Svg { x1 = double.parse (d[i].substring (2)) + x; y1 = -double.parse (d[i+1]) + y; - x1 *= scale;- y1 *= scale;- cr.move_to (x1, y1); continue; }