The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Show curve orientation with an arrow

These changes was commited to the Birdfont repository Sat, 11 Apr 2015 20:57:41 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Sat, 11 Apr 2015 20:57:41 +0000]

Updated Files

libbirdfont/DrawingTools.vala
libbirdfont/Glyph.vala
libbirdfont/OrientationTool.vala
libbirdfont/Path.vala
libbirdfont/Theme.vala
resources/icons.bf
--- a/libbirdfont/DrawingTools.vala +++ b/libbirdfont/DrawingTools.vala @@ -85,7 +85,7 @@ Tool undo_tool; Tool select_all_button; - Tool reverse_path_tool; + OrientationTool reverse_path_tool; Tool move_layer; Tool flip_vertical; Tool flip_horizontal; @@ -579,16 +579,7 @@ }); draw_tool_modifiers.add_tool (create_line); - reverse_path_tool = new Tool ("reverse_path", t_("Create counter from outline")); - reverse_path_tool.select_action.connect ((self) => { - Glyph g = MainWindow.get_current_glyph (); - - foreach (Path p in g.active_paths) { - p.reverse (); - } - - g.redraw_area (0, 0, g.allocation.width, g.allocation.height); - }); + reverse_path_tool = new OrientationTool ("reverse_path", t_("Create counter from outline")); draw_tool_modifiers.add_tool (reverse_path_tool); move_layer = new Tool ("move_layer", t_("Move to path to the bottom layer"));
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -105,6 +105,8 @@ public const double CANVAS_MIN = -10000; public const double CANVAS_MAX = 10000; + + public bool show_orientation_arrow = false; public Glyph (string name, unichar unichar_code = 0) { this.name = name; @@ -1437,7 +1439,7 @@ /** Draw filled paths. */ public void draw_paths (Context cr) { PathList stroke; - + cr.save (); cr.new_path (); foreach (Path p in path_list) { @@ -1453,12 +1455,14 @@ } public void draw_path (Context cr) { + PathList stroke; if (is_open () && Path.fill_open_path) { cr.save (); cr.new_path (); foreach (Path p in path_list) { if (p.stroke > 0) { - draw_path_list (StrokeTool.get_stroke (p, p.stroke), cr, get_path_fill_color ()); + stroke = StrokeTool.get_stroke (p, p.stroke); + draw_path_list (stroke, cr, get_path_fill_color ()); } p.draw_path (cr, this, get_path_fill_color ()); @@ -1471,27 +1475,29 @@ cr.save (); cr.new_path (); foreach (Path p in path_list) { - if (p.stroke > 0) { - draw_outline_for_paths (StrokeTool.get_stroke (p, p.stroke), cr); + if (p.stroke > 0) { + stroke = StrokeTool.get_stroke (p, p.stroke); + draw_outline_for_paths (stroke, cr); } p.draw_outline (cr); - p.draw_edit_points (cr); + p.draw_edit_points (cr); } cr.restore (); } - + if (!is_open ()) { // This was good for testing but it is way too slow: // Svg.draw_svg_path (cr, get_svg_data (), Glyph.xc () + left, Glyph.yc () - baseline); - + cr.save (); cr.new_path (); foreach (Path p in path_list) { if (p.stroke == 0) { p.draw_path (cr, this, Color.black ()); } else { - draw_path_list (StrokeTool.get_stroke (p, p.stroke), cr, Color.black ()); + stroke = StrokeTool.get_stroke (p, p.stroke); + draw_path_list (stroke, cr, Color.black ()); } } cr.close_path (); @@ -1509,6 +1515,19 @@ cr.close_path (); cr.fill (); cr.restore (); + } + } + + if (show_orientation_arrow) { + foreach (Path p in path_list) { + if (p.stroke > 0) { + stroke = StrokeTool.get_stroke (p, p.stroke); + foreach (Path ps in stroke.paths) { + ps.draw_orientation_arrow (cr); + } + } else { + p.draw_orientation_arrow (cr); + } } } }
--- /dev/null +++ b/libbirdfont/OrientationTool.vala @@ -1,1 +1,66 @@ + /* + Copyright (C) 2015 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 + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + */ + + using Math; + using Cairo; + + namespace BirdFont { + + public class OrientationTool : Tool { + + public OrientationTool (string n, string tip) { + base (n, tip); + + select_action.connect ((self) => { + Glyph g = MainWindow.get_current_glyph (); + + foreach (Path p in g.active_paths) { + p.reverse (); + } + + GlyphCanvas.redraw (); + }); + + panel_move_action.connect ((t, x, y) => { + Glyph g = MainWindow.get_current_glyph (); + + if (!g.show_orientation_arrow && is_active ()) { + g.show_orientation_arrow = true; + GlyphCanvas.redraw (); + } + + return false; + }); + + move_out_action.connect ((t) => { + Glyph g = MainWindow.get_current_glyph (); + + if (g.show_orientation_arrow) { + g.show_orientation_arrow = false; + GlyphCanvas.redraw (); + } + }); + + draw_action.connect ((self, cr, glyph) => { + draw_actions (cr); + }); + } + + public static void draw_actions (Context cr) { + + } + } + + }
--- a/libbirdfont/Path.vala +++ b/libbirdfont/Path.vala @@ -280,12 +280,42 @@ c = (!) color; cr.set_source_rgba (c.r, c.g, c.b, c.a); } else { - if (is_clockwise ()) { - cr.set_source_rgba (80/255.0, 95/255.0, 137/255.0, 0.5); - } else { - cr.set_source_rgba (144/255.0, 145/255.0, 236/255.0, 0.5); + Theme.color (cr, "Selected Objects"); + } + } + + public void draw_orientation_arrow (Context cr) { + EditPoint top = new EditPoint (); + double max = Glyph.CANVAS_MIN; + Text arrow; + double x, y, angle; + double size = 50 * Glyph.ivz (); + + foreach (EditPoint e in points) { + if (e.y > max) { + max = e.y; + top = e; } } + + arrow = new Text ("orientation_arrow", size); + arrow.load_font ("icons.bf"); + arrow.use_cache (false); + + Theme.text_color (arrow, "Highlighted 1"); + + angle = top.get_right_handle ().angle; + x = Glyph.xc () + top.x + cos (angle + PI / 2) * 10 * Glyph.ivz (); + y = Glyph.yc () - top.y - sin (angle + PI / 2) * 10 * Glyph.ivz (); + + cr.save (); + cr.translate (x, y); + cr.rotate (-angle); + cr.translate (-x, -y); + + arrow.draw_at_baseline (cr, x, y); + + cr.restore (); } private void draw_next (EditPoint e, EditPoint en, Context cr, bool highlighted = false) {
--- a/libbirdfont/Theme.vala +++ b/libbirdfont/Theme.vala @@ -100,6 +100,7 @@ Theme.set_default_color ("Stroke Color", 0, 0, 0, 1); Theme.set_default_color ("Handle Color", 0, 0, 0, 1); Theme.set_default_color ("Fill Color", 0.5, 0.5, 0.5, 1); + Theme.set_default_color ("Selected Objects", 0.5, 0.5, 0.5, 1); Theme.set_default_color ("Background 1", 1, 1, 1, 1); Theme.set_default_color ("Background 2", 101 / 255.0, 108 / 255.0, 116 / 255.0, 1);
--- a/resources/icons.bf +++ b/resources/icons.bf @@ -574,6 +574,12 @@ <collection unicode="U+6f"> <selected id="1"/> <glyph id="1" left="-28" right="28"> + </glyph> + </collection> + <collection name="orientation_arrow"> + <selected id="1"/> + <glyph id="1" left="-28" right="28"> + <path stroke="0" skew="0" data="S -41.4110032362,2.3559870550 L -21.4110032362,2.3559870550 L -21.4110032362,6.3559870550 L -13.1715210356,0.0809061489 L -21.4110032362,-5.6440129450 L -21.4110032362,-5.6440129450 L -21.4110032362,-1.6440129450 L -41.4110032362,-1.6440129450 L -41.4110032362,2.3559870550" /> </glyph> </collection> <collection unicode="U+70"> @@ -971,6 +977,7 @@ <ligature sequence="n e x t _ k e r n i n g _ s t r i n g" replacement="next_kerning_string"/> <ligature sequence="k e r n i n g _ t e x t _ i n p u t" replacement="kerning_text_input"/> <ligature sequence="c o n t r a s t _ t h r e s h o l d" replacement="contrast_threshold"/> + <ligature sequence="o r i e n t a t i o n _ a r r o w" replacement="orientation_arrow"/> <ligature sequence="d e l e t e _ b a c k g r o u n d" replacement="delete_background"/> <ligature sequence="n e w _ p o i n t _ o n _ p a t h" replacement="new_point_on_path"/> <ligature sequence="i n s e r t _ b a c k g r o u n d" replacement="insert_background"/>