Commit 8acc3cc
Stroke property for paths
Changed files (9)
modifiedbirdfont/GtkWindow.valamodifiedlibbirdfont/DrawingTools.valamodifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/MoveTool.valamodifiedlibbirdfont/OpenFontFormat/DirectoryTable.valamodifiedlibbirdfont/Path.valamodifiedlibbirdfont/SpinButton.valamodifiedlibbirdfont/StrokeTool.valamodifiedlibbirdfont/Toolbox.vala
Diff
@@ -930,8 +930,8 @@ class ToolboxCanvas : DrawingArea { get_allocation (out allocation); Context cw = cairo_create(get_window());- tb.allocation_width = allocation.width;- tb.allocation_height = allocation.height;+ Toolbox.allocation_width = allocation.width;+ Toolbox.allocation_height = allocation.height; tb.draw (allocation.width, allocation.height, cw); return true;@@ -34,6 +34,8 @@ public class DrawingTools : ToolCollection { public static PointType point_type = PointType.DOUBLE_CURVE; + public static SpinButton object_stroke;+ public DrawingTools (GlyphCanvas main_glyph_canvas) { glyph_canvas = main_glyph_canvas; @@ -71,7 +73,7 @@ public class DrawingTools : ToolCollection { draw_tools.add_tool (resize_tool); Tool stroke_tool = new StrokeTool ("stroke");- draw_tools.add_tool (stroke_tool); + draw_tools.add_tool (stroke_tool); // quadratic Bézier points Tool quadratic_points = new Tool ("quadratic_points", t_("Create quadratic Bézier curves"));@@ -106,6 +108,16 @@ public class DrawingTools : ToolCollection { convert_points.set_persistent (false); draw_tool_modifiers.add_tool (convert_points); + // edit stroke width+ object_stroke = new SpinButton ("object_stroke", t_("Stroke width"));+ object_stroke.set_int_value ("0.000");+ + object_stroke.new_value_action.connect((self) => {+ StrokeTool.set_stroke_for_selected_paths (object_stroke.get_value ());+ });+ + draw_tool_modifiers.add_tool (object_stroke); + // tie edit point handles Tool tie_handles = new Tool ("tie_point", t_("Tie curve handles for the selected edit point"), 'w'); tie_handles.select_action.connect ((self) => {@@ -537,6 +549,17 @@ public class DrawingTools : ToolCollection { SpinButton stroke_width; stroke_width = new SpinButton ("stroke_width", t_("Stroke width")); + style_tools.add_tool (stroke_width);+ + stroke_width.set_max (4);+ stroke_width.set_min (0.002);+ stroke_width.set_value_round (1);++ if (Preferences.get ("stroke_width") != "") {+ print ("PREF\n"); // DELETE+ stroke_width.set_value (Preferences.get ("stroke_width"));+ }+ stroke_width.new_value_action.connect ((self) => { Glyph g = MainWindow.get_current_glyph (); Path.stroke_width = stroke_width.get_value ();@@ -544,15 +567,8 @@ public class DrawingTools : ToolCollection { Preferences.set ("stroke_width", stroke_width.get_display_value ()); MainWindow.get_toolbox ().redraw ((int) stroke_width.x, (int) stroke_width.y, 70, 70); });- style_tools.add_tool (stroke_width);- - stroke_width.set_max (4);- stroke_width.set_min (0.2);- stroke_width.set_value_round (1); - if (Preferences.get ("stroke_width") != "") {- stroke_width.set_value (Preferences.get ("stroke_width"));- }+ Path.stroke_width = stroke_width.get_value (); ColorTool handle_color = new ColorTool (t_("Handle color")); handle_color.color_updated.connect (() => {@@ -140,7 +140,7 @@ public class Glyph : FontDisplay { foreach (Path p in path_list) { if (p.points.length () > 0) {- active_paths.append (p);+ add_active_path (p); } } }@@ -152,7 +152,11 @@ public class Glyph : FontDisplay { } public void add_active_path (Path? p) {+ Path path; if (p != null) {+ path = (!) p;+ + Toolbox.set_object_stroke (path.stroke); foreach (Path pi in active_paths) { if (pi == p) {@@ -160,7 +164,7 @@ public class Glyph : FontDisplay { } } - active_paths.append ((!) p);+ active_paths.append (path); } } @@ -1069,7 +1073,8 @@ public class Glyph : FontDisplay { } } - clear_active_paths ();+ // FIXME: delete+ // clear_active_paths (); redraw_area (0, 0, allocation.width, allocation.height); @@ -1359,9 +1364,11 @@ public class Glyph : FontDisplay { // draw stroke foreach (unowned Path p in path_list) {- stroke = StrokeTool.get_stroke (p, 3);- stroke.close ();- stroke.draw_outline (cr, allocation, view_zoom);+ if (p.stroke > 0) { + stroke = StrokeTool.get_stroke (p, p.stroke);+ stroke.close ();+ stroke.draw_outline (cr, allocation, view_zoom);+ } } } @@ -173,7 +173,7 @@ class MoveTool : Tool { foreach (Path p in glyph.path_list) { if (p.xmin > x1 && p.xmax < x2 && p.ymin < y1 && p.ymax > y2) { if (p.points.length () > 0) {- glyph.active_paths.append (p);+ glyph.add_active_path (p); } } }@@ -219,7 +219,7 @@ public class DirectoryTable : Table { } } - public void parse_all_tables (FontData dis, OpenFontFormatReader reader_callback) {+ public void parse_all_tables (FontData dis, OpenFontFormatReader reader_callback) throws Error { head_table.parse (dis); hhea_table.parse (dis);@@ -249,7 +249,7 @@ public class DirectoryTable : Table { } } - public void parse_kern_table (FontData dis) {+ public void parse_kern_table (FontData dis) throws Error { if (kern_table.has_data ()) { kern_table.parse (dis); } else {@@ -257,7 +257,7 @@ public class DirectoryTable : Table { } } - public void parse_cmap_table (FontData dis) {+ public void parse_cmap_table (FontData dis) throws Error { if (cmap_table.has_data ()) { cmap_table.parse (dis); } else {@@ -265,7 +265,7 @@ public class DirectoryTable : Table { } } - public void parse_head_table (FontData dis) {+ public void parse_head_table (FontData dis) throws Error { if (head_table.has_data ()) { head_table.parse (dis); } else {@@ -35,6 +35,9 @@ public class Path { public double ymax = double.MIN; public double ymin = double.MAX; + /** The width of a stroked outline. */+ public double stroke = 0;+ bool edit = true; bool open = true; bool direction_is_set = false;@@ -86,7 +89,8 @@ public class Path { public static double fill_color_g = 0; public static double fill_color_b = 0; public static double fill_color_a = 1;- + + /** The stroke of an outline when the path is not filled. */ public static double stroke_width = 1; public static bool show_all_line_handles = true; public static bool fill_open_path = false;@@ -139,6 +143,10 @@ public class Path { return points.length () == 0; } + public void set_stroke (double width) {+ stroke = width;+ }+ public void draw_boundries (Context cr, WidgetAllocation allocation, double view_zoom) { double x = Glyph.reverse_path_coordinate_x (xmin); double y = Glyph.reverse_path_coordinate_y (ymin);@@ -1601,12 +1609,10 @@ public class Path { handle_y0 = 0; handle_y1 = 0; - //FIXME:+ //FIXME: all beziér paths //double_bezier_vector (s, start.x, start.get_right_handle ().x (), stop.get_left_handle ().x (), stop.x, out handle_x0, out handle_x1); //double_bezier_vector (s, start.y, start.get_right_handle ().y (), stop.get_left_handle ().y (), stop.y, out handle_y0, out handle_y1); - print (@"s: $s\n");- bezier_vector (s, start.x, start.get_right_handle ().x (), stop.get_left_handle ().x (), stop.x, out handle_x0, out handle_x1); bezier_vector (s, start.y, start.get_right_handle ().y (), stop.get_left_handle ().y (), stop.y, out handle_y0, out handle_y1); @@ -1,4 +1,3 @@- /* Copyright (C) 2012 Johan Mattsson @@ -30,8 +29,8 @@ public class SpinButton : Tool { double begin_y = 0; int begin_value = 0; - int max = 9999;- int min = 0;+ public int max = 9999;+ public int min = 0; public SpinButton (string? name = null, string tip = "", unichar key = '\0', uint modifier_flag = 0) { base (null , tip, key, modifier_flag);@@ -202,8 +201,6 @@ public class SpinButton : Tool { } else { v += "0"; }- - return; } if (v.substring (v.index_of_nth_char (1), 1) != ".") {@@ -215,11 +212,13 @@ public class SpinButton : Tool { centi = (int8) int.parse (v.substring (v.index_of_nth_char (3), 1)); milli = (int8) int.parse (v.substring (v.index_of_nth_char (4), 1)); - if (check_boundries && get_value () > max) {+ if (check_boundries && get_value () > max / 1000.0) {+ warning (@"Out of bounds ($new_value > $max)."); set_value_round (max, false); } - if (check_boundries && get_value () < min) {+ if (check_boundries && get_value () < min / 1000.0) {+ warning (@"Out of bounds ($new_value < $min)."); set_value_round (min, false); } @@ -24,14 +24,25 @@ public class StrokeTool : Tool { stroke_selected_paths (); }); }+ + public static void set_stroke_for_selected_paths (double width) {+ Glyph g = MainWindow.get_current_glyph ();+ + foreach (Path p in g.active_paths) {+ p.set_stroke (width);+ }+ + GlyphCanvas.redraw ();+ } + // convert stroke to outline void stroke_selected_paths () { Glyph g = MainWindow.get_current_glyph (); List<Path> paths = new List<Path> (); - foreach (Path p in g.path_list) {- paths.append (get_stroke (p, 4));- paths.append (get_stroke (p, -4));+ foreach (Path p in g.active_paths) {+ paths.append (get_stroke (p, p.stroke));+ paths.append (get_stroke (p, -1 * p.stroke)); } foreach (Path np in paths) {@@ -254,6 +265,9 @@ public class StrokeTool : Tool { double avg_angle; double angle; + double m, n, o, p;+ double ldnx, ldny;+ e.recalculate_linear_handles (); ra = e.get_right_handle ().angle;@@ -272,11 +286,6 @@ public class StrokeTool : Tool { angle = avg_angle - PI / 2; - ldnx = 0;- ldny = 0;- - double m, n, o, p;- m = cos (ra + PI / 2) * thickness; n = sin (ra + PI / 2) * thickness; @@ -62,6 +62,11 @@ public class Toolbox : GLib.Object { update_expanders (); } + public static void set_object_stroke (double width) {+ DrawingTools.object_stroke.set_value_round (width);+ redraw_tool_box ();+ }+ public static void set_allocation (int w, int h) { allocation_width = w; allocation_height = h;