Commit 1c73c33
Use the new coordinate system for vertical lines
Changed files (9)
modifiedlibbirdfont/BirdFontFile.valamodifiedlibbirdfont/FileTab.valamodifiedlibbirdfont/Font.valamodifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/GridTool.valamodifiedlibbirdfont/Line.valamodifiedlibbirdfont/Path.valamodifiedlibbirdfont/PenTool.valamodifiedlibbirdfont/TrackTool.vala
Diff
@@ -131,16 +131,14 @@ class BirdFontFile { os.put_string (@"<copyright>$(font.copyright)</copyright>\n"); os.put_string ("\n");- os.put_string ("<lines>\n");- + os.put_string ("<horizontal>\n"); os.put_string (@"\t<top_limit>$(font.top_limit)</top_limit>\n"); os.put_string (@"\t<top_position>$(font.top_position)</top_position>\n"); os.put_string (@"\t<x-height>$(font.xheight_position)</x-height>\n"); os.put_string (@"\t<base_line>$(font.base_line)</base_line>\n"); os.put_string (@"\t<bottom_position>$(font.bottom_position)</bottom_position>\n"); os.put_string (@"\t<bottom_limit>$(font.bottom_limit)</bottom_limit>\n");- - os.put_string ("</lines>\n\n");+ os.put_string ("</horizontal>\n\n"); foreach (string gv in font.grid_width) { os.put_string (@"<grid width=\"$(gv)\"/>\n");@@ -493,9 +491,14 @@ class BirdFontFile { parse_glyph_collection (iter); } + // horizontal lines in the old format if (iter->name == "lines") { parse_font_boundaries (iter); }+ + if (iter->name == "horizontal") {+ parse_horizontal_lines (iter);+ } if (iter->name == "grid") { parse_grid (iter);@@ -807,7 +810,7 @@ class BirdFontFile { } } - private void parse_font_boundaries (Xml.Node* node) {+ private void parse_horizontal_lines (Xml.Node* node) { for (Xml.Node* iter = node->children; iter != null; iter = iter->next) { if (iter->name == "top_limit" && "" != iter->children->content) { font.top_limit = parse_double_from_node (iter);@@ -832,6 +835,35 @@ class BirdFontFile { if (iter->name == "bottom_limit" && "" != iter->children->content) { font.bottom_limit = parse_double_from_node (iter); }+ } + }+ + /** @deprecated horizontal in older .bf files */+ private void parse_font_boundaries (Xml.Node* node) {+ for (Xml.Node* iter = node->children; iter != null; iter = iter->next) {+ if (iter->name == "top_limit" && "" != iter->children->content) {+ font.top_limit = -parse_double_from_node (iter);+ }+ + if (iter->name == "top_position" && "" != iter->children->content) {+ font.top_position = -parse_double_from_node (iter);+ }+ + if (iter->name == "x-height" && "" != iter->children->content) {+ font.xheight_position = -parse_double_from_node (iter);+ }+ + if (iter->name == "base_line" && "" != iter->children->content) {+ font.base_line = -parse_double_from_node (iter);+ }+ + if (iter->name == "bottom_position" && "" != iter->children->content) {+ font.bottom_position = -parse_double_from_node (iter);+ }+ + if (iter->name == "bottom_limit" && "" != iter->children->content) {+ font.bottom_limit = -parse_double_from_node (iter);+ } } } @@ -135,9 +135,24 @@ public class FileTab : FontDisplay { return; } + if (is_null (recent_fonts.data)) {+ warning ("Recent font 1 has no data");+ return;+ }+ foreach (Font font in recent_fonts) {+ + if (is_null (font)) {+ warning ("Can't find font in list.");+ break;+ }++ if (is_null (font.font_file)) {+ warning ("File is not set for font.");+ break;+ }+ if (i == r) {- return_if_fail (font.font_file != null); load_font ((!) font.font_file); open_file (); }@@ -105,12 +105,12 @@ public class Font : GLib.Object { // positions in pixels at first zoom level // default x-height should be 60 in 1:1- top_limit = -84 ;- top_position = -72;- xheight_position = -56;+ top_limit = 84 ;+ top_position = 72;+ xheight_position = 56; base_line = 0;- bottom_position = 20;- bottom_limit = 27;+ bottom_position = -20;+ bottom_limit = -27; } public void set_weight (string w) {@@ -554,7 +554,7 @@ public class Glyph : FontDisplay { return name; } - private void help_line_event (double x, double y) {+ private void help_line_event (int x, int y) { bool m = false; foreach (Line line in vertical_help_lines) {@@ -615,8 +615,7 @@ public class Glyph : FontDisplay { return; } - help_line_event (x, y);- + help_line_event ((int) x, (int) y); t.move_action (t, (int) x, (int) y); motion_x = x * ivz () - xc () + view_offset_x;@@ -1257,24 +1256,22 @@ public class Glyph : FontDisplay { public Line get_lower_line () requires (horizontal_help_lines.length () > 2) {- return horizontal_help_lines.last ().prev.data;+ return get_line ("baseline"); } /** Set default zoom. See default_zoom. */ public void set_default_zoom () {- int l, t, b, r;- - double bottom = 0;- double top = 0;- double left = 0;- double right = 0;+ int bottom = 0;+ int top = 0;+ int left = 0;+ int right = 0; unowned List<Line>? n = horizontal_help_lines; unowned List<Line>? v = vertical_help_lines; if (unlikely (n == null)) { warning ("n == null");- warning (@"Can not set default zoom for $name, help lines are not available.");+ warning (@"Can not set default zoom for $name, lines are not available."); } return_if_fail (v != null);@@ -1283,18 +1280,13 @@ public class Glyph : FontDisplay { reset_zoom (); - bottom = -get_lower_line ().get_pos ();- top = -get_upper_line ().get_pos ();+ bottom = get_lower_line ().get_position_pixel ();+ top = get_upper_line ().get_position_pixel (); - left = vertical_help_lines.last ().data.get_pos ();- right = vertical_help_lines.first ().data.get_pos ();- - l = reverse_path_coordinate_x (left);- t = reverse_path_coordinate_y (top);- r = reverse_path_coordinate_x (right); - b = reverse_path_coordinate_y (bottom);+ left = vertical_help_lines.last ().data.get_position_pixel ();+ right = vertical_help_lines.first ().data.get_position_pixel (); - set_zoom_area (l + 10, t - 10, r - 10, b + 10);+ set_zoom_area (left + 10, top - 10, right - 10, bottom + 10); set_zoom_from_area (); } @@ -1446,8 +1438,6 @@ public class Glyph : FontDisplay { if (show_help_lines) { cmp.save ();- cmp.scale (view_zoom, view_zoom);- cmp.translate (-view_offset_x, -view_offset_y); draw_help_lines (cmp); cmp.restore (); }@@ -143,7 +143,7 @@ class GridTool : Tool { } n = 0;- for (i = baseline.get_pos () - step; i >= top_margin.get_pos () - 7 * step; i -= step) {+ for (i = baseline.get_pos () - step; i >= bottom_margin.get_pos () - 7 * step; i -= step) { t = new Line ("grid", i, Line.HORIZONTAL); t.set_moveable (false); t.set_color (0.2, 0.6, 0.2, 0.2);@@ -155,7 +155,7 @@ class GridTool : Tool { } - for (i = baseline.get_pos (); i <= bottom_margin.get_pos () + 7 * step; i += step) {+ for (i = baseline.get_pos (); i <= top_margin.get_pos () + 7 * step; i += step) { u = new Line ("grid", i, Line.HORIZONTAL); u.set_moveable (false); u.set_color (0.2, 0.6, 0.2, 0.2);@@ -239,7 +239,7 @@ class GridTool : Tool { return y; } } else {- if (!(starty.pos < -y < stopy.pos)) {+ if (!(starty.pos < y < stopy.pos)) { return y; } }@@ -248,7 +248,7 @@ class GridTool : Tool { ypos = new Line ("", 0, Line.HORIZONTAL); ypos.pos = Glyph.path_coordinate_y (y); } else {- ypos = new Line ("", -y, Line.HORIZONTAL);+ ypos = new Line ("", y, Line.HORIZONTAL); } m = double.MAX;@@ -265,7 +265,7 @@ class GridTool : Tool { if (!coordinate) { y = Glyph.reverse_path_coordinate_y (ymin.get_pos ()); } else {- y = -ymin.get_pos ();+ y = ymin.get_pos (); } return y;@@ -1,5 +1,5 @@ /*- Copyright (C) 2012 Johan Mattsson+ Copyright (C) 2012 2014 Johan Mattsson This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -118,17 +118,17 @@ public class Line : GLib.Object { p = Glyph.reverse_path_coordinate_x (pos); queue_draw_area ((int)p - 100, 0, 200, g.allocation.height); } else {- p = Glyph.reverse_path_coordinate_y (-pos);+ p = Glyph.reverse_path_coordinate_y (pos); queue_draw_area (0, (int)p - 100, g.allocation.width, 300); } } - public void move_line_to (double x, double y, WidgetAllocation allocation) {+ public void move_line_to (int x, int y, WidgetAllocation allocation) { set_move (true); event_move_to (x, y, allocation); } - public bool event_move_to (double x, double y, WidgetAllocation allocation) {+ public bool event_move_to (int x, int y, WidgetAllocation allocation) { double p, c; bool a = false; Glyph g = MainWindow.get_current_glyph ();@@ -143,10 +143,8 @@ public class Line : GLib.Object { if (is_vertical ()) { // over line handle (y) if (y > g.allocation.height - 10) {- - p = get_coordinate ();-- c = x * ivz + g.view_offset_x;+ p = pos;+ c = Glyph.path_coordinate_x (x); a = (p - margin * ivz <= c <= p + margin * ivz); } @@ -156,10 +154,10 @@ public class Line : GLib.Object { set_active (a); - } else { // over line handle (x+ } else { // over line handle (x) if (x > g.allocation.width - 10) {- p = get_coordinate ();- c = y * ivz + g.view_offset_y;+ p = pos;+ c = Glyph.path_coordinate_y (y); a = (p - margin * ivz <= c <= p + margin * ivz); } @@ -181,16 +179,12 @@ public class Line : GLib.Object { if (GridTool.is_visible ()) { GridTool.tie_coordinate (ref pos, ref none); }- redraw_line (); // draw at new position } else {- // FIXME: flip the y axis for lines+ pos = Glyph.path_coordinate_y (y);+ if (GridTool.is_visible ()) {- tpy = Glyph.path_coordinate_y (y);- GridTool.tie_coordinate (ref none, ref tpy);- pos = -tpy;- } else {- pos = -Glyph.path_coordinate_y (y);+ GridTool.tie_coordinate (ref none, ref pos); } redraw_line (); }@@ -223,45 +217,40 @@ public class Line : GLib.Object { return vertical; } - public double get_coordinate () {- Glyph g = MainWindow.get_current_glyph ();- double t = (is_vertical ()) ? (g.allocation.width / 2.0) : (g.allocation.height / 2.0);- return pos + t;+ public int get_position_pixel () {+ if (is_vertical ()) {+ return Glyph.reverse_path_coordinate_x (pos);+ }+ + return Glyph.reverse_path_coordinate_y (pos) ; } public double get_pos () { return pos; } - private double get_handle_size () {- Glyph g = MainWindow.get_current_glyph ();- double ivz = 1/g.view_zoom;- return (get_active ()) ? (10 * ivz) : (5 * ivz);- }- public void draw (Context cr, WidgetAllocation allocation) { Glyph g = MainWindow.get_current_glyph (); double p, h, w; double ivz = 1/g.view_zoom; - double size = get_handle_size ();+ double size = (active) ? 8 : 5; if (!visible) return; cr.save ();- cr.set_line_width (ivz);+ cr.set_line_width (1); if (active) cr.set_source_rgba (0, 0, 0.3, 1); else cr.set_source_rgba (r, this.g, b, a); // Line if (is_vertical ()) {- p = get_coordinate ();- - h = g.allocation.height * ivz + g.view_offset_y;+ p = Glyph.reverse_path_coordinate_x (pos);+ h = g.allocation.height; - cr.move_to (p, g.view_offset_y);+ cr.move_to (p, 0); cr.line_to (p, h); cr.stroke (); @@ -277,11 +266,10 @@ public class Line : GLib.Object { } } else {- p = get_coordinate ();- - w = g.allocation.width * ivz + g.view_offset_x;+ p = Glyph.reverse_path_coordinate_y (pos);+ w = g.allocation.width; - cr.move_to (g.view_offset_x, p);+ cr.move_to (0, p); cr.line_to (w, p); cr.stroke (); @@ -298,11 +286,11 @@ public class Line : GLib.Object { // Label if (get_active ()) { if (is_vertical ()) {- h = g.allocation.height * ivz + g.view_offset_y;- cr.move_to (p + 8*ivz, h - 30*ivz);+ h = g.allocation.height;+ cr.move_to (p + 8 * ivz, h - 30 * ivz); } else {- w = g.allocation.width * ivz + g.view_offset_x;- cr.move_to (w - 70*ivz, p + 15*ivz);+ w = g.allocation.width;+ cr.move_to (w - 70 * ivz, p + 15 * ivz); } cr.set_font_size (12 * ivz);@@ -354,7 +354,7 @@ public class Path { yd = - en.y; } - /** Line points relative to center. */+ /** Line points relative to centrum. */ public static void get_line_points (EditPoint e, EditPoint en, out double xa, out double ya, out double xb, out double yb) { double xc = Glyph.xc (); double yc = Glyph.yc ();@@ -1473,7 +1473,8 @@ public class PenTool : Tool { ep.set_reflective_handles (false); if (ep.next == null) {- warning ("Next is null.");+ // FIXME: write a new function for this case+ // warning ("Next is null."); } if (ep.prev == null) {@@ -189,8 +189,9 @@ public class TrackTool : Tool { if (DrawingTools.get_selected_point_type () == PointType.QUADRATIC) { foreach (EditPoint e in p.points) {- e.set_tie_handle (true);+ if (e.tie_handles) { e.process_tied_handle (); + } } }