The Birdfont Source Code
Convert last node to corner in Beziér tool
These changes was commited to the Birdfont repository Thu, 21 May 2015 07:33:36 +0000.
Contributing
Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
Convert last node to corner in Beziér tool
--- a/libbirdfont/BezierTool.vala
+++ b/libbirdfont/BezierTool.vala
@@ -38,6 +38,12 @@
double last_release_time = 0;
double last_press_time = 0;
bool button_down = false;
+
+ /** Create a corner instead of a control point with reflective handles. */
+ bool corner_node = false;
+
+ /** Swap right and left handles if orientation changes */
+ bool swap = false;
public BezierTool (string name) {
base (name, t_ ("Create Beziér curves"));
@@ -93,9 +99,11 @@
button_down = true;
- return_if_fail (state != MOVE_HANDLES);
- return_if_fail (state != MOVE_LAST_HANDLE_RIGHT);
- return_if_fail (state != MOVE_LAST_HANDLE_LEFT);
+ if (state == MOVE_HANDLES
+ || state == MOVE_LAST_HANDLE_RIGHT
+ || state == MOVE_LAST_HANDLE_LEFT) {
+ return;
+ }
if (b == 2) {
if (g.is_open ()) {
@@ -131,8 +139,22 @@
if (GridTool.is_visible ()) {
GridTool.tie_coordinate (ref px, ref py);
}
-
- if (state == NONE) {
+
+ if (corner_node) {
+ if (current_path.is_open ()) {
+ current_point = current_path.add (px, py);
+ current_path.hide_end_handle = true;
+ current_point.get_left_handle ().convert_to_line ();
+ current_point.recalculate_linear_handles ();
+ set_point_type ();
+ g.clear_active_paths ();
+ g.add_active_path (current_path);
+ GlyphCanvas.redraw ();
+ state = MOVE_POINT;
+ } else {
+ state = NONE;
+ }
+ } else if (state == NONE) {
g.open_path ();
current_path = new Path ();
current_path.reopen ();
@@ -156,7 +178,6 @@
} else if (state == MOVE_POINT) {
if (PenTool.can_join (current_point)) {
EditPoint first = current_path.get_first_point ();
- bool swap;
p = PenTool.join_paths (current_point);
return_if_fail (p != null);
@@ -204,7 +225,11 @@
button_down = false;
- return_if_fail (state != MOVE_POINT);
+ if (state == NONE || state == MOVE_POINT) {
+ return;
+ }
+
+ corner_node = false;
// ignore double clicks
if ((GLib.get_real_time () - last_release_time) / 1000000.0 < 0.2) {
@@ -230,6 +255,7 @@
set_point_type ();
g.clear_active_paths ();
g.add_active_path (current_path);
+
GlyphCanvas.redraw ();
state = MOVE_POINT;
} else if (state == MOVE_LAST_HANDLE_LEFT || state == MOVE_LAST_HANDLE_RIGHT) {
@@ -274,8 +300,11 @@
|| state == MOVE_LAST_HANDLE_RIGHT) {
current_path.hide_end_handle = false;
- current_point.set_reflective_handles (true);
- current_point.convert_to_curve ();
+
+ if (!corner_node) {
+ current_point.set_reflective_handles (true);
+ current_point.convert_to_curve ();
+ }
if (state == MOVE_LAST_HANDLE_LEFT) {
current_point.get_left_handle ().move_to_coordinate (px, py);
@@ -311,7 +340,10 @@
}
public void stop_drawing () {
- if (state == MOVE_POINT && current_path.points.size > 0) {
+ if (state == MOVE_POINT
+ && current_path.points.size > 0
+ && current_path.is_open ()) {
+
current_path.delete_last_point ();
current_path.reset_stroke ();
current_path.create_full_stroke (); // cache better stroke
@@ -328,8 +360,27 @@
MainWindow.set_cursor (NativeWindow.VISIBLE);
state = NONE;
}
+ }
+
+ public void create_corner () {
+ Glyph g = MainWindow.get_current_glyph ();
+
+ corner_node = true;
+ g.open_path ();
+
+ if (current_path.is_open ()) {
+ current_path.delete_last_point ();
+ current_path.reset_stroke ();
+ current_point = current_path.get_last_point ();
+ state = MOVE_HANDLES;
+ } else {
+ state = swap ? MOVE_LAST_HANDLE_RIGHT : MOVE_LAST_HANDLE_LEFT;
+ }
+
+ current_point.set_reflective_handles (false);
+ current_point.get_right_handle ().convert_to_curve ();
}
}
}
--- a/libbirdfont/HiddenTools.vala
+++ b/libbirdfont/HiddenTools.vala
@@ -47,7 +47,15 @@
bezier_line.is_tool_modifier = true;
hidden_expander.add_tool (bezier_line);
bezier_line.set_tool_visibility (false);
-
+
+ Tool bezier_corner = new Tool ("bezier_corner", t_("Convert the last control point to a corner node"));
+ bezier_corner.select_action.connect ((self) => {
+ DrawingTools.bezier_tool.create_corner ();
+ });
+ bezier_corner.is_tool_modifier = true;
+ hidden_expander.add_tool (bezier_corner);
+ bezier_corner.set_tool_visibility (false);
+
expanders.add (hidden_expander);
}
--- a/resources/key_bindings.xml
+++ b/resources/key_bindings.xml
@@ -5,9 +5,6 @@
<action key="r" ctrl="true" alt="false" command="false" shift="false" action="recent files" />
<action key="s" ctrl="true" alt="false" command="false" shift="false" action="save" />
<action key="S" ctrl="true" alt="false" command="false" shift="true" action="save as" />
- <action key="e" ctrl="true" alt="false" command="false" shift="false" action="export" />
- <action key="" ctrl="false" alt="false" command="false" shift="false" action="export settings" />
- <action key="p" ctrl="true" alt="false" command="false" shift="false" action="preview" />
<action key="" ctrl="false" alt="false" command="false" shift="false" action="select character set" />
<action key="" ctrl="false" alt="false" command="false" shift="false" action="quit" />
<action key="z" ctrl="true" alt="false" command="false" shift="false" action="undo" />
@@ -18,9 +15,6 @@
<action key="a" ctrl="true" alt="false" command="false" shift="false" action="select all paths" />
<action key="" ctrl="false" alt="false" command="false" shift="false" action="move to baseline" />
<action key="f" ctrl="true" alt="false" command="false" shift="false" action="search" />
- <action key="E" ctrl="true" alt="false" command="false" shift="true" action="export glyph as svg" />
- <action key="i" ctrl="true" alt="false" command="false" shift="false" action="import svg file" />
- <action key="b" ctrl="true" alt="false" command="false" shift="false" action="import background image" />
<action key="" ctrl="false" alt="false" command="false" shift="false" action="simplify path" />
<action key="" ctrl="false" alt="false" command="false" shift="false" action="close path" />
<action key="" ctrl="false" alt="false" command="false" shift="false" action="glyph sequence" />
@@ -32,6 +26,13 @@
<action key="s" ctrl="true" alt="false" command="false" shift="false" action="select next point" />
<action key="q" ctrl="true" alt="false" command="false" shift="false" action="select previous point" />
<action key="t" ctrl="true" alt="false" command="false" shift="false" action="select point below" />
+ <action key="e" ctrl="true" alt="false" command="false" shift="false" action="export" />
+ <action key="E" ctrl="true" alt="false" command="false" shift="true" action="export glyph as svg" />
+ <action key="i" ctrl="true" alt="false" command="false" shift="false" action="import svg file" />
+ <action key="" ctrl="false" alt="false" command="false" shift="false" action="import svg folder" />
+ <action key="b" ctrl="true" alt="false" command="false" shift="false" action="import background image" />
+ <action key="" ctrl="false" alt="false" command="false" shift="false" action="export settings" />
+ <action key="p" ctrl="true" alt="false" command="false" shift="false" action="preview" />
<action key="" ctrl="false" alt="false" command="false" shift="false" action="next tab" />
<action key="" ctrl="false" alt="false" command="false" shift="false" action="previous tab" />
<action key="w" ctrl="true" alt="false" command="false" shift="false" action="close tab" />
@@ -89,6 +90,9 @@
<action key="" ctrl="false" alt="false" command="false" shift="false" action="apply_stroke" />
<action key="" ctrl="false" alt="false" command="false" shift="false" action="object_stroke" />
<action key="" ctrl="false" alt="false" command="false" shift="false" action="stroke_to_outline" />
+ <action key="" ctrl="false" alt="false" command="false" shift="false" action="line_cap_butt" />
+ <action key="" ctrl="false" alt="false" command="false" shift="false" action="line_cap_round" />
+ <action key="" ctrl="false" alt="false" command="false" shift="false" action="line_cap_square" />
<action key="" ctrl="false" alt="false" command="false" shift="false" action="help_lines" />
<action key="" ctrl="false" alt="false" command="false" shift="false" action="show_xheight_helplines" />
<action key="" ctrl="false" alt="false" command="false" shift="false" action="background_help_lines" />
@@ -116,5 +120,6 @@
<action key="+" ctrl="true" alt="false" command="false" shift="false" action="zoom_in" />
<action key="-" ctrl="true" alt="false" command="false" shift="false" action="zoom_out" />
<action key="s" ctrl="false" alt="false" command="false" shift="false" action="bezier_line" />
+ <action key="u" ctrl="false" alt="false" command="false" shift="false" action="bezier_corner" />
</bindings>