/* PenTool.c generated by valac 0.56.17, the Vala compiler
 * generated from PenTool.vala, do not modify */

/*
Copyright (C) 2012 2013 2014 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.
*/

#include "birdfont.h"
#include <glib.h>
#include <float.h>
#include <math.h>
#include <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <cairo-gobject.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	BIRD_FONT_PEN_TOOL_0_PROPERTY,
	BIRD_FONT_PEN_TOOL_NUM_PROPERTIES
};
static GParamSpec* bird_font_pen_tool_properties[BIRD_FONT_PEN_TOOL_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block52Data Block52Data;
#define _bird_font_color_unref0(var) ((var == NULL) ? NULL : (var = (bird_font_color_unref (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _BirdFontPenToolPrivate {
	gboolean first_move_action;
	gboolean last_selected_is_handle;
};

struct _Block52Data {
	int _ref_count_;
	gdouble nx;
	gdouble ny;
	gdouble df;
	gdouble dn;
	BirdFontEditPoint* oe0;
	BirdFontEditPoint* oe1;
	BirdFontEditPoint* oe2;
};

static gint BirdFontPenTool_private_offset;
static gpointer bird_font_pen_tool_parent_class = NULL;
gboolean bird_font_pen_tool_move_selected = FALSE;
gboolean bird_font_pen_tool_move_selected_handle = FALSE;
gboolean bird_font_pen_tool_move_point_on_path = FALSE;
gboolean bird_font_pen_tool_edit_active_corner = FALSE;
gboolean bird_font_pen_tool_move_point_independent_of_handle = FALSE;
GeeArrayList* bird_font_pen_tool_selected_points = NULL;
BirdFontEditPointHandle* bird_font_pen_tool_active_handle = NULL;
BirdFontEditPointHandle* bird_font_pen_tool_selected_handle = NULL;
BirdFontPointSelection* bird_font_pen_tool_handle_selection = NULL;
BirdFontEditPoint* bird_font_pen_tool_active_edit_point = NULL;
BirdFontPath* bird_font_pen_tool_active_path = NULL;
BirdFontEditPoint* bird_font_pen_tool_selected_point = NULL;
BirdFontPath* bird_font_pen_tool_selected_path = NULL;
gdouble bird_font_pen_tool_last_point_x = (gdouble) 0;
gdouble bird_font_pen_tool_last_point_y = (gdouble) 0;
gboolean bird_font_pen_tool_show_selection_box = FALSE;
static gdouble bird_font_pen_tool_selection_box_x;
static gdouble bird_font_pen_tool_selection_box_x = (gdouble) 0;
static gdouble bird_font_pen_tool_selection_box_y;
static gdouble bird_font_pen_tool_selection_box_y = (gdouble) 0;
static gdouble bird_font_pen_tool_selection_box_last_x;
static gdouble bird_font_pen_tool_selection_box_last_x = (gdouble) 0;
static gdouble bird_font_pen_tool_selection_box_last_y;
static gdouble bird_font_pen_tool_selection_box_last_y = (gdouble) 0;
static gboolean bird_font_pen_tool_point_selection_image;
static gboolean bird_font_pen_tool_point_selection_image = FALSE;
gdouble bird_font_pen_tool_precision = (gdouble) 1;
gint bird_font_pen_tool_begin_action_x = 0;
gint bird_font_pen_tool_begin_action_y = 0;
static GeeArrayList* bird_font_pen_tool_clockwise;
static GeeArrayList* bird_font_pen_tool_clockwise = NULL;
static GeeArrayList* bird_font_pen_tool_counter_clockwise;
static GeeArrayList* bird_font_pen_tool_counter_clockwise = NULL;
gdouble bird_font_pen_tool_path_stroke_width = (gdouble) 0;
gdouble bird_font_pen_tool_simplification_threshold = 0.5;
gboolean bird_font_pen_tool_retain_angle = FALSE;
gboolean bird_font_pen_tool_on_axis = FALSE;
VALA_EXTERN BirdFontSpinButton* bird_font_settings_display_precision;

static void __lambda25_ (BirdFontPenTool* self,
                  BirdFontTool* _self_);
static void ___lambda25__bird_font_tool_select_action (BirdFontTool* _sender,
                                                BirdFontTool* selected,
                                                gpointer self);
static void __lambda26_ (BirdFontPenTool* self,
                  BirdFontTool* _self_);
static void ___lambda26__bird_font_tool_deselect_action (BirdFontTool* _sender,
                                                  BirdFontTool* selected,
                                                  gpointer self);
static void __lambda27_ (BirdFontPenTool* self,
                  BirdFontTool* _self_,
                  gint b,
                  gint x,
                  gint y);
static void ___lambda27__bird_font_tool_press_action (BirdFontTool* _sender,
                                               BirdFontTool* selected,
                                               gint button,
                                               gint x,
                                               gint y,
                                               gpointer self);
static void __lambda367_ (BirdFontPenTool* self,
                   BirdFontTool* _self_,
                   gint b,
                   gint x,
                   gint y);
static void ___lambda367__bird_font_tool_double_click_action (BirdFontTool* _sender,
                                                       BirdFontTool* selected,
                                                       gint button,
                                                       gint x,
                                                       gint y,
                                                       gpointer self);
static void __lambda368_ (BirdFontPenTool* self,
                   BirdFontTool* _self_,
                   gint b,
                   gint ix,
                   gint iy);
static void ___lambda368__bird_font_tool_release_action (BirdFontTool* _sender,
                                                  BirdFontTool* selected,
                                                  gint button,
                                                  gint x,
                                                  gint y,
                                                  gpointer self);
static void __lambda369_ (BirdFontPenTool* self,
                   BirdFontTool* _self_,
                   gint x,
                   gint y);
static void ___lambda369__bird_font_tool_move_action (BirdFontTool* _sender,
                                               BirdFontTool* selected,
                                               gint x,
                                               gint y,
                                               gpointer self);
static void __lambda370_ (BirdFontPenTool* self,
                   BirdFontTool* _self_,
                   guint32 keyval);
VALA_EXTERN gboolean bird_font_is_arrow_key (guint keyval);
static void bird_font_pen_tool_move_selected_points (BirdFontPenTool* self,
                                              guint keyval);
static void bird_font_pen_tool_move_select_next_point (guint keyval);
static void ___lambda370__bird_font_tool_key_press_action (BirdFontTool* _sender,
                                                    BirdFontTool* selected,
                                                    guint32 keyval,
                                                    gpointer self);
static void __lambda371_ (BirdFontPenTool* self,
                   BirdFontTool* _self_,
                   guint32 keyval);
static void ___lambda371__bird_font_tool_key_release_action (BirdFontTool* _sender,
                                                      BirdFontTool* selected,
                                                      guint32 keyval,
                                                      gpointer self);
static void __lambda372_ (BirdFontPenTool* self,
                   BirdFontTool* tool,
                   cairo_t* cairo_context,
                   BirdFontGlyph* glyph);
static void ___lambda372__bird_font_tool_draw_action (BirdFontTool* _sender,
                                               BirdFontTool* selected,
                                               cairo_t* cr,
                                               BirdFontGlyph* glyph,
                                               gpointer self);
static void bird_font_pen_tool_get_tie_position (BirdFontEditPoint* current_point,
                                          gdouble* x,
                                          gdouble* y);
static void bird_font_pen_tool_process_deleted (void);
static void bird_font_pen_tool_get_closes_point_in_segment (BirdFontEditPoint* ep0,
                                                     BirdFontEditPoint* ep1,
                                                     BirdFontEditPoint* ep2,
                                                     gdouble px,
                                                     gdouble py,
                                                     gdouble* nx,
                                                     gdouble* ny);
static Block52Data* block52_data_ref (Block52Data* _data52_);
static void block52_data_unref (void * _userdata_);
static gboolean __lambda34_ (Block52Data* _data52_,
                      gdouble xa,
                      gdouble ya,
                      gdouble ta);
static gboolean ___lambda34__bird_font_path_raster_iterator (gdouble x,
                                                      gdouble y,
                                                      gdouble step,
                                                      gpointer self);
static void bird_font_pen_tool_cancel_stroke_creator (void);
static void bird_font_pen_tool_curve_active_corner_event (BirdFontPenTool* self,
                                                   gdouble event_x,
                                                   gdouble event_y);
static void bird_font_pen_tool_set_type_for_moving_handle (BirdFontPenTool* self);
static void bird_font_pen_tool_move_point_on_handles (BirdFontPenTool* self,
                                               gdouble px,
                                               gdouble py,
                                               gdouble* cx,
                                               gdouble* cy);
static gboolean bird_font_pen_tool_is_over_handle (BirdFontPenTool* self,
                                            gdouble event_x,
                                            gdouble event_y);
static void bird_font_pen_tool_curve_corner_event (BirdFontPenTool* self,
                                            gdouble event_x,
                                            gdouble event_y);
static void bird_font_pen_tool_draw_selection_box (BirdFontPenTool* self,
                                            cairo_t* cr);
static void bird_font_pen_tool_draw_point_selection_circle (BirdFontPenTool* self,
                                                     cairo_t* cr);
static void bird_font_pen_tool_draw_merge_icon (BirdFontPenTool* self,
                                         cairo_t* cr);
static BirdFontPointSelection* bird_font_pen_tool_get_closest_point (BirdFontPenTool* self,
                                                              gdouble ex,
                                                              gdouble ey,
                                                              BirdFontPath** path);
static gboolean bird_font_pen_tool_is_close_to_path (BirdFontPenTool* self,
                                              BirdFontPath* p,
                                              gdouble event_x,
                                              gdouble event_y);
static gdouble bird_font_pen_tool_get_contact_surface (void);
static BirdFontPointSelection* bird_font_pen_tool_insert_edit_point (gdouble x,
                                                              gdouble y);
static void bird_font_pen_tool_set_point_type (BirdFontEditPoint* p);
static void bird_font_pen_tool_set_default_handle_positions_on_path (BirdFontPath* path);
static gboolean bird_font_pen_tool_is_close_to_handle (BirdFontPenTool* self,
                                                BirdFontEditPoint* selected_corner,
                                                gdouble event_x,
                                                gdouble event_y,
                                                gdouble distance_to_edit_point);
static BirdFontPointSelection* bird_font_pen_tool_get_closest_handle (BirdFontPenTool* self,
                                                               gdouble event_x,
                                                               gdouble event_y);
static BirdFontPointSelection* bird_font_pen_tool_get_next_point_up (void);
static BirdFontPointSelection* bird_font_pen_tool_get_next_point_down (void);
static BirdFontPointSelection* bird_font_pen_tool_get_next_point_left (void);
static BirdFontPointSelection* bird_font_pen_tool_get_next_point_right (void);
static void bird_font_pen_tool_set_selected_point (BirdFontEditPoint* ep,
                                            BirdFontPath* p);
static BirdFontPointSelection* bird_font_pen_tool_get_next_point (gdouble angle);
static void bird_font_pen_tool_finalize (GObject * obj);
static GType bird_font_pen_tool_get_type_once (void);
static void _vala_bird_font_pen_tool_get_property (GObject * object,
                                            guint property_id,
                                            GValue * value,
                                            GParamSpec * pspec);

static inline gpointer
bird_font_pen_tool_get_instance_private (BirdFontPenTool* self)
{
	return G_STRUCT_MEMBER_P (self, BirdFontPenTool_private_offset);
}

static void
__lambda25_ (BirdFontPenTool* self,
             BirdFontTool* _self_)
{
	g_return_if_fail (_self_ != NULL);
}

static void
___lambda25__bird_font_tool_select_action (BirdFontTool* _sender,
                                           BirdFontTool* selected,
                                           gpointer self)
{
	__lambda25_ ((BirdFontPenTool*) self, selected);
}

static void
__lambda26_ (BirdFontPenTool* self,
             BirdFontTool* _self_)
{
	g_return_if_fail (_self_ != NULL);
}

static void
___lambda26__bird_font_tool_deselect_action (BirdFontTool* _sender,
                                             BirdFontTool* selected,
                                             gpointer self)
{
	__lambda26_ ((BirdFontPenTool*) self, selected);
}

static void
__lambda27_ (BirdFontPenTool* self,
             BirdFontTool* _self_,
             gint b,
             gint x,
             gint y)
{
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp1_;
	BirdFontFont* _tmp2_;
	BirdFontFont* _tmp3_;
	gboolean _tmp4_ = FALSE;
	g_return_if_fail (_self_ != NULL);
	_tmp0_ = gee_array_list_new (BIRD_FONT_TYPE_PATH, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (bird_font_pen_tool_clockwise);
	bird_font_pen_tool_clockwise = _tmp0_;
	_tmp1_ = gee_array_list_new (BIRD_FONT_TYPE_PATH, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (bird_font_pen_tool_counter_clockwise);
	bird_font_pen_tool_counter_clockwise = _tmp1_;
	bird_font_pen_tool_begin_action_x = x;
	bird_font_pen_tool_begin_action_y = y;
	bird_font_pen_tool_update_orientation ();
	self->priv->first_move_action = TRUE;
	bird_font_pen_tool_last_point_x = bird_font_glyph_path_coordinate_x ((gdouble) x);
	bird_font_pen_tool_last_point_y = bird_font_glyph_path_coordinate_y ((gdouble) y);
	g_signal_emit_by_name ((BirdFontTool*) self, "move-action", (BirdFontTool*) self, x, y);
	bird_font_pen_tool_press (self, b, x, y, FALSE);
	if (bird_font_bird_font_android) {
		bird_font_pen_tool_point_selection_image = TRUE;
	}
	bird_font_pen_tool_selection_box_x = (gdouble) x;
	bird_font_pen_tool_selection_box_y = (gdouble) y;
	bird_font_pen_tool_last_point_x = bird_font_glyph_path_coordinate_x ((gdouble) x);
	bird_font_pen_tool_last_point_y = bird_font_glyph_path_coordinate_y ((gdouble) y);
	_tmp2_ = bird_font_bird_font_get_current_font ();
	_tmp3_ = _tmp2_;
	bird_font_font_touch (_tmp3_);
	_g_object_unref0 (_tmp3_);
	if (b == 1) {
		gboolean _tmp5_ = FALSE;
		if (bird_font_grid_tool_has_ttf_grid ()) {
			_tmp5_ = TRUE;
		} else {
			_tmp5_ = bird_font_grid_tool_is_visible ();
		}
		_tmp4_ = _tmp5_;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		bird_font_pen_tool_move (self, x, y);
	}
	bird_font_pen_tool_reset_stroke ();
}

static void
___lambda27__bird_font_tool_press_action (BirdFontTool* _sender,
                                          BirdFontTool* selected,
                                          gint button,
                                          gint x,
                                          gint y,
                                          gpointer self)
{
	__lambda27_ ((BirdFontPenTool*) self, selected, button, x, y);
}

static void
__lambda367_ (BirdFontPenTool* self,
              BirdFontTool* _self_,
              gint b,
              gint x,
              gint y)
{
	g_return_if_fail (_self_ != NULL);
	bird_font_pen_tool_last_point_x = bird_font_glyph_path_coordinate_x ((gdouble) x);
	bird_font_pen_tool_last_point_y = bird_font_glyph_path_coordinate_y ((gdouble) y);
	bird_font_pen_tool_press (self, b, (gint) x, (gint) y, TRUE);
}

static void
___lambda367__bird_font_tool_double_click_action (BirdFontTool* _sender,
                                                  BirdFontTool* selected,
                                                  gint button,
                                                  gint x,
                                                  gint y,
                                                  gpointer self)
{
	__lambda367_ ((BirdFontPenTool*) self, selected, button, x, y);
}

static void
__lambda368_ (BirdFontPenTool* self,
              BirdFontTool* _self_,
              gint b,
              gint ix,
              gint iy)
{
	gdouble x = 0.0;
	gdouble y = 0.0;
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	gboolean _tmp1_ = FALSE;
	BirdFontEditPointHandle* _tmp6_;
	BirdFontFont* _tmp7_;
	BirdFontFont* _tmp8_;
	g_return_if_fail (_self_ != NULL);
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	_g_object_unref0 (g);
	g = _tmp0_;
	x = bird_font_glyph_path_coordinate_x ((gdouble) ix);
	y = bird_font_glyph_path_coordinate_y ((gdouble) iy);
	if (bird_font_pen_tool_has_join_icon (self)) {
		BirdFontEditPoint* _tmp2_;
		_tmp2_ = bird_font_pen_tool_active_edit_point;
		_tmp1_ = _tmp2_ != NULL;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		BirdFontEditPoint* _tmp3_;
		BirdFontPath* _tmp4_;
		BirdFontPath* _tmp5_;
		_tmp3_ = bird_font_pen_tool_active_edit_point;
		_tmp4_ = bird_font_pen_tool_join_paths (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, BIRD_FONT_TYPE_EDIT_POINT, BirdFontEditPoint));
		_tmp5_ = _tmp4_;
		_g_object_unref0 (_tmp5_);
	}
	_tmp6_ = bird_font_edit_point_handle_new_empty ();
	_g_object_unref0 (bird_font_pen_tool_active_handle);
	bird_font_pen_tool_active_handle = _tmp6_;
	if (bird_font_pen_tool_show_selection_box) {
		bird_font_pen_tool_select_points_in_box ();
	}
	bird_font_pen_tool_move_selected = FALSE;
	bird_font_pen_tool_move_selected_handle = FALSE;
	bird_font_pen_tool_edit_active_corner = FALSE;
	bird_font_pen_tool_show_selection_box = FALSE;
	bird_font_pen_tool_set_orientation ();
	bird_font_main_window_set_cursor (BIRD_FONT_NATIVE_WINDOW_VISIBLE);
	bird_font_pen_tool_point_selection_image = FALSE;
	_tmp7_ = bird_font_bird_font_get_current_font ();
	_tmp8_ = _tmp7_;
	bird_font_font_touch (_tmp8_);
	_g_object_unref0 (_tmp8_);
	{
		GeeArrayList* _p_list = NULL;
		BirdFontGlyph* _tmp9_;
		GeeArrayList* _tmp10_;
		gint _p_size = 0;
		GeeArrayList* _tmp11_;
		gint _tmp12_;
		gint _tmp13_;
		gint _p_index = 0;
		_tmp9_ = g;
		_tmp10_ = bird_font_glyph_get_visible_paths (_tmp9_);
		_p_list = _tmp10_;
		_tmp11_ = _p_list;
		_tmp12_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp11_);
		_tmp13_ = _tmp12_;
		_p_size = _tmp13_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp14_;
			gint _tmp15_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp16_;
			gpointer _tmp17_;
			gboolean _tmp18_ = FALSE;
			BirdFontPath* _tmp19_;
			BirdFontPath* _tmp37_;
			BirdFontPathList* _tmp38_;
			_p_index = _p_index + 1;
			_tmp14_ = _p_index;
			_tmp15_ = _p_size;
			if (!(_tmp14_ < _tmp15_)) {
				break;
			}
			_tmp16_ = _p_list;
			_tmp17_ = gee_abstract_list_get ((GeeAbstractList*) _tmp16_, _p_index);
			p = (BirdFontPath*) _tmp17_;
			_tmp19_ = p;
			if (bird_font_path_is_open (_tmp19_)) {
				BirdFontPath* _tmp20_;
				GeeArrayList* _tmp21_;
				GeeArrayList* _tmp22_;
				gint _tmp23_;
				gint _tmp24_;
				_tmp20_ = p;
				_tmp21_ = bird_font_path_get_points (_tmp20_);
				_tmp22_ = _tmp21_;
				_tmp23_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp22_);
				_tmp24_ = _tmp23_;
				_tmp18_ = _tmp24_ > 0;
			} else {
				_tmp18_ = FALSE;
			}
			if (_tmp18_) {
				BirdFontPath* _tmp25_;
				BirdFontEditPoint* _tmp26_;
				BirdFontEditPoint* _tmp27_;
				BirdFontPath* _tmp28_;
				BirdFontEditPoint* _tmp29_;
				BirdFontEditPoint* _tmp30_;
				BirdFontPath* _tmp31_;
				BirdFontEditPoint* _tmp32_;
				BirdFontEditPoint* _tmp33_;
				BirdFontPath* _tmp34_;
				BirdFontEditPoint* _tmp35_;
				BirdFontEditPoint* _tmp36_;
				_tmp25_ = p;
				_tmp26_ = bird_font_path_get_first_point (_tmp25_);
				_tmp27_ = _tmp26_;
				bird_font_edit_point_set_tie_handle (_tmp27_, FALSE);
				_g_object_unref0 (_tmp27_);
				_tmp28_ = p;
				_tmp29_ = bird_font_path_get_first_point (_tmp28_);
				_tmp30_ = _tmp29_;
				bird_font_edit_point_set_reflective_handles (_tmp30_, FALSE);
				_g_object_unref0 (_tmp30_);
				_tmp31_ = p;
				_tmp32_ = bird_font_path_get_last_point (_tmp31_);
				_tmp33_ = _tmp32_;
				bird_font_edit_point_set_tie_handle (_tmp33_, FALSE);
				_g_object_unref0 (_tmp33_);
				_tmp34_ = p;
				_tmp35_ = bird_font_path_get_last_point (_tmp34_);
				_tmp36_ = _tmp35_;
				bird_font_edit_point_set_reflective_handles (_tmp36_, FALSE);
				_g_object_unref0 (_tmp36_);
			}
			_tmp37_ = p;
			_tmp38_ = _tmp37_->full_stroke;
			if (_tmp38_ == NULL) {
				BirdFontPath* _tmp39_;
				_tmp39_ = p;
				bird_font_path_create_full_stroke (_tmp39_);
			}
			_g_object_unref0 (p);
		}
		_g_object_unref0 (_p_list);
	}
	if (bird_font_key_bindings_has_shift ()) {
		BirdFontEditPoint* _tmp40_;
		bird_font_pen_tool_control_point_event (self, x, y, FALSE);
		_tmp40_ = bird_font_pen_tool_active_edit_point;
		if (_tmp40_ != NULL) {
			gboolean _tmp41_ = FALSE;
			BirdFontEditPoint* _tmp42_;
			_tmp42_ = bird_font_pen_tool_active_edit_point;
			if (bird_font_edit_point_is_selected (G_TYPE_CHECK_INSTANCE_CAST (_tmp42_, BIRD_FONT_TYPE_EDIT_POINT, BirdFontEditPoint))) {
				GeeArrayList* _tmp43_;
				gint _tmp44_;
				gint _tmp45_;
				_tmp43_ = bird_font_pen_tool_selected_points;
				_tmp44_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp43_);
				_tmp45_ = _tmp44_;
				_tmp41_ = _tmp45_ > 1;
			} else {
				_tmp41_ = FALSE;
			}
			if (_tmp41_) {
				BirdFontEditPoint* _tmp46_;
				_tmp46_ = bird_font_pen_tool_active_edit_point;
				bird_font_edit_point_set_selected (G_TYPE_CHECK_INSTANCE_CAST (_tmp46_, BIRD_FONT_TYPE_EDIT_POINT, BirdFontEditPoint), FALSE);
			} else {
				BirdFontEditPoint* _tmp47_;
				_tmp47_ = bird_font_pen_tool_active_edit_point;
				bird_font_edit_point_set_selected (G_TYPE_CHECK_INSTANCE_CAST (_tmp47_, BIRD_FONT_TYPE_EDIT_POINT, BirdFontEditPoint), TRUE);
			}
			bird_font_pen_tool_update_selection ();
		}
	}
	bird_font_pen_tool_update_boundaries_for_selected_paths ();
	bird_font_pen_tool_on_axis = FALSE;
	_g_object_unref0 (g);
}

static void
___lambda368__bird_font_tool_release_action (BirdFontTool* _sender,
                                             BirdFontTool* selected,
                                             gint button,
                                             gint x,
                                             gint y,
                                             gpointer self)
{
	__lambda368_ ((BirdFontPenTool*) self, selected, button, x, y);
}

static void
__lambda369_ (BirdFontPenTool* self,
              BirdFontTool* _self_,
              gint x,
              gint y)
{
	g_return_if_fail (_self_ != NULL);
	bird_font_pen_tool_selection_box_last_x = (gdouble) x;
	bird_font_pen_tool_selection_box_last_y = (gdouble) y;
	if (bird_font_path_distance ((gdouble) bird_font_pen_tool_begin_action_x, (gdouble) x, (gdouble) bird_font_pen_tool_begin_action_y, (gdouble) y) > ((gdouble) 10)) {
		bird_font_pen_tool_point_selection_image = FALSE;
	}
	bird_font_pen_tool_move (self, x, y);
}

static void
___lambda369__bird_font_tool_move_action (BirdFontTool* _sender,
                                          BirdFontTool* selected,
                                          gint x,
                                          gint y,
                                          gpointer self)
{
	__lambda369_ ((BirdFontPenTool*) self, selected, x, y);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
__lambda370_ (BirdFontPenTool* self,
              BirdFontTool* _self_,
              guint32 keyval)
{
	gboolean _tmp0_ = FALSE;
	BirdFontFont* _tmp9_;
	BirdFontFont* _tmp10_;
	g_return_if_fail (_self_ != NULL);
	bird_font_pen_tool_reset_stroke ();
	if (keyval == ((guint32) BIRD_FONT_KEY_DEL)) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = keyval == ((guint32) BIRD_FONT_KEY_BACK_SPACE);
	}
	if (_tmp0_) {
		if (bird_font_key_bindings_has_shift ()) {
			bird_font_pen_tool_delete_selected_points ();
		} else {
			bird_font_pen_tool_delete_simplify ();
		}
	}
	if (bird_font_is_arrow_key ((guint) keyval)) {
		if (bird_font_key_bindings_modifier != BIRD_FONT_CTRL) {
			BirdFontEditPoint* _tmp1_;
			BirdFontEditPoint* _tmp2_;
			bird_font_pen_tool_move_selected_points (self, (guint) keyval);
			_tmp1_ = bird_font_pen_tool_selected_point;
			_tmp2_ = _g_object_ref0 (_tmp1_);
			_g_object_unref0 (bird_font_pen_tool_active_edit_point);
			bird_font_pen_tool_active_edit_point = _tmp2_;
		} else {
			bird_font_pen_tool_move_select_next_point ((guint) keyval);
		}
	}
	if (bird_font_key_bindings_has_shift ()) {
		gboolean _tmp3_ = FALSE;
		BirdFontEditPoint* _tmp4_;
		gboolean _tmp5_;
		gboolean _tmp6_;
		_tmp4_ = bird_font_pen_tool_selected_point;
		_tmp5_ = bird_font_edit_point_get_tie_handles (_tmp4_);
		_tmp6_ = _tmp5_;
		if (_tmp6_) {
			_tmp3_ = bird_font_key_bindings_modifier == BIRD_FONT_SHIFT;
		} else {
			_tmp3_ = FALSE;
		}
		if (_tmp3_) {
			BirdFontEditPoint* _tmp7_;
			BirdFontEditPoint* _tmp8_;
			_tmp7_ = bird_font_pen_tool_selected_point;
			bird_font_pen_tool_last_point_x = _tmp7_->x;
			_tmp8_ = bird_font_pen_tool_selected_point;
			bird_font_pen_tool_last_point_y = _tmp8_->y;
		}
	}
	bird_font_glyph_canvas_redraw ();
	_tmp9_ = bird_font_bird_font_get_current_font ();
	_tmp10_ = _tmp9_;
	bird_font_font_touch (_tmp10_);
	_g_object_unref0 (_tmp10_);
}

static void
___lambda370__bird_font_tool_key_press_action (BirdFontTool* _sender,
                                               BirdFontTool* selected,
                                               guint32 keyval,
                                               gpointer self)
{
	__lambda370_ ((BirdFontPenTool*) self, selected, keyval);
}

static void
__lambda371_ (BirdFontPenTool* self,
              BirdFontTool* _self_,
              guint32 keyval)
{
	gdouble x = 0.0;
	gdouble y = 0.0;
	g_return_if_fail (_self_ != NULL);
	if (bird_font_is_arrow_key ((guint) keyval)) {
		gboolean _tmp0_ = FALSE;
		if (bird_font_key_bindings_modifier != BIRD_FONT_CTRL) {
			BirdFontEditPoint* _tmp1_;
			_tmp1_ = bird_font_pen_tool_active_edit_point;
			_tmp0_ = _tmp1_ != NULL;
		} else {
			_tmp0_ = FALSE;
		}
		if (_tmp0_) {
			BirdFontEditPoint* _tmp2_;
			BirdFontEditPoint* _tmp3_;
			BirdFontEditPoint* _tmp4_;
			BirdFontPath* _tmp5_;
			BirdFontPath* _tmp6_;
			_tmp2_ = bird_font_pen_tool_selected_point;
			x = (gdouble) bird_font_glyph_reverse_path_coordinate_x (_tmp2_->x);
			_tmp3_ = bird_font_pen_tool_selected_point;
			y = (gdouble) bird_font_glyph_reverse_path_coordinate_y (_tmp3_->y);
			_tmp4_ = bird_font_pen_tool_active_edit_point;
			_tmp5_ = bird_font_pen_tool_join_paths (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, BIRD_FONT_TYPE_EDIT_POINT, BirdFontEditPoint));
			_tmp6_ = _tmp5_;
			_g_object_unref0 (_tmp6_);
			bird_font_pen_tool_reset_stroke ();
		}
	}
}

static void
___lambda371__bird_font_tool_key_release_action (BirdFontTool* _sender,
                                                 BirdFontTool* selected,
                                                 guint32 keyval,
                                                 gpointer self)
{
	__lambda371_ ((BirdFontPenTool*) self, selected, keyval);
}

static void
__lambda372_ (BirdFontPenTool* self,
              BirdFontTool* tool,
              cairo_t* cairo_context,
              BirdFontGlyph* glyph)
{
	g_return_if_fail (tool != NULL);
	g_return_if_fail (cairo_context != NULL);
	g_return_if_fail (glyph != NULL);
	bird_font_pen_tool_draw_on_canvas (self, cairo_context, glyph);
}

static void
___lambda372__bird_font_tool_draw_action (BirdFontTool* _sender,
                                          BirdFontTool* selected,
                                          cairo_t* cr,
                                          BirdFontGlyph* glyph,
                                          gpointer self)
{
	__lambda372_ ((BirdFontPenTool*) self, selected, cr, glyph);
}

BirdFontPenTool*
bird_font_pen_tool_construct (GType object_type,
                              const gchar* name)
{
	BirdFontPenTool * self = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	GeeArrayList* _tmp2_;
	BirdFontEditPointHandle* _tmp3_;
	BirdFontEditPointHandle* _tmp4_;
	BirdFontPointSelection* _tmp5_;
	BirdFontEditPoint* _tmp6_;
	BirdFontPath* _tmp7_;
	BirdFontPath* _tmp8_;
	BirdFontEditPoint* _tmp9_;
	GeeArrayList* _tmp10_;
	GeeArrayList* _tmp11_;
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = bird_font_t_ ("Add new points");
	_tmp1_ = _tmp0_;
	self = (BirdFontPenTool*) bird_font_tool_construct (object_type, name, _tmp1_);
	_g_free0 (_tmp1_);
	_tmp2_ = gee_array_list_new (BIRD_FONT_TYPE_POINT_SELECTION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (bird_font_pen_tool_selected_points);
	bird_font_pen_tool_selected_points = _tmp2_;
	_tmp3_ = bird_font_edit_point_handle_new_empty ();
	_g_object_unref0 (bird_font_pen_tool_active_handle);
	bird_font_pen_tool_active_handle = _tmp3_;
	_tmp4_ = bird_font_edit_point_handle_new_empty ();
	_g_object_unref0 (bird_font_pen_tool_selected_handle);
	bird_font_pen_tool_selected_handle = _tmp4_;
	_tmp5_ = bird_font_point_selection_new_empty ();
	_g_object_unref0 (bird_font_pen_tool_handle_selection);
	bird_font_pen_tool_handle_selection = _tmp5_;
	_tmp6_ = bird_font_edit_point_new ((gdouble) 0, (gdouble) 0, BIRD_FONT_POINT_TYPE_NONE);
	_g_object_unref0 (bird_font_pen_tool_active_edit_point);
	bird_font_pen_tool_active_edit_point = _tmp6_;
	_tmp7_ = bird_font_path_new ();
	_g_object_unref0 (bird_font_pen_tool_active_path);
	bird_font_pen_tool_active_path = _tmp7_;
	_tmp8_ = bird_font_path_new ();
	_g_object_unref0 (bird_font_pen_tool_selected_path);
	bird_font_pen_tool_selected_path = _tmp8_;
	_tmp9_ = bird_font_edit_point_new ((gdouble) 0, (gdouble) 0, BIRD_FONT_POINT_TYPE_NONE);
	_g_object_unref0 (bird_font_pen_tool_selected_point);
	bird_font_pen_tool_selected_point = _tmp9_;
	_tmp10_ = gee_array_list_new (BIRD_FONT_TYPE_PATH, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (bird_font_pen_tool_clockwise);
	bird_font_pen_tool_clockwise = _tmp10_;
	_tmp11_ = gee_array_list_new (BIRD_FONT_TYPE_PATH, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_g_object_unref0 (bird_font_pen_tool_counter_clockwise);
	bird_font_pen_tool_counter_clockwise = _tmp11_;
	g_signal_connect_object ((BirdFontTool*) self, "select-action", (GCallback) ___lambda25__bird_font_tool_select_action, self, 0);
	g_signal_connect_object ((BirdFontTool*) self, "deselect-action", (GCallback) ___lambda26__bird_font_tool_deselect_action, self, 0);
	g_signal_connect_object ((BirdFontTool*) self, "press-action", (GCallback) ___lambda27__bird_font_tool_press_action, self, 0);
	g_signal_connect_object ((BirdFontTool*) self, "double-click-action", (GCallback) ___lambda367__bird_font_tool_double_click_action, self, 0);
	g_signal_connect_object ((BirdFontTool*) self, "release-action", (GCallback) ___lambda368__bird_font_tool_release_action, self, 0);
	g_signal_connect_object ((BirdFontTool*) self, "move-action", (GCallback) ___lambda369__bird_font_tool_move_action, self, 0);
	g_signal_connect_object ((BirdFontTool*) self, "key-press-action", (GCallback) ___lambda370__bird_font_tool_key_press_action, self, 0);
	g_signal_connect_object ((BirdFontTool*) self, "key-release-action", (GCallback) ___lambda371__bird_font_tool_key_release_action, self, 0);
	g_signal_connect_object ((BirdFontTool*) self, "draw-action", (GCallback) ___lambda372__bird_font_tool_draw_action, self, 0);
	return self;
}

BirdFontPenTool*
bird_font_pen_tool_new (const gchar* name)
{
	return bird_font_pen_tool_construct (BIRD_FONT_TYPE_PEN_TOOL, name);
}

void
bird_font_pen_tool_update_orientation (void)
{
	BirdFontGlyph* glyph = NULL;
	BirdFontGlyph* _tmp0_;
	GeeArrayList* _tmp1_;
	GeeArrayList* _tmp2_;
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	glyph = _tmp0_;
	_tmp1_ = bird_font_pen_tool_clockwise;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp1_);
	_tmp2_ = bird_font_pen_tool_counter_clockwise;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp2_);
	{
		GeeArrayList* _p_list = NULL;
		BirdFontGlyph* _tmp3_;
		GeeArrayList* _tmp4_;
		gint _p_size = 0;
		GeeArrayList* _tmp5_;
		gint _tmp6_;
		gint _tmp7_;
		gint _p_index = 0;
		_tmp3_ = glyph;
		_tmp4_ = bird_font_glyph_get_visible_paths (_tmp3_);
		_p_list = _tmp4_;
		_tmp5_ = _p_list;
		_tmp6_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp5_);
		_tmp7_ = _tmp6_;
		_p_size = _tmp7_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp8_;
			gint _tmp9_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp10_;
			gpointer _tmp11_;
			BirdFontPath* _tmp12_;
			BirdFontPath* _tmp13_;
			_p_index = _p_index + 1;
			_tmp8_ = _p_index;
			_tmp9_ = _p_size;
			if (!(_tmp8_ < _tmp9_)) {
				break;
			}
			_tmp10_ = _p_list;
			_tmp11_ = gee_abstract_list_get ((GeeAbstractList*) _tmp10_, _p_index);
			p = (BirdFontPath*) _tmp11_;
			_tmp12_ = p;
			_tmp12_->direction_is_set = TRUE;
			_tmp13_ = p;
			if (bird_font_path_is_clockwise (_tmp13_)) {
				GeeArrayList* _tmp14_;
				BirdFontPath* _tmp15_;
				_tmp14_ = bird_font_pen_tool_clockwise;
				_tmp15_ = p;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp14_, _tmp15_);
			} else {
				GeeArrayList* _tmp16_;
				BirdFontPath* _tmp17_;
				_tmp16_ = bird_font_pen_tool_counter_clockwise;
				_tmp17_ = p;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp16_, _tmp17_);
			}
			_g_object_unref0 (p);
		}
		_g_object_unref0 (_p_list);
	}
	_g_object_unref0 (glyph);
}

void
bird_font_pen_tool_set_orientation (void)
{
	{
		GeeArrayList* _p_list = NULL;
		GeeArrayList* _tmp0_;
		gint _p_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _p_index = 0;
		_tmp0_ = bird_font_pen_tool_clockwise;
		_p_list = _tmp0_;
		_tmp1_ = _p_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_p_size = _tmp3_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			gboolean _tmp8_ = FALSE;
			BirdFontPath* _tmp9_;
			_p_index = _p_index + 1;
			_tmp4_ = _p_index;
			_tmp5_ = _p_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _p_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _p_index);
			p = (BirdFontPath*) _tmp7_;
			_tmp9_ = p;
			if (!bird_font_path_is_open (_tmp9_)) {
				BirdFontPath* _tmp10_;
				_tmp10_ = p;
				_tmp8_ = !bird_font_path_is_clockwise (_tmp10_);
			} else {
				_tmp8_ = FALSE;
			}
			if (_tmp8_) {
				BirdFontPath* _tmp11_;
				_tmp11_ = p;
				bird_font_path_reverse (_tmp11_);
				bird_font_pen_tool_update_selection ();
			}
			_g_object_unref0 (p);
		}
	}
	{
		GeeArrayList* _p_list = NULL;
		GeeArrayList* _tmp12_;
		gint _p_size = 0;
		GeeArrayList* _tmp13_;
		gint _tmp14_;
		gint _tmp15_;
		gint _p_index = 0;
		_tmp12_ = bird_font_pen_tool_counter_clockwise;
		_p_list = _tmp12_;
		_tmp13_ = _p_list;
		_tmp14_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp13_);
		_tmp15_ = _tmp14_;
		_p_size = _tmp15_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp16_;
			gint _tmp17_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp18_;
			gpointer _tmp19_;
			gboolean _tmp20_ = FALSE;
			BirdFontPath* _tmp21_;
			_p_index = _p_index + 1;
			_tmp16_ = _p_index;
			_tmp17_ = _p_size;
			if (!(_tmp16_ < _tmp17_)) {
				break;
			}
			_tmp18_ = _p_list;
			_tmp19_ = gee_abstract_list_get ((GeeAbstractList*) _tmp18_, _p_index);
			p = (BirdFontPath*) _tmp19_;
			_tmp21_ = p;
			if (!bird_font_path_is_open (_tmp21_)) {
				BirdFontPath* _tmp22_;
				_tmp22_ = p;
				_tmp20_ = bird_font_path_is_clockwise (_tmp22_);
			} else {
				_tmp20_ = FALSE;
			}
			if (_tmp20_) {
				BirdFontPath* _tmp23_;
				_tmp23_ = p;
				bird_font_path_reverse (_tmp23_);
				bird_font_pen_tool_update_selection ();
			}
			_g_object_unref0 (p);
		}
	}
}

gboolean
bird_font_pen_tool_has_join_icon (BirdFontPenTool* self)
{
	BirdFontEditPoint* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = bird_font_pen_tool_active_edit_point;
	if (_tmp0_ != NULL) {
		BirdFontEditPoint* _tmp1_;
		_tmp1_ = bird_font_pen_tool_active_edit_point;
		result = bird_font_pen_tool_can_join (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, BIRD_FONT_TYPE_EDIT_POINT, BirdFontEditPoint));
		return result;
	}
	result = FALSE;
	return result;
}

gboolean
bird_font_pen_tool_can_join (BirdFontEditPoint* ep)
{
	gdouble mx = 0.0;
	gdouble my = 0.0;
	gdouble _tmp0_ = 0.0;
	gdouble _tmp1_ = 0.0;
	gboolean _tmp2_ = FALSE;
	gboolean result;
	g_return_val_if_fail (ep != NULL, FALSE);
	bird_font_pen_tool_get_tie_position (ep, &_tmp0_, &_tmp1_);
	mx = _tmp0_;
	my = _tmp1_;
	if (mx > ((gdouble) -10)) {
		_tmp2_ = my > ((gdouble) -10);
	} else {
		_tmp2_ = FALSE;
	}
	result = _tmp2_;
	return result;
}

void
bird_font_pen_tool_select_points_in_box (void)
{
	gdouble x1 = 0.0;
	gdouble y1 = 0.0;
	gdouble x2 = 0.0;
	gdouble y2 = 0.0;
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	_g_object_unref0 (g);
	g = _tmp0_;
	x1 = bird_font_glyph_path_coordinate_x (fmin (bird_font_pen_tool_selection_box_x, bird_font_pen_tool_selection_box_last_x));
	y1 = bird_font_glyph_path_coordinate_y (fmin (bird_font_pen_tool_selection_box_y, bird_font_pen_tool_selection_box_last_y));
	x2 = bird_font_glyph_path_coordinate_x (fmax (bird_font_pen_tool_selection_box_x, bird_font_pen_tool_selection_box_last_x));
	y2 = bird_font_glyph_path_coordinate_y (fmax (bird_font_pen_tool_selection_box_y, bird_font_pen_tool_selection_box_last_y));
	if (!bird_font_key_bindings_has_shift ()) {
		bird_font_pen_tool_remove_all_selected_points ();
	}
	{
		GeeArrayList* _p_list = NULL;
		BirdFontGlyph* _tmp1_;
		GeeArrayList* _tmp2_;
		gint _p_size = 0;
		GeeArrayList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		gint _p_index = 0;
		_tmp1_ = g;
		_tmp2_ = bird_font_glyph_get_paths_in_current_layer (_tmp1_);
		_p_list = _tmp2_;
		_tmp3_ = _p_list;
		_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
		_tmp5_ = _tmp4_;
		_p_size = _tmp5_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp6_;
			gint _tmp7_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp8_;
			gpointer _tmp9_;
			_p_index = _p_index + 1;
			_tmp6_ = _p_index;
			_tmp7_ = _p_size;
			if (!(_tmp6_ < _tmp7_)) {
				break;
			}
			_tmp8_ = _p_list;
			_tmp9_ = gee_abstract_list_get ((GeeAbstractList*) _tmp8_, _p_index);
			p = (BirdFontPath*) _tmp9_;
			{
				GeeArrayList* _ep_list = NULL;
				BirdFontPath* _tmp10_;
				GeeArrayList* _tmp11_;
				GeeArrayList* _tmp12_;
				gint _ep_size = 0;
				GeeArrayList* _tmp13_;
				gint _tmp14_;
				gint _tmp15_;
				gint _ep_index = 0;
				_tmp10_ = p;
				_tmp11_ = bird_font_path_get_points (_tmp10_);
				_tmp12_ = _tmp11_;
				_ep_list = _tmp12_;
				_tmp13_ = _ep_list;
				_tmp14_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp13_);
				_tmp15_ = _tmp14_;
				_ep_size = _tmp15_;
				_ep_index = -1;
				while (TRUE) {
					gint _tmp16_;
					gint _tmp17_;
					BirdFontEditPoint* ep = NULL;
					GeeArrayList* _tmp18_;
					gpointer _tmp19_;
					gboolean _tmp20_ = FALSE;
					BirdFontEditPoint* _tmp21_;
					gdouble _tmp22_;
					_ep_index = _ep_index + 1;
					_tmp16_ = _ep_index;
					_tmp17_ = _ep_size;
					if (!(_tmp16_ < _tmp17_)) {
						break;
					}
					_tmp18_ = _ep_list;
					_tmp19_ = gee_abstract_list_get ((GeeAbstractList*) _tmp18_, _ep_index);
					ep = (BirdFontEditPoint*) _tmp19_;
					_tmp21_ = ep;
					_tmp22_ = _tmp21_->x;
					if ((x1 <= _tmp22_) && (_tmp22_ <= x2)) {
						BirdFontEditPoint* _tmp23_;
						gdouble _tmp24_;
						_tmp23_ = ep;
						_tmp24_ = _tmp23_->y;
						_tmp20_ = (y2 <= _tmp24_) && (_tmp24_ <= y1);
					} else {
						_tmp20_ = FALSE;
					}
					if (_tmp20_) {
						BirdFontEditPoint* _tmp25_;
						BirdFontPath* _tmp26_;
						BirdFontEditPoint* _tmp27_;
						_tmp25_ = ep;
						_tmp26_ = p;
						bird_font_pen_tool_add_selected_point (_tmp25_, _tmp26_);
						_tmp27_ = ep;
						bird_font_edit_point_set_selected (_tmp27_, TRUE);
					}
					_g_object_unref0 (ep);
				}
			}
			_g_object_unref0 (p);
		}
		_g_object_unref0 (_p_list);
	}
	_g_object_unref0 (g);
}

void
bird_font_pen_tool_delete_selected_points (void)
{
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	BirdFontGlyph* _tmp21_;
	GeeArrayList* _tmp22_;
	BirdFontEditPointHandle* _tmp23_;
	BirdFontEditPointHandle* _tmp24_;
	BirdFontEditPointHandle* _tmp25_;
	BirdFontEditPoint* _tmp26_;
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	{
		GeeArrayList* _p_list = NULL;
		GeeArrayList* _tmp1_;
		gint _p_size = 0;
		GeeArrayList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _p_index = 0;
		_tmp1_ = bird_font_pen_tool_selected_points;
		_p_list = _tmp1_;
		_tmp2_ = _p_list;
		_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_p_size = _tmp4_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			BirdFontPointSelection* p = NULL;
			GeeArrayList* _tmp7_;
			gpointer _tmp8_;
			BirdFontPointSelection* _tmp9_;
			BirdFontEditPoint* _tmp10_;
			_p_index = _p_index + 1;
			_tmp5_ = _p_index;
			_tmp6_ = _p_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _p_list;
			_tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, _p_index);
			p = (BirdFontPointSelection*) _tmp8_;
			_tmp9_ = p;
			_tmp10_ = _tmp9_->point;
			bird_font_edit_point_set_deleted (_tmp10_, TRUE);
			_g_object_unref0 (p);
		}
	}
	bird_font_pen_tool_process_deleted ();
	{
		GeeArrayList* _p_list = NULL;
		BirdFontGlyph* _tmp11_;
		GeeArrayList* _tmp12_;
		gint _p_size = 0;
		GeeArrayList* _tmp13_;
		gint _tmp14_;
		gint _tmp15_;
		gint _p_index = 0;
		_tmp11_ = g;
		_tmp12_ = bird_font_glyph_get_all_paths (_tmp11_);
		_p_list = _tmp12_;
		_tmp13_ = _p_list;
		_tmp14_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp13_);
		_tmp15_ = _tmp14_;
		_p_size = _tmp15_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp16_;
			gint _tmp17_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp18_;
			gpointer _tmp19_;
			BirdFontPath* _tmp20_;
			_p_index = _p_index + 1;
			_tmp16_ = _p_index;
			_tmp17_ = _p_size;
			if (!(_tmp16_ < _tmp17_)) {
				break;
			}
			_tmp18_ = _p_list;
			_tmp19_ = gee_abstract_list_get ((GeeAbstractList*) _tmp18_, _p_index);
			p = (BirdFontPath*) _tmp19_;
			_tmp20_ = p;
			if (bird_font_path_has_deleted_point (_tmp20_)) {
				bird_font_pen_tool_process_deleted ();
			}
			_g_object_unref0 (p);
		}
		_g_object_unref0 (_p_list);
	}
	_tmp21_ = g;
	bird_font_glyph_update_view (_tmp21_);
	_tmp22_ = bird_font_pen_tool_selected_points;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp22_);
	_tmp23_ = bird_font_pen_tool_selected_handle;
	_tmp23_->selected = FALSE;
	_tmp24_ = bird_font_edit_point_handle_new_empty ();
	_g_object_unref0 (bird_font_pen_tool_active_handle);
	bird_font_pen_tool_active_handle = _tmp24_;
	_tmp25_ = bird_font_edit_point_handle_new_empty ();
	_g_object_unref0 (bird_font_pen_tool_selected_handle);
	bird_font_pen_tool_selected_handle = _tmp25_;
	_g_object_unref0 (bird_font_pen_tool_active_edit_point);
	bird_font_pen_tool_active_edit_point = NULL;
	_tmp26_ = bird_font_edit_point_new ((gdouble) 0, (gdouble) 0, BIRD_FONT_POINT_TYPE_NONE);
	_g_object_unref0 (bird_font_pen_tool_selected_point);
	bird_font_pen_tool_selected_point = _tmp26_;
	_g_object_unref0 (g);
}

static void
bird_font_pen_tool_get_closes_point_in_segment (BirdFontEditPoint* ep0,
                                                BirdFontEditPoint* ep1,
                                                BirdFontEditPoint* ep2,
                                                gdouble px,
                                                gdouble py,
                                                gdouble* nx,
                                                gdouble* ny)
{
	gdouble _vala_nx = 0.0;
	gdouble _vala_ny = 0.0;
	gdouble npx0 = 0.0;
	gdouble npy0 = 0.0;
	gdouble npx1 = 0.0;
	gdouble npy1 = 0.0;
	gdouble _tmp0_ = 0.0;
	gdouble _tmp1_ = 0.0;
	gdouble _tmp2_ = 0.0;
	gdouble _tmp3_ = 0.0;
	g_return_if_fail (ep0 != NULL);
	g_return_if_fail (ep1 != NULL);
	g_return_if_fail (ep2 != NULL);
	bird_font_path_find_closes_point_in_segment (ep0, ep1, px, py, &_tmp0_, &_tmp1_, (gdouble) 50);
	npx0 = _tmp0_;
	npy0 = _tmp1_;
	bird_font_path_find_closes_point_in_segment (ep1, ep2, px, py, &_tmp2_, &_tmp3_, (gdouble) 50);
	npx1 = _tmp2_;
	npy1 = _tmp3_;
	if (bird_font_path_distance (px, npx0, py, npy0) < bird_font_path_distance (px, npx1, py, npy1)) {
		_vala_nx = npx0;
		_vala_ny = npy0;
	} else {
		_vala_nx = npx1;
		_vala_ny = npy1;
	}
	if (nx) {
		*nx = _vala_nx;
	}
	if (ny) {
		*ny = _vala_ny;
	}
}

static Block52Data*
block52_data_ref (Block52Data* _data52_)
{
	g_atomic_int_inc (&_data52_->_ref_count_);
	return _data52_;
}

static void
block52_data_unref (void * _userdata_)
{
	Block52Data* _data52_;
	_data52_ = (Block52Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data52_->_ref_count_)) {
		_g_object_unref0 (_data52_->oe0);
		_g_object_unref0 (_data52_->oe1);
		_g_object_unref0 (_data52_->oe2);
		g_slice_free (Block52Data, _data52_);
	}
}

static gboolean
__lambda34_ (Block52Data* _data52_,
             gdouble xa,
             gdouble ya,
             gdouble ta)
{
	gdouble f = 0.0;
	gdouble n = 0.0;
	gdouble _tmp0_ = 0.0;
	gdouble _tmp1_ = 0.0;
	gboolean result;
	bird_font_pen_tool_get_closes_point_in_segment (_data52_->oe0, _data52_->oe1, _data52_->oe2, xa, ya, &_tmp0_, &_tmp1_);
	_data52_->nx = _tmp0_;
	_data52_->ny = _tmp1_;
	if (ta < 0.5) {
		f = bird_font_path_distance (_data52_->nx, xa, _data52_->ny, ya);
		if (f > _data52_->df) {
			_data52_->df += f;
		}
	} else {
		n = bird_font_path_distance (_data52_->nx, xa, _data52_->ny, ya);
		if (n > _data52_->dn) {
			_data52_->dn += n;
		}
	}
	result = TRUE;
	return result;
}

static gboolean
___lambda34__bird_font_path_raster_iterator (gdouble x,
                                             gdouble y,
                                             gdouble step,
                                             gpointer self)
{
	gboolean result;
	result = __lambda34_ (self, x, y, step);
	return result;
}

void
bird_font_pen_tool_get_path_distortion (BirdFontEditPoint* oe0,
                                        BirdFontEditPoint* oe1,
                                        BirdFontEditPoint* oe2,
                                        BirdFontEditPoint* ep1,
                                        BirdFontEditPoint* ep2,
                                        gdouble* distortion_first,
                                        gdouble* distortion_next)
{
	gdouble _vala_distortion_first = 0.0;
	gdouble _vala_distortion_next = 0.0;
	Block52Data* _data52_;
	BirdFontEditPoint* _tmp0_;
	BirdFontEditPoint* _tmp1_;
	BirdFontEditPoint* _tmp2_;
	gint step = 0;
	g_return_if_fail (oe0 != NULL);
	g_return_if_fail (oe1 != NULL);
	g_return_if_fail (oe2 != NULL);
	g_return_if_fail (ep1 != NULL);
	g_return_if_fail (ep2 != NULL);
	_data52_ = g_slice_new0 (Block52Data);
	_data52_->_ref_count_ = 1;
	_tmp0_ = _g_object_ref0 (oe0);
	_g_object_unref0 (_data52_->oe0);
	_data52_->oe0 = _tmp0_;
	_tmp1_ = _g_object_ref0 (oe1);
	_g_object_unref0 (_data52_->oe1);
	_data52_->oe1 = _tmp1_;
	_tmp2_ = _g_object_ref0 (oe2);
	_g_object_unref0 (_data52_->oe2);
	_data52_->oe2 = _tmp2_;
	_data52_->df = (gdouble) 0;
	_data52_->dn = (gdouble) 0;
	_data52_->nx = (gdouble) 0;
	_data52_->ny = (gdouble) 0;
	step = 4;
	bird_font_path_all_of (ep1, ep2, ___lambda34__bird_font_path_raster_iterator, _data52_, step, (gdouble) 0, (gdouble) 1);
	_vala_distortion_first = _data52_->df;
	_vala_distortion_next = _data52_->dn;
	if (distortion_first) {
		*distortion_first = _vala_distortion_first;
	}
	if (distortion_next) {
		*distortion_next = _vala_distortion_next;
	}
	block52_data_unref (_data52_);
	_data52_ = NULL;
}

void
bird_font_pen_tool_update_boundaries_for_selected_paths (void)
{
	GeeArrayList* paths = NULL;
	GeeArrayList* _tmp0_;
	_tmp0_ = gee_array_list_new (BIRD_FONT_TYPE_PATH, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	paths = _tmp0_;
	{
		GeeArrayList* _p_list = NULL;
		GeeArrayList* _tmp1_;
		gint _p_size = 0;
		GeeArrayList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _p_index = 0;
		_tmp1_ = bird_font_pen_tool_selected_points;
		_p_list = _tmp1_;
		_tmp2_ = _p_list;
		_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_p_size = _tmp4_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			BirdFontPointSelection* p = NULL;
			GeeArrayList* _tmp7_;
			gpointer _tmp8_;
			GeeArrayList* _tmp9_;
			BirdFontPointSelection* _tmp10_;
			BirdFontPath* _tmp11_;
			_p_index = _p_index + 1;
			_tmp5_ = _p_index;
			_tmp6_ = _p_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _p_list;
			_tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, _p_index);
			p = (BirdFontPointSelection*) _tmp8_;
			_tmp9_ = paths;
			_tmp10_ = p;
			_tmp11_ = _tmp10_->path;
			if (gee_abstract_list_index_of ((GeeAbstractList*) _tmp9_, _tmp11_) == -1) {
				GeeArrayList* _tmp12_;
				BirdFontPointSelection* _tmp13_;
				BirdFontPath* _tmp14_;
				_tmp12_ = paths;
				_tmp13_ = p;
				_tmp14_ = _tmp13_->path;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp12_, _tmp14_);
			}
			_g_object_unref0 (p);
		}
	}
	{
		GeeArrayList* _p_list = NULL;
		GeeArrayList* _tmp15_;
		gint _p_size = 0;
		GeeArrayList* _tmp16_;
		gint _tmp17_;
		gint _tmp18_;
		gint _p_index = 0;
		_tmp15_ = paths;
		_p_list = _tmp15_;
		_tmp16_ = _p_list;
		_tmp17_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp16_);
		_tmp18_ = _tmp17_;
		_p_size = _tmp18_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp19_;
			gint _tmp20_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp21_;
			gpointer _tmp22_;
			BirdFontPath* _tmp23_;
			_p_index = _p_index + 1;
			_tmp19_ = _p_index;
			_tmp20_ = _p_size;
			if (!(_tmp19_ < _tmp20_)) {
				break;
			}
			_tmp21_ = _p_list;
			_tmp22_ = gee_abstract_list_get ((GeeAbstractList*) _tmp21_, _p_index);
			p = (BirdFontPath*) _tmp22_;
			_tmp23_ = p;
			bird_font_path_update_region_boundaries (_tmp23_);
			_g_object_unref0 (p);
		}
	}
	_g_object_unref0 (paths);
}

void
bird_font_pen_tool_delete_simplify (void)
{
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	BirdFontGlyph* _tmp22_;
	GeeArrayList* _tmp23_;
	BirdFontEditPointHandle* _tmp24_;
	BirdFontEditPointHandle* _tmp25_;
	BirdFontEditPointHandle* _tmp26_;
	BirdFontEditPoint* _tmp27_;
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	{
		GeeArrayList* _p_list = NULL;
		GeeArrayList* _tmp1_;
		gint _p_size = 0;
		GeeArrayList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _p_index = 0;
		_tmp1_ = bird_font_pen_tool_selected_points;
		_p_list = _tmp1_;
		_tmp2_ = _p_list;
		_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_p_size = _tmp4_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			BirdFontPointSelection* p = NULL;
			GeeArrayList* _tmp7_;
			gpointer _tmp8_;
			BirdFontPointSelection* _tmp9_;
			BirdFontPointSelection* _tmp10_;
			BirdFontPath* _tmp11_;
			_p_index = _p_index + 1;
			_tmp5_ = _p_index;
			_tmp6_ = _p_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _p_list;
			_tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, _p_index);
			p = (BirdFontPointSelection*) _tmp8_;
			_tmp9_ = p;
			bird_font_pen_tool_remove_point_simplify (_tmp9_, 0.6);
			_tmp10_ = p;
			_tmp11_ = _tmp10_->path;
			bird_font_path_reset_stroke (_tmp11_);
			_g_object_unref0 (p);
		}
	}
	{
		GeeArrayList* _p_list = NULL;
		GeeArrayList* _tmp12_;
		gint _p_size = 0;
		GeeArrayList* _tmp13_;
		gint _tmp14_;
		gint _tmp15_;
		gint _p_index = 0;
		_tmp12_ = bird_font_pen_tool_selected_points;
		_p_list = _tmp12_;
		_tmp13_ = _p_list;
		_tmp14_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp13_);
		_tmp15_ = _tmp14_;
		_p_size = _tmp15_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp16_;
			gint _tmp17_;
			BirdFontPointSelection* p = NULL;
			GeeArrayList* _tmp18_;
			gpointer _tmp19_;
			BirdFontPointSelection* _tmp20_;
			BirdFontPath* _tmp21_;
			_p_index = _p_index + 1;
			_tmp16_ = _p_index;
			_tmp17_ = _p_size;
			if (!(_tmp16_ < _tmp17_)) {
				break;
			}
			_tmp18_ = _p_list;
			_tmp19_ = gee_abstract_list_get ((GeeAbstractList*) _tmp18_, _p_index);
			p = (BirdFontPointSelection*) _tmp19_;
			_tmp20_ = p;
			_tmp21_ = _tmp20_->path;
			bird_font_path_create_full_stroke (_tmp21_);
			_g_object_unref0 (p);
		}
	}
	_tmp22_ = g;
	bird_font_glyph_update_view (_tmp22_);
	_tmp23_ = bird_font_pen_tool_selected_points;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp23_);
	_tmp24_ = bird_font_pen_tool_selected_handle;
	_tmp24_->selected = FALSE;
	_tmp25_ = bird_font_edit_point_handle_new_empty ();
	_g_object_unref0 (bird_font_pen_tool_active_handle);
	bird_font_pen_tool_active_handle = _tmp25_;
	_tmp26_ = bird_font_edit_point_handle_new_empty ();
	_g_object_unref0 (bird_font_pen_tool_selected_handle);
	bird_font_pen_tool_selected_handle = _tmp26_;
	_g_object_unref0 (bird_font_pen_tool_active_edit_point);
	bird_font_pen_tool_active_edit_point = NULL;
	_tmp27_ = bird_font_edit_point_new ((gdouble) 0, (gdouble) 0, BIRD_FONT_POINT_TYPE_NONE);
	_g_object_unref0 (bird_font_pen_tool_selected_point);
	bird_font_pen_tool_selected_point = _tmp27_;
	_g_object_unref0 (g);
}

/** @return path distortion. */
gdouble
bird_font_pen_tool_remove_point_simplify (BirdFontPointSelection* p,
                                          gdouble tolerance)
{
	gdouble e = 0.0;
	BirdFontPath* _tmp0_;
	gdouble result;
	g_return_val_if_fail (p != NULL, 0.0);
	e = bird_font_pen_tool_remove_point_simplify_path (p, tolerance, BIRD_FONT_GLYPH_CANVAS_MAX);
	_tmp0_ = p->path;
	bird_font_path_update_region_boundaries (_tmp0_);
	result = e;
	return result;
}

/** @return path distortion. */
gdouble
bird_font_pen_tool_remove_point_simplify_path (BirdFontPointSelection* p,
                                               gdouble tolerance,
                                               gdouble keep_tolerance)
{
	gdouble start_length = 0.0;
	gdouble stop_length = 0.0;
	gdouble start_distortion = 0.0;
	gdouble start_min_distortion = 0.0;
	gdouble start_previous_length = 0.0;
	gdouble stop_distortion = 0.0;
	gdouble stop_min_distortion = 0.0;
	gdouble stop_previous_length = 0.0;
	gdouble distortion = 0.0;
	gdouble min_distortion = 0.0;
	gdouble prev_length_adjustment = 0.0;
	gdouble next_length_adjustment = 0.0;
	gdouble prev_length_adjustment_reverse = 0.0;
	gdouble next_length_adjustment_reverse = 0.0;
	BirdFontEditPoint* ep1 = NULL;
	BirdFontEditPoint* ep2 = NULL;
	BirdFontEditPoint* next = NULL;
	BirdFontEditPoint* prev = NULL;
	gdouble step = 0.0;
	gdouble distance = 0.0;
	BirdFontPath* _tmp0_;
	GeeArrayList* _tmp1_;
	GeeArrayList* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	BirdFontPath* _tmp5_;
	GeeArrayList* _tmp6_;
	GeeArrayList* _tmp7_;
	gint _tmp8_;
	gint _tmp9_;
	BirdFontEditPoint* _tmp12_;
	BirdFontEditPoint* _tmp13_;
	BirdFontEditPoint* _tmp14_;
	BirdFontEditPoint* _tmp22_;
	BirdFontEditPoint* _tmp23_;
	BirdFontEditPoint* _tmp36_;
	BirdFontEditPointHandle* _tmp37_;
	BirdFontEditPoint* _tmp38_;
	BirdFontEditPointHandle* _tmp39_;
	gboolean _tmp40_ = FALSE;
	BirdFontEditPoint* _tmp41_;
	BirdFontEditPointHandle* _tmp42_;
	gboolean _tmp48_ = FALSE;
	BirdFontEditPoint* _tmp49_;
	BirdFontEditPointHandle* _tmp50_;
	BirdFontEditPoint* _tmp56_;
	BirdFontEditPoint* _tmp57_;
	BirdFontEditPoint* _tmp58_;
	BirdFontEditPoint* _tmp59_;
	BirdFontEditPoint* _tmp60_;
	BirdFontEditPointHandle* _tmp61_;
	BirdFontEditPoint* _tmp62_;
	BirdFontEditPointHandle* _tmp63_;
	BirdFontEditPoint* _tmp64_;
	BirdFontEditPointHandle* _tmp65_;
	BirdFontEditPoint* _tmp66_;
	BirdFontEditPointHandle* _tmp67_;
	BirdFontEditPoint* _tmp68_;
	BirdFontEditPoint* _tmp69_;
	BirdFontEditPoint* _tmp70_;
	BirdFontEditPoint* _tmp71_;
	gboolean _tmp89_ = FALSE;
	gdouble result;
	g_return_val_if_fail (p != NULL, 0.0);
	_tmp0_ = p->path;
	_tmp1_ = bird_font_path_get_points (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
	_tmp4_ = _tmp3_;
	g_return_val_if_fail (_tmp4_ > 0, 0);
	_tmp5_ = p->path;
	_tmp6_ = bird_font_path_get_points (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp7_);
	_tmp9_ = _tmp8_;
	if (_tmp9_ <= 2) {
		BirdFontEditPoint* _tmp10_;
		BirdFontPath* _tmp11_;
		_tmp10_ = p->point;
		bird_font_edit_point_set_deleted (_tmp10_, TRUE);
		_tmp11_ = p->path;
		bird_font_path_remove_deleted_points (_tmp11_);
		result = (gdouble) 0;
		_g_object_unref0 (prev);
		_g_object_unref0 (next);
		_g_object_unref0 (ep2);
		_g_object_unref0 (ep1);
		return result;
	}
	_tmp12_ = p->point;
	bird_font_edit_point_set_deleted (_tmp12_, TRUE);
	_tmp13_ = p->point;
	_tmp14_ = _tmp13_->next;
	if (_tmp14_ != NULL) {
		BirdFontEditPoint* _tmp15_;
		BirdFontEditPoint* _tmp16_;
		BirdFontEditPoint* _tmp17_;
		_tmp15_ = p->point;
		_tmp16_ = bird_font_edit_point_get_next (_tmp15_);
		_tmp17_ = _g_object_ref0 (_tmp16_);
		_g_object_unref0 (next);
		next = _tmp17_;
	} else {
		BirdFontPath* _tmp18_;
		GeeArrayList* _tmp19_;
		GeeArrayList* _tmp20_;
		gpointer _tmp21_;
		_tmp18_ = p->path;
		_tmp19_ = bird_font_path_get_points (_tmp18_);
		_tmp20_ = _tmp19_;
		_tmp21_ = gee_abstract_list_get ((GeeAbstractList*) _tmp20_, 0);
		_g_object_unref0 (next);
		next = (BirdFontEditPoint*) _tmp21_;
	}
	_tmp22_ = p->point;
	_tmp23_ = _tmp22_->prev;
	if (_tmp23_ != NULL) {
		BirdFontEditPoint* _tmp24_;
		BirdFontEditPoint* _tmp25_;
		BirdFontEditPoint* _tmp26_;
		_tmp24_ = p->point;
		_tmp25_ = bird_font_edit_point_get_prev (_tmp24_);
		_tmp26_ = _g_object_ref0 (_tmp25_);
		_g_object_unref0 (prev);
		prev = _tmp26_;
	} else {
		BirdFontPath* _tmp27_;
		GeeArrayList* _tmp28_;
		GeeArrayList* _tmp29_;
		BirdFontPath* _tmp30_;
		GeeArrayList* _tmp31_;
		GeeArrayList* _tmp32_;
		gint _tmp33_;
		gint _tmp34_;
		gpointer _tmp35_;
		_tmp27_ = p->path;
		_tmp28_ = bird_font_path_get_points (_tmp27_);
		_tmp29_ = _tmp28_;
		_tmp30_ = p->path;
		_tmp31_ = bird_font_path_get_points (_tmp30_);
		_tmp32_ = _tmp31_;
		_tmp33_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp32_);
		_tmp34_ = _tmp33_;
		_tmp35_ = gee_abstract_list_get ((GeeAbstractList*) _tmp29_, _tmp34_ - 1);
		_g_object_unref0 (prev);
		prev = (BirdFontEditPoint*) _tmp35_;
	}
	_tmp36_ = prev;
	_tmp37_ = bird_font_edit_point_get_right_handle (_tmp36_);
	bird_font_edit_point_handle_convert_to_curve (_tmp37_);
	_tmp38_ = next;
	_tmp39_ = bird_font_edit_point_get_left_handle (_tmp38_);
	bird_font_edit_point_handle_convert_to_curve (_tmp39_);
	_tmp41_ = prev;
	_tmp42_ = bird_font_edit_point_get_right_handle (_tmp41_);
	if (_tmp42_->type == BIRD_FONT_POINT_TYPE_QUADRATIC) {
		BirdFontEditPoint* _tmp43_;
		BirdFontEditPointHandle* _tmp44_;
		_tmp43_ = next;
		_tmp44_ = bird_font_edit_point_get_left_handle (_tmp43_);
		_tmp40_ = _tmp44_->type != BIRD_FONT_POINT_TYPE_QUADRATIC;
	} else {
		_tmp40_ = FALSE;
	}
	if (_tmp40_) {
		BirdFontEditPoint* _tmp45_;
		BirdFontEditPoint* _tmp46_;
		BirdFontEditPointHandle* _tmp47_;
		_tmp45_ = prev;
		_tmp46_ = next;
		_tmp47_ = bird_font_edit_point_get_left_handle (_tmp46_);
		bird_font_pen_tool_convert_point_type (_tmp45_, _tmp47_->type);
	}
	_tmp49_ = prev;
	_tmp50_ = bird_font_edit_point_get_right_handle (_tmp49_);
	if (_tmp50_->type != BIRD_FONT_POINT_TYPE_QUADRATIC) {
		BirdFontEditPoint* _tmp51_;
		BirdFontEditPointHandle* _tmp52_;
		_tmp51_ = next;
		_tmp52_ = bird_font_edit_point_get_left_handle (_tmp51_);
		_tmp48_ = _tmp52_->type == BIRD_FONT_POINT_TYPE_QUADRATIC;
	} else {
		_tmp48_ = FALSE;
	}
	if (_tmp48_) {
		BirdFontEditPoint* _tmp53_;
		BirdFontEditPoint* _tmp54_;
		BirdFontEditPointHandle* _tmp55_;
		_tmp53_ = next;
		_tmp54_ = prev;
		_tmp55_ = bird_font_edit_point_get_right_handle (_tmp54_);
		bird_font_pen_tool_convert_point_type (_tmp53_, _tmp55_->type);
	}
	_tmp56_ = prev;
	_tmp57_ = bird_font_edit_point_copy (_tmp56_);
	_g_object_unref0 (ep1);
	ep1 = _tmp57_;
	_tmp58_ = next;
	_tmp59_ = bird_font_edit_point_copy (_tmp58_);
	_g_object_unref0 (ep2);
	ep2 = _tmp59_;
	_tmp60_ = ep1;
	_tmp61_ = bird_font_edit_point_get_right_handle (_tmp60_);
	start_length = _tmp61_->length;
	_tmp62_ = ep2;
	_tmp63_ = bird_font_edit_point_get_left_handle (_tmp62_);
	stop_length = _tmp63_->length;
	stop_previous_length = start_length;
	start_previous_length = stop_length;
	stop_min_distortion = DBL_MAX;
	_tmp64_ = ep1;
	_tmp65_ = bird_font_edit_point_get_right_handle (_tmp64_);
	_tmp65_->length = start_length;
	start_min_distortion = DBL_MAX;
	_tmp66_ = ep2;
	_tmp67_ = bird_font_edit_point_get_left_handle (_tmp66_);
	_tmp67_->length = stop_length;
	prev_length_adjustment = (gdouble) 0;
	next_length_adjustment = (gdouble) 0;
	prev_length_adjustment_reverse = (gdouble) 0;
	next_length_adjustment_reverse = (gdouble) 0;
	min_distortion = DBL_MAX;
	_tmp68_ = ep1;
	_tmp69_ = ep2;
	_tmp70_ = ep1;
	_tmp71_ = ep2;
	distance = bird_font_path_distance (_tmp68_->x, _tmp69_->x, _tmp70_->y, _tmp71_->y);
	{
		gdouble m = 0.0;
		m = 50.0;
		{
			gboolean _tmp72_ = FALSE;
			_tmp72_ = TRUE;
			while (TRUE) {
				gdouble _tmp73_ = 0.0;
				gdouble first = 0.0;
				if (!_tmp72_) {
					m /= 10.0;
				}
				_tmp72_ = FALSE;
				if (!(m >= (tolerance / 2.0))) {
					break;
				}
				step = m / 10.0;
				min_distortion = DBL_MAX;
				if (m == 50.0) {
					_tmp73_ = (gdouble) 0;
				} else {
					_tmp73_ = -m;
				}
				first = _tmp73_;
				{
					gdouble a = 0.0;
					a = first;
					{
						gboolean _tmp74_ = FALSE;
						_tmp74_ = TRUE;
						while (TRUE) {
							if (!_tmp74_) {
								a += step;
							}
							_tmp74_ = FALSE;
							if (!(a < m)) {
								break;
							}
							{
								gdouble b = 0.0;
								b = first;
								{
									gboolean _tmp75_ = FALSE;
									_tmp75_ = TRUE;
									while (TRUE) {
										BirdFontEditPoint* _tmp76_;
										BirdFontEditPointHandle* _tmp77_;
										BirdFontEditPoint* _tmp78_;
										BirdFontEditPointHandle* _tmp79_;
										BirdFontEditPoint* _tmp80_;
										BirdFontEditPoint* _tmp81_;
										BirdFontEditPoint* _tmp82_;
										BirdFontEditPoint* _tmp83_;
										BirdFontEditPoint* _tmp84_;
										gdouble _tmp85_ = 0.0;
										gdouble _tmp86_ = 0.0;
										gboolean _tmp87_ = FALSE;
										gboolean _tmp88_ = FALSE;
										if (!_tmp75_) {
											b += step;
										}
										_tmp75_ = FALSE;
										if (!(b < m)) {
											break;
										}
										if ((((start_length + a) + stop_length) + b) > distance) {
											break;
										}
										_tmp76_ = ep1;
										_tmp77_ = bird_font_edit_point_get_right_handle (_tmp76_);
										_tmp77_->length = start_length + a;
										_tmp78_ = ep2;
										_tmp79_ = bird_font_edit_point_get_left_handle (_tmp78_);
										_tmp79_->length = stop_length + b;
										_tmp80_ = prev;
										_tmp81_ = p->point;
										_tmp82_ = next;
										_tmp83_ = ep1;
										_tmp84_ = ep2;
										bird_font_pen_tool_get_path_distortion (_tmp80_, _tmp81_, _tmp82_, _tmp83_, _tmp84_, &_tmp85_, &_tmp86_);
										start_distortion = _tmp85_;
										stop_distortion = _tmp86_;
										distortion = fmax (start_distortion, stop_distortion);
										if (distortion < min_distortion) {
											_tmp88_ = (start_length + a) > ((gdouble) 0);
										} else {
											_tmp88_ = FALSE;
										}
										if (_tmp88_) {
											_tmp87_ = (stop_length + b) > ((gdouble) 0);
										} else {
											_tmp87_ = FALSE;
										}
										if (_tmp87_) {
											min_distortion = distortion;
											prev_length_adjustment_reverse = a;
											next_length_adjustment = b;
										}
									}
								}
							}
						}
					}
				}
				start_length += prev_length_adjustment_reverse;
				stop_length += next_length_adjustment;
			}
		}
	}
	if (min_distortion < keep_tolerance) {
		_tmp89_ = TRUE;
	} else {
		_tmp89_ = keep_tolerance >= BIRD_FONT_GLYPH_CANVAS_MAX;
	}
	if (_tmp89_) {
		BirdFontEditPoint* _tmp90_;
		BirdFontEditPointHandle* _tmp91_;
		BirdFontEditPoint* _tmp92_;
		BirdFontEditPointHandle* _tmp93_;
		BirdFontEditPoint* _tmp106_;
		BirdFontPath* _tmp107_;
		_tmp90_ = prev;
		_tmp91_ = bird_font_edit_point_get_right_handle (_tmp90_);
		_tmp91_->length = start_length;
		_tmp92_ = prev;
		_tmp93_ = bird_font_edit_point_get_right_handle (_tmp92_);
		if (_tmp93_->type != BIRD_FONT_POINT_TYPE_QUADRATIC) {
			BirdFontEditPoint* _tmp94_;
			BirdFontEditPointHandle* _tmp95_;
			_tmp94_ = next;
			_tmp95_ = bird_font_edit_point_get_left_handle (_tmp94_);
			_tmp95_->length = stop_length;
		} else {
			BirdFontEditPoint* _tmp96_;
			BirdFontEditPointHandle* _tmp97_;
			BirdFontEditPoint* _tmp98_;
			BirdFontEditPointHandle* _tmp99_;
			gdouble _tmp100_;
			gdouble _tmp101_;
			BirdFontEditPoint* _tmp102_;
			BirdFontEditPointHandle* _tmp103_;
			gdouble _tmp104_;
			gdouble _tmp105_;
			_tmp96_ = next;
			_tmp97_ = bird_font_edit_point_get_left_handle (_tmp96_);
			_tmp98_ = prev;
			_tmp99_ = bird_font_edit_point_get_right_handle (_tmp98_);
			_tmp100_ = bird_font_edit_point_handle_get_x (_tmp99_);
			_tmp101_ = _tmp100_;
			_tmp102_ = prev;
			_tmp103_ = bird_font_edit_point_get_right_handle (_tmp102_);
			_tmp104_ = bird_font_edit_point_handle_get_y (_tmp103_);
			_tmp105_ = _tmp104_;
			bird_font_edit_point_handle_move_to_coordinate (_tmp97_, _tmp101_, _tmp105_);
		}
		_tmp106_ = p->point;
		bird_font_edit_point_set_deleted (_tmp106_, TRUE);
		_tmp107_ = p->path;
		bird_font_path_remove_deleted_points (_tmp107_);
	}
	result = min_distortion;
	_g_object_unref0 (prev);
	_g_object_unref0 (next);
	_g_object_unref0 (ep2);
	_g_object_unref0 (ep1);
	return result;
}

/** @return path distortion. */
gdouble
bird_font_pen_tool_remove_point_simplify_path_fast (BirdFontPointSelection* p,
                                                    gdouble tolerance,
                                                    gdouble keep_tolerance)
{
	gdouble start_length = 0.0;
	gdouble stop_length = 0.0;
	gdouble start_distortion = 0.0;
	gdouble start_min_distortion = 0.0;
	gdouble start_previous_length = 0.0;
	gdouble stop_distortion = 0.0;
	gdouble stop_min_distortion = 0.0;
	gdouble stop_previous_length = 0.0;
	gdouble distortion = 0.0;
	gdouble min_distortion = 0.0;
	gdouble prev_length_adjustment = 0.0;
	gdouble next_length_adjustment = 0.0;
	gdouble prev_length_adjustment_reverse = 0.0;
	gdouble next_length_adjustment_reverse = 0.0;
	BirdFontEditPoint* ep1 = NULL;
	BirdFontEditPoint* ep2 = NULL;
	BirdFontEditPoint* next = NULL;
	BirdFontEditPoint* prev = NULL;
	gdouble step = 0.0;
	gdouble distance = 0.0;
	BirdFontPath* _tmp0_;
	GeeArrayList* _tmp1_;
	GeeArrayList* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	BirdFontPath* _tmp5_;
	GeeArrayList* _tmp6_;
	GeeArrayList* _tmp7_;
	gint _tmp8_;
	gint _tmp9_;
	BirdFontEditPoint* _tmp12_;
	BirdFontEditPoint* _tmp13_;
	BirdFontEditPoint* _tmp14_;
	BirdFontEditPoint* _tmp22_;
	BirdFontEditPoint* _tmp23_;
	BirdFontEditPoint* _tmp36_;
	BirdFontEditPointHandle* _tmp37_;
	BirdFontEditPoint* _tmp38_;
	BirdFontEditPointHandle* _tmp39_;
	gboolean _tmp40_ = FALSE;
	BirdFontEditPoint* _tmp41_;
	BirdFontEditPointHandle* _tmp42_;
	gboolean _tmp48_ = FALSE;
	BirdFontEditPoint* _tmp49_;
	BirdFontEditPointHandle* _tmp50_;
	BirdFontEditPoint* _tmp56_;
	BirdFontEditPoint* _tmp57_;
	BirdFontEditPoint* _tmp58_;
	BirdFontEditPoint* _tmp59_;
	BirdFontEditPoint* _tmp60_;
	BirdFontEditPointHandle* _tmp61_;
	BirdFontEditPoint* _tmp62_;
	BirdFontEditPointHandle* _tmp63_;
	BirdFontEditPoint* _tmp64_;
	BirdFontEditPointHandle* _tmp65_;
	BirdFontEditPoint* _tmp66_;
	BirdFontEditPointHandle* _tmp67_;
	BirdFontEditPoint* _tmp68_;
	BirdFontEditPoint* _tmp69_;
	BirdFontEditPoint* _tmp70_;
	BirdFontEditPoint* _tmp71_;
	gboolean _tmp89_ = FALSE;
	gdouble result;
	g_return_val_if_fail (p != NULL, 0.0);
	_tmp0_ = p->path;
	_tmp1_ = bird_font_path_get_points (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
	_tmp4_ = _tmp3_;
	g_return_val_if_fail (_tmp4_ > 0, 0);
	_tmp5_ = p->path;
	_tmp6_ = bird_font_path_get_points (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp7_);
	_tmp9_ = _tmp8_;
	if (_tmp9_ <= 2) {
		BirdFontEditPoint* _tmp10_;
		BirdFontPath* _tmp11_;
		_tmp10_ = p->point;
		bird_font_edit_point_set_deleted (_tmp10_, TRUE);
		_tmp11_ = p->path;
		bird_font_path_remove_deleted_points (_tmp11_);
		result = (gdouble) 0;
		_g_object_unref0 (prev);
		_g_object_unref0 (next);
		_g_object_unref0 (ep2);
		_g_object_unref0 (ep1);
		return result;
	}
	_tmp12_ = p->point;
	bird_font_edit_point_set_deleted (_tmp12_, TRUE);
	_tmp13_ = p->point;
	_tmp14_ = _tmp13_->next;
	if (_tmp14_ != NULL) {
		BirdFontEditPoint* _tmp15_;
		BirdFontEditPoint* _tmp16_;
		BirdFontEditPoint* _tmp17_;
		_tmp15_ = p->point;
		_tmp16_ = bird_font_edit_point_get_next (_tmp15_);
		_tmp17_ = _g_object_ref0 (_tmp16_);
		_g_object_unref0 (next);
		next = _tmp17_;
	} else {
		BirdFontPath* _tmp18_;
		GeeArrayList* _tmp19_;
		GeeArrayList* _tmp20_;
		gpointer _tmp21_;
		_tmp18_ = p->path;
		_tmp19_ = bird_font_path_get_points (_tmp18_);
		_tmp20_ = _tmp19_;
		_tmp21_ = gee_abstract_list_get ((GeeAbstractList*) _tmp20_, 0);
		_g_object_unref0 (next);
		next = (BirdFontEditPoint*) _tmp21_;
	}
	_tmp22_ = p->point;
	_tmp23_ = _tmp22_->prev;
	if (_tmp23_ != NULL) {
		BirdFontEditPoint* _tmp24_;
		BirdFontEditPoint* _tmp25_;
		BirdFontEditPoint* _tmp26_;
		_tmp24_ = p->point;
		_tmp25_ = bird_font_edit_point_get_prev (_tmp24_);
		_tmp26_ = _g_object_ref0 (_tmp25_);
		_g_object_unref0 (prev);
		prev = _tmp26_;
	} else {
		BirdFontPath* _tmp27_;
		GeeArrayList* _tmp28_;
		GeeArrayList* _tmp29_;
		BirdFontPath* _tmp30_;
		GeeArrayList* _tmp31_;
		GeeArrayList* _tmp32_;
		gint _tmp33_;
		gint _tmp34_;
		gpointer _tmp35_;
		_tmp27_ = p->path;
		_tmp28_ = bird_font_path_get_points (_tmp27_);
		_tmp29_ = _tmp28_;
		_tmp30_ = p->path;
		_tmp31_ = bird_font_path_get_points (_tmp30_);
		_tmp32_ = _tmp31_;
		_tmp33_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp32_);
		_tmp34_ = _tmp33_;
		_tmp35_ = gee_abstract_list_get ((GeeAbstractList*) _tmp29_, _tmp34_ - 1);
		_g_object_unref0 (prev);
		prev = (BirdFontEditPoint*) _tmp35_;
	}
	_tmp36_ = prev;
	_tmp37_ = bird_font_edit_point_get_right_handle (_tmp36_);
	bird_font_edit_point_handle_convert_to_curve (_tmp37_);
	_tmp38_ = next;
	_tmp39_ = bird_font_edit_point_get_left_handle (_tmp38_);
	bird_font_edit_point_handle_convert_to_curve (_tmp39_);
	_tmp41_ = prev;
	_tmp42_ = bird_font_edit_point_get_right_handle (_tmp41_);
	if (_tmp42_->type == BIRD_FONT_POINT_TYPE_QUADRATIC) {
		BirdFontEditPoint* _tmp43_;
		BirdFontEditPointHandle* _tmp44_;
		_tmp43_ = next;
		_tmp44_ = bird_font_edit_point_get_left_handle (_tmp43_);
		_tmp40_ = _tmp44_->type != BIRD_FONT_POINT_TYPE_QUADRATIC;
	} else {
		_tmp40_ = FALSE;
	}
	if (_tmp40_) {
		BirdFontEditPoint* _tmp45_;
		BirdFontEditPoint* _tmp46_;
		BirdFontEditPointHandle* _tmp47_;
		_tmp45_ = prev;
		_tmp46_ = next;
		_tmp47_ = bird_font_edit_point_get_left_handle (_tmp46_);
		bird_font_pen_tool_convert_point_type (_tmp45_, _tmp47_->type);
	}
	_tmp49_ = prev;
	_tmp50_ = bird_font_edit_point_get_right_handle (_tmp49_);
	if (_tmp50_->type != BIRD_FONT_POINT_TYPE_QUADRATIC) {
		BirdFontEditPoint* _tmp51_;
		BirdFontEditPointHandle* _tmp52_;
		_tmp51_ = next;
		_tmp52_ = bird_font_edit_point_get_left_handle (_tmp51_);
		_tmp48_ = _tmp52_->type == BIRD_FONT_POINT_TYPE_QUADRATIC;
	} else {
		_tmp48_ = FALSE;
	}
	if (_tmp48_) {
		BirdFontEditPoint* _tmp53_;
		BirdFontEditPoint* _tmp54_;
		BirdFontEditPointHandle* _tmp55_;
		_tmp53_ = next;
		_tmp54_ = prev;
		_tmp55_ = bird_font_edit_point_get_right_handle (_tmp54_);
		bird_font_pen_tool_convert_point_type (_tmp53_, _tmp55_->type);
	}
	_tmp56_ = prev;
	_tmp57_ = bird_font_edit_point_copy (_tmp56_);
	_g_object_unref0 (ep1);
	ep1 = _tmp57_;
	_tmp58_ = next;
	_tmp59_ = bird_font_edit_point_copy (_tmp58_);
	_g_object_unref0 (ep2);
	ep2 = _tmp59_;
	_tmp60_ = ep1;
	_tmp61_ = bird_font_edit_point_get_right_handle (_tmp60_);
	start_length = _tmp61_->length;
	_tmp62_ = ep2;
	_tmp63_ = bird_font_edit_point_get_left_handle (_tmp62_);
	stop_length = _tmp63_->length;
	stop_previous_length = start_length;
	start_previous_length = stop_length;
	stop_min_distortion = DBL_MAX;
	_tmp64_ = ep1;
	_tmp65_ = bird_font_edit_point_get_right_handle (_tmp64_);
	_tmp65_->length = start_length;
	start_min_distortion = DBL_MAX;
	_tmp66_ = ep2;
	_tmp67_ = bird_font_edit_point_get_left_handle (_tmp66_);
	_tmp67_->length = stop_length;
	prev_length_adjustment = (gdouble) 0;
	next_length_adjustment = (gdouble) 0;
	prev_length_adjustment_reverse = (gdouble) 0;
	next_length_adjustment_reverse = (gdouble) 0;
	min_distortion = DBL_MAX;
	_tmp68_ = ep1;
	_tmp69_ = ep2;
	_tmp70_ = ep1;
	_tmp71_ = ep2;
	distance = bird_font_path_distance (_tmp68_->x, _tmp69_->x, _tmp70_->y, _tmp71_->y);
	{
		gdouble m = 0.0;
		m = 50.0;
		{
			gboolean _tmp72_ = FALSE;
			_tmp72_ = TRUE;
			while (TRUE) {
				gdouble _tmp73_ = 0.0;
				gdouble first = 0.0;
				if (!_tmp72_) {
					m /= 10.0;
				}
				_tmp72_ = FALSE;
				if (!(m >= (tolerance / 2.0))) {
					break;
				}
				step = m / 10.0;
				min_distortion = DBL_MAX;
				if (m == 50.0) {
					_tmp73_ = (gdouble) 0;
				} else {
					_tmp73_ = -m;
				}
				first = _tmp73_;
				{
					gdouble a = 0.0;
					a = first;
					{
						gboolean _tmp74_ = FALSE;
						_tmp74_ = TRUE;
						while (TRUE) {
							if (!_tmp74_) {
								a += step;
							}
							_tmp74_ = FALSE;
							if (!(a < m)) {
								break;
							}
							{
								gdouble b = 0.0;
								b = first;
								{
									gboolean _tmp75_ = FALSE;
									_tmp75_ = TRUE;
									while (TRUE) {
										BirdFontEditPoint* _tmp76_;
										BirdFontEditPointHandle* _tmp77_;
										BirdFontEditPoint* _tmp78_;
										BirdFontEditPointHandle* _tmp79_;
										BirdFontEditPoint* _tmp80_;
										BirdFontEditPoint* _tmp81_;
										BirdFontEditPoint* _tmp82_;
										BirdFontEditPoint* _tmp83_;
										BirdFontEditPoint* _tmp84_;
										gdouble _tmp85_ = 0.0;
										gdouble _tmp86_ = 0.0;
										gboolean _tmp87_ = FALSE;
										gboolean _tmp88_ = FALSE;
										if (!_tmp75_) {
											b += step;
										}
										_tmp75_ = FALSE;
										if (!(b < m)) {
											break;
										}
										if ((((start_length + a) + stop_length) + b) > distance) {
											break;
										}
										_tmp76_ = ep1;
										_tmp77_ = bird_font_edit_point_get_right_handle (_tmp76_);
										_tmp77_->length = start_length + a;
										_tmp78_ = ep2;
										_tmp79_ = bird_font_edit_point_get_left_handle (_tmp78_);
										_tmp79_->length = stop_length + b;
										_tmp80_ = prev;
										_tmp81_ = p->point;
										_tmp82_ = next;
										_tmp83_ = ep1;
										_tmp84_ = ep2;
										bird_font_pen_tool_get_path_distortion (_tmp80_, _tmp81_, _tmp82_, _tmp83_, _tmp84_, &_tmp85_, &_tmp86_);
										start_distortion = _tmp85_;
										stop_distortion = _tmp86_;
										distortion = fmax (start_distortion, stop_distortion);
										if (distortion < min_distortion) {
											_tmp88_ = (start_length + a) > ((gdouble) 0);
										} else {
											_tmp88_ = FALSE;
										}
										if (_tmp88_) {
											_tmp87_ = (stop_length + b) > ((gdouble) 0);
										} else {
											_tmp87_ = FALSE;
										}
										if (_tmp87_) {
											min_distortion = distortion;
											prev_length_adjustment_reverse = a;
											next_length_adjustment = b;
										}
									}
								}
							}
						}
					}
				}
				start_length += prev_length_adjustment_reverse;
				stop_length += next_length_adjustment;
			}
		}
	}
	if (min_distortion < keep_tolerance) {
		_tmp89_ = TRUE;
	} else {
		_tmp89_ = keep_tolerance >= BIRD_FONT_GLYPH_CANVAS_MAX;
	}
	if (_tmp89_) {
		BirdFontEditPoint* _tmp90_;
		BirdFontEditPointHandle* _tmp91_;
		BirdFontEditPoint* _tmp92_;
		BirdFontEditPointHandle* _tmp93_;
		BirdFontEditPoint* _tmp106_;
		BirdFontPath* _tmp107_;
		_tmp90_ = prev;
		_tmp91_ = bird_font_edit_point_get_right_handle (_tmp90_);
		_tmp91_->length = start_length;
		_tmp92_ = prev;
		_tmp93_ = bird_font_edit_point_get_right_handle (_tmp92_);
		if (_tmp93_->type != BIRD_FONT_POINT_TYPE_QUADRATIC) {
			BirdFontEditPoint* _tmp94_;
			BirdFontEditPointHandle* _tmp95_;
			_tmp94_ = next;
			_tmp95_ = bird_font_edit_point_get_left_handle (_tmp94_);
			_tmp95_->length = stop_length;
		} else {
			BirdFontEditPoint* _tmp96_;
			BirdFontEditPointHandle* _tmp97_;
			BirdFontEditPoint* _tmp98_;
			BirdFontEditPointHandle* _tmp99_;
			gdouble _tmp100_;
			gdouble _tmp101_;
			BirdFontEditPoint* _tmp102_;
			BirdFontEditPointHandle* _tmp103_;
			gdouble _tmp104_;
			gdouble _tmp105_;
			_tmp96_ = next;
			_tmp97_ = bird_font_edit_point_get_left_handle (_tmp96_);
			_tmp98_ = prev;
			_tmp99_ = bird_font_edit_point_get_right_handle (_tmp98_);
			_tmp100_ = bird_font_edit_point_handle_get_x (_tmp99_);
			_tmp101_ = _tmp100_;
			_tmp102_ = prev;
			_tmp103_ = bird_font_edit_point_get_right_handle (_tmp102_);
			_tmp104_ = bird_font_edit_point_handle_get_y (_tmp103_);
			_tmp105_ = _tmp104_;
			bird_font_edit_point_handle_move_to_coordinate (_tmp97_, _tmp101_, _tmp105_);
		}
		_tmp106_ = p->point;
		bird_font_edit_point_set_deleted (_tmp106_, TRUE);
		_tmp107_ = p->path;
		bird_font_path_remove_deleted_points (_tmp107_);
	}
	result = min_distortion;
	_g_object_unref0 (prev);
	_g_object_unref0 (next);
	_g_object_unref0 (ep2);
	_g_object_unref0 (ep1);
	return result;
}

/** Retain selected points even if path is copied after running reverse. */
void
bird_font_pen_tool_update_selection (void)
{
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	GeeArrayList* _tmp1_;
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	_tmp1_ = bird_font_pen_tool_selected_points;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp1_);
	{
		GeeArrayList* _p_list = NULL;
		BirdFontGlyph* _tmp2_;
		GeeArrayList* _tmp3_;
		gint _p_size = 0;
		GeeArrayList* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		gint _p_index = 0;
		_tmp2_ = g;
		_tmp3_ = bird_font_glyph_get_visible_paths (_tmp2_);
		_p_list = _tmp3_;
		_tmp4_ = _p_list;
		_tmp5_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp4_);
		_tmp6_ = _tmp5_;
		_p_size = _tmp6_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp7_;
			gint _tmp8_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp9_;
			gpointer _tmp10_;
			_p_index = _p_index + 1;
			_tmp7_ = _p_index;
			_tmp8_ = _p_size;
			if (!(_tmp7_ < _tmp8_)) {
				break;
			}
			_tmp9_ = _p_list;
			_tmp10_ = gee_abstract_list_get ((GeeAbstractList*) _tmp9_, _p_index);
			p = (BirdFontPath*) _tmp10_;
			{
				GeeArrayList* _e_list = NULL;
				BirdFontPath* _tmp11_;
				GeeArrayList* _tmp12_;
				GeeArrayList* _tmp13_;
				gint _e_size = 0;
				GeeArrayList* _tmp14_;
				gint _tmp15_;
				gint _tmp16_;
				gint _e_index = 0;
				_tmp11_ = p;
				_tmp12_ = bird_font_path_get_points (_tmp11_);
				_tmp13_ = _tmp12_;
				_e_list = _tmp13_;
				_tmp14_ = _e_list;
				_tmp15_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp14_);
				_tmp16_ = _tmp15_;
				_e_size = _tmp16_;
				_e_index = -1;
				while (TRUE) {
					gint _tmp17_;
					gint _tmp18_;
					BirdFontEditPoint* e = NULL;
					GeeArrayList* _tmp19_;
					gpointer _tmp20_;
					BirdFontEditPoint* _tmp21_;
					_e_index = _e_index + 1;
					_tmp17_ = _e_index;
					_tmp18_ = _e_size;
					if (!(_tmp17_ < _tmp18_)) {
						break;
					}
					_tmp19_ = _e_list;
					_tmp20_ = gee_abstract_list_get ((GeeAbstractList*) _tmp19_, _e_index);
					e = (BirdFontEditPoint*) _tmp20_;
					_tmp21_ = e;
					if (bird_font_edit_point_is_selected (_tmp21_)) {
						GeeArrayList* _tmp22_;
						BirdFontEditPoint* _tmp23_;
						BirdFontPath* _tmp24_;
						BirdFontPointSelection* _tmp25_;
						BirdFontPointSelection* _tmp26_;
						_tmp22_ = bird_font_pen_tool_selected_points;
						_tmp23_ = e;
						_tmp24_ = p;
						_tmp25_ = bird_font_point_selection_new (_tmp23_, _tmp24_);
						_tmp26_ = _tmp25_;
						gee_abstract_collection_add ((GeeAbstractCollection*) _tmp22_, _tmp26_);
						_g_object_unref0 (_tmp26_);
					}
					_g_object_unref0 (e);
				}
			}
			_g_object_unref0 (p);
		}
		_g_object_unref0 (_p_list);
	}
	_g_object_unref0 (g);
}

static void
bird_font_pen_tool_process_deleted (void)
{
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	while (TRUE) {
		BirdFontGlyph* _tmp1_;
		_tmp1_ = g;
		if (!bird_font_glyph_process_deleted (_tmp1_)) {
			break;
		}
	}
	_g_object_unref0 (g);
}

void
bird_font_pen_tool_close_all_paths (void)
{
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	BirdFontGlyph* _tmp14_;
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	{
		GeeArrayList* _p_list = NULL;
		BirdFontGlyph* _tmp1_;
		GeeArrayList* _tmp2_;
		gint _p_size = 0;
		GeeArrayList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		gint _p_index = 0;
		_tmp1_ = g;
		_tmp2_ = bird_font_glyph_get_visible_paths (_tmp1_);
		_p_list = _tmp2_;
		_tmp3_ = _p_list;
		_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
		_tmp5_ = _tmp4_;
		_p_size = _tmp5_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp6_;
			gint _tmp7_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp8_;
			gpointer _tmp9_;
			BirdFontPath* _tmp10_;
			gdouble _tmp11_;
			gdouble _tmp12_;
			_p_index = _p_index + 1;
			_tmp6_ = _p_index;
			_tmp7_ = _p_size;
			if (!(_tmp6_ < _tmp7_)) {
				break;
			}
			_tmp8_ = _p_list;
			_tmp9_ = gee_abstract_list_get ((GeeAbstractList*) _tmp8_, _p_index);
			p = (BirdFontPath*) _tmp9_;
			_tmp10_ = p;
			_tmp11_ = bird_font_path_get_stroke (_tmp10_);
			_tmp12_ = _tmp11_;
			if (_tmp12_ == ((gdouble) 0)) {
				BirdFontPath* _tmp13_;
				_tmp13_ = p;
				bird_font_path_close (_tmp13_);
			}
			_g_object_unref0 (p);
		}
		_g_object_unref0 (_p_list);
	}
	_tmp14_ = g;
	bird_font_glyph_close_path (_tmp14_);
	bird_font_glyph_canvas_redraw ();
	_g_object_unref0 (g);
}

void
bird_font_pen_tool_set_precision (BirdFontPenTool* self,
                                  gdouble p)
{
	BirdFontSpinButton* _tmp0_;
	g_return_if_fail (self != NULL);
	bird_font_pen_tool_precision = p;
	_tmp0_ = bird_font_settings_display_precision;
	bird_font_spin_button_set_value_round (_tmp0_, p, FALSE, FALSE);
}

void
bird_font_pen_tool_reset_stroke (void)
{
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	{
		GeeArrayList* _p_list = NULL;
		GeeArrayList* _tmp1_;
		gint _p_size = 0;
		GeeArrayList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _p_index = 0;
		_tmp1_ = bird_font_pen_tool_selected_points;
		_p_list = _tmp1_;
		_tmp2_ = _p_list;
		_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_p_size = _tmp4_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			BirdFontPointSelection* p = NULL;
			GeeArrayList* _tmp7_;
			gpointer _tmp8_;
			BirdFontPointSelection* _tmp9_;
			BirdFontPath* _tmp10_;
			_p_index = _p_index + 1;
			_tmp5_ = _p_index;
			_tmp6_ = _p_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _p_list;
			_tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, _p_index);
			p = (BirdFontPointSelection*) _tmp8_;
			_tmp9_ = p;
			_tmp10_ = _tmp9_->path;
			bird_font_path_reset_stroke (_tmp10_);
			_g_object_unref0 (p);
		}
	}
	{
		GeeArrayList* _path_list = NULL;
		BirdFontGlyph* _tmp11_;
		GeeArrayList* _tmp12_;
		gint _path_size = 0;
		GeeArrayList* _tmp13_;
		gint _tmp14_;
		gint _tmp15_;
		gint _path_index = 0;
		_tmp11_ = g;
		_tmp12_ = _tmp11_->active_paths;
		_path_list = _tmp12_;
		_tmp13_ = _path_list;
		_tmp14_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp13_);
		_tmp15_ = _tmp14_;
		_path_size = _tmp15_;
		_path_index = -1;
		while (TRUE) {
			gint _tmp16_;
			gint _tmp17_;
			BirdFontPath* path = NULL;
			GeeArrayList* _tmp18_;
			gpointer _tmp19_;
			BirdFontPath* _tmp20_;
			_path_index = _path_index + 1;
			_tmp16_ = _path_index;
			_tmp17_ = _path_size;
			if (!(_tmp16_ < _tmp17_)) {
				break;
			}
			_tmp18_ = _path_list;
			_tmp19_ = gee_abstract_list_get ((GeeAbstractList*) _tmp18_, _path_index);
			path = (BirdFontPath*) _tmp19_;
			_tmp20_ = path;
			bird_font_path_reset_stroke (_tmp20_);
			_g_object_unref0 (path);
		}
	}
	_g_object_unref0 (g);
}

void
bird_font_pen_tool_move (BirdFontPenTool* self,
                         gint x,
                         gint y)
{
	gdouble coordinate_x = 0.0;
	gdouble coordinate_y = 0.0;
	gdouble delta_coordinate_x = 0.0;
	gdouble delta_coordinate_y = 0.0;
	gdouble angle = 0.0;
	gboolean tied = FALSE;
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp44_ = FALSE;
	g_return_if_fail (self != NULL);
	angle = (gdouble) 0;
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	_g_object_unref0 (g);
	g = _tmp0_;
	if (bird_font_pen_tool_move_selected) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = bird_font_pen_tool_move_selected_handle;
	}
	if (_tmp1_) {
		bird_font_pen_tool_cancel_stroke_creator ();
	}
	bird_font_pen_tool_control_point_event (self, (gdouble) x, (gdouble) y, TRUE);
	bird_font_pen_tool_curve_active_corner_event (self, (gdouble) x, (gdouble) y);
	bird_font_pen_tool_set_default_handle_positions ();
	if (bird_font_pen_tool_move_selected_handle) {
		_tmp2_ = bird_font_pen_tool_move_selected;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		g_warning ("PenTool.vala:791: move_selected_handle && move_selected");
		bird_font_pen_tool_move_selected = FALSE;
		bird_font_pen_tool_move_selected_handle = FALSE;
	}
	if (bird_font_pen_tool_move_selected_handle) {
		_tmp3_ = TRUE;
	} else {
		_tmp3_ = bird_font_pen_tool_move_selected;
	}
	if (_tmp3_) {
		bird_font_main_window_set_cursor (BIRD_FONT_NATIVE_WINDOW_HIDDEN);
		bird_font_pen_tool_reset_stroke ();
	} else {
		bird_font_main_window_set_cursor (BIRD_FONT_NATIVE_WINDOW_VISIBLE);
	}
	if (bird_font_pen_tool_move_selected_handle) {
		gboolean _tmp4_ = FALSE;
		gboolean _tmp16_ = FALSE;
		BirdFontPointSelection* _tmp30_;
		BirdFontPath* _tmp31_;
		bird_font_pen_tool_set_type_for_moving_handle (self);
		if (bird_font_key_bindings_modifier == BIRD_FONT_SHIFT) {
			_tmp4_ = TRUE;
		} else {
			_tmp4_ = bird_font_pen_tool_retain_angle;
		}
		if (_tmp4_) {
			BirdFontEditPointHandle* _tmp5_;
			_tmp5_ = bird_font_pen_tool_selected_handle;
			angle = _tmp5_->angle;
		}
		if (bird_font_grid_tool_is_visible ()) {
			BirdFontEditPointHandle* _tmp6_;
			coordinate_x = bird_font_glyph_path_coordinate_x ((gdouble) x);
			coordinate_y = bird_font_glyph_path_coordinate_y ((gdouble) y);
			bird_font_grid_tool_tie_coordinate (&coordinate_x, &coordinate_y);
			delta_coordinate_x = coordinate_x - bird_font_pen_tool_last_point_x;
			delta_coordinate_y = coordinate_y - bird_font_pen_tool_last_point_y;
			_tmp6_ = bird_font_pen_tool_selected_handle;
			bird_font_edit_point_handle_move_delta_coordinate (_tmp6_, delta_coordinate_x, delta_coordinate_y);
		} else {
			if (bird_font_grid_tool_has_ttf_grid ()) {
				BirdFontEditPointHandle* _tmp7_;
				coordinate_x = bird_font_glyph_path_coordinate_x ((gdouble) x);
				coordinate_y = bird_font_glyph_path_coordinate_y ((gdouble) y);
				bird_font_grid_tool_ttf_grid_coordinate (&coordinate_x, &coordinate_y);
				delta_coordinate_x = coordinate_x - bird_font_pen_tool_last_point_x;
				delta_coordinate_y = coordinate_y - bird_font_pen_tool_last_point_y;
				_tmp7_ = bird_font_pen_tool_selected_handle;
				bird_font_edit_point_handle_move_delta_coordinate (_tmp7_, delta_coordinate_x, delta_coordinate_y);
			} else {
				BirdFontEditPointHandle* _tmp8_;
				coordinate_x = bird_font_glyph_path_coordinate_x ((gdouble) x);
				coordinate_y = bird_font_glyph_path_coordinate_y ((gdouble) y);
				_tmp8_ = bird_font_pen_tool_selected_handle;
				bird_font_edit_point_handle_move_to_coordinate (_tmp8_, coordinate_x, coordinate_y);
				if (bird_font_pen_tool_on_axis) {
					gdouble tied_x = 0.0;
					gdouble tied_y = 0.0;
					BirdFontEditPointHandle* _tmp9_;
					BirdFontEditPoint* _tmp10_;
					BirdFontEditPointHandle* _tmp11_;
					BirdFontEditPoint* _tmp12_;
					gdouble _tmp13_ = 0.0;
					gdouble _tmp14_ = 0.0;
					BirdFontEditPointHandle* _tmp15_;
					tied_x = (gdouble) 0;
					tied_y = (gdouble) 0;
					_tmp9_ = bird_font_pen_tool_selected_handle;
					_tmp10_ = _tmp9_->parent;
					_tmp11_ = bird_font_pen_tool_selected_handle;
					_tmp12_ = _tmp11_->parent;
					bird_font_point_tool_tie_angle (_tmp10_->x, _tmp12_->y, coordinate_x, coordinate_y, &_tmp13_, &_tmp14_);
					tied_x = _tmp13_;
					tied_y = _tmp14_;
					_tmp15_ = bird_font_pen_tool_selected_handle;
					bird_font_edit_point_handle_move_to_coordinate (_tmp15_, tied_x, tied_y);
				}
			}
		}
		if (bird_font_key_bindings_modifier == BIRD_FONT_SHIFT) {
			_tmp16_ = TRUE;
		} else {
			_tmp16_ = bird_font_pen_tool_retain_angle;
		}
		if (_tmp16_) {
			BirdFontEditPointHandle* _tmp17_;
			BirdFontEditPointHandle* _tmp18_;
			BirdFontEditPointHandle* _tmp19_;
			BirdFontEditPoint* _tmp20_;
			gboolean _tmp21_;
			gboolean _tmp22_;
			_tmp17_ = bird_font_pen_tool_selected_handle;
			_tmp17_->angle = angle;
			_tmp18_ = bird_font_pen_tool_selected_handle;
			bird_font_edit_point_handle_process_connected_handle (_tmp18_);
			_tmp19_ = bird_font_pen_tool_selected_handle;
			_tmp20_ = _tmp19_->parent;
			_tmp21_ = bird_font_edit_point_get_tie_handles (_tmp20_);
			_tmp22_ = _tmp21_;
			if (_tmp22_) {
				BirdFontEditPointHandle* _tmp23_;
				_tmp23_ = bird_font_pen_tool_selected_handle;
				if (bird_font_edit_point_handle_is_left_handle (_tmp23_)) {
					BirdFontEditPointHandle* _tmp24_;
					BirdFontEditPoint* _tmp25_;
					BirdFontEditPointHandle* _tmp26_;
					_tmp24_ = bird_font_pen_tool_selected_handle;
					_tmp25_ = _tmp24_->parent;
					_tmp26_ = bird_font_edit_point_get_right_handle (_tmp25_);
					_tmp26_->angle = angle - G_PI;
				} else {
					BirdFontEditPointHandle* _tmp27_;
					BirdFontEditPoint* _tmp28_;
					BirdFontEditPointHandle* _tmp29_;
					_tmp27_ = bird_font_pen_tool_selected_handle;
					_tmp28_ = _tmp27_->parent;
					_tmp29_ = bird_font_edit_point_get_left_handle (_tmp28_);
					_tmp29_->angle = angle + G_PI;
				}
			}
		}
		_tmp30_ = bird_font_pen_tool_handle_selection;
		_tmp31_ = _tmp30_->path;
		bird_font_path_update_region_boundaries (_tmp31_);
		bird_font_glyph_canvas_redraw ();
		if (bird_font_grid_tool_is_visible ()) {
			BirdFontEditPointHandle* _tmp32_;
			gdouble _tmp33_;
			gdouble _tmp34_;
			BirdFontEditPointHandle* _tmp35_;
			gdouble _tmp36_;
			gdouble _tmp37_;
			_tmp32_ = bird_font_pen_tool_selected_handle;
			_tmp33_ = bird_font_edit_point_handle_get_x (_tmp32_);
			_tmp34_ = _tmp33_;
			bird_font_pen_tool_last_point_x = _tmp34_;
			_tmp35_ = bird_font_pen_tool_selected_handle;
			_tmp36_ = bird_font_edit_point_handle_get_y (_tmp35_);
			_tmp37_ = _tmp36_;
			bird_font_pen_tool_last_point_y = _tmp37_;
		} else {
			if (bird_font_grid_tool_has_ttf_grid ()) {
				BirdFontEditPointHandle* _tmp38_;
				gdouble _tmp39_;
				gdouble _tmp40_;
				BirdFontEditPointHandle* _tmp41_;
				gdouble _tmp42_;
				gdouble _tmp43_;
				_tmp38_ = bird_font_pen_tool_selected_handle;
				_tmp39_ = bird_font_edit_point_handle_get_x (_tmp38_);
				_tmp40_ = _tmp39_;
				bird_font_pen_tool_last_point_x = _tmp40_;
				_tmp41_ = bird_font_pen_tool_selected_handle;
				_tmp42_ = bird_font_edit_point_handle_get_y (_tmp41_);
				_tmp43_ = _tmp42_;
				bird_font_pen_tool_last_point_y = _tmp43_;
			} else {
				bird_font_pen_tool_last_point_x = bird_font_glyph_path_coordinate_x ((gdouble) x);
				bird_font_pen_tool_last_point_y = bird_font_glyph_path_coordinate_y ((gdouble) y);
			}
		}
	}
	if (bird_font_pen_tool_move_selected) {
		_tmp44_ = !bird_font_pen_tool_show_selection_box;
	} else {
		_tmp44_ = FALSE;
	}
	if (_tmp44_) {
		gboolean _tmp164_ = FALSE;
		BirdFontEditPoint* _tmp165_;
		gboolean _tmp166_;
		gboolean _tmp167_;
		if (bird_font_grid_tool_is_visible ()) {
			gboolean _tmp45_ = FALSE;
			BirdFontEditPoint* _tmp46_;
			gboolean _tmp47_;
			gboolean _tmp48_;
			coordinate_x = bird_font_glyph_path_coordinate_x ((gdouble) x);
			coordinate_y = bird_font_glyph_path_coordinate_y ((gdouble) y);
			_tmp46_ = bird_font_pen_tool_selected_point;
			_tmp47_ = bird_font_edit_point_get_tie_handles (_tmp46_);
			_tmp48_ = _tmp47_;
			if (_tmp48_) {
				_tmp45_ = bird_font_key_bindings_modifier == BIRD_FONT_SHIFT;
			} else {
				_tmp45_ = FALSE;
			}
			if (_tmp45_) {
				gdouble _tmp51_ = 0.0;
				gdouble _tmp52_ = 0.0;
				if (self->priv->first_move_action) {
					BirdFontEditPoint* _tmp49_;
					BirdFontEditPoint* _tmp50_;
					_tmp49_ = bird_font_pen_tool_selected_point;
					bird_font_pen_tool_last_point_x = _tmp49_->x;
					_tmp50_ = bird_font_pen_tool_selected_point;
					bird_font_pen_tool_last_point_y = _tmp50_->y;
				}
				bird_font_pen_tool_move_point_on_handles (self, coordinate_x, coordinate_y, &_tmp51_, &_tmp52_);
				coordinate_x = _tmp51_;
				coordinate_y = _tmp52_;
			} else {
				bird_font_grid_tool_tie_coordinate (&coordinate_x, &coordinate_y);
			}
			delta_coordinate_x = coordinate_x - bird_font_pen_tool_last_point_x;
			delta_coordinate_y = coordinate_y - bird_font_pen_tool_last_point_y;
			{
				GeeArrayList* _selected_list = NULL;
				GeeArrayList* _tmp53_;
				gint _selected_size = 0;
				GeeArrayList* _tmp54_;
				gint _tmp55_;
				gint _tmp56_;
				gint _selected_index = 0;
				_tmp53_ = bird_font_pen_tool_selected_points;
				_selected_list = _tmp53_;
				_tmp54_ = _selected_list;
				_tmp55_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp54_);
				_tmp56_ = _tmp55_;
				_selected_size = _tmp56_;
				_selected_index = -1;
				while (TRUE) {
					gint _tmp57_;
					gint _tmp58_;
					BirdFontPointSelection* selected = NULL;
					GeeArrayList* _tmp59_;
					gpointer _tmp60_;
					gboolean _tmp61_ = FALSE;
					BirdFontPointSelection* _tmp74_;
					BirdFontPath* _tmp75_;
					BirdFontPointSelection* _tmp76_;
					BirdFontPath* _tmp77_;
					BirdFontPointSelection* _tmp78_;
					BirdFontEditPoint* _tmp79_;
					BirdFontPointSelection* _tmp80_;
					BirdFontPath* _tmp81_;
					_selected_index = _selected_index + 1;
					_tmp57_ = _selected_index;
					_tmp58_ = _selected_size;
					if (!(_tmp57_ < _tmp58_)) {
						break;
					}
					_tmp59_ = _selected_list;
					_tmp60_ = gee_abstract_list_get ((GeeAbstractList*) _tmp59_, _selected_index);
					selected = (BirdFontPointSelection*) _tmp60_;
					if (bird_font_pen_tool_move_point_independent_of_handle) {
						_tmp61_ = TRUE;
					} else {
						_tmp61_ = bird_font_key_bindings_modifier == BIRD_FONT_SHIFT;
					}
					if (_tmp61_) {
						BirdFontPointSelection* _tmp62_;
						BirdFontEditPoint* _tmp63_;
						BirdFontPointSelection* _tmp64_;
						BirdFontEditPoint* _tmp65_;
						BirdFontPointSelection* _tmp66_;
						BirdFontEditPoint* _tmp67_;
						_tmp62_ = selected;
						_tmp63_ = _tmp62_->point;
						_tmp64_ = selected;
						_tmp65_ = _tmp64_->point;
						_tmp66_ = selected;
						_tmp67_ = _tmp66_->point;
						bird_font_edit_point_set_independet_position (_tmp63_, _tmp65_->x + delta_coordinate_x, _tmp67_->y + delta_coordinate_y);
					} else {
						BirdFontPointSelection* _tmp68_;
						BirdFontEditPoint* _tmp69_;
						BirdFontPointSelection* _tmp70_;
						BirdFontEditPoint* _tmp71_;
						BirdFontPointSelection* _tmp72_;
						BirdFontEditPoint* _tmp73_;
						_tmp68_ = selected;
						_tmp69_ = _tmp68_->point;
						_tmp70_ = selected;
						_tmp71_ = _tmp70_->point;
						_tmp72_ = selected;
						_tmp73_ = _tmp72_->point;
						bird_font_edit_point_set_position (_tmp69_, _tmp71_->x + delta_coordinate_x, _tmp73_->y + delta_coordinate_y);
					}
					_tmp74_ = selected;
					_tmp75_ = _tmp74_->path;
					bird_font_path_reset_stroke (_tmp75_);
					_tmp76_ = selected;
					_tmp77_ = _tmp76_->path;
					_tmp78_ = selected;
					_tmp79_ = _tmp78_->point;
					bird_font_path_recalculate_linear_handles_for_point (_tmp77_, _tmp79_);
					_tmp80_ = selected;
					_tmp81_ = _tmp80_->path;
					bird_font_path_update_region_boundaries (_tmp81_);
					_g_object_unref0 (selected);
				}
			}
		} else {
			if (bird_font_grid_tool_has_ttf_grid ()) {
				gboolean _tmp82_ = FALSE;
				BirdFontEditPoint* _tmp83_;
				gboolean _tmp84_;
				gboolean _tmp85_;
				coordinate_x = bird_font_glyph_path_coordinate_x ((gdouble) x);
				coordinate_y = bird_font_glyph_path_coordinate_y ((gdouble) y);
				bird_font_grid_tool_ttf_grid_coordinate (&coordinate_x, &coordinate_y);
				_tmp83_ = bird_font_pen_tool_selected_point;
				_tmp84_ = bird_font_edit_point_get_tie_handles (_tmp83_);
				_tmp85_ = _tmp84_;
				if (_tmp85_) {
					_tmp82_ = bird_font_key_bindings_modifier == BIRD_FONT_SHIFT;
				} else {
					_tmp82_ = FALSE;
				}
				if (_tmp82_) {
					gdouble _tmp88_ = 0.0;
					gdouble _tmp89_ = 0.0;
					if (self->priv->first_move_action) {
						BirdFontEditPoint* _tmp86_;
						BirdFontEditPoint* _tmp87_;
						_tmp86_ = bird_font_pen_tool_selected_point;
						bird_font_pen_tool_last_point_x = _tmp86_->x;
						_tmp87_ = bird_font_pen_tool_selected_point;
						bird_font_pen_tool_last_point_y = _tmp87_->y;
					}
					bird_font_pen_tool_move_point_on_handles (self, coordinate_x, coordinate_y, &_tmp88_, &_tmp89_);
					coordinate_x = _tmp88_;
					coordinate_y = _tmp89_;
				}
				delta_coordinate_x = coordinate_x - bird_font_pen_tool_last_point_x;
				delta_coordinate_y = coordinate_y - bird_font_pen_tool_last_point_y;
				{
					GeeArrayList* _selected_list = NULL;
					GeeArrayList* _tmp90_;
					gint _selected_size = 0;
					GeeArrayList* _tmp91_;
					gint _tmp92_;
					gint _tmp93_;
					gint _selected_index = 0;
					_tmp90_ = bird_font_pen_tool_selected_points;
					_selected_list = _tmp90_;
					_tmp91_ = _selected_list;
					_tmp92_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp91_);
					_tmp93_ = _tmp92_;
					_selected_size = _tmp93_;
					_selected_index = -1;
					while (TRUE) {
						gint _tmp94_;
						gint _tmp95_;
						BirdFontPointSelection* selected = NULL;
						GeeArrayList* _tmp96_;
						gpointer _tmp97_;
						gboolean _tmp98_ = FALSE;
						BirdFontPointSelection* _tmp119_;
						BirdFontPath* _tmp120_;
						BirdFontPointSelection* _tmp121_;
						BirdFontPath* _tmp122_;
						BirdFontPointSelection* _tmp123_;
						BirdFontEditPoint* _tmp124_;
						BirdFontPointSelection* _tmp125_;
						BirdFontPath* _tmp126_;
						_selected_index = _selected_index + 1;
						_tmp94_ = _selected_index;
						_tmp95_ = _selected_size;
						if (!(_tmp94_ < _tmp95_)) {
							break;
						}
						_tmp96_ = _selected_list;
						_tmp97_ = gee_abstract_list_get ((GeeAbstractList*) _tmp96_, _selected_index);
						selected = (BirdFontPointSelection*) _tmp97_;
						if (bird_font_pen_tool_move_point_independent_of_handle) {
							_tmp98_ = TRUE;
						} else {
							_tmp98_ = bird_font_key_bindings_modifier == BIRD_FONT_SHIFT;
						}
						if (_tmp98_) {
							BirdFontPointSelection* _tmp99_;
							BirdFontEditPoint* _tmp100_;
							gboolean _tmp101_;
							gboolean _tmp102_;
							BirdFontPointSelection* _tmp103_;
							BirdFontEditPoint* _tmp104_;
							BirdFontPointSelection* _tmp105_;
							BirdFontEditPoint* _tmp106_;
							BirdFontPointSelection* _tmp107_;
							BirdFontEditPoint* _tmp108_;
							BirdFontPointSelection* _tmp109_;
							BirdFontEditPoint* _tmp110_;
							BirdFontPointSelection* _tmp111_;
							BirdFontEditPoint* _tmp112_;
							_tmp99_ = selected;
							_tmp100_ = _tmp99_->point;
							_tmp101_ = bird_font_edit_point_get_tie_handles (_tmp100_);
							_tmp102_ = _tmp101_;
							tied = _tmp102_;
							_tmp103_ = selected;
							_tmp104_ = _tmp103_->point;
							bird_font_edit_point_set_tie_handles (_tmp104_, FALSE);
							_tmp105_ = selected;
							_tmp106_ = _tmp105_->point;
							_tmp107_ = selected;
							_tmp108_ = _tmp107_->point;
							_tmp109_ = selected;
							_tmp110_ = _tmp109_->point;
							bird_font_edit_point_set_independet_position (_tmp106_, _tmp108_->x + delta_coordinate_x, _tmp110_->y + delta_coordinate_y);
							_tmp111_ = selected;
							_tmp112_ = _tmp111_->point;
							bird_font_edit_point_set_tie_handles (_tmp112_, tied);
						} else {
							BirdFontPointSelection* _tmp113_;
							BirdFontEditPoint* _tmp114_;
							BirdFontPointSelection* _tmp115_;
							BirdFontEditPoint* _tmp116_;
							BirdFontPointSelection* _tmp117_;
							BirdFontEditPoint* _tmp118_;
							_tmp113_ = selected;
							_tmp114_ = _tmp113_->point;
							_tmp115_ = selected;
							_tmp116_ = _tmp115_->point;
							_tmp117_ = selected;
							_tmp118_ = _tmp117_->point;
							bird_font_edit_point_set_position (_tmp114_, _tmp116_->x + delta_coordinate_x, _tmp118_->y + delta_coordinate_y);
						}
						_tmp119_ = selected;
						_tmp120_ = _tmp119_->path;
						bird_font_path_reset_stroke (_tmp120_);
						_tmp121_ = selected;
						_tmp122_ = _tmp121_->path;
						_tmp123_ = selected;
						_tmp124_ = _tmp123_->point;
						bird_font_path_recalculate_linear_handles_for_point (_tmp122_, _tmp124_);
						_tmp125_ = selected;
						_tmp126_ = _tmp125_->path;
						bird_font_path_update_region_boundaries (_tmp126_);
						_g_object_unref0 (selected);
					}
				}
			} else {
				gboolean _tmp127_ = FALSE;
				BirdFontEditPoint* _tmp128_;
				gboolean _tmp129_;
				gboolean _tmp130_;
				coordinate_x = bird_font_glyph_path_coordinate_x ((gdouble) x);
				coordinate_y = bird_font_glyph_path_coordinate_y ((gdouble) y);
				_tmp128_ = bird_font_pen_tool_selected_point;
				_tmp129_ = bird_font_edit_point_get_tie_handles (_tmp128_);
				_tmp130_ = _tmp129_;
				if (_tmp130_) {
					_tmp127_ = bird_font_key_bindings_modifier == BIRD_FONT_SHIFT;
				} else {
					_tmp127_ = FALSE;
				}
				if (_tmp127_) {
					gdouble _tmp133_ = 0.0;
					gdouble _tmp134_ = 0.0;
					if (self->priv->first_move_action) {
						BirdFontEditPoint* _tmp131_;
						BirdFontEditPoint* _tmp132_;
						_tmp131_ = bird_font_pen_tool_selected_point;
						bird_font_pen_tool_last_point_x = _tmp131_->x;
						_tmp132_ = bird_font_pen_tool_selected_point;
						bird_font_pen_tool_last_point_y = _tmp132_->y;
					}
					bird_font_pen_tool_move_point_on_handles (self, coordinate_x, coordinate_y, &_tmp133_, &_tmp134_);
					coordinate_x = _tmp133_;
					coordinate_y = _tmp134_;
					delta_coordinate_x = coordinate_x - bird_font_pen_tool_last_point_x;
					delta_coordinate_y = coordinate_y - bird_font_pen_tool_last_point_y;
				} else {
					delta_coordinate_x = coordinate_x - bird_font_pen_tool_last_point_x;
					delta_coordinate_y = coordinate_y - bird_font_pen_tool_last_point_y;
				}
				{
					GeeArrayList* _selected_list = NULL;
					GeeArrayList* _tmp135_;
					gint _selected_size = 0;
					GeeArrayList* _tmp136_;
					gint _tmp137_;
					gint _tmp138_;
					gint _selected_index = 0;
					_tmp135_ = bird_font_pen_tool_selected_points;
					_selected_list = _tmp135_;
					_tmp136_ = _selected_list;
					_tmp137_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp136_);
					_tmp138_ = _tmp137_;
					_selected_size = _tmp138_;
					_selected_index = -1;
					while (TRUE) {
						gint _tmp139_;
						gint _tmp140_;
						BirdFontPointSelection* selected = NULL;
						GeeArrayList* _tmp141_;
						gpointer _tmp142_;
						gboolean _tmp143_ = FALSE;
						BirdFontPointSelection* _tmp156_;
						BirdFontPath* _tmp157_;
						BirdFontPointSelection* _tmp158_;
						BirdFontEditPoint* _tmp159_;
						BirdFontPointSelection* _tmp160_;
						BirdFontPath* _tmp161_;
						BirdFontPointSelection* _tmp162_;
						BirdFontPath* _tmp163_;
						_selected_index = _selected_index + 1;
						_tmp139_ = _selected_index;
						_tmp140_ = _selected_size;
						if (!(_tmp139_ < _tmp140_)) {
							break;
						}
						_tmp141_ = _selected_list;
						_tmp142_ = gee_abstract_list_get ((GeeAbstractList*) _tmp141_, _selected_index);
						selected = (BirdFontPointSelection*) _tmp142_;
						if (bird_font_pen_tool_move_point_independent_of_handle) {
							_tmp143_ = TRUE;
						} else {
							_tmp143_ = bird_font_key_bindings_modifier == BIRD_FONT_SHIFT;
						}
						if (_tmp143_) {
							BirdFontPointSelection* _tmp144_;
							BirdFontEditPoint* _tmp145_;
							BirdFontPointSelection* _tmp146_;
							BirdFontEditPoint* _tmp147_;
							BirdFontPointSelection* _tmp148_;
							BirdFontEditPoint* _tmp149_;
							_tmp144_ = selected;
							_tmp145_ = _tmp144_->point;
							_tmp146_ = selected;
							_tmp147_ = _tmp146_->point;
							_tmp148_ = selected;
							_tmp149_ = _tmp148_->point;
							bird_font_edit_point_set_independet_position (_tmp145_, _tmp147_->x + delta_coordinate_x, _tmp149_->y + delta_coordinate_y);
						} else {
							BirdFontPointSelection* _tmp150_;
							BirdFontEditPoint* _tmp151_;
							BirdFontPointSelection* _tmp152_;
							BirdFontEditPoint* _tmp153_;
							BirdFontPointSelection* _tmp154_;
							BirdFontEditPoint* _tmp155_;
							_tmp150_ = selected;
							_tmp151_ = _tmp150_->point;
							_tmp152_ = selected;
							_tmp153_ = _tmp152_->point;
							_tmp154_ = selected;
							_tmp155_ = _tmp154_->point;
							bird_font_edit_point_set_position (_tmp151_, _tmp153_->x + delta_coordinate_x, _tmp155_->y + delta_coordinate_y);
						}
						_tmp156_ = selected;
						_tmp157_ = _tmp156_->path;
						_tmp158_ = selected;
						_tmp159_ = _tmp158_->point;
						bird_font_path_recalculate_linear_handles_for_point (_tmp157_, _tmp159_);
						_tmp160_ = selected;
						_tmp161_ = _tmp160_->path;
						bird_font_path_reset_stroke (_tmp161_);
						_tmp162_ = selected;
						_tmp163_ = _tmp162_->path;
						bird_font_path_update_region_boundaries (_tmp163_);
						_g_object_unref0 (selected);
					}
				}
			}
		}
		_tmp165_ = bird_font_pen_tool_selected_point;
		_tmp166_ = bird_font_edit_point_get_tie_handles (_tmp165_);
		_tmp167_ = _tmp166_;
		if (_tmp167_) {
			_tmp164_ = bird_font_key_bindings_modifier == BIRD_FONT_SHIFT;
		} else {
			_tmp164_ = FALSE;
		}
		if (_tmp164_) {
			BirdFontEditPoint* _tmp168_;
			BirdFontEditPoint* _tmp169_;
			_tmp168_ = bird_font_pen_tool_selected_point;
			bird_font_pen_tool_last_point_x = _tmp168_->x;
			_tmp169_ = bird_font_pen_tool_selected_point;
			bird_font_pen_tool_last_point_y = _tmp169_->y;
		} else {
			if (bird_font_grid_tool_is_visible ()) {
				BirdFontEditPoint* _tmp170_;
				BirdFontEditPoint* _tmp171_;
				_tmp170_ = bird_font_pen_tool_selected_point;
				bird_font_pen_tool_last_point_x = _tmp170_->x;
				_tmp171_ = bird_font_pen_tool_selected_point;
				bird_font_pen_tool_last_point_y = _tmp171_->y;
			} else {
				if (bird_font_grid_tool_has_ttf_grid ()) {
					BirdFontEditPoint* _tmp172_;
					BirdFontEditPoint* _tmp173_;
					_tmp172_ = bird_font_pen_tool_selected_point;
					bird_font_pen_tool_last_point_x = _tmp172_->x;
					_tmp173_ = bird_font_pen_tool_selected_point;
					bird_font_pen_tool_last_point_y = _tmp173_->y;
				} else {
					bird_font_pen_tool_last_point_x = bird_font_glyph_path_coordinate_x ((gdouble) x);
					bird_font_pen_tool_last_point_y = bird_font_glyph_path_coordinate_y ((gdouble) y);
				}
			}
		}
		bird_font_glyph_canvas_redraw ();
	}
	if (bird_font_pen_tool_show_selection_box) {
		bird_font_glyph_canvas_redraw ();
	}
	_g_object_unref0 (g);
}

static void
bird_font_pen_tool_cancel_stroke_creator (void)
{
	{
		GeeArrayList* _p_list = NULL;
		GeeArrayList* _tmp0_;
		gint _p_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _p_index = 0;
		_tmp0_ = bird_font_pen_tool_selected_points;
		_p_list = _tmp0_;
		_tmp1_ = _p_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_p_size = _tmp3_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			BirdFontPointSelection* p = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			BirdFontPointSelection* _tmp8_;
			BirdFontPath* _tmp9_;
			_p_index = _p_index + 1;
			_tmp4_ = _p_index;
			_tmp5_ = _p_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _p_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _p_index);
			p = (BirdFontPointSelection*) _tmp7_;
			_tmp8_ = p;
			_tmp9_ = _tmp8_->path;
			bird_font_path_stop_stroke_creator (_tmp9_);
			_g_object_unref0 (p);
		}
	}
}

static void
bird_font_pen_tool_move_point_on_handles (BirdFontPenTool* self,
                                          gdouble px,
                                          gdouble py,
                                          gdouble* cx,
                                          gdouble* cy)
{
	gdouble _vala_cx = 0.0;
	gdouble _vala_cy = 0.0;
	BirdFontEditPoint* ep = NULL;
	BirdFontEditPoint* _tmp0_;
	BirdFontEditPoint* _tmp1_;
	BirdFontEditPointHandle* _tmp2_;
	BirdFontEditPointHandle* _tmp3_;
	BirdFontEditPointHandle* _tmp4_;
	BirdFontEditPoint* _tmp5_;
	BirdFontEditPointHandle* _tmp6_;
	gdouble _tmp7_ = 0.0;
	gdouble _tmp8_ = 0.0;
	g_return_if_fail (self != NULL);
	_tmp0_ = bird_font_pen_tool_selected_point;
	_tmp1_ = bird_font_edit_point_copy (_tmp0_);
	_g_object_unref0 (ep);
	ep = _tmp1_;
	bird_font_edit_point_set_tie_handles (ep, FALSE);
	bird_font_edit_point_set_reflective_point (ep, FALSE);
	_tmp2_ = bird_font_edit_point_get_right_handle (ep);
	_tmp3_ = bird_font_edit_point_get_right_handle (ep);
	_tmp3_->angle = _tmp3_->angle + (G_PI / 2);
	ep->x = px;
	ep->y = py;
	_tmp4_ = bird_font_edit_point_get_right_handle (ep);
	_tmp5_ = bird_font_pen_tool_selected_point;
	_tmp6_ = bird_font_edit_point_get_right_handle (_tmp5_);
	bird_font_path_find_intersection_handle (_tmp4_, _tmp6_, &_tmp7_, &_tmp8_);
	_vala_cx = _tmp7_;
	_vala_cy = _tmp8_;
	_g_object_unref0 (ep);
	if (cx) {
		*cx = _vala_cx;
	}
	if (cy) {
		*cy = _vala_cy;
	}
}

void
bird_font_pen_tool_press (BirdFontPenTool* self,
                          gint button,
                          gint x,
                          gint y,
                          gboolean double_click)
{
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	BirdFontGlyph* glyph = NULL;
	BirdFontGlyph* _tmp1_;
	BirdFontGlyph* _tmp2_;
	gboolean reflective = FALSE;
	BirdFontGlyph* _tmp3_;
	gboolean _tmp4_ = FALSE;
	gboolean _tmp5_ = FALSE;
	gboolean _tmp12_ = FALSE;
	gboolean _tmp54_ = FALSE;
	g_return_if_fail (self != NULL);
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	_tmp1_ = g;
	_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, BIRD_FONT_TYPE_GLYPH, BirdFontGlyph));
	glyph = _tmp2_;
	_tmp3_ = g;
	g_return_if_fail (_tmp3_ != NULL);
	if (double_click) {
		_tmp5_ = !bird_font_bird_font_android;
	} else {
		_tmp5_ = FALSE;
	}
	if (_tmp5_) {
		_tmp4_ = TRUE;
	} else {
		BirdFontDrawingTools* _tmp6_;
		BirdFontTool* _tmp7_;
		_tmp6_ = bird_font_toolbox_drawing_tools;
		_tmp7_ = _tmp6_->insert_point_on_path_tool;
		_tmp4_ = bird_font_tool_is_selected (_tmp7_);
	}
	if (_tmp4_) {
		BirdFontGlyph* _tmp8_;
		_tmp8_ = glyph;
		bird_font_glyph_insert_new_point_on_path (_tmp8_, (gdouble) x, (gdouble) y);
		_g_object_unref0 (glyph);
		_g_object_unref0 (g);
		return;
	}
	if (button == 1) {
		bird_font_pen_tool_add_point_event (self, x, y);
		_g_object_unref0 (glyph);
		_g_object_unref0 (g);
		return;
	}
	if (button == 2) {
		BirdFontGlyph* _tmp9_;
		_tmp9_ = glyph;
		if (bird_font_glyph_is_open (_tmp9_)) {
			BirdFontGlyph* _tmp10_;
			bird_font_pen_tool_force_direction ();
			_tmp10_ = glyph;
			bird_font_glyph_close_path (_tmp10_);
		} else {
			BirdFontGlyph* _tmp11_;
			_tmp11_ = glyph;
			bird_font_glyph_open_path (_tmp11_);
		}
		_g_object_unref0 (glyph);
		_g_object_unref0 (g);
		return;
	}
	if (button == 3) {
		_tmp12_ = !bird_font_key_bindings_has_shift ();
	} else {
		_tmp12_ = FALSE;
	}
	if (_tmp12_) {
		BirdFontGlyph* _tmp13_;
		BirdFontPath* _tmp14_;
		BirdFontPath* _tmp15_;
		gboolean _tmp16_ = FALSE;
		gboolean _tmp17_ = FALSE;
		_tmp13_ = glyph;
		bird_font_glyph_clear_active_paths (_tmp13_);
		_tmp14_ = bird_font_pen_tool_active_path;
		_tmp15_ = _g_object_ref0 (_tmp14_);
		_g_object_unref0 (bird_font_pen_tool_selected_path);
		bird_font_pen_tool_selected_path = _tmp15_;
		bird_font_pen_tool_move_point_event (self, x, y);
		if (bird_font_key_bindings_has_alt ()) {
			_tmp17_ = TRUE;
		} else {
			_tmp17_ = bird_font_key_bindings_has_ctrl ();
		}
		if (_tmp17_) {
			_tmp16_ = bird_font_pen_tool_is_over_handle (self, (gdouble) x, (gdouble) y);
		} else {
			_tmp16_ = FALSE;
		}
		if (_tmp16_) {
			reflective = TRUE;
			{
				GeeArrayList* _path_list = NULL;
				BirdFontGlyph* _tmp18_;
				BirdFontGlyph* _tmp19_;
				GeeArrayList* _tmp20_;
				GeeArrayList* _tmp21_;
				gint _path_size = 0;
				GeeArrayList* _tmp22_;
				gint _tmp23_;
				gint _tmp24_;
				gint _path_index = 0;
				_tmp18_ = bird_font_main_window_get_current_glyph ();
				_tmp19_ = _tmp18_;
				_tmp20_ = _tmp19_->active_paths;
				_tmp21_ = _tmp20_;
				_g_object_unref0 (_tmp19_);
				_path_list = _tmp21_;
				_tmp22_ = _path_list;
				_tmp23_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp22_);
				_tmp24_ = _tmp23_;
				_path_size = _tmp24_;
				_path_index = -1;
				while (TRUE) {
					gint _tmp25_;
					gint _tmp26_;
					BirdFontPath* path = NULL;
					GeeArrayList* _tmp27_;
					gpointer _tmp28_;
					gboolean _tmp29_ = FALSE;
					BirdFontPath* _tmp30_;
					_path_index = _path_index + 1;
					_tmp25_ = _path_index;
					_tmp26_ = _path_size;
					if (!(_tmp25_ < _tmp26_)) {
						break;
					}
					_tmp27_ = _path_list;
					_tmp28_ = gee_abstract_list_get ((GeeAbstractList*) _tmp27_, _path_index);
					path = (BirdFontPath*) _tmp28_;
					_tmp30_ = path;
					if (bird_font_path_is_open (_tmp30_)) {
						BirdFontPath* _tmp31_;
						GeeArrayList* _tmp32_;
						GeeArrayList* _tmp33_;
						gint _tmp34_;
						gint _tmp35_;
						_tmp31_ = path;
						_tmp32_ = bird_font_path_get_points (_tmp31_);
						_tmp33_ = _tmp32_;
						_tmp34_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp33_);
						_tmp35_ = _tmp34_;
						_tmp29_ = _tmp35_ > 0;
					} else {
						_tmp29_ = FALSE;
					}
					if (_tmp29_) {
						gboolean _tmp36_ = FALSE;
						BirdFontEditPointHandle* _tmp37_;
						BirdFontEditPoint* _tmp38_;
						BirdFontPath* _tmp39_;
						BirdFontEditPoint* _tmp40_;
						BirdFontEditPoint* _tmp41_;
						gboolean _tmp42_;
						_tmp37_ = bird_font_pen_tool_selected_handle;
						_tmp38_ = _tmp37_->parent;
						_tmp39_ = path;
						_tmp40_ = bird_font_path_get_first_point (_tmp39_);
						_tmp41_ = _tmp40_;
						_tmp42_ = _tmp38_ == _tmp41_;
						_g_object_unref0 (_tmp41_);
						if (_tmp42_) {
							_tmp36_ = TRUE;
						} else {
							BirdFontEditPointHandle* _tmp43_;
							BirdFontEditPoint* _tmp44_;
							BirdFontPath* _tmp45_;
							BirdFontEditPoint* _tmp46_;
							BirdFontEditPoint* _tmp47_;
							_tmp43_ = bird_font_pen_tool_selected_handle;
							_tmp44_ = _tmp43_->parent;
							_tmp45_ = path;
							_tmp46_ = bird_font_path_get_last_point (_tmp45_);
							_tmp47_ = _tmp46_;
							_tmp36_ = _tmp44_ == _tmp47_;
							_g_object_unref0 (_tmp47_);
						}
						if (_tmp36_) {
							reflective = FALSE;
						}
					}
					_g_object_unref0 (path);
				}
			}
			if (reflective) {
				BirdFontEditPointHandle* _tmp48_;
				BirdFontEditPoint* _tmp49_;
				BirdFontEditPointHandle* _tmp50_;
				BirdFontEditPoint* _tmp51_;
				_tmp48_ = bird_font_pen_tool_selected_handle;
				_tmp49_ = _tmp48_->parent;
				bird_font_edit_point_set_reflective_handles (_tmp49_, FALSE);
				_tmp50_ = bird_font_pen_tool_selected_handle;
				_tmp51_ = _tmp50_->parent;
				bird_font_edit_point_set_tie_handle (_tmp51_, FALSE);
				bird_font_glyph_canvas_redraw ();
			}
		}
		_g_object_unref0 (glyph);
		_g_object_unref0 (g);
		return;
	}
	if (button == 3) {
		BirdFontPath* _tmp52_;
		BirdFontPath* _tmp53_;
		_tmp52_ = bird_font_pen_tool_active_path;
		_tmp53_ = _g_object_ref0 (_tmp52_);
		_g_object_unref0 (bird_font_pen_tool_selected_path);
		bird_font_pen_tool_selected_path = _tmp53_;
		bird_font_pen_tool_move_point_event (self, x, y);
	}
	if (bird_font_key_bindings_has_shift ()) {
		_tmp54_ = !bird_font_pen_tool_is_over_handle (self, (gdouble) x, (gdouble) y);
	} else {
		_tmp54_ = FALSE;
	}
	if (_tmp54_) {
		bird_font_pen_tool_show_selection_box = TRUE;
		_g_object_unref0 (glyph);
		_g_object_unref0 (g);
		return;
	}
	_g_object_unref0 (glyph);
	_g_object_unref0 (g);
}

void
bird_font_pen_tool_add_point_event (BirdFontPenTool* self,
                                    gint x,
                                    gint y)
{
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	BirdFontGlyph* glyph = NULL;
	BirdFontGlyph* _tmp1_;
	BirdFontGlyph* _tmp2_;
	BirdFontPointSelection* ps = NULL;
	BirdFontGlyph* _tmp3_;
	BirdFontPointSelection* _tmp4_;
	BirdFontPointSelection* _tmp5_;
	BirdFontPath* _tmp6_;
	BirdFontPath* _tmp7_;
	BirdFontGlyph* _tmp8_;
	g_return_if_fail (self != NULL);
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	_tmp1_ = g;
	_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, BIRD_FONT_TYPE_GLYPH, BirdFontGlyph));
	glyph = _tmp2_;
	if (bird_font_pen_tool_move_selected_handle) {
		g_warning ("PenTool.vala:1091: moving handle");
		_g_object_unref0 (ps);
		_g_object_unref0 (glyph);
		_g_object_unref0 (g);
		return;
	}
	_tmp3_ = g;
	g_return_if_fail (_tmp3_ != NULL);
	bird_font_pen_tool_remove_all_selected_points ();
	_tmp4_ = bird_font_pen_tool_new_point_action (self, x, y);
	_g_object_unref0 (ps);
	ps = _tmp4_;
	_tmp5_ = ps;
	_tmp6_ = _tmp5_->path;
	_tmp7_ = _g_object_ref0 (_tmp6_);
	_g_object_unref0 (bird_font_pen_tool_active_path);
	bird_font_pen_tool_active_path = _tmp7_;
	_tmp8_ = glyph;
	bird_font_glyph_store_undo_state (_tmp8_, FALSE);
	_g_object_unref0 (ps);
	_g_object_unref0 (glyph);
	_g_object_unref0 (g);
}

void
bird_font_pen_tool_move_point_event (BirdFontPenTool* self,
                                     gint x,
                                     gint y)
{
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	BirdFontGlyph* glyph = NULL;
	BirdFontGlyph* _tmp1_;
	BirdFontGlyph* _tmp2_;
	BirdFontGlyph* _tmp3_;
	gboolean _tmp4_ = FALSE;
	gboolean _tmp5_ = FALSE;
	BirdFontGlyph* _tmp10_;
	g_return_if_fail (self != NULL);
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	_tmp1_ = g;
	_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, BIRD_FONT_TYPE_GLYPH, BirdFontGlyph));
	glyph = _tmp2_;
	_tmp3_ = g;
	g_return_if_fail (_tmp3_ != NULL);
	bird_font_pen_tool_control_point_event (self, (gdouble) x, (gdouble) y, TRUE);
	bird_font_pen_tool_curve_corner_event (self, (gdouble) x, (gdouble) y);
	if (!bird_font_pen_tool_move_selected_handle) {
		bird_font_pen_tool_select_active_point (self, (gdouble) x, (gdouble) y);
		self->priv->last_selected_is_handle = FALSE;
	}
	if (!bird_font_key_bindings_has_shift ()) {
		GeeArrayList* _tmp6_;
		gint _tmp7_;
		gint _tmp8_;
		_tmp6_ = bird_font_pen_tool_selected_points;
		_tmp7_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp6_);
		_tmp8_ = _tmp7_;
		_tmp5_ = _tmp8_ == 0;
	} else {
		_tmp5_ = FALSE;
	}
	if (_tmp5_) {
		BirdFontEditPointHandle* _tmp9_;
		_tmp9_ = bird_font_pen_tool_active_handle;
		_tmp4_ = !_tmp9_->active;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		bird_font_pen_tool_show_selection_box = TRUE;
	}
	_tmp10_ = glyph;
	bird_font_glyph_store_undo_state (_tmp10_, FALSE);
	_g_object_unref0 (glyph);
	_g_object_unref0 (g);
}

static void
bird_font_pen_tool_set_type_for_moving_handle (BirdFontPenTool* self)
{
	BirdFontEditPointHandle* _tmp0_;
	BirdFontEditPointHandle* _tmp2_;
	BirdFontEditPointHandle* _tmp4_;
	g_return_if_fail (self != NULL);
	_tmp0_ = bird_font_pen_tool_selected_handle;
	if (_tmp0_->type == BIRD_FONT_POINT_TYPE_LINE_CUBIC) {
		BirdFontEditPointHandle* _tmp1_;
		_tmp1_ = bird_font_pen_tool_selected_handle;
		bird_font_edit_point_handle_set_point_type (_tmp1_, BIRD_FONT_POINT_TYPE_CUBIC);
	}
	_tmp2_ = bird_font_pen_tool_selected_handle;
	if (_tmp2_->type == BIRD_FONT_POINT_TYPE_LINE_QUADRATIC) {
		BirdFontEditPointHandle* _tmp3_;
		_tmp3_ = bird_font_pen_tool_selected_handle;
		bird_font_edit_point_handle_set_point_type (_tmp3_, BIRD_FONT_POINT_TYPE_QUADRATIC);
	}
	_tmp4_ = bird_font_pen_tool_selected_handle;
	if (_tmp4_->type == BIRD_FONT_POINT_TYPE_LINE_DOUBLE_CURVE) {
		BirdFontEditPointHandle* _tmp5_;
		_tmp5_ = bird_font_pen_tool_selected_handle;
		bird_font_edit_point_handle_set_point_type (_tmp5_, BIRD_FONT_POINT_TYPE_DOUBLE_CURVE);
	}
}

/** Set fill property to transparend for counter paths. */
void
bird_font_pen_tool_force_direction (void)
{
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	bird_font_pen_tool_clear_directions ();
	{
		GeeArrayList* _p_list = NULL;
		BirdFontGlyph* _tmp1_;
		GeeArrayList* _tmp2_;
		gint _p_size = 0;
		GeeArrayList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		gint _p_index = 0;
		_tmp1_ = g;
		_tmp2_ = bird_font_glyph_get_visible_paths (_tmp1_);
		_p_list = _tmp2_;
		_tmp3_ = _p_list;
		_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
		_tmp5_ = _tmp4_;
		_p_size = _tmp5_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp6_;
			gint _tmp7_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp8_;
			gpointer _tmp9_;
			BirdFontPath* _tmp10_;
			_p_index = _p_index + 1;
			_tmp6_ = _p_index;
			_tmp7_ = _p_size;
			if (!(_tmp6_ < _tmp7_)) {
				break;
			}
			_tmp8_ = _p_list;
			_tmp9_ = gee_abstract_list_get ((GeeAbstractList*) _tmp8_, _p_index);
			p = (BirdFontPath*) _tmp9_;
			_tmp10_ = p;
			if (!bird_font_path_has_direction (_tmp10_)) {
				BirdFontPath* _tmp11_;
				_tmp11_ = p;
				if (bird_font_pen_tool_is_counter_path (_tmp11_)) {
					BirdFontPath* _tmp12_;
					_tmp12_ = p;
					bird_font_path_force_direction (_tmp12_, BIRD_FONT_DIRECTION_COUNTER_CLOCKWISE);
				} else {
					BirdFontPath* _tmp13_;
					_tmp13_ = p;
					bird_font_path_force_direction (_tmp13_, BIRD_FONT_DIRECTION_CLOCKWISE);
				}
			}
			_g_object_unref0 (p);
		}
		_g_object_unref0 (_p_list);
	}
	bird_font_pen_tool_update_selected_points ();
	_g_object_unref0 (g);
}

void
bird_font_pen_tool_clear_directions (void)
{
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp1_;
	_tmp0_ = bird_font_pen_tool_clockwise;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp0_);
	_tmp1_ = bird_font_pen_tool_counter_clockwise;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp1_);
}

gboolean
bird_font_pen_tool_is_counter_path (BirdFontPath* path)
{
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	BirdFontPathList* pl = NULL;
	BirdFontPathList* _tmp1_;
	BirdFontPathList* _tmp13_;
	gboolean result;
	g_return_val_if_fail (path != NULL, FALSE);
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	_tmp1_ = bird_font_path_list_new ();
	pl = _tmp1_;
	{
		GeeArrayList* _p_list = NULL;
		BirdFontGlyph* _tmp2_;
		GeeArrayList* _tmp3_;
		gint _p_size = 0;
		GeeArrayList* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		gint _p_index = 0;
		_tmp2_ = g;
		_tmp3_ = bird_font_glyph_get_visible_paths (_tmp2_);
		_p_list = _tmp3_;
		_tmp4_ = _p_list;
		_tmp5_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp4_);
		_tmp6_ = _tmp5_;
		_p_size = _tmp6_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp7_;
			gint _tmp8_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp9_;
			gpointer _tmp10_;
			BirdFontPathList* _tmp11_;
			BirdFontPath* _tmp12_;
			_p_index = _p_index + 1;
			_tmp7_ = _p_index;
			_tmp8_ = _p_size;
			if (!(_tmp7_ < _tmp8_)) {
				break;
			}
			_tmp9_ = _p_list;
			_tmp10_ = gee_abstract_list_get ((GeeAbstractList*) _tmp9_, _p_index);
			p = (BirdFontPath*) _tmp10_;
			_tmp11_ = pl;
			_tmp12_ = p;
			bird_font_path_list_add (_tmp11_, _tmp12_);
			_g_object_unref0 (p);
		}
		_g_object_unref0 (_p_list);
	}
	_tmp13_ = pl;
	result = bird_font_path_is_counter (_tmp13_, path);
	_g_object_unref0 (pl);
	_g_object_unref0 (g);
	return result;
}

void
bird_font_pen_tool_remove_from_selected (BirdFontPenTool* self,
                                         BirdFontEditPoint* ep)
{
	GeeArrayList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	GeeArrayList* remove = NULL;
	GeeArrayList* _tmp3_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (ep != NULL);
	_tmp0_ = bird_font_pen_tool_selected_points;
	_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	_vala_return_if_fail (_tmp2_ > 0, "selected_points.size > 0");
	_tmp3_ = gee_array_list_new (BIRD_FONT_TYPE_POINT_SELECTION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	remove = _tmp3_;
	{
		GeeArrayList* _e_list = NULL;
		GeeArrayList* _tmp4_;
		gint _e_size = 0;
		GeeArrayList* _tmp5_;
		gint _tmp6_;
		gint _tmp7_;
		gint _e_index = 0;
		_tmp4_ = bird_font_pen_tool_selected_points;
		_e_list = _tmp4_;
		_tmp5_ = _e_list;
		_tmp6_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp5_);
		_tmp7_ = _tmp6_;
		_e_size = _tmp7_;
		_e_index = -1;
		while (TRUE) {
			gint _tmp8_;
			gint _tmp9_;
			BirdFontPointSelection* e = NULL;
			GeeArrayList* _tmp10_;
			gpointer _tmp11_;
			BirdFontPointSelection* _tmp12_;
			BirdFontEditPoint* _tmp13_;
			BirdFontPointSelection* _tmp14_;
			BirdFontEditPoint* _tmp15_;
			_e_index = _e_index + 1;
			_tmp8_ = _e_index;
			_tmp9_ = _e_size;
			if (!(_tmp8_ < _tmp9_)) {
				break;
			}
			_tmp10_ = _e_list;
			_tmp11_ = gee_abstract_list_get ((GeeAbstractList*) _tmp10_, _e_index);
			e = (BirdFontPointSelection*) _tmp11_;
			_tmp12_ = e;
			_tmp13_ = _tmp12_->point;
			_tmp14_ = e;
			_tmp15_ = _tmp14_->point;
			if (bird_font_edit_point_equals (_tmp13_, _tmp15_)) {
				GeeArrayList* _tmp16_;
				BirdFontPointSelection* _tmp17_;
				_tmp16_ = remove;
				_tmp17_ = e;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp16_, _tmp17_);
			}
			_g_object_unref0 (e);
		}
	}
	{
		GeeArrayList* _e_list = NULL;
		GeeArrayList* _tmp18_;
		gint _e_size = 0;
		GeeArrayList* _tmp19_;
		gint _tmp20_;
		gint _tmp21_;
		gint _e_index = 0;
		_tmp18_ = remove;
		_e_list = _tmp18_;
		_tmp19_ = _e_list;
		_tmp20_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp19_);
		_tmp21_ = _tmp20_;
		_e_size = _tmp21_;
		_e_index = -1;
		while (TRUE) {
			gint _tmp22_;
			gint _tmp23_;
			BirdFontPointSelection* e = NULL;
			GeeArrayList* _tmp24_;
			gpointer _tmp25_;
			GeeArrayList* _tmp26_;
			BirdFontPointSelection* _tmp27_;
			_e_index = _e_index + 1;
			_tmp22_ = _e_index;
			_tmp23_ = _e_size;
			if (!(_tmp22_ < _tmp23_)) {
				break;
			}
			_tmp24_ = _e_list;
			_tmp25_ = gee_abstract_list_get ((GeeAbstractList*) _tmp24_, _e_index);
			e = (BirdFontPointSelection*) _tmp25_;
			_tmp26_ = bird_font_pen_tool_selected_points;
			_tmp27_ = e;
			gee_abstract_collection_remove ((GeeAbstractCollection*) _tmp26_, _tmp27_);
			_g_object_unref0 (e);
		}
	}
	_g_object_unref0 (remove);
}

void
bird_font_pen_tool_select_active_point (BirdFontPenTool* self,
                                        gdouble x,
                                        gdouble y)
{
	BirdFontGlyph* glyph = NULL;
	BirdFontGlyph* _tmp0_;
	gboolean reverse = FALSE;
	gboolean _tmp61_ = FALSE;
	BirdFontEditPoint* _tmp62_;
	BirdFontEditPoint* _tmp63_;
	g_return_if_fail (self != NULL);
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	glyph = _tmp0_;
	bird_font_pen_tool_control_point_event (self, x, y, TRUE);
	reverse = FALSE;
	{
		GeeArrayList* _p_list = NULL;
		BirdFontGlyph* _tmp1_;
		GeeArrayList* _tmp2_;
		gint _p_size = 0;
		GeeArrayList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		gint _p_index = 0;
		_tmp1_ = glyph;
		_tmp2_ = bird_font_glyph_get_visible_paths (_tmp1_);
		_p_list = _tmp2_;
		_tmp3_ = _p_list;
		_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
		_tmp5_ = _tmp4_;
		_p_size = _tmp5_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp6_;
			gint _tmp7_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp8_;
			gpointer _tmp9_;
			gboolean _tmp10_ = FALSE;
			gboolean _tmp11_ = FALSE;
			BirdFontPath* _tmp12_;
			_p_index = _p_index + 1;
			_tmp6_ = _p_index;
			_tmp7_ = _p_size;
			if (!(_tmp6_ < _tmp7_)) {
				break;
			}
			_tmp8_ = _p_list;
			_tmp9_ = gee_abstract_list_get ((GeeAbstractList*) _tmp8_, _p_index);
			p = (BirdFontPath*) _tmp9_;
			_tmp12_ = p;
			if (bird_font_path_is_open (_tmp12_)) {
				BirdFontPath* _tmp13_;
				GeeArrayList* _tmp14_;
				GeeArrayList* _tmp15_;
				gint _tmp16_;
				gint _tmp17_;
				_tmp13_ = p;
				_tmp14_ = bird_font_path_get_points (_tmp13_);
				_tmp15_ = _tmp14_;
				_tmp16_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp15_);
				_tmp17_ = _tmp16_;
				_tmp11_ = _tmp17_ >= 1;
			} else {
				_tmp11_ = FALSE;
			}
			if (_tmp11_) {
				gboolean _tmp18_ = FALSE;
				BirdFontEditPoint* _tmp19_;
				BirdFontPath* _tmp20_;
				GeeArrayList* _tmp21_;
				GeeArrayList* _tmp22_;
				gpointer _tmp23_;
				BirdFontEditPoint* _tmp24_;
				gboolean _tmp25_;
				_tmp19_ = bird_font_pen_tool_active_edit_point;
				_tmp20_ = p;
				_tmp21_ = bird_font_path_get_points (_tmp20_);
				_tmp22_ = _tmp21_;
				_tmp23_ = gee_abstract_list_get ((GeeAbstractList*) _tmp22_, 0);
				_tmp24_ = (BirdFontEditPoint*) _tmp23_;
				_tmp25_ = _tmp19_ == _tmp24_;
				_g_object_unref0 (_tmp24_);
				if (_tmp25_) {
					_tmp18_ = TRUE;
				} else {
					BirdFontEditPoint* _tmp26_;
					BirdFontPath* _tmp27_;
					GeeArrayList* _tmp28_;
					GeeArrayList* _tmp29_;
					BirdFontPath* _tmp30_;
					GeeArrayList* _tmp31_;
					GeeArrayList* _tmp32_;
					gint _tmp33_;
					gint _tmp34_;
					gpointer _tmp35_;
					BirdFontEditPoint* _tmp36_;
					_tmp26_ = bird_font_pen_tool_active_edit_point;
					_tmp27_ = p;
					_tmp28_ = bird_font_path_get_points (_tmp27_);
					_tmp29_ = _tmp28_;
					_tmp30_ = p;
					_tmp31_ = bird_font_path_get_points (_tmp30_);
					_tmp32_ = _tmp31_;
					_tmp33_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp32_);
					_tmp34_ = _tmp33_;
					_tmp35_ = gee_abstract_list_get ((GeeAbstractList*) _tmp29_, _tmp34_ - 1);
					_tmp36_ = (BirdFontEditPoint*) _tmp35_;
					_tmp18_ = _tmp26_ == _tmp36_;
					_g_object_unref0 (_tmp36_);
				}
				_tmp10_ = _tmp18_;
			} else {
				_tmp10_ = FALSE;
			}
			if (_tmp10_) {
				bird_font_pen_tool_update_selection ();
				reverse = TRUE;
				bird_font_pen_tool_control_point_event (self, x, y, TRUE);
				_g_object_unref0 (p);
				break;
			}
			_g_object_unref0 (p);
		}
		_g_object_unref0 (_p_list);
	}
	{
		GeeArrayList* _p_list = NULL;
		BirdFontGlyph* _tmp37_;
		GeeArrayList* _tmp38_;
		gint _p_size = 0;
		GeeArrayList* _tmp39_;
		gint _tmp40_;
		gint _tmp41_;
		gint _p_index = 0;
		_tmp37_ = glyph;
		_tmp38_ = bird_font_glyph_get_visible_paths (_tmp37_);
		_p_list = _tmp38_;
		_tmp39_ = _p_list;
		_tmp40_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp39_);
		_tmp41_ = _tmp40_;
		_p_size = _tmp41_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp42_;
			gint _tmp43_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp44_;
			gpointer _tmp45_;
			gboolean _tmp46_ = FALSE;
			gboolean _tmp47_ = FALSE;
			BirdFontPath* _tmp48_;
			_p_index = _p_index + 1;
			_tmp42_ = _p_index;
			_tmp43_ = _p_size;
			if (!(_tmp42_ < _tmp43_)) {
				break;
			}
			_tmp44_ = _p_list;
			_tmp45_ = gee_abstract_list_get ((GeeAbstractList*) _tmp44_, _p_index);
			p = (BirdFontPath*) _tmp45_;
			_tmp48_ = p;
			if (bird_font_path_is_open (_tmp48_)) {
				BirdFontPath* _tmp49_;
				GeeArrayList* _tmp50_;
				GeeArrayList* _tmp51_;
				gint _tmp52_;
				gint _tmp53_;
				_tmp49_ = p;
				_tmp50_ = bird_font_path_get_points (_tmp49_);
				_tmp51_ = _tmp50_;
				_tmp52_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp51_);
				_tmp53_ = _tmp52_;
				_tmp47_ = _tmp53_ > 1;
			} else {
				_tmp47_ = FALSE;
			}
			if (_tmp47_) {
				BirdFontEditPoint* _tmp54_;
				BirdFontPath* _tmp55_;
				GeeArrayList* _tmp56_;
				GeeArrayList* _tmp57_;
				gpointer _tmp58_;
				BirdFontEditPoint* _tmp59_;
				_tmp54_ = bird_font_pen_tool_active_edit_point;
				_tmp55_ = p;
				_tmp56_ = bird_font_path_get_points (_tmp55_);
				_tmp57_ = _tmp56_;
				_tmp58_ = gee_abstract_list_get ((GeeAbstractList*) _tmp57_, 0);
				_tmp59_ = (BirdFontEditPoint*) _tmp58_;
				_tmp46_ = _tmp54_ == _tmp59_;
				_g_object_unref0 (_tmp59_);
			} else {
				_tmp46_ = FALSE;
			}
			if (_tmp46_) {
				BirdFontPath* _tmp60_;
				_tmp60_ = p;
				bird_font_path_reverse (_tmp60_);
				bird_font_pen_tool_update_selection ();
				reverse = TRUE;
				bird_font_pen_tool_control_point_event (self, x, y, TRUE);
				_g_object_unref0 (p);
				break;
			}
			_g_object_unref0 (p);
		}
		_g_object_unref0 (_p_list);
	}
	_tmp62_ = bird_font_pen_tool_active_edit_point;
	if (_tmp62_ == NULL) {
		_tmp61_ = bird_font_key_bindings_modifier != BIRD_FONT_SHIFT;
	} else {
		_tmp61_ = FALSE;
	}
	if (_tmp61_) {
		bird_font_pen_tool_remove_all_selected_points ();
	}
	bird_font_pen_tool_move_selected = TRUE;
	bird_font_pen_tool_move_point_on_path = TRUE;
	_tmp63_ = bird_font_pen_tool_active_edit_point;
	if (_tmp63_ != NULL) {
		BirdFontGlyph* _tmp64_;
		BirdFontGlyph* _tmp65_;
		BirdFontPath* _tmp66_;
		_tmp64_ = glyph;
		bird_font_glyph_clear_active_paths (_tmp64_);
		_tmp65_ = glyph;
		_tmp66_ = bird_font_pen_tool_active_path;
		bird_font_glyph_add_active_path (_tmp65_, NULL, _tmp66_);
		bird_font_drawing_tools_update_stroke_settings ();
		if (bird_font_key_bindings_modifier != BIRD_FONT_SHIFT) {
			BirdFontEditPoint* _tmp67_;
			BirdFontEditPoint* _tmp68_;
			BirdFontEditPoint* _tmp69_;
			gboolean _tmp75_ = FALSE;
			_tmp67_ = bird_font_pen_tool_active_edit_point;
			_tmp68_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp67_, BIRD_FONT_TYPE_EDIT_POINT, BirdFontEditPoint));
			_g_object_unref0 (bird_font_pen_tool_selected_point);
			bird_font_pen_tool_selected_point = _tmp68_;
			_tmp69_ = bird_font_pen_tool_active_edit_point;
			if (!bird_font_edit_point_is_selected (G_TYPE_CHECK_INSTANCE_CAST (_tmp69_, BIRD_FONT_TYPE_EDIT_POINT, BirdFontEditPoint))) {
				BirdFontEditPoint* _tmp70_;
				BirdFontEditPoint* _tmp71_;
				BirdFontEditPoint* _tmp72_;
				BirdFontEditPoint* _tmp73_;
				BirdFontPath* _tmp74_;
				bird_font_pen_tool_remove_all_selected_points ();
				_tmp70_ = bird_font_pen_tool_active_edit_point;
				bird_font_edit_point_set_selected (G_TYPE_CHECK_INSTANCE_CAST (_tmp70_, BIRD_FONT_TYPE_EDIT_POINT, BirdFontEditPoint), TRUE);
				_tmp71_ = bird_font_pen_tool_active_edit_point;
				_tmp72_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp71_, BIRD_FONT_TYPE_EDIT_POINT, BirdFontEditPoint));
				_g_object_unref0 (bird_font_pen_tool_selected_point);
				bird_font_pen_tool_selected_point = _tmp72_;
				_tmp73_ = bird_font_pen_tool_selected_point;
				_tmp74_ = bird_font_pen_tool_active_path;
				bird_font_pen_tool_add_selected_point (_tmp73_, _tmp74_);
				self->priv->last_selected_is_handle = FALSE;
			}
			if (bird_font_key_bindings_has_alt ()) {
				_tmp75_ = TRUE;
			} else {
				_tmp75_ = bird_font_key_bindings_has_ctrl ();
			}
			if (_tmp75_) {
				BirdFontEditPoint* _tmp76_;
				BirdFontEditPoint* _tmp77_;
				BirdFontEditPointHandle* _tmp78_;
				_tmp76_ = bird_font_pen_tool_selected_point;
				bird_font_edit_point_set_reflective_handles (_tmp76_, TRUE);
				_tmp77_ = bird_font_pen_tool_selected_point;
				_tmp78_ = bird_font_edit_point_get_right_handle (_tmp77_);
				bird_font_edit_point_handle_process_symmetrical_handle (_tmp78_);
				bird_font_glyph_canvas_redraw ();
			}
		}
	}
	if (reverse) {
		GeeArrayList* _tmp79_;
		GeeArrayList* _tmp80_;
		_tmp79_ = bird_font_pen_tool_clockwise;
		gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp79_);
		_tmp80_ = bird_font_pen_tool_counter_clockwise;
		gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp80_);
	}
	_g_object_unref0 (glyph);
}

BirdFontPath*
bird_font_pen_tool_find_path_to_join (BirdFontEditPoint* end_point)
{
	BirdFontPath* m = NULL;
	BirdFontGlyph* glyph = NULL;
	BirdFontGlyph* _tmp0_;
	BirdFontEditPoint* ep_last = NULL;
	BirdFontEditPoint* ep_first = NULL;
	BirdFontPath* result;
	g_return_val_if_fail (end_point != NULL, NULL);
	m = NULL;
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	glyph = _tmp0_;
	{
		GeeArrayList* _path_list = NULL;
		BirdFontGlyph* _tmp1_;
		GeeArrayList* _tmp2_;
		gint _path_size = 0;
		GeeArrayList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		gint _path_index = 0;
		_tmp1_ = glyph;
		_tmp2_ = bird_font_glyph_get_visible_paths (_tmp1_);
		_path_list = _tmp2_;
		_tmp3_ = _path_list;
		_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
		_tmp5_ = _tmp4_;
		_path_size = _tmp5_;
		_path_index = -1;
		while (TRUE) {
			gint _tmp6_;
			gint _tmp7_;
			BirdFontPath* path = NULL;
			GeeArrayList* _tmp8_;
			gpointer _tmp9_;
			BirdFontPath* _tmp10_;
			GeeArrayList* _tmp11_;
			GeeArrayList* _tmp12_;
			gint _tmp13_;
			gint _tmp14_;
			BirdFontPath* _tmp15_;
			GeeArrayList* _tmp16_;
			GeeArrayList* _tmp17_;
			BirdFontPath* _tmp18_;
			GeeArrayList* _tmp19_;
			GeeArrayList* _tmp20_;
			gint _tmp21_;
			gint _tmp22_;
			gpointer _tmp23_;
			BirdFontPath* _tmp24_;
			GeeArrayList* _tmp25_;
			GeeArrayList* _tmp26_;
			gpointer _tmp27_;
			BirdFontEditPoint* _tmp28_;
			BirdFontEditPoint* _tmp31_;
			_path_index = _path_index + 1;
			_tmp6_ = _path_index;
			_tmp7_ = _path_size;
			if (!(_tmp6_ < _tmp7_)) {
				break;
			}
			_tmp8_ = _path_list;
			_tmp9_ = gee_abstract_list_get ((GeeAbstractList*) _tmp8_, _path_index);
			path = (BirdFontPath*) _tmp9_;
			_tmp10_ = path;
			_tmp11_ = bird_font_path_get_points (_tmp10_);
			_tmp12_ = _tmp11_;
			_tmp13_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp12_);
			_tmp14_ = _tmp13_;
			if (_tmp14_ == 0) {
				_g_object_unref0 (path);
				continue;
			}
			_tmp15_ = path;
			_tmp16_ = bird_font_path_get_points (_tmp15_);
			_tmp17_ = _tmp16_;
			_tmp18_ = path;
			_tmp19_ = bird_font_path_get_points (_tmp18_);
			_tmp20_ = _tmp19_;
			_tmp21_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp20_);
			_tmp22_ = _tmp21_;
			_tmp23_ = gee_abstract_list_get ((GeeAbstractList*) _tmp17_, _tmp22_ - 1);
			_g_object_unref0 (ep_last);
			ep_last = (BirdFontEditPoint*) _tmp23_;
			_tmp24_ = path;
			_tmp25_ = bird_font_path_get_points (_tmp24_);
			_tmp26_ = _tmp25_;
			_tmp27_ = gee_abstract_list_get ((GeeAbstractList*) _tmp26_, 0);
			_g_object_unref0 (ep_first);
			ep_first = (BirdFontEditPoint*) _tmp27_;
			_tmp28_ = ep_last;
			if (end_point == _tmp28_) {
				BirdFontPath* _tmp29_;
				BirdFontPath* _tmp30_;
				_tmp29_ = path;
				_tmp30_ = _g_object_ref0 (_tmp29_);
				_g_object_unref0 (m);
				m = _tmp30_;
				_g_object_unref0 (path);
				break;
			}
			_tmp31_ = ep_first;
			if (end_point == _tmp31_) {
				BirdFontPath* _tmp32_;
				BirdFontPath* _tmp33_;
				_tmp32_ = path;
				_tmp33_ = _g_object_ref0 (_tmp32_);
				_g_object_unref0 (m);
				m = _tmp33_;
				_g_object_unref0 (path);
				break;
			}
			_g_object_unref0 (path);
		}
		_g_object_unref0 (_path_list);
	}
	result = m;
	_g_object_unref0 (ep_first);
	_g_object_unref0 (ep_last);
	_g_object_unref0 (glyph);
	return result;
}

BirdFontPath*
bird_font_pen_tool_merge_open_paths (BirdFontPath* path1,
                                     BirdFontPath* path2)
{
	BirdFontPath* _union_ = NULL;
	BirdFontPath* merge = NULL;
	BirdFontEditPoint* first_point = NULL;
	BirdFontPath* _tmp0_;
	BirdFontPath* _tmp1_;
	GeeArrayList* _tmp2_;
	GeeArrayList* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	BirdFontPath* _tmp6_;
	GeeArrayList* _tmp7_;
	GeeArrayList* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	BirdFontPath* _tmp11_;
	BirdFontPath* _tmp12_;
	GeeArrayList* _tmp13_;
	GeeArrayList* _tmp14_;
	gpointer _tmp15_;
	BirdFontEditPoint* _tmp16_;
	BirdFontPath* _tmp17_;
	GeeArrayList* _tmp18_;
	GeeArrayList* _tmp19_;
	gpointer _tmp20_;
	BirdFontEditPoint* _tmp21_;
	BirdFontPath* _tmp22_;
	GeeArrayList* _tmp23_;
	GeeArrayList* _tmp24_;
	BirdFontPath* _tmp25_;
	GeeArrayList* _tmp26_;
	GeeArrayList* _tmp27_;
	gint _tmp28_;
	gint _tmp29_;
	gpointer _tmp30_;
	BirdFontEditPoint* _tmp31_;
	BirdFontPath* _tmp32_;
	GeeArrayList* _tmp33_;
	GeeArrayList* _tmp34_;
	BirdFontPath* _tmp35_;
	GeeArrayList* _tmp36_;
	GeeArrayList* _tmp37_;
	gint _tmp38_;
	gint _tmp39_;
	gpointer _tmp40_;
	BirdFontEditPoint* _tmp41_;
	BirdFontPath* _tmp42_;
	GeeArrayList* _tmp43_;
	GeeArrayList* _tmp44_;
	BirdFontPath* _tmp45_;
	GeeArrayList* _tmp46_;
	GeeArrayList* _tmp47_;
	gint _tmp48_;
	gint _tmp49_;
	gpointer _tmp50_;
	BirdFontEditPoint* _tmp51_;
	BirdFontPath* _tmp52_;
	GeeArrayList* _tmp53_;
	GeeArrayList* _tmp54_;
	BirdFontPath* _tmp55_;
	GeeArrayList* _tmp56_;
	GeeArrayList* _tmp57_;
	gint _tmp58_;
	gint _tmp59_;
	gpointer _tmp60_;
	BirdFontEditPoint* _tmp61_;
	BirdFontPath* _tmp62_;
	GeeArrayList* _tmp63_;
	GeeArrayList* _tmp64_;
	gpointer _tmp65_;
	BirdFontEditPoint* _tmp66_;
	BirdFontPath* _tmp67_;
	GeeArrayList* _tmp68_;
	GeeArrayList* _tmp69_;
	gpointer _tmp70_;
	BirdFontEditPoint* _tmp71_;
	BirdFontPath* _tmp72_;
	BirdFontEditPoint* _tmp73_;
	BirdFontPath* _tmp74_;
	BirdFontEditPoint* _tmp75_;
	BirdFontEditPoint* _tmp76_;
	BirdFontEditPointHandle* _tmp77_;
	gboolean _tmp78_;
	BirdFontEditPoint* _tmp84_;
	BirdFontPath* _tmp99_;
	BirdFontEditPoint* _tmp100_;
	BirdFontEditPoint* _tmp101_;
	BirdFontPath* _tmp102_;
	BirdFontPath* _tmp103_;
	BirdFontPath* result;
	g_return_val_if_fail (path1 != NULL, NULL);
	g_return_val_if_fail (path2 != NULL, NULL);
	_tmp0_ = bird_font_path_copy (path1);
	_g_object_unref0 (_union_);
	_union_ = _tmp0_;
	_tmp1_ = bird_font_path_copy (path2);
	_g_object_unref0 (merge);
	merge = _tmp1_;
	_tmp2_ = bird_font_path_get_points (path1);
	_tmp3_ = _tmp2_;
	_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = merge;
	g_return_val_if_fail (_tmp5_ >= 1, _tmp6_);
	_tmp7_ = bird_font_path_get_points (path2);
	_tmp8_ = _tmp7_;
	_tmp9_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = _union_;
	g_return_val_if_fail (_tmp10_ >= 1, _tmp11_);
	_tmp12_ = merge;
	_tmp13_ = bird_font_path_get_points (_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp15_ = gee_abstract_list_get ((GeeAbstractList*) _tmp14_, 0);
	_tmp16_ = (BirdFontEditPoint*) _tmp15_;
	bird_font_edit_point_set_tie_handle (_tmp16_, FALSE);
	_g_object_unref0 (_tmp16_);
	_tmp17_ = merge;
	_tmp18_ = bird_font_path_get_points (_tmp17_);
	_tmp19_ = _tmp18_;
	_tmp20_ = gee_abstract_list_get ((GeeAbstractList*) _tmp19_, 0);
	_tmp21_ = (BirdFontEditPoint*) _tmp20_;
	bird_font_edit_point_set_reflective_handles (_tmp21_, FALSE);
	_g_object_unref0 (_tmp21_);
	_tmp22_ = merge;
	_tmp23_ = bird_font_path_get_points (_tmp22_);
	_tmp24_ = _tmp23_;
	_tmp25_ = merge;
	_tmp26_ = bird_font_path_get_points (_tmp25_);
	_tmp27_ = _tmp26_;
	_tmp28_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp27_);
	_tmp29_ = _tmp28_;
	_tmp30_ = gee_abstract_list_get ((GeeAbstractList*) _tmp24_, _tmp29_ - 1);
	_tmp31_ = (BirdFontEditPoint*) _tmp30_;
	bird_font_edit_point_set_tie_handle (_tmp31_, FALSE);
	_g_object_unref0 (_tmp31_);
	_tmp32_ = merge;
	_tmp33_ = bird_font_path_get_points (_tmp32_);
	_tmp34_ = _tmp33_;
	_tmp35_ = merge;
	_tmp36_ = bird_font_path_get_points (_tmp35_);
	_tmp37_ = _tmp36_;
	_tmp38_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp37_);
	_tmp39_ = _tmp38_;
	_tmp40_ = gee_abstract_list_get ((GeeAbstractList*) _tmp34_, _tmp39_ - 1);
	_tmp41_ = (BirdFontEditPoint*) _tmp40_;
	bird_font_edit_point_set_reflective_handles (_tmp41_, FALSE);
	_g_object_unref0 (_tmp41_);
	_tmp42_ = _union_;
	_tmp43_ = bird_font_path_get_points (_tmp42_);
	_tmp44_ = _tmp43_;
	_tmp45_ = _union_;
	_tmp46_ = bird_font_path_get_points (_tmp45_);
	_tmp47_ = _tmp46_;
	_tmp48_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp47_);
	_tmp49_ = _tmp48_;
	_tmp50_ = gee_abstract_list_get ((GeeAbstractList*) _tmp44_, _tmp49_ - 1);
	_tmp51_ = (BirdFontEditPoint*) _tmp50_;
	bird_font_edit_point_set_tie_handle (_tmp51_, FALSE);
	_g_object_unref0 (_tmp51_);
	_tmp52_ = _union_;
	_tmp53_ = bird_font_path_get_points (_tmp52_);
	_tmp54_ = _tmp53_;
	_tmp55_ = _union_;
	_tmp56_ = bird_font_path_get_points (_tmp55_);
	_tmp57_ = _tmp56_;
	_tmp58_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp57_);
	_tmp59_ = _tmp58_;
	_tmp60_ = gee_abstract_list_get ((GeeAbstractList*) _tmp54_, _tmp59_ - 1);
	_tmp61_ = (BirdFontEditPoint*) _tmp60_;
	bird_font_edit_point_set_reflective_handles (_tmp61_, FALSE);
	_g_object_unref0 (_tmp61_);
	_tmp62_ = _union_;
	_tmp63_ = bird_font_path_get_points (_tmp62_);
	_tmp64_ = _tmp63_;
	_tmp65_ = gee_abstract_list_get ((GeeAbstractList*) _tmp64_, 0);
	_tmp66_ = (BirdFontEditPoint*) _tmp65_;
	bird_font_edit_point_set_tie_handle (_tmp66_, FALSE);
	_g_object_unref0 (_tmp66_);
	_tmp67_ = _union_;
	_tmp68_ = bird_font_path_get_points (_tmp67_);
	_tmp69_ = _tmp68_;
	_tmp70_ = gee_abstract_list_get ((GeeAbstractList*) _tmp69_, 0);
	_tmp71_ = (BirdFontEditPoint*) _tmp70_;
	bird_font_edit_point_set_reflective_handles (_tmp71_, FALSE);
	_g_object_unref0 (_tmp71_);
	_tmp72_ = merge;
	_tmp73_ = bird_font_path_get_first_point (_tmp72_);
	_g_object_unref0 (first_point);
	first_point = _tmp73_;
	_tmp74_ = _union_;
	_tmp75_ = bird_font_path_get_last_point (_tmp74_);
	_tmp76_ = _tmp75_;
	_tmp77_ = bird_font_edit_point_get_left_handle (_tmp76_);
	_tmp78_ = bird_font_edit_point_handle_is_curve (_tmp77_);
	_g_object_unref0 (_tmp76_);
	if (_tmp78_) {
		BirdFontEditPoint* _tmp79_;
		BirdFontEditPointHandle* _tmp80_;
		_tmp79_ = first_point;
		_tmp80_ = bird_font_edit_point_get_left_handle (_tmp79_);
		bird_font_edit_point_handle_convert_to_curve (_tmp80_);
	} else {
		BirdFontEditPoint* _tmp81_;
		_tmp81_ = first_point;
		if (_tmp81_->type != BIRD_FONT_POINT_TYPE_QUADRATIC) {
			BirdFontEditPoint* _tmp82_;
			BirdFontEditPointHandle* _tmp83_;
			_tmp82_ = first_point;
			_tmp83_ = bird_font_edit_point_get_left_handle (_tmp82_);
			bird_font_edit_point_handle_convert_to_line (_tmp83_);
		}
	}
	_tmp84_ = first_point;
	if (_tmp84_->type != BIRD_FONT_POINT_TYPE_QUADRATIC) {
		BirdFontEditPoint* _tmp85_;
		BirdFontEditPointHandle* _tmp86_;
		BirdFontPath* _tmp87_;
		BirdFontEditPoint* _tmp88_;
		BirdFontEditPoint* _tmp89_;
		BirdFontEditPointHandle* _tmp90_;
		gdouble _tmp91_;
		gdouble _tmp92_;
		BirdFontPath* _tmp93_;
		BirdFontEditPoint* _tmp94_;
		BirdFontEditPoint* _tmp95_;
		BirdFontEditPointHandle* _tmp96_;
		gdouble _tmp97_;
		gdouble _tmp98_;
		_tmp85_ = first_point;
		_tmp86_ = bird_font_edit_point_get_left_handle (_tmp85_);
		_tmp87_ = _union_;
		_tmp88_ = bird_font_path_get_last_point (_tmp87_);
		_tmp89_ = _tmp88_;
		_tmp90_ = bird_font_edit_point_get_left_handle (_tmp89_);
		_tmp91_ = bird_font_edit_point_handle_get_x (_tmp90_);
		_tmp92_ = _tmp91_;
		_tmp93_ = _union_;
		_tmp94_ = bird_font_path_get_last_point (_tmp93_);
		_tmp95_ = _tmp94_;
		_tmp96_ = bird_font_edit_point_get_left_handle (_tmp95_);
		_tmp97_ = bird_font_edit_point_handle_get_y (_tmp96_);
		_tmp98_ = _tmp97_;
		bird_font_edit_point_handle_move_to_coordinate_internal (_tmp86_, _tmp92_, _tmp98_);
		_g_object_unref0 (_tmp95_);
		_g_object_unref0 (_tmp89_);
	}
	_tmp99_ = _union_;
	_tmp100_ = bird_font_path_delete_last_point (_tmp99_);
	_tmp101_ = _tmp100_;
	_g_object_unref0 (_tmp101_);
	_tmp102_ = _union_;
	_tmp103_ = merge;
	bird_font_path_append_path (_tmp102_, _tmp103_);
	result = _union_;
	_g_object_unref0 (first_point);
	_g_object_unref0 (merge);
	return result;
}

void
bird_font_pen_tool_close_path (BirdFontPath* path)
{
	gboolean last_segment_is_line = FALSE;
	gboolean first_segment_is_line = FALSE;
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	BirdFontEditPoint* _tmp4_;
	BirdFontEditPoint* _tmp5_;
	BirdFontEditPointHandle* _tmp6_;
	BirdFontEditPoint* _tmp7_;
	BirdFontEditPoint* _tmp8_;
	BirdFontEditPointHandle* _tmp9_;
	GeeArrayList* _tmp10_;
	GeeArrayList* _tmp11_;
	gpointer _tmp12_;
	BirdFontEditPoint* _tmp13_;
	BirdFontEditPointHandle* _tmp14_;
	GeeArrayList* _tmp15_;
	GeeArrayList* _tmp16_;
	GeeArrayList* _tmp17_;
	GeeArrayList* _tmp18_;
	gint _tmp19_;
	gint _tmp20_;
	gpointer _tmp21_;
	BirdFontEditPoint* _tmp22_;
	BirdFontEditPointHandle* _tmp23_;
	gdouble _tmp24_;
	gdouble _tmp25_;
	GeeArrayList* _tmp26_;
	GeeArrayList* _tmp27_;
	GeeArrayList* _tmp28_;
	GeeArrayList* _tmp29_;
	gint _tmp30_;
	gint _tmp31_;
	gpointer _tmp32_;
	BirdFontEditPoint* _tmp33_;
	BirdFontEditPointHandle* _tmp34_;
	gdouble _tmp35_;
	gdouble _tmp36_;
	GeeArrayList* _tmp37_;
	GeeArrayList* _tmp38_;
	gpointer _tmp39_;
	BirdFontEditPoint* _tmp40_;
	BirdFontEditPointHandle* _tmp41_;
	GeeArrayList* _tmp42_;
	GeeArrayList* _tmp43_;
	GeeArrayList* _tmp44_;
	GeeArrayList* _tmp45_;
	gint _tmp46_;
	gint _tmp47_;
	gpointer _tmp48_;
	BirdFontEditPoint* _tmp49_;
	BirdFontEditPointHandle* _tmp50_;
	GeeArrayList* _tmp51_;
	GeeArrayList* _tmp52_;
	gpointer _tmp53_;
	BirdFontEditPoint* _tmp54_;
	GeeArrayList* _tmp55_;
	GeeArrayList* _tmp56_;
	GeeArrayList* _tmp57_;
	GeeArrayList* _tmp58_;
	gint _tmp59_;
	gint _tmp60_;
	gpointer _tmp61_;
	BirdFontEditPoint* _tmp62_;
	GeeArrayList* _tmp63_;
	GeeArrayList* _tmp64_;
	gpointer _tmp65_;
	BirdFontEditPoint* _tmp66_;
	GeeArrayList* _tmp67_;
	GeeArrayList* _tmp68_;
	gpointer _tmp69_;
	BirdFontEditPoint* _tmp70_;
	GeeArrayList* _tmp71_;
	GeeArrayList* _tmp72_;
	gpointer _tmp73_;
	BirdFontEditPoint* _tmp74_;
	GeeArrayList* _tmp75_;
	GeeArrayList* _tmp76_;
	GeeArrayList* _tmp77_;
	GeeArrayList* _tmp78_;
	gint _tmp79_;
	gint _tmp80_;
	gpointer _tmp81_;
	BirdFontEditPoint* _tmp82_;
	g_return_if_fail (path != NULL);
	_tmp0_ = bird_font_path_get_points (path);
	_tmp1_ = _tmp0_;
	_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
	_tmp3_ = _tmp2_;
	g_return_if_fail (_tmp3_ > 1);
	_tmp4_ = bird_font_path_get_last_point (path);
	_tmp5_ = _tmp4_;
	_tmp6_ = bird_font_edit_point_get_left_handle (_tmp5_);
	last_segment_is_line = bird_font_edit_point_handle_is_line (_tmp6_);
	_g_object_unref0 (_tmp5_);
	_tmp7_ = bird_font_path_get_first_point (path);
	_tmp8_ = _tmp7_;
	_tmp9_ = bird_font_edit_point_get_right_handle (_tmp8_);
	first_segment_is_line = bird_font_edit_point_handle_is_line (_tmp9_);
	_g_object_unref0 (_tmp8_);
	_tmp10_ = bird_font_path_get_points (path);
	_tmp11_ = _tmp10_;
	_tmp12_ = gee_abstract_list_get ((GeeAbstractList*) _tmp11_, 0);
	_tmp13_ = (BirdFontEditPoint*) _tmp12_;
	_tmp14_ = _tmp13_->left_handle;
	_tmp15_ = bird_font_path_get_points (path);
	_tmp16_ = _tmp15_;
	_tmp17_ = bird_font_path_get_points (path);
	_tmp18_ = _tmp17_;
	_tmp19_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp18_);
	_tmp20_ = _tmp19_;
	_tmp21_ = gee_abstract_list_get ((GeeAbstractList*) _tmp16_, _tmp20_ - 1);
	_tmp22_ = (BirdFontEditPoint*) _tmp21_;
	_tmp23_ = _tmp22_->left_handle;
	_tmp24_ = bird_font_edit_point_handle_get_x (_tmp23_);
	_tmp25_ = _tmp24_;
	_tmp26_ = bird_font_path_get_points (path);
	_tmp27_ = _tmp26_;
	_tmp28_ = bird_font_path_get_points (path);
	_tmp29_ = _tmp28_;
	_tmp30_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp29_);
	_tmp31_ = _tmp30_;
	_tmp32_ = gee_abstract_list_get ((GeeAbstractList*) _tmp27_, _tmp31_ - 1);
	_tmp33_ = (BirdFontEditPoint*) _tmp32_;
	_tmp34_ = _tmp33_->left_handle;
	_tmp35_ = bird_font_edit_point_handle_get_y (_tmp34_);
	_tmp36_ = _tmp35_;
	bird_font_edit_point_handle_move_to_coordinate (_tmp14_, _tmp25_, _tmp36_);
	_g_object_unref0 (_tmp33_);
	_g_object_unref0 (_tmp22_);
	_g_object_unref0 (_tmp13_);
	_tmp37_ = bird_font_path_get_points (path);
	_tmp38_ = _tmp37_;
	_tmp39_ = gee_abstract_list_get ((GeeAbstractList*) _tmp38_, 0);
	_tmp40_ = (BirdFontEditPoint*) _tmp39_;
	_tmp41_ = _tmp40_->left_handle;
	_tmp42_ = bird_font_path_get_points (path);
	_tmp43_ = _tmp42_;
	_tmp44_ = bird_font_path_get_points (path);
	_tmp45_ = _tmp44_;
	_tmp46_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp45_);
	_tmp47_ = _tmp46_;
	_tmp48_ = gee_abstract_list_get ((GeeAbstractList*) _tmp43_, _tmp47_ - 1);
	_tmp49_ = (BirdFontEditPoint*) _tmp48_;
	_tmp50_ = _tmp49_->left_handle;
	_tmp41_->type = _tmp50_->type;
	_g_object_unref0 (_tmp49_);
	_g_object_unref0 (_tmp40_);
	_tmp51_ = bird_font_path_get_points (path);
	_tmp52_ = _tmp51_;
	_tmp53_ = gee_abstract_list_get ((GeeAbstractList*) _tmp52_, 0);
	_tmp54_ = (BirdFontEditPoint*) _tmp53_;
	bird_font_path_recalculate_linear_handles_for_point (path, _tmp54_);
	_g_object_unref0 (_tmp54_);
	_tmp55_ = bird_font_path_get_points (path);
	_tmp56_ = _tmp55_;
	_tmp57_ = bird_font_path_get_points (path);
	_tmp58_ = _tmp57_;
	_tmp59_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp58_);
	_tmp60_ = _tmp59_;
	_tmp61_ = gee_abstract_list_get ((GeeAbstractList*) _tmp56_, _tmp60_ - 1);
	_tmp62_ = (BirdFontEditPoint*) _tmp61_;
	bird_font_path_recalculate_linear_handles_for_point (path, _tmp62_);
	_g_object_unref0 (_tmp62_);
	_tmp63_ = bird_font_path_get_points (path);
	_tmp64_ = _tmp63_;
	_tmp65_ = gee_abstract_list_get ((GeeAbstractList*) _tmp64_, 0);
	_tmp66_ = (BirdFontEditPoint*) _tmp65_;
	_tmp67_ = bird_font_path_get_points (path);
	_tmp68_ = _tmp67_;
	_tmp69_ = gee_abstract_list_get ((GeeAbstractList*) _tmp68_, 0);
	_tmp70_ = (BirdFontEditPoint*) _tmp69_;
	_tmp71_ = bird_font_path_get_points (path);
	_tmp72_ = _tmp71_;
	_tmp73_ = gee_abstract_list_get ((GeeAbstractList*) _tmp72_, 0);
	_tmp74_ = (BirdFontEditPoint*) _tmp73_;
	bird_font_edit_point_set_position (_tmp66_, _tmp70_->x, _tmp74_->y);
	_g_object_unref0 (_tmp74_);
	_g_object_unref0 (_tmp70_);
	_g_object_unref0 (_tmp66_);
	_tmp75_ = bird_font_path_get_points (path);
	_tmp76_ = _tmp75_;
	_tmp77_ = bird_font_path_get_points (path);
	_tmp78_ = _tmp77_;
	_tmp79_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp78_);
	_tmp80_ = _tmp79_;
	_tmp81_ = gee_abstract_list_remove_at ((GeeAbstractList*) _tmp76_, _tmp80_ - 1);
	_tmp82_ = (BirdFontEditPoint*) _tmp81_;
	_g_object_unref0 (_tmp82_);
	bird_font_path_close (path);
	if (last_segment_is_line) {
		BirdFontEditPoint* _tmp83_;
		BirdFontEditPoint* _tmp84_;
		BirdFontEditPointHandle* _tmp85_;
		BirdFontEditPoint* _tmp86_;
		BirdFontEditPoint* _tmp87_;
		_tmp83_ = bird_font_path_get_first_point (path);
		_tmp84_ = _tmp83_;
		_tmp85_ = bird_font_edit_point_get_left_handle (_tmp84_);
		bird_font_edit_point_handle_convert_to_line (_tmp85_);
		_g_object_unref0 (_tmp84_);
		_tmp86_ = bird_font_path_get_first_point (path);
		_tmp87_ = _tmp86_;
		bird_font_path_recalculate_linear_handles_for_point (path, _tmp87_);
		_g_object_unref0 (_tmp87_);
	}
	if (first_segment_is_line) {
		BirdFontEditPoint* _tmp88_;
		BirdFontEditPoint* _tmp89_;
		BirdFontEditPointHandle* _tmp90_;
		BirdFontEditPoint* _tmp91_;
		BirdFontEditPoint* _tmp92_;
		_tmp88_ = bird_font_path_get_first_point (path);
		_tmp89_ = _tmp88_;
		_tmp90_ = bird_font_edit_point_get_right_handle (_tmp89_);
		bird_font_edit_point_handle_convert_to_line (_tmp90_);
		_g_object_unref0 (_tmp89_);
		_tmp91_ = bird_font_path_get_first_point (path);
		_tmp92_ = _tmp91_;
		bird_font_path_recalculate_linear_handles_for_point (path, _tmp92_);
		_g_object_unref0 (_tmp92_);
	}
}

/** @return the new path or null if no path could be merged with the end point. */
BirdFontPath*
bird_font_pen_tool_join_paths (BirdFontEditPoint* end_point)
{
	BirdFontGlyph* glyph = NULL;
	BirdFontGlyph* _tmp0_;
	BirdFontPath* p = NULL;
	BirdFontPath* path = NULL;
	BirdFontPath* _union_ = NULL;
	gboolean direction_changed = FALSE;
	gint px = 0;
	gint py = 0;
	GeeArrayList* paths = NULL;
	BirdFontGlyph* _tmp1_;
	GeeArrayList* _tmp2_;
	GeeArrayList* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	BirdFontPath* _tmp6_;
	BirdFontPath* _tmp7_;
	BirdFontPath* _tmp8_;
	BirdFontPath* _tmp9_;
	BirdFontPath* _tmp10_;
	BirdFontPath* _tmp11_;
	GeeArrayList* _tmp12_;
	GeeArrayList* _tmp13_;
	gint _tmp14_;
	gint _tmp15_;
	BirdFontPath* _tmp16_;
	GeeArrayList* _tmp17_;
	GeeArrayList* _tmp18_;
	gint _tmp19_;
	gint _tmp20_;
	BirdFontEditPoint* _tmp67_;
	BirdFontPath* _tmp68_;
	GeeArrayList* _tmp69_;
	GeeArrayList* _tmp70_;
	gpointer _tmp71_;
	BirdFontEditPoint* _tmp72_;
	gboolean _tmp73_;
	BirdFontPath* _tmp87_;
	GeeArrayList* _tmp88_;
	GeeArrayList* _tmp89_;
	gpointer _tmp90_;
	BirdFontEditPoint* _tmp91_;
	BirdFontEditPoint* _tmp92_;
	gboolean _tmp93_;
	BirdFontPath* _tmp94_;
	GeeArrayList* _tmp95_;
	GeeArrayList* _tmp96_;
	gpointer _tmp97_;
	BirdFontEditPoint* _tmp98_;
	gboolean _tmp99_;
	BirdFontPath* result;
	g_return_val_if_fail (end_point != NULL, NULL);
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	glyph = _tmp0_;
	direction_changed = FALSE;
	_tmp1_ = glyph;
	_tmp2_ = bird_font_glyph_get_visible_paths (_tmp1_);
	paths = _tmp2_;
	_tmp3_ = paths;
	_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
	_tmp5_ = _tmp4_;
	if (_tmp5_ == 0) {
		g_warning ("PenTool.vala:1381: No paths.");
		result = NULL;
		_g_object_unref0 (paths);
		_g_object_unref0 (_union_);
		_g_object_unref0 (path);
		_g_object_unref0 (p);
		_g_object_unref0 (glyph);
		return result;
	}
	_tmp6_ = bird_font_pen_tool_find_path_to_join (end_point);
	_g_object_unref0 (p);
	p = _tmp6_;
	_tmp7_ = p;
	if (_tmp7_ == NULL) {
		g_warning ("PenTool.vala:1387: No path to join.");
		result = NULL;
		_g_object_unref0 (paths);
		_g_object_unref0 (_union_);
		_g_object_unref0 (path);
		_g_object_unref0 (p);
		_g_object_unref0 (glyph);
		return result;
	}
	_tmp8_ = p;
	_tmp9_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, BIRD_FONT_TYPE_PATH, BirdFontPath));
	_g_object_unref0 (path);
	path = _tmp9_;
	_tmp10_ = path;
	if (!bird_font_path_is_open (_tmp10_)) {
		g_warning ("PenTool.vala:1393: Path is closed.");
		result = NULL;
		_g_object_unref0 (paths);
		_g_object_unref0 (_union_);
		_g_object_unref0 (path);
		_g_object_unref0 (p);
		_g_object_unref0 (glyph);
		return result;
	}
	_tmp11_ = path;
	_tmp12_ = bird_font_path_get_points (_tmp11_);
	_tmp13_ = _tmp12_;
	_tmp14_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp13_);
	_tmp15_ = _tmp14_;
	g_return_val_if_fail (_tmp15_ > 0, NULL);
	px = bird_font_glyph_reverse_path_coordinate_x (end_point->x);
	py = bird_font_glyph_reverse_path_coordinate_y (end_point->y);
	_tmp16_ = path;
	_tmp17_ = bird_font_path_get_points (_tmp16_);
	_tmp18_ = _tmp17_;
	_tmp19_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp18_);
	_tmp20_ = _tmp19_;
	if (_tmp20_ == 1) {
		BirdFontGlyph* _tmp21_;
		BirdFontPath* _tmp22_;
		BirdFontGlyph* _tmp23_;
		_tmp21_ = glyph;
		_tmp22_ = path;
		bird_font_glyph_delete_path (_tmp21_, _tmp22_);
		_tmp23_ = glyph;
		bird_font_glyph_clear_active_paths (_tmp23_);
		{
			GeeArrayList* _merge_list = NULL;
			GeeArrayList* _tmp24_;
			gint _merge_size = 0;
			GeeArrayList* _tmp25_;
			gint _tmp26_;
			gint _tmp27_;
			gint _merge_index = 0;
			_tmp24_ = paths;
			_merge_list = _tmp24_;
			_tmp25_ = _merge_list;
			_tmp26_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp25_);
			_tmp27_ = _tmp26_;
			_merge_size = _tmp27_;
			_merge_index = -1;
			while (TRUE) {
				gint _tmp28_;
				gint _tmp29_;
				BirdFontPath* merge = NULL;
				GeeArrayList* _tmp30_;
				gpointer _tmp31_;
				BirdFontPath* _tmp32_;
				GeeArrayList* _tmp33_;
				GeeArrayList* _tmp34_;
				gint _tmp35_;
				gint _tmp36_;
				_merge_index = _merge_index + 1;
				_tmp28_ = _merge_index;
				_tmp29_ = _merge_size;
				if (!(_tmp28_ < _tmp29_)) {
					break;
				}
				_tmp30_ = _merge_list;
				_tmp31_ = gee_abstract_list_get ((GeeAbstractList*) _tmp30_, _merge_index);
				merge = (BirdFontPath*) _tmp31_;
				_tmp32_ = merge;
				_tmp33_ = bird_font_path_get_points (_tmp32_);
				_tmp34_ = _tmp33_;
				_tmp35_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp34_);
				_tmp36_ = _tmp35_;
				if (_tmp36_ > 0) {
					BirdFontPath* _tmp37_;
					GeeArrayList* _tmp38_;
					GeeArrayList* _tmp39_;
					BirdFontPath* _tmp40_;
					GeeArrayList* _tmp41_;
					GeeArrayList* _tmp42_;
					gint _tmp43_;
					gint _tmp44_;
					gpointer _tmp45_;
					BirdFontEditPoint* _tmp46_;
					gboolean _tmp47_;
					BirdFontPath* _tmp54_;
					GeeArrayList* _tmp55_;
					GeeArrayList* _tmp56_;
					gpointer _tmp57_;
					BirdFontEditPoint* _tmp58_;
					gboolean _tmp59_;
					_tmp37_ = merge;
					_tmp38_ = bird_font_path_get_points (_tmp37_);
					_tmp39_ = _tmp38_;
					_tmp40_ = merge;
					_tmp41_ = bird_font_path_get_points (_tmp40_);
					_tmp42_ = _tmp41_;
					_tmp43_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp42_);
					_tmp44_ = _tmp43_;
					_tmp45_ = gee_abstract_list_get ((GeeAbstractList*) _tmp39_, _tmp44_ - 1);
					_tmp46_ = (BirdFontEditPoint*) _tmp45_;
					_tmp47_ = bird_font_pen_tool_is_close_to_point (_tmp46_, (gdouble) px, (gdouble) py);
					_g_object_unref0 (_tmp46_);
					if (_tmp47_) {
						BirdFontGlyph* _tmp48_;
						BirdFontPath* _tmp49_;
						BirdFontPath* _tmp50_;
						BirdFontPath* _tmp51_;
						BirdFontPath* _tmp52_;
						BirdFontGlyph* _tmp53_;
						_tmp48_ = glyph;
						_tmp49_ = merge;
						bird_font_glyph_add_active_path (_tmp48_, NULL, _tmp49_);
						_tmp50_ = merge;
						_tmp51_ = _g_object_ref0 (_tmp50_);
						_g_object_unref0 (bird_font_pen_tool_active_path);
						bird_font_pen_tool_active_path = _tmp51_;
						_tmp52_ = merge;
						bird_font_path_reopen (_tmp52_);
						_tmp53_ = glyph;
						bird_font_glyph_open_path (_tmp53_);
						result = merge;
						_g_object_unref0 (paths);
						_g_object_unref0 (_union_);
						_g_object_unref0 (path);
						_g_object_unref0 (p);
						_g_object_unref0 (glyph);
						return result;
					}
					_tmp54_ = merge;
					_tmp55_ = bird_font_path_get_points (_tmp54_);
					_tmp56_ = _tmp55_;
					_tmp57_ = gee_abstract_list_get ((GeeAbstractList*) _tmp56_, 0);
					_tmp58_ = (BirdFontEditPoint*) _tmp57_;
					_tmp59_ = bird_font_pen_tool_is_close_to_point (_tmp58_, (gdouble) px, (gdouble) py);
					_g_object_unref0 (_tmp58_);
					if (_tmp59_) {
						BirdFontGlyph* _tmp60_;
						BirdFontPath* _tmp61_;
						BirdFontPath* _tmp62_;
						BirdFontPath* _tmp63_;
						BirdFontPath* _tmp64_;
						BirdFontGlyph* _tmp65_;
						BirdFontPath* _tmp66_;
						_tmp60_ = glyph;
						_tmp61_ = merge;
						bird_font_glyph_add_active_path (_tmp60_, NULL, _tmp61_);
						_tmp62_ = merge;
						_tmp63_ = _g_object_ref0 (_tmp62_);
						_g_object_unref0 (bird_font_pen_tool_active_path);
						bird_font_pen_tool_active_path = _tmp63_;
						bird_font_pen_tool_clear_directions ();
						_tmp64_ = merge;
						bird_font_path_reopen (_tmp64_);
						_tmp65_ = glyph;
						bird_font_glyph_open_path (_tmp65_);
						_tmp66_ = merge;
						bird_font_path_reverse (_tmp66_);
						result = merge;
						_g_object_unref0 (paths);
						_g_object_unref0 (_union_);
						_g_object_unref0 (path);
						_g_object_unref0 (p);
						_g_object_unref0 (glyph);
						return result;
					}
				}
				_g_object_unref0 (merge);
			}
		}
		g_warning ("PenTool.vala:1428: No point to merge.");
		result = NULL;
		_g_object_unref0 (paths);
		_g_object_unref0 (_union_);
		_g_object_unref0 (path);
		_g_object_unref0 (p);
		_g_object_unref0 (glyph);
		return result;
	}
	_tmp67_ = bird_font_pen_tool_active_edit_point;
	_tmp68_ = path;
	_tmp69_ = bird_font_path_get_points (_tmp68_);
	_tmp70_ = _tmp69_;
	_tmp71_ = gee_abstract_list_get ((GeeAbstractList*) _tmp70_, 0);
	_tmp72_ = (BirdFontEditPoint*) _tmp71_;
	_tmp73_ = _tmp67_ == _tmp72_;
	_g_object_unref0 (_tmp72_);
	if (_tmp73_) {
		BirdFontPath* _tmp74_;
		BirdFontPath* _tmp75_;
		BirdFontPath* _tmp76_;
		GeeArrayList* _tmp77_;
		GeeArrayList* _tmp78_;
		BirdFontPath* _tmp79_;
		GeeArrayList* _tmp80_;
		GeeArrayList* _tmp81_;
		gint _tmp82_;
		gint _tmp83_;
		gpointer _tmp84_;
		BirdFontPath* _tmp85_;
		BirdFontPath* _tmp86_;
		_tmp74_ = path;
		bird_font_path_reverse (_tmp74_);
		bird_font_pen_tool_update_selection ();
		_tmp75_ = path;
		bird_font_path_recalculate_linear_handles (_tmp75_);
		direction_changed = TRUE;
		_tmp76_ = path;
		_tmp77_ = bird_font_path_get_points (_tmp76_);
		_tmp78_ = _tmp77_;
		_tmp79_ = path;
		_tmp80_ = bird_font_path_get_points (_tmp79_);
		_tmp81_ = _tmp80_;
		_tmp82_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp81_);
		_tmp83_ = _tmp82_;
		_tmp84_ = gee_abstract_list_get ((GeeAbstractList*) _tmp78_, _tmp83_ - 1);
		_g_object_unref0 (bird_font_pen_tool_active_edit_point);
		bird_font_pen_tool_active_edit_point = (BirdFontEditPoint*) _tmp84_;
		_tmp85_ = path;
		_tmp86_ = _g_object_ref0 (_tmp85_);
		_g_object_unref0 (bird_font_pen_tool_active_path);
		bird_font_pen_tool_active_path = _tmp86_;
	}
	_tmp87_ = path;
	_tmp88_ = bird_font_path_get_points (_tmp87_);
	_tmp89_ = _tmp88_;
	_tmp90_ = gee_abstract_list_get ((GeeAbstractList*) _tmp89_, 0);
	_tmp91_ = (BirdFontEditPoint*) _tmp90_;
	_tmp92_ = bird_font_pen_tool_active_edit_point;
	_tmp93_ = _tmp91_ == _tmp92_;
	_g_object_unref0 (_tmp91_);
	if (_tmp93_) {
		g_warning ("PenTool.vala:1442: Wrong direction.");
		result = NULL;
		_g_object_unref0 (paths);
		_g_object_unref0 (_union_);
		_g_object_unref0 (path);
		_g_object_unref0 (p);
		_g_object_unref0 (glyph);
		return result;
	}
	_tmp94_ = path;
	_tmp95_ = bird_font_path_get_points (_tmp94_);
	_tmp96_ = _tmp95_;
	_tmp97_ = gee_abstract_list_get ((GeeAbstractList*) _tmp96_, 0);
	_tmp98_ = (BirdFontEditPoint*) _tmp97_;
	_tmp99_ = bird_font_pen_tool_is_close_to_point (_tmp98_, (gdouble) px, (gdouble) py);
	_g_object_unref0 (_tmp98_);
	if (_tmp99_) {
		BirdFontPath* _tmp100_;
		BirdFontGlyph* _tmp101_;
		BirdFontGlyph* _tmp102_;
		BirdFontGlyph* _tmp103_;
		BirdFontPath* _tmp104_;
		BirdFontPath* _tmp105_;
		_tmp100_ = path;
		bird_font_pen_tool_close_path (_tmp100_);
		_tmp101_ = glyph;
		bird_font_glyph_close_path (_tmp101_);
		bird_font_pen_tool_force_direction ();
		_tmp102_ = glyph;
		bird_font_glyph_clear_active_paths (_tmp102_);
		_tmp103_ = glyph;
		_tmp104_ = path;
		bird_font_glyph_add_active_path (_tmp103_, NULL, _tmp104_);
		_tmp105_ = path;
		bird_font_path_close (_tmp105_);
		if (direction_changed) {
			BirdFontPath* _tmp106_;
			_tmp106_ = path;
			bird_font_path_reverse (_tmp106_);
			bird_font_pen_tool_update_selection ();
		}
		bird_font_pen_tool_remove_all_selected_points ();
		result = path;
		_g_object_unref0 (paths);
		_g_object_unref0 (_union_);
		_g_object_unref0 (p);
		_g_object_unref0 (glyph);
		return result;
	}
	{
		GeeArrayList* _merge_list = NULL;
		GeeArrayList* _tmp107_;
		gint _merge_size = 0;
		GeeArrayList* _tmp108_;
		gint _tmp109_;
		gint _tmp110_;
		gint _merge_index = 0;
		_tmp107_ = paths;
		_merge_list = _tmp107_;
		_tmp108_ = _merge_list;
		_tmp109_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp108_);
		_tmp110_ = _tmp109_;
		_merge_size = _tmp110_;
		_merge_index = -1;
		while (TRUE) {
			gint _tmp111_;
			gint _tmp112_;
			BirdFontPath* merge = NULL;
			GeeArrayList* _tmp113_;
			gpointer _tmp114_;
			BirdFontPath* _tmp115_;
			BirdFontPath* _tmp116_;
			gboolean _tmp117_ = FALSE;
			BirdFontPath* _tmp118_;
			GeeArrayList* _tmp119_;
			GeeArrayList* _tmp120_;
			gint _tmp121_;
			gint _tmp122_;
			BirdFontPath* _tmp128_;
			GeeArrayList* _tmp129_;
			GeeArrayList* _tmp130_;
			BirdFontPath* _tmp131_;
			GeeArrayList* _tmp132_;
			GeeArrayList* _tmp133_;
			gint _tmp134_;
			gint _tmp135_;
			gpointer _tmp136_;
			BirdFontEditPoint* _tmp137_;
			gboolean _tmp138_;
			BirdFontPath* _tmp140_;
			GeeArrayList* _tmp141_;
			GeeArrayList* _tmp142_;
			gint _tmp143_;
			gint _tmp144_;
			BirdFontPath* _tmp145_;
			GeeArrayList* _tmp146_;
			GeeArrayList* _tmp147_;
			gpointer _tmp148_;
			BirdFontEditPoint* _tmp149_;
			gboolean _tmp150_;
			_merge_index = _merge_index + 1;
			_tmp111_ = _merge_index;
			_tmp112_ = _merge_size;
			if (!(_tmp111_ < _tmp112_)) {
				break;
			}
			_tmp113_ = _merge_list;
			_tmp114_ = gee_abstract_list_get ((GeeAbstractList*) _tmp113_, _merge_index);
			merge = (BirdFontPath*) _tmp114_;
			_tmp115_ = path;
			_tmp116_ = merge;
			if (_tmp115_ == _tmp116_) {
				_g_object_unref0 (merge);
				continue;
			}
			_tmp118_ = merge;
			_tmp119_ = bird_font_path_get_points (_tmp118_);
			_tmp120_ = _tmp119_;
			_tmp121_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp120_);
			_tmp122_ = _tmp121_;
			if (_tmp122_ <= 1) {
				_tmp117_ = TRUE;
			} else {
				BirdFontPath* _tmp123_;
				GeeArrayList* _tmp124_;
				GeeArrayList* _tmp125_;
				gint _tmp126_;
				gint _tmp127_;
				_tmp123_ = path;
				_tmp124_ = bird_font_path_get_points (_tmp123_);
				_tmp125_ = _tmp124_;
				_tmp126_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp125_);
				_tmp127_ = _tmp126_;
				_tmp117_ = _tmp127_ <= 1;
			}
			if (_tmp117_) {
				_g_object_unref0 (merge);
				continue;
			}
			_tmp128_ = merge;
			_tmp129_ = bird_font_path_get_points (_tmp128_);
			_tmp130_ = _tmp129_;
			_tmp131_ = merge;
			_tmp132_ = bird_font_path_get_points (_tmp131_);
			_tmp133_ = _tmp132_;
			_tmp134_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp133_);
			_tmp135_ = _tmp134_;
			_tmp136_ = gee_abstract_list_get ((GeeAbstractList*) _tmp130_, _tmp135_ - 1);
			_tmp137_ = (BirdFontEditPoint*) _tmp136_;
			_tmp138_ = bird_font_pen_tool_is_close_to_point (_tmp137_, (gdouble) px, (gdouble) py);
			_g_object_unref0 (_tmp137_);
			if (_tmp138_) {
				BirdFontPath* _tmp139_;
				_tmp139_ = merge;
				bird_font_path_reverse (_tmp139_);
				bird_font_pen_tool_update_selection ();
				direction_changed = !direction_changed;
			}
			_tmp140_ = merge;
			_tmp141_ = bird_font_path_get_points (_tmp140_);
			_tmp142_ = _tmp141_;
			_tmp143_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp142_);
			_tmp144_ = _tmp143_;
			g_return_val_if_fail (_tmp144_ > 0, NULL);
			_tmp145_ = merge;
			_tmp146_ = bird_font_path_get_points (_tmp145_);
			_tmp147_ = _tmp146_;
			_tmp148_ = gee_abstract_list_get ((GeeAbstractList*) _tmp147_, 0);
			_tmp149_ = (BirdFontEditPoint*) _tmp148_;
			_tmp150_ = bird_font_pen_tool_is_close_to_point (_tmp149_, (gdouble) px, (gdouble) py);
			_g_object_unref0 (_tmp149_);
			if (_tmp150_) {
				BirdFontPath* _tmp151_;
				GeeArrayList* _tmp152_;
				GeeArrayList* _tmp153_;
				gint _tmp154_;
				gint _tmp155_;
				_tmp151_ = path;
				_tmp152_ = bird_font_path_get_points (_tmp151_);
				_tmp153_ = _tmp152_;
				_tmp154_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp153_);
				_tmp155_ = _tmp154_;
				if (_tmp155_ == 1) {
					g_warning ("PenTool.vala:1488: path.points.size == 1\n");
				} else {
					BirdFontPath* _tmp156_;
					GeeArrayList* _tmp157_;
					GeeArrayList* _tmp158_;
					gint _tmp159_;
					gint _tmp160_;
					_tmp156_ = merge;
					_tmp157_ = bird_font_path_get_points (_tmp156_);
					_tmp158_ = _tmp157_;
					_tmp159_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp158_);
					_tmp160_ = _tmp159_;
					if (_tmp160_ == 1) {
						g_warning ("PenTool.vala:1490: merge.points.size == 1\n");
					} else {
						BirdFontPath* _tmp161_;
						BirdFontPath* _tmp162_;
						BirdFontPath* _tmp163_;
						BirdFontGlyph* _tmp164_;
						BirdFontPath* _tmp165_;
						BirdFontGlyph* _tmp166_;
						BirdFontPath* _tmp167_;
						BirdFontGlyph* _tmp168_;
						BirdFontPath* _tmp169_;
						BirdFontGlyph* _tmp170_;
						BirdFontGlyph* _tmp171_;
						BirdFontPath* _tmp172_;
						BirdFontPath* _tmp173_;
						BirdFontPath* _tmp174_;
						BirdFontPath* _tmp176_;
						_tmp161_ = path;
						_tmp162_ = merge;
						_tmp163_ = bird_font_pen_tool_merge_open_paths (_tmp161_, _tmp162_);
						_g_object_unref0 (_union_);
						_union_ = _tmp163_;
						_tmp164_ = glyph;
						_tmp165_ = _union_;
						bird_font_glyph_add_path (_tmp164_, _tmp165_);
						_tmp166_ = glyph;
						_tmp167_ = path;
						bird_font_glyph_delete_path (_tmp166_, _tmp167_);
						_tmp168_ = glyph;
						_tmp169_ = merge;
						bird_font_glyph_delete_path (_tmp168_, _tmp169_);
						_tmp170_ = glyph;
						bird_font_glyph_clear_active_paths (_tmp170_);
						_tmp171_ = glyph;
						_tmp172_ = _union_;
						bird_font_glyph_add_active_path (_tmp171_, NULL, _tmp172_);
						_tmp173_ = _union_;
						bird_font_path_reopen (_tmp173_);
						_tmp174_ = _union_;
						bird_font_path_create_list (_tmp174_);
						bird_font_pen_tool_force_direction ();
						if (direction_changed) {
							BirdFontPath* _tmp175_;
							_tmp175_ = path;
							bird_font_path_reverse (_tmp175_);
							bird_font_pen_tool_update_selection ();
						}
						_tmp176_ = _union_;
						bird_font_path_update_region_boundaries (_tmp176_);
						result = _union_;
						_g_object_unref0 (merge);
						_g_object_unref0 (paths);
						_g_object_unref0 (path);
						_g_object_unref0 (p);
						_g_object_unref0 (glyph);
						return result;
					}
				}
			}
			_g_object_unref0 (merge);
		}
	}
	if (direction_changed) {
		BirdFontPath* _tmp177_;
		_tmp177_ = path;
		bird_font_path_reverse (_tmp177_);
		bird_font_pen_tool_update_selection ();
	}
	g_warning ("PenTool.vala:1522: No paths merged.");
	result = NULL;
	_g_object_unref0 (paths);
	_g_object_unref0 (_union_);
	_g_object_unref0 (path);
	_g_object_unref0 (p);
	_g_object_unref0 (glyph);
	return result;
}

/** Merge paths if ends are close. */
gboolean
bird_font_pen_tool_is_close_to_point (BirdFontEditPoint* ep,
                                      gdouble x,
                                      gdouble y)
{
	gdouble px = 0.0;
	gdouble py = 0.0;
	gdouble distance = 0.0;
	gboolean result;
	g_return_val_if_fail (ep != NULL, FALSE);
	px = (gdouble) bird_font_glyph_reverse_path_coordinate_x (ep->x);
	py = (gdouble) bird_font_glyph_reverse_path_coordinate_y (ep->y);
	distance = sqrt (fabs (pow (px - x, (gdouble) 2)) + fabs (pow (py - y, (gdouble) 2)));
	result = distance < ((gdouble) 7);
	return result;
}

/** Show the user that curves will be merged on release. */
void
bird_font_pen_tool_draw_on_canvas (BirdFontPenTool* self,
                                   cairo_t* cr,
                                   BirdFontGlyph* glyph)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (cr != NULL);
	g_return_if_fail (glyph != NULL);
	if (bird_font_pen_tool_show_selection_box) {
		bird_font_pen_tool_draw_selection_box (self, cr);
	}
	if (bird_font_pen_tool_point_selection_image) {
		bird_font_pen_tool_draw_point_selection_circle (self, cr);
	}
	bird_font_pen_tool_draw_merge_icon (self, cr);
}

/** Higlight the selected point on Android. */
static void
bird_font_pen_tool_draw_point_selection_circle (BirdFontPenTool* self,
                                                cairo_t* cr)
{
	BirdFontPointSelection* ps = NULL;
	BirdFontEditPointHandle* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (cr != NULL);
	_tmp0_ = bird_font_pen_tool_active_handle;
	if (_tmp0_->active) {
		BirdFontColor* _tmp1_;
		BirdFontColor* _tmp2_;
		_tmp1_ = bird_font_theme_get_color ("Active Handle");
		_tmp2_ = _tmp1_;
		bird_font_path_draw_control_point (cr, bird_font_glyph_path_coordinate_x ((gdouble) bird_font_pen_tool_begin_action_x), bird_font_glyph_path_coordinate_y ((gdouble) bird_font_pen_tool_begin_action_y), _tmp2_, 3.5);
		_bird_font_color_unref0 (_tmp2_);
	} else {
		GeeArrayList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		_tmp3_ = bird_font_pen_tool_selected_points;
		_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
		_tmp5_ = _tmp4_;
		if (_tmp5_ > 0) {
			GeeArrayList* _tmp6_;
			GeeArrayList* _tmp7_;
			gint _tmp8_;
			gint _tmp9_;
			gpointer _tmp10_;
			BirdFontPointSelection* _tmp11_;
			BirdFontEditPoint* _tmp12_;
			_tmp6_ = bird_font_pen_tool_selected_points;
			_tmp7_ = bird_font_pen_tool_selected_points;
			_tmp8_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp7_);
			_tmp9_ = _tmp8_;
			_tmp10_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _tmp9_ - 1);
			_g_object_unref0 (ps);
			ps = (BirdFontPointSelection*) _tmp10_;
			_tmp11_ = ps;
			_tmp12_ = _tmp11_->point;
			if (_tmp12_->type == BIRD_FONT_POINT_TYPE_CUBIC) {
				BirdFontColor* _tmp13_;
				BirdFontColor* _tmp14_;
				_tmp13_ = bird_font_theme_get_color ("Selected Cubic Control Point");
				_tmp14_ = _tmp13_;
				bird_font_path_draw_control_point (cr, bird_font_glyph_path_coordinate_x ((gdouble) bird_font_pen_tool_begin_action_x), bird_font_glyph_path_coordinate_y ((gdouble) bird_font_pen_tool_begin_action_y), _tmp14_, 3.5);
				_bird_font_color_unref0 (_tmp14_);
			} else {
				BirdFontColor* _tmp15_;
				BirdFontColor* _tmp16_;
				_tmp15_ = bird_font_theme_get_color ("Selected Quadratic Control Point");
				_tmp16_ = _tmp15_;
				bird_font_path_draw_control_point (cr, bird_font_glyph_path_coordinate_x ((gdouble) bird_font_pen_tool_begin_action_x), bird_font_glyph_path_coordinate_y ((gdouble) bird_font_pen_tool_begin_action_y), _tmp16_, 3.5);
				_bird_font_color_unref0 (_tmp16_);
			}
		}
	}
	_g_object_unref0 (ps);
}

static void
bird_font_pen_tool_draw_selection_box (BirdFontPenTool* self,
                                       cairo_t* cr)
{
	gdouble x = 0.0;
	gdouble y = 0.0;
	gdouble w = 0.0;
	gdouble h = 0.0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (cr != NULL);
	x = fmin (bird_font_pen_tool_selection_box_x, bird_font_pen_tool_selection_box_last_x);
	y = fmin (bird_font_pen_tool_selection_box_y, bird_font_pen_tool_selection_box_last_y);
	w = fmax (bird_font_pen_tool_selection_box_x, bird_font_pen_tool_selection_box_last_x) - x;
	h = fmax (bird_font_pen_tool_selection_box_y, bird_font_pen_tool_selection_box_last_y) - y;
	cairo_save (cr);
	bird_font_theme_color (cr, "Foreground 1");
	cairo_set_line_width (cr, (gdouble) 2);
	cairo_rectangle (cr, x, y, w, h);
	cairo_stroke (cr);
	cairo_restore (cr);
}

void
bird_font_pen_tool_draw_join_icon (cairo_t* cr,
                                   gdouble x,
                                   gdouble y)
{
	g_return_if_fail (cr != NULL);
	cairo_save (cr);
	bird_font_theme_color (cr, "Merge");
	cairo_move_to (cr, x, y);
	cairo_arc (cr, x, y, (gdouble) 15, (gdouble) 0, 2 * G_PI);
	cairo_close_path (cr);
	cairo_fill (cr);
	cairo_restore (cr);
}

static void
bird_font_pen_tool_draw_merge_icon (BirdFontPenTool* self,
                                    cairo_t* cr)
{
	gdouble x = 0.0;
	gdouble y = 0.0;
	BirdFontEditPoint* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (cr != NULL);
	_tmp0_ = bird_font_pen_tool_active_edit_point;
	if (_tmp0_ != NULL) {
		BirdFontEditPoint* _tmp1_;
		gdouble _tmp2_ = 0.0;
		gdouble _tmp3_ = 0.0;
		_tmp1_ = bird_font_pen_tool_active_edit_point;
		bird_font_pen_tool_get_tie_position (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, BIRD_FONT_TYPE_EDIT_POINT, BirdFontEditPoint), &_tmp2_, &_tmp3_);
		x = _tmp2_;
		y = _tmp3_;
		bird_font_pen_tool_draw_join_icon (cr, x, y);
	}
}

/** Obtain the position where to ends meet. */
static void
bird_font_pen_tool_get_tie_position (BirdFontEditPoint* current_point,
                                     gdouble* x,
                                     gdouble* y)
{
	gdouble _vala_x = 0.0;
	gdouble _vala_y = 0.0;
	BirdFontGlyph* glyph = NULL;
	BirdFontEditPoint* active = NULL;
	gdouble px = 0.0;
	gdouble py = 0.0;
	BirdFontGlyph* _tmp0_;
	BirdFontEditPoint* _tmp1_;
	BirdFontGlyph* _tmp2_;
	BirdFontEditPoint* _tmp3_;
	BirdFontEditPoint* _tmp4_;
	g_return_if_fail (current_point != NULL);
	_vala_x = (gdouble) -100;
	_vala_y = (gdouble) -100;
	if (!bird_font_pen_tool_is_endpoint (current_point)) {
		_g_object_unref0 (active);
		_g_object_unref0 (glyph);
		if (x) {
			*x = _vala_x;
		}
		if (y) {
			*y = _vala_y;
		}
		return;
	}
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	_g_object_unref0 (glyph);
	glyph = _tmp0_;
	_tmp1_ = _g_object_ref0 (current_point);
	_g_object_unref0 (active);
	active = _tmp1_;
	_tmp2_ = glyph;
	g_return_if_fail (!bird_font_is_null (_tmp2_));
	_tmp3_ = active;
	px = (gdouble) bird_font_glyph_reverse_path_coordinate_x (_tmp3_->x);
	_tmp4_ = active;
	py = (gdouble) bird_font_glyph_reverse_path_coordinate_y (_tmp4_->y);
	{
		GeeArrayList* _path_list = NULL;
		BirdFontGlyph* _tmp5_;
		GeeArrayList* _tmp6_;
		gint _path_size = 0;
		GeeArrayList* _tmp7_;
		gint _tmp8_;
		gint _tmp9_;
		gint _path_index = 0;
		_tmp5_ = glyph;
		_tmp6_ = bird_font_glyph_get_visible_paths (_tmp5_);
		_path_list = _tmp6_;
		_tmp7_ = _path_list;
		_tmp8_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp7_);
		_tmp9_ = _tmp8_;
		_path_size = _tmp9_;
		_path_index = -1;
		while (TRUE) {
			gint _tmp10_;
			gint _tmp11_;
			BirdFontPath* path = NULL;
			GeeArrayList* _tmp12_;
			gpointer _tmp13_;
			BirdFontPath* _tmp14_;
			BirdFontPath* _tmp15_;
			GeeArrayList* _tmp16_;
			GeeArrayList* _tmp17_;
			gint _tmp18_;
			gint _tmp19_;
			_path_index = _path_index + 1;
			_tmp10_ = _path_index;
			_tmp11_ = _path_size;
			if (!(_tmp10_ < _tmp11_)) {
				break;
			}
			_tmp12_ = _path_list;
			_tmp13_ = gee_abstract_list_get ((GeeAbstractList*) _tmp12_, _path_index);
			path = (BirdFontPath*) _tmp13_;
			_tmp14_ = path;
			if (!bird_font_path_is_open (_tmp14_)) {
				_g_object_unref0 (path);
				continue;
			}
			_tmp15_ = path;
			_tmp16_ = bird_font_path_get_points (_tmp15_);
			_tmp17_ = _tmp16_;
			_tmp18_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp17_);
			_tmp19_ = _tmp18_;
			if (_tmp19_ == 0) {
				_g_object_unref0 (path);
				continue;
			}
			{
				GeeArrayList* _ep_list = NULL;
				BirdFontPath* _tmp20_;
				GeeArrayList* _tmp21_;
				GeeArrayList* _tmp22_;
				gint _ep_size = 0;
				GeeArrayList* _tmp23_;
				gint _tmp24_;
				gint _tmp25_;
				gint _ep_index = 0;
				_tmp20_ = path;
				_tmp21_ = bird_font_path_get_points (_tmp20_);
				_tmp22_ = _tmp21_;
				_ep_list = _tmp22_;
				_tmp23_ = _ep_list;
				_tmp24_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp23_);
				_tmp25_ = _tmp24_;
				_ep_size = _tmp25_;
				_ep_index = -1;
				while (TRUE) {
					gint _tmp26_;
					gint _tmp27_;
					BirdFontEditPoint* ep = NULL;
					GeeArrayList* _tmp28_;
					gpointer _tmp29_;
					gboolean _tmp30_ = FALSE;
					BirdFontEditPoint* _tmp31_;
					BirdFontEditPoint* _tmp32_;
					BirdFontEditPoint* _tmp34_;
					_ep_index = _ep_index + 1;
					_tmp26_ = _ep_index;
					_tmp27_ = _ep_size;
					if (!(_tmp26_ < _tmp27_)) {
						break;
					}
					_tmp28_ = _ep_list;
					_tmp29_ = gee_abstract_list_get ((GeeAbstractList*) _tmp28_, _ep_index);
					ep = (BirdFontEditPoint*) _tmp29_;
					_tmp31_ = ep;
					_tmp32_ = active;
					if (_tmp31_ == _tmp32_) {
						_tmp30_ = TRUE;
					} else {
						BirdFontEditPoint* _tmp33_;
						_tmp33_ = ep;
						_tmp30_ = !bird_font_pen_tool_is_endpoint (_tmp33_);
					}
					if (_tmp30_) {
						_g_object_unref0 (ep);
						continue;
					}
					_tmp34_ = ep;
					if (bird_font_pen_tool_is_close_to_point (_tmp34_, px, py)) {
						BirdFontEditPoint* _tmp35_;
						BirdFontEditPoint* _tmp36_;
						_tmp35_ = ep;
						_vala_x = (gdouble) bird_font_glyph_reverse_path_coordinate_x (_tmp35_->x);
						_tmp36_ = ep;
						_vala_y = (gdouble) bird_font_glyph_reverse_path_coordinate_y (_tmp36_->y);
						_g_object_unref0 (ep);
						_g_object_unref0 (path);
						_g_object_unref0 (_path_list);
						_g_object_unref0 (active);
						_g_object_unref0 (glyph);
						if (x) {
							*x = _vala_x;
						}
						if (y) {
							*y = _vala_y;
						}
						return;
					}
					_g_object_unref0 (ep);
				}
			}
			_g_object_unref0 (path);
		}
		_g_object_unref0 (_path_list);
	}
	_g_object_unref0 (active);
	_g_object_unref0 (glyph);
	if (x) {
		*x = _vala_x;
	}
	if (y) {
		*y = _vala_y;
	}
}

gboolean
bird_font_pen_tool_is_endpoint (BirdFontEditPoint* ep)
{
	BirdFontEditPoint* start = NULL;
	BirdFontEditPoint* end = NULL;
	BirdFontGlyph* glyph = NULL;
	BirdFontGlyph* _tmp0_;
	gboolean result;
	g_return_val_if_fail (ep != NULL, FALSE);
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	glyph = _tmp0_;
	{
		GeeArrayList* _path_list = NULL;
		BirdFontGlyph* _tmp1_;
		GeeArrayList* _tmp2_;
		gint _path_size = 0;
		GeeArrayList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		gint _path_index = 0;
		_tmp1_ = glyph;
		_tmp2_ = bird_font_glyph_get_visible_paths (_tmp1_);
		_path_list = _tmp2_;
		_tmp3_ = _path_list;
		_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
		_tmp5_ = _tmp4_;
		_path_size = _tmp5_;
		_path_index = -1;
		while (TRUE) {
			gint _tmp6_;
			gint _tmp7_;
			BirdFontPath* path = NULL;
			GeeArrayList* _tmp8_;
			gpointer _tmp9_;
			BirdFontPath* _tmp10_;
			GeeArrayList* _tmp11_;
			GeeArrayList* _tmp12_;
			gint _tmp13_;
			gint _tmp14_;
			BirdFontPath* _tmp15_;
			GeeArrayList* _tmp16_;
			GeeArrayList* _tmp17_;
			gpointer _tmp18_;
			BirdFontPath* _tmp19_;
			GeeArrayList* _tmp20_;
			GeeArrayList* _tmp21_;
			BirdFontPath* _tmp22_;
			GeeArrayList* _tmp23_;
			GeeArrayList* _tmp24_;
			gint _tmp25_;
			gint _tmp26_;
			gpointer _tmp27_;
			gboolean _tmp28_ = FALSE;
			BirdFontEditPoint* _tmp29_;
			_path_index = _path_index + 1;
			_tmp6_ = _path_index;
			_tmp7_ = _path_size;
			if (!(_tmp6_ < _tmp7_)) {
				break;
			}
			_tmp8_ = _path_list;
			_tmp9_ = gee_abstract_list_get ((GeeAbstractList*) _tmp8_, _path_index);
			path = (BirdFontPath*) _tmp9_;
			_tmp10_ = path;
			_tmp11_ = bird_font_path_get_points (_tmp10_);
			_tmp12_ = _tmp11_;
			_tmp13_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp12_);
			_tmp14_ = _tmp13_;
			if (_tmp14_ < 1) {
				_g_object_unref0 (path);
				continue;
			}
			_tmp15_ = path;
			_tmp16_ = bird_font_path_get_points (_tmp15_);
			_tmp17_ = _tmp16_;
			_tmp18_ = gee_abstract_list_get ((GeeAbstractList*) _tmp17_, 0);
			_g_object_unref0 (start);
			start = (BirdFontEditPoint*) _tmp18_;
			_tmp19_ = path;
			_tmp20_ = bird_font_path_get_points (_tmp19_);
			_tmp21_ = _tmp20_;
			_tmp22_ = path;
			_tmp23_ = bird_font_path_get_points (_tmp22_);
			_tmp24_ = _tmp23_;
			_tmp25_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp24_);
			_tmp26_ = _tmp25_;
			_tmp27_ = gee_abstract_list_get ((GeeAbstractList*) _tmp21_, _tmp26_ - 1);
			_g_object_unref0 (end);
			end = (BirdFontEditPoint*) _tmp27_;
			_tmp29_ = start;
			if (ep == _tmp29_) {
				_tmp28_ = TRUE;
			} else {
				BirdFontEditPoint* _tmp30_;
				_tmp30_ = end;
				_tmp28_ = ep == _tmp30_;
			}
			if (_tmp28_) {
				result = TRUE;
				_g_object_unref0 (path);
				_g_object_unref0 (_path_list);
				_g_object_unref0 (glyph);
				_g_object_unref0 (end);
				_g_object_unref0 (start);
				return result;
			}
			_g_object_unref0 (path);
		}
		_g_object_unref0 (_path_list);
	}
	result = FALSE;
	_g_object_unref0 (glyph);
	_g_object_unref0 (end);
	_g_object_unref0 (start);
	return result;
}

void
bird_font_pen_tool_set_active_edit_point (BirdFontEditPoint* e,
                                          BirdFontPath* path)
{
	gboolean redraw = FALSE;
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	BirdFontEditPoint* _tmp21_;
	BirdFontEditPoint* _tmp22_;
	BirdFontPath* _tmp23_;
	g_return_if_fail (path != NULL);
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	{
		GeeArrayList* _p_list = NULL;
		BirdFontGlyph* _tmp1_;
		GeeArrayList* _tmp2_;
		gint _p_size = 0;
		GeeArrayList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		gint _p_index = 0;
		_tmp1_ = g;
		_tmp2_ = bird_font_glyph_get_visible_paths (_tmp1_);
		_p_list = _tmp2_;
		_tmp3_ = _p_list;
		_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
		_tmp5_ = _tmp4_;
		_p_size = _tmp5_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp6_;
			gint _tmp7_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp8_;
			gpointer _tmp9_;
			_p_index = _p_index + 1;
			_tmp6_ = _p_index;
			_tmp7_ = _p_size;
			if (!(_tmp6_ < _tmp7_)) {
				break;
			}
			_tmp8_ = _p_list;
			_tmp9_ = gee_abstract_list_get ((GeeAbstractList*) _tmp8_, _p_index);
			p = (BirdFontPath*) _tmp9_;
			{
				GeeArrayList* _ep_list = NULL;
				BirdFontPath* _tmp10_;
				GeeArrayList* _tmp11_;
				GeeArrayList* _tmp12_;
				gint _ep_size = 0;
				GeeArrayList* _tmp13_;
				gint _tmp14_;
				gint _tmp15_;
				gint _ep_index = 0;
				_tmp10_ = p;
				_tmp11_ = bird_font_path_get_points (_tmp10_);
				_tmp12_ = _tmp11_;
				_ep_list = _tmp12_;
				_tmp13_ = _ep_list;
				_tmp14_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp13_);
				_tmp15_ = _tmp14_;
				_ep_size = _tmp15_;
				_ep_index = -1;
				while (TRUE) {
					gint _tmp16_;
					gint _tmp17_;
					BirdFontEditPoint* ep = NULL;
					GeeArrayList* _tmp18_;
					gpointer _tmp19_;
					BirdFontEditPoint* _tmp20_;
					_ep_index = _ep_index + 1;
					_tmp16_ = _ep_index;
					_tmp17_ = _ep_size;
					if (!(_tmp16_ < _tmp17_)) {
						break;
					}
					_tmp18_ = _ep_list;
					_tmp19_ = gee_abstract_list_get ((GeeAbstractList*) _tmp18_, _ep_index);
					ep = (BirdFontEditPoint*) _tmp19_;
					_tmp20_ = ep;
					bird_font_edit_point_set_active (_tmp20_, FALSE);
					_g_object_unref0 (ep);
				}
			}
			_g_object_unref0 (p);
		}
		_g_object_unref0 (_p_list);
	}
	_tmp21_ = bird_font_pen_tool_active_edit_point;
	redraw = _tmp21_ != e;
	_tmp22_ = _g_object_ref0 (e);
	_g_object_unref0 (bird_font_pen_tool_active_edit_point);
	bird_font_pen_tool_active_edit_point = _tmp22_;
	_tmp23_ = _g_object_ref0 (path);
	_g_object_unref0 (bird_font_pen_tool_active_path);
	bird_font_pen_tool_active_path = _tmp23_;
	if (e != NULL) {
		bird_font_edit_point_set_active (G_TYPE_CHECK_INSTANCE_CAST (e, BIRD_FONT_TYPE_EDIT_POINT, BirdFontEditPoint), TRUE);
	}
	if (redraw) {
		bird_font_glyph_canvas_redraw ();
	}
	_g_object_unref0 (g);
}

static BirdFontPointSelection*
bird_font_pen_tool_get_closest_point (BirdFontPenTool* self,
                                      gdouble ex,
                                      gdouble ey,
                                      BirdFontPath** path)
{
	BirdFontPath* _vala_path = NULL;
	gdouble x = 0.0;
	gdouble y = 0.0;
	gdouble d = 0.0;
	gdouble nd = 0.0;
	BirdFontPointSelection* ep = NULL;
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	BirdFontPointSelection* result;
	g_return_val_if_fail (self != NULL, NULL);
	x = bird_font_glyph_path_coordinate_x (ex);
	y = bird_font_glyph_path_coordinate_y (ey);
	d = DBL_MAX;
	ep = NULL;
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	_g_object_unref0 (_vala_path);
	_vala_path = NULL;
	{
		GeeArrayList* _current_path_list = NULL;
		BirdFontGlyph* _tmp1_;
		GeeArrayList* _tmp2_;
		gint _current_path_size = 0;
		GeeArrayList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		gint _current_path_index = 0;
		_tmp1_ = g;
		_tmp2_ = bird_font_glyph_get_paths_in_current_layer (_tmp1_);
		_current_path_list = _tmp2_;
		_tmp3_ = _current_path_list;
		_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
		_tmp5_ = _tmp4_;
		_current_path_size = _tmp5_;
		_current_path_index = -1;
		while (TRUE) {
			gint _tmp6_;
			gint _tmp7_;
			BirdFontPath* current_path = NULL;
			GeeArrayList* _tmp8_;
			gpointer _tmp9_;
			BirdFontPath* _tmp10_;
			_current_path_index = _current_path_index + 1;
			_tmp6_ = _current_path_index;
			_tmp7_ = _current_path_size;
			if (!(_tmp6_ < _tmp7_)) {
				break;
			}
			_tmp8_ = _current_path_list;
			_tmp9_ = gee_abstract_list_get ((GeeAbstractList*) _tmp8_, _current_path_index);
			current_path = (BirdFontPath*) _tmp9_;
			_tmp10_ = current_path;
			if (bird_font_pen_tool_is_close_to_path (self, _tmp10_, ex, ey)) {
				{
					GeeArrayList* _e_list = NULL;
					BirdFontPath* _tmp11_;
					GeeArrayList* _tmp12_;
					GeeArrayList* _tmp13_;
					gint _e_size = 0;
					GeeArrayList* _tmp14_;
					gint _tmp15_;
					gint _tmp16_;
					gint _e_index = 0;
					_tmp11_ = current_path;
					_tmp12_ = bird_font_path_get_points (_tmp11_);
					_tmp13_ = _tmp12_;
					_e_list = _tmp13_;
					_tmp14_ = _e_list;
					_tmp15_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp14_);
					_tmp16_ = _tmp15_;
					_e_size = _tmp16_;
					_e_index = -1;
					while (TRUE) {
						gint _tmp17_;
						gint _tmp18_;
						BirdFontEditPoint* e = NULL;
						GeeArrayList* _tmp19_;
						gpointer _tmp20_;
						BirdFontEditPoint* _tmp21_;
						_e_index = _e_index + 1;
						_tmp17_ = _e_index;
						_tmp18_ = _e_size;
						if (!(_tmp17_ < _tmp18_)) {
							break;
						}
						_tmp19_ = _e_list;
						_tmp20_ = gee_abstract_list_get ((GeeAbstractList*) _tmp19_, _e_index);
						e = (BirdFontEditPoint*) _tmp20_;
						_tmp21_ = e;
						nd = bird_font_edit_point_get_distance (_tmp21_, x, y);
						if (nd < d) {
							BirdFontEditPoint* _tmp22_;
							BirdFontPath* _tmp23_;
							BirdFontPointSelection* _tmp24_;
							BirdFontPath* _tmp25_;
							BirdFontPath* _tmp26_;
							d = nd;
							_tmp22_ = e;
							_tmp23_ = current_path;
							_tmp24_ = bird_font_point_selection_new (_tmp22_, _tmp23_);
							_g_object_unref0 (ep);
							ep = _tmp24_;
							_tmp25_ = current_path;
							_tmp26_ = _g_object_ref0 (_tmp25_);
							_g_object_unref0 (_vala_path);
							_vala_path = _tmp26_;
						}
						_g_object_unref0 (e);
					}
				}
			}
			_g_object_unref0 (current_path);
		}
		_g_object_unref0 (_current_path_list);
	}
	result = ep;
	_g_object_unref0 (g);
	if (path) {
		*path = _vala_path;
	} else {
		_g_object_unref0 (_vala_path);
	}
	return result;
}

gdouble
bird_font_pen_tool_get_distance_to_closest_edit_point (BirdFontPenTool* self,
                                                       gdouble event_x,
                                                       gdouble event_y)
{
	BirdFontPath* p = NULL;
	BirdFontPointSelection* e = NULL;
	BirdFontPointSelection* ep = NULL;
	BirdFontPath* _tmp0_ = NULL;
	BirdFontPointSelection* _tmp1_;
	gdouble x = 0.0;
	gdouble y = 0.0;
	BirdFontPointSelection* _tmp2_;
	BirdFontPointSelection* _tmp3_;
	BirdFontPointSelection* _tmp4_;
	BirdFontPointSelection* _tmp5_;
	BirdFontEditPoint* _tmp6_;
	gdouble result;
	g_return_val_if_fail (self != NULL, 0.0);
	_tmp1_ = bird_font_pen_tool_get_closest_point (self, event_x, event_y, &_tmp0_);
	_g_object_unref0 (p);
	p = _tmp0_;
	ep = _tmp1_;
	x = bird_font_glyph_path_coordinate_x (event_x);
	y = bird_font_glyph_path_coordinate_y (event_y);
	_tmp2_ = ep;
	if (_tmp2_ == NULL) {
		result = DBL_MAX;
		_g_object_unref0 (ep);
		_g_object_unref0 (e);
		_g_object_unref0 (p);
		return result;
	}
	_tmp3_ = ep;
	_tmp4_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, BIRD_FONT_TYPE_POINT_SELECTION, BirdFontPointSelection));
	_g_object_unref0 (e);
	e = _tmp4_;
	_tmp5_ = e;
	_tmp6_ = _tmp5_->point;
	result = bird_font_edit_point_get_distance (_tmp6_, x, y);
	_g_object_unref0 (ep);
	_g_object_unref0 (e);
	_g_object_unref0 (p);
	return result;
}

void
bird_font_pen_tool_control_point_event (BirdFontPenTool* self,
                                        gdouble event_x,
                                        gdouble event_y,
                                        gboolean reset_active_point)
{
	BirdFontPath* p = NULL;
	BirdFontPointSelection* ep = NULL;
	BirdFontPath* _tmp0_ = NULL;
	BirdFontPointSelection* _tmp1_;
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp2_;
	gdouble x = 0.0;
	gdouble y = 0.0;
	gdouble distance = 0.0;
	BirdFontPointSelection* e = NULL;
	BirdFontPointSelection* _tmp5_;
	BirdFontPointSelection* _tmp6_;
	BirdFontPointSelection* _tmp7_;
	BirdFontPointSelection* _tmp8_;
	BirdFontEditPoint* _tmp9_;
	BirdFontGlyph* _tmp10_;
	gdouble _tmp11_;
	gdouble _tmp12_;
	g_return_if_fail (self != NULL);
	_tmp1_ = bird_font_pen_tool_get_closest_point (self, event_x, event_y, &_tmp0_);
	_g_object_unref0 (p);
	p = _tmp0_;
	ep = _tmp1_;
	_tmp2_ = bird_font_main_window_get_current_glyph ();
	g = _tmp2_;
	x = bird_font_glyph_path_coordinate_x (event_x);
	y = bird_font_glyph_path_coordinate_y (event_y);
	if (reset_active_point) {
		BirdFontPath* _tmp3_;
		BirdFontPath* _tmp4_;
		_tmp3_ = bird_font_path_new ();
		_tmp4_ = _tmp3_;
		bird_font_pen_tool_set_active_edit_point (NULL, _tmp4_);
		_g_object_unref0 (_tmp4_);
	}
	_tmp5_ = ep;
	if (_tmp5_ == NULL) {
		_g_object_unref0 (e);
		_g_object_unref0 (g);
		_g_object_unref0 (ep);
		_g_object_unref0 (p);
		return;
	}
	_tmp6_ = ep;
	_tmp7_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp6_, BIRD_FONT_TYPE_POINT_SELECTION, BirdFontPointSelection));
	_g_object_unref0 (e);
	e = _tmp7_;
	_tmp8_ = e;
	_tmp9_ = _tmp8_->point;
	_tmp10_ = g;
	distance = bird_font_edit_point_get_distance (_tmp9_, x, y) * _tmp10_->view_zoom;
	_tmp11_ = bird_font_pen_tool_get_contact_surface ();
	_tmp12_ = _tmp11_;
	if (distance < _tmp12_) {
		BirdFontPointSelection* _tmp13_;
		BirdFontEditPoint* _tmp14_;
		BirdFontPointSelection* _tmp15_;
		BirdFontPath* _tmp16_;
		_tmp13_ = e;
		_tmp14_ = _tmp13_->point;
		_tmp15_ = e;
		_tmp16_ = _tmp15_->path;
		bird_font_pen_tool_set_active_edit_point (_tmp14_, _tmp16_);
	}
	_g_object_unref0 (e);
	_g_object_unref0 (g);
	_g_object_unref0 (ep);
	_g_object_unref0 (p);
}

BirdFontPointSelection*
bird_font_pen_tool_new_point_action (BirdFontPenTool* self,
                                     gint x,
                                     gint y)
{
	BirdFontGlyph* glyph = NULL;
	BirdFontPointSelection* new_point = NULL;
	BirdFontGlyph* _tmp0_;
	BirdFontPointSelection* _tmp1_;
	BirdFontEditPoint* _tmp2_;
	BirdFontEditPoint* _tmp3_;
	BirdFontEditPoint* _tmp4_;
	BirdFontEditPoint* _tmp5_;
	BirdFontEditPoint* _tmp6_;
	GeeArrayList* _tmp7_;
	gint _tmp8_;
	gint _tmp9_;
	BirdFontPointSelection* _tmp10_;
	BirdFontPointSelection* _tmp11_;
	BirdFontEditPoint* _tmp12_;
	GeeArrayList* _tmp13_;
	GeeArrayList* _tmp14_;
	gint _tmp15_;
	gint _tmp16_;
	gpointer _tmp17_;
	BirdFontPath* _tmp18_;
	BirdFontPath* _tmp19_;
	BirdFontPath* _tmp20_;
	BirdFontPath* _tmp21_;
	BirdFontPointSelection* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	_g_object_unref0 (glyph);
	glyph = _tmp0_;
	bird_font_glyph_open_path (glyph);
	bird_font_pen_tool_remove_all_selected_points ();
	_tmp1_ = bird_font_pen_tool_add_new_edit_point (x, y);
	_g_object_unref0 (new_point);
	new_point = _tmp1_;
	_tmp2_ = new_point->point;
	bird_font_edit_point_set_selected (_tmp2_, TRUE);
	_tmp3_ = new_point->point;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	_g_object_unref0 (bird_font_pen_tool_selected_point);
	bird_font_pen_tool_selected_point = _tmp4_;
	_tmp5_ = new_point->point;
	_tmp6_ = _g_object_ref0 (_tmp5_);
	_g_object_unref0 (bird_font_pen_tool_active_edit_point);
	bird_font_pen_tool_active_edit_point = _tmp6_;
	_tmp7_ = glyph->active_paths;
	_tmp8_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = bird_font_point_selection_new_empty ();
	_tmp11_ = _tmp10_;
	g_return_val_if_fail (_tmp9_ > 0, _tmp11_);
	_g_object_unref0 (_tmp11_);
	_tmp12_ = bird_font_pen_tool_selected_point;
	_tmp13_ = glyph->active_paths;
	_tmp14_ = glyph->active_paths;
	_tmp15_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp14_);
	_tmp16_ = _tmp15_;
	_tmp17_ = gee_abstract_list_get ((GeeAbstractList*) _tmp13_, _tmp16_ - 1);
	_tmp18_ = (BirdFontPath*) _tmp17_;
	bird_font_pen_tool_add_selected_point (_tmp12_, _tmp18_);
	_g_object_unref0 (_tmp18_);
	_tmp19_ = new_point->path;
	_tmp20_ = _g_object_ref0 (_tmp19_);
	_g_object_unref0 (bird_font_pen_tool_active_path);
	bird_font_pen_tool_active_path = _tmp20_;
	bird_font_glyph_clear_active_paths (glyph);
	_tmp21_ = new_point->path;
	bird_font_glyph_add_active_path (glyph, NULL, _tmp21_);
	bird_font_pen_tool_move_selected = TRUE;
	result = new_point;
	_g_object_unref0 (glyph);
	return result;
}

BirdFontPointSelection*
bird_font_pen_tool_add_new_edit_point (gint x,
                                       gint y)
{
	BirdFontPointSelection* new_point = NULL;
	BirdFontPointSelection* _tmp0_;
	BirdFontPointSelection* _tmp1_;
	BirdFontPath* _tmp2_;
	gboolean _tmp3_ = FALSE;
	BirdFontPointSelection* _tmp4_;
	BirdFontPath* _tmp5_;
	BirdFontPointSelection* _tmp28_;
	BirdFontEditPoint* _tmp29_;
	BirdFontEditPoint* _tmp30_;
	BirdFontPointSelection* _tmp31_;
	BirdFontEditPoint* _tmp32_;
	BirdFontEditPoint* _tmp33_;
	BirdFontEditPoint* _tmp34_;
	GeeArrayList* _tmp35_;
	BirdFontPointSelection* _tmp36_;
	BirdFontEditPoint* _tmp37_;
	BirdFontPointSelection* _tmp38_;
	BirdFontPath* _tmp39_;
	BirdFontPointSelection* result;
	_tmp0_ = bird_font_pen_tool_insert_edit_point ((gdouble) x, (gdouble) y);
	_g_object_unref0 (new_point);
	new_point = _tmp0_;
	_tmp1_ = new_point;
	_tmp2_ = _tmp1_->path;
	bird_font_path_update_region_boundaries (_tmp2_);
	_tmp4_ = new_point;
	_tmp5_ = _tmp4_->path;
	if (bird_font_path_is_open (_tmp5_)) {
		BirdFontPointSelection* _tmp6_;
		BirdFontPath* _tmp7_;
		GeeArrayList* _tmp8_;
		GeeArrayList* _tmp9_;
		gint _tmp10_;
		gint _tmp11_;
		_tmp6_ = new_point;
		_tmp7_ = _tmp6_->path;
		_tmp8_ = bird_font_path_get_points (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp10_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp9_);
		_tmp11_ = _tmp10_;
		_tmp3_ = _tmp11_ > 0;
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		BirdFontPointSelection* _tmp12_;
		BirdFontPath* _tmp13_;
		BirdFontEditPoint* _tmp14_;
		BirdFontEditPoint* _tmp15_;
		BirdFontPointSelection* _tmp16_;
		BirdFontPath* _tmp17_;
		BirdFontEditPoint* _tmp18_;
		BirdFontEditPoint* _tmp19_;
		BirdFontPointSelection* _tmp20_;
		BirdFontPath* _tmp21_;
		BirdFontEditPoint* _tmp22_;
		BirdFontEditPoint* _tmp23_;
		BirdFontPointSelection* _tmp24_;
		BirdFontPath* _tmp25_;
		BirdFontEditPoint* _tmp26_;
		BirdFontEditPoint* _tmp27_;
		_tmp12_ = new_point;
		_tmp13_ = _tmp12_->path;
		_tmp14_ = bird_font_path_get_first_point (_tmp13_);
		_tmp15_ = _tmp14_;
		bird_font_edit_point_set_reflective_handles (_tmp15_, FALSE);
		_g_object_unref0 (_tmp15_);
		_tmp16_ = new_point;
		_tmp17_ = _tmp16_->path;
		_tmp18_ = bird_font_path_get_first_point (_tmp17_);
		_tmp19_ = _tmp18_;
		bird_font_edit_point_set_tie_handle (_tmp19_, FALSE);
		_g_object_unref0 (_tmp19_);
		_tmp20_ = new_point;
		_tmp21_ = _tmp20_->path;
		_tmp22_ = bird_font_path_get_last_point (_tmp21_);
		_tmp23_ = _tmp22_;
		bird_font_edit_point_set_reflective_handles (_tmp23_, FALSE);
		_g_object_unref0 (_tmp23_);
		_tmp24_ = new_point;
		_tmp25_ = _tmp24_->path;
		_tmp26_ = bird_font_path_get_last_point (_tmp25_);
		_tmp27_ = _tmp26_;
		bird_font_edit_point_set_tie_handle (_tmp27_, FALSE);
		_g_object_unref0 (_tmp27_);
	}
	_tmp28_ = new_point;
	_tmp29_ = _tmp28_->point;
	_tmp30_ = _g_object_ref0 (_tmp29_);
	_g_object_unref0 (bird_font_pen_tool_selected_point);
	bird_font_pen_tool_selected_point = _tmp30_;
	_tmp31_ = new_point;
	_tmp32_ = _tmp31_->point;
	_tmp33_ = _g_object_ref0 (_tmp32_);
	_g_object_unref0 (bird_font_pen_tool_active_edit_point);
	bird_font_pen_tool_active_edit_point = _tmp33_;
	_tmp34_ = bird_font_pen_tool_selected_point;
	bird_font_pen_tool_set_point_type (_tmp34_);
	bird_font_pen_tool_set_default_handle_positions ();
	_tmp35_ = bird_font_pen_tool_selected_points;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp35_);
	_tmp36_ = new_point;
	_tmp37_ = _tmp36_->point;
	_tmp38_ = new_point;
	_tmp39_ = _tmp38_->path;
	bird_font_pen_tool_add_selected_point (_tmp37_, _tmp39_);
	result = new_point;
	return result;
}

static BirdFontPointSelection*
bird_font_pen_tool_insert_edit_point (gdouble x,
                                      gdouble y)
{
	gdouble xt = 0.0;
	gdouble yt = 0.0;
	BirdFontPath* np = NULL;
	BirdFontEditPoint* inserted = NULL;
	gboolean stroke = FALSE;
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	BirdFontGlyph* _tmp1_;
	GeeArrayList* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	BirdFontPath* _tmp17_;
	BirdFontGlyph* _tmp35_;
	BirdFontGlyph* _tmp36_;
	BirdFontPath* _tmp37_;
	BirdFontPath* _tmp38_;
	BirdFontPath* _tmp39_;
	BirdFontPath* _tmp40_;
	BirdFontPath* _tmp41_;
	BirdFontPath* _tmp42_;
	GeeArrayList* _tmp43_;
	GeeArrayList* _tmp44_;
	BirdFontPath* _tmp45_;
	GeeArrayList* _tmp46_;
	GeeArrayList* _tmp47_;
	gint _tmp48_;
	gint _tmp49_;
	gpointer _tmp50_;
	BirdFontPath* _tmp51_;
	BirdFontPointSelection* _tmp52_;
	BirdFontPointSelection* result;
	stroke = bird_font_stroke_tool_add_stroke;
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	_tmp1_ = g;
	_tmp2_ = _tmp1_->active_paths;
	_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
	_tmp4_ = _tmp3_;
	if (_tmp4_ == 0) {
		BirdFontPath* _tmp5_;
		BirdFontGlyph* _tmp6_;
		BirdFontPath* _tmp7_;
		gdouble _tmp8_ = 0.0;
		BirdFontPath* _tmp9_;
		BirdFontPath* _tmp10_;
		BirdFontGlyph* _tmp11_;
		BirdFontPath* _tmp12_;
		BirdFontPath* _tmp13_;
		BirdFontPath* _tmp14_;
		BirdFontPath* _tmp15_;
		BirdFontPath* _tmp16_;
		_tmp5_ = bird_font_path_new ();
		_g_object_unref0 (np);
		np = _tmp5_;
		_tmp6_ = g;
		_tmp7_ = np;
		bird_font_glyph_add_path (_tmp6_, _tmp7_);
		if (stroke) {
			_tmp8_ = bird_font_stroke_tool_stroke_width;
		} else {
			_tmp8_ = (gdouble) 0;
		}
		_tmp9_ = np;
		bird_font_path_set_stroke (_tmp9_, _tmp8_);
		_tmp10_ = np;
		_tmp10_->line_cap = bird_font_stroke_tool_line_cap;
		_tmp11_ = g;
		_tmp12_ = np;
		bird_font_glyph_add_active_path (_tmp11_, NULL, _tmp12_);
		_tmp13_ = np;
		_tmp14_ = _g_object_ref0 (_tmp13_);
		_g_object_unref0 (bird_font_pen_tool_active_path);
		bird_font_pen_tool_active_path = _tmp14_;
		_tmp15_ = np;
		_tmp16_ = _g_object_ref0 (_tmp15_);
		_g_object_unref0 (bird_font_pen_tool_selected_path);
		bird_font_pen_tool_selected_path = _tmp16_;
	}
	xt = bird_font_glyph_path_coordinate_x (x);
	yt = bird_font_glyph_path_coordinate_y (y);
	_tmp17_ = bird_font_pen_tool_selected_path;
	if (bird_font_path_is_open (_tmp17_)) {
		BirdFontPath* _tmp18_;
		BirdFontPath* _tmp19_;
		BirdFontPath* _tmp20_;
		BirdFontEditPoint* _tmp21_;
		BirdFontEditPoint* _tmp22_;
		_tmp18_ = bird_font_pen_tool_selected_path;
		_tmp19_ = _g_object_ref0 (_tmp18_);
		_g_object_unref0 (np);
		np = _tmp19_;
		_tmp20_ = np;
		_tmp21_ = bird_font_path_add (_tmp20_, xt, yt);
		_tmp22_ = _tmp21_;
		_g_object_unref0 (_tmp22_);
	} else {
		BirdFontPath* _tmp23_;
		gdouble _tmp24_ = 0.0;
		BirdFontPath* _tmp25_;
		BirdFontGlyph* _tmp26_;
		BirdFontPath* _tmp27_;
		BirdFontPath* _tmp28_;
		BirdFontEditPoint* _tmp29_;
		BirdFontEditPoint* _tmp30_;
		BirdFontPenTool* _tmp31_;
		BirdFontPath* _tmp33_;
		BirdFontPath* _tmp34_;
		_tmp23_ = bird_font_path_new ();
		_g_object_unref0 (np);
		np = _tmp23_;
		if (stroke) {
			_tmp24_ = bird_font_stroke_tool_stroke_width;
		} else {
			_tmp24_ = (gdouble) 0;
		}
		_tmp25_ = np;
		bird_font_path_set_stroke (_tmp25_, _tmp24_);
		_tmp26_ = g;
		_tmp27_ = np;
		bird_font_glyph_add_path (_tmp26_, _tmp27_);
		_tmp28_ = np;
		_tmp29_ = bird_font_path_add (_tmp28_, xt, yt);
		_tmp30_ = _tmp29_;
		_g_object_unref0 (_tmp30_);
		_tmp31_ = bird_font_drawing_tools_pen_tool;
		if (bird_font_tool_is_selected ((BirdFontTool*) _tmp31_)) {
			BirdFontPath* _tmp32_;
			_tmp32_ = np;
			bird_font_path_set_stroke (_tmp32_, bird_font_pen_tool_path_stroke_width);
		}
		_tmp33_ = np;
		_tmp34_ = _g_object_ref0 (_tmp33_);
		_g_object_unref0 (bird_font_pen_tool_active_path);
		bird_font_pen_tool_active_path = _tmp34_;
	}
	_tmp35_ = g;
	bird_font_glyph_clear_active_paths (_tmp35_);
	_tmp36_ = g;
	_tmp37_ = np;
	bird_font_glyph_add_active_path (_tmp36_, NULL, _tmp37_);
	_tmp38_ = np;
	_tmp39_ = _g_object_ref0 (_tmp38_);
	_g_object_unref0 (bird_font_pen_tool_active_path);
	bird_font_pen_tool_active_path = _tmp39_;
	_tmp40_ = np;
	_tmp41_ = _g_object_ref0 (_tmp40_);
	_g_object_unref0 (bird_font_pen_tool_selected_path);
	bird_font_pen_tool_selected_path = _tmp41_;
	_tmp42_ = np;
	_tmp43_ = bird_font_path_get_points (_tmp42_);
	_tmp44_ = _tmp43_;
	_tmp45_ = np;
	_tmp46_ = bird_font_path_get_points (_tmp45_);
	_tmp47_ = _tmp46_;
	_tmp48_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp47_);
	_tmp49_ = _tmp48_;
	_tmp50_ = gee_abstract_list_get ((GeeAbstractList*) _tmp44_, _tmp49_ - 1);
	_g_object_unref0 (inserted);
	inserted = (BirdFontEditPoint*) _tmp50_;
	_tmp51_ = np;
	_tmp52_ = bird_font_point_selection_new (inserted, _tmp51_);
	result = _tmp52_;
	_g_object_unref0 (g);
	_g_object_unref0 (inserted);
	_g_object_unref0 (np);
	return result;
}

static void
bird_font_pen_tool_set_point_type (BirdFontEditPoint* p)
{
	gboolean _tmp0_ = FALSE;
	BirdFontEditPoint* _tmp1_;
	g_return_if_fail (p != NULL);
	_tmp1_ = p->prev;
	if (_tmp1_ != NULL) {
		BirdFontEditPoint* _tmp2_;
		BirdFontEditPointHandle* _tmp3_;
		_tmp2_ = bird_font_edit_point_get_prev (p);
		_tmp3_ = _tmp2_->right_handle;
		_tmp0_ = _tmp3_->type == BIRD_FONT_POINT_TYPE_QUADRATIC;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		BirdFontEditPointHandle* _tmp4_;
		BirdFontEditPointHandle* _tmp5_;
		_tmp4_ = p->left_handle;
		_tmp4_->type = BIRD_FONT_POINT_TYPE_QUADRATIC;
		_tmp5_ = p->right_handle;
		_tmp5_->type = BIRD_FONT_POINT_TYPE_LINE_QUADRATIC;
		p->type = BIRD_FONT_POINT_TYPE_QUADRATIC;
	} else {
		if (bird_font_drawing_tools_get_selected_point_type () == BIRD_FONT_POINT_TYPE_QUADRATIC) {
			BirdFontEditPointHandle* _tmp6_;
			BirdFontEditPointHandle* _tmp7_;
			_tmp6_ = p->left_handle;
			_tmp6_->type = BIRD_FONT_POINT_TYPE_LINE_QUADRATIC;
			_tmp7_ = p->right_handle;
			_tmp7_->type = BIRD_FONT_POINT_TYPE_LINE_QUADRATIC;
			p->type = BIRD_FONT_POINT_TYPE_LINE_QUADRATIC;
		} else {
			if (bird_font_drawing_tools_get_selected_point_type () == BIRD_FONT_POINT_TYPE_DOUBLE_CURVE) {
				BirdFontEditPointHandle* _tmp8_;
				BirdFontEditPointHandle* _tmp9_;
				_tmp8_ = p->left_handle;
				_tmp8_->type = BIRD_FONT_POINT_TYPE_LINE_DOUBLE_CURVE;
				_tmp9_ = p->right_handle;
				_tmp9_->type = BIRD_FONT_POINT_TYPE_LINE_DOUBLE_CURVE;
				p->type = BIRD_FONT_POINT_TYPE_DOUBLE_CURVE;
			} else {
				BirdFontEditPointHandle* _tmp10_;
				BirdFontEditPointHandle* _tmp11_;
				_tmp10_ = p->left_handle;
				_tmp10_->type = BIRD_FONT_POINT_TYPE_LINE_CUBIC;
				_tmp11_ = p->right_handle;
				_tmp11_->type = BIRD_FONT_POINT_TYPE_LINE_CUBIC;
				p->type = BIRD_FONT_POINT_TYPE_CUBIC;
			}
		}
	}
}

void
bird_font_pen_tool_set_default_handle_positions (void)
{
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	{
		GeeArrayList* _p_list = NULL;
		BirdFontGlyph* _tmp1_;
		GeeArrayList* _tmp2_;
		gint _p_size = 0;
		GeeArrayList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		gint _p_index = 0;
		_tmp1_ = g;
		_tmp2_ = bird_font_glyph_get_visible_paths (_tmp1_);
		_p_list = _tmp2_;
		_tmp3_ = _p_list;
		_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
		_tmp5_ = _tmp4_;
		_p_size = _tmp5_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp6_;
			gint _tmp7_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp8_;
			gpointer _tmp9_;
			BirdFontPath* _tmp10_;
			_p_index = _p_index + 1;
			_tmp6_ = _p_index;
			_tmp7_ = _p_size;
			if (!(_tmp6_ < _tmp7_)) {
				break;
			}
			_tmp8_ = _p_list;
			_tmp9_ = gee_abstract_list_get ((GeeAbstractList*) _tmp8_, _p_index);
			p = (BirdFontPath*) _tmp9_;
			_tmp10_ = p;
			if (bird_font_path_is_editable (_tmp10_)) {
				BirdFontPath* _tmp11_;
				BirdFontPath* _tmp12_;
				_tmp11_ = p;
				bird_font_path_create_list (_tmp11_);
				_tmp12_ = p;
				bird_font_pen_tool_set_default_handle_positions_on_path (_tmp12_);
			}
			_g_object_unref0 (p);
		}
		_g_object_unref0 (_p_list);
	}
	_g_object_unref0 (g);
}

static void
bird_font_pen_tool_set_default_handle_positions_on_path (BirdFontPath* path)
{
	g_return_if_fail (path != NULL);
	{
		GeeArrayList* _e_list = NULL;
		GeeArrayList* _tmp0_;
		GeeArrayList* _tmp1_;
		gint _e_size = 0;
		GeeArrayList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _e_index = 0;
		_tmp0_ = bird_font_path_get_points (path);
		_tmp1_ = _tmp0_;
		_e_list = _tmp1_;
		_tmp2_ = _e_list;
		_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_e_size = _tmp4_;
		_e_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			BirdFontEditPoint* e = NULL;
			GeeArrayList* _tmp7_;
			gpointer _tmp8_;
			gboolean _tmp9_ = FALSE;
			BirdFontEditPoint* _tmp10_;
			gboolean _tmp11_;
			gboolean _tmp12_;
			_e_index = _e_index + 1;
			_tmp5_ = _e_index;
			_tmp6_ = _e_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _e_list;
			_tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, _e_index);
			e = (BirdFontEditPoint*) _tmp8_;
			_tmp10_ = e;
			_tmp11_ = bird_font_edit_point_get_tie_handles (_tmp10_);
			_tmp12_ = _tmp11_;
			if (!_tmp12_) {
				BirdFontEditPoint* _tmp13_;
				gboolean _tmp14_;
				gboolean _tmp15_;
				_tmp13_ = e;
				_tmp14_ = bird_font_edit_point_get_reflective_point (_tmp13_);
				_tmp15_ = _tmp14_;
				_tmp9_ = !_tmp15_;
			} else {
				_tmp9_ = FALSE;
			}
			if (_tmp9_) {
				BirdFontEditPoint* _tmp16_;
				_tmp16_ = e;
				bird_font_path_recalculate_linear_handles_for_point (path, _tmp16_);
			}
			_g_object_unref0 (e);
		}
	}
}

static gboolean
bird_font_pen_tool_is_over_handle (BirdFontPenTool* self,
                                   gdouble event_x,
                                   gdouble event_y)
{
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	gdouble distance_to_edit_point = 0.0;
	BirdFontGlyph* _tmp1_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	_tmp1_ = g;
	distance_to_edit_point = _tmp1_->view_zoom * bird_font_pen_tool_get_distance_to_closest_edit_point (self, event_x, event_y);
	if (!bird_font_path_show_all_line_handles) {
		{
			GeeArrayList* _selected_corner_list = NULL;
			GeeArrayList* _tmp2_;
			gint _selected_corner_size = 0;
			GeeArrayList* _tmp3_;
			gint _tmp4_;
			gint _tmp5_;
			gint _selected_corner_index = 0;
			_tmp2_ = bird_font_pen_tool_selected_points;
			_selected_corner_list = _tmp2_;
			_tmp3_ = _selected_corner_list;
			_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
			_tmp5_ = _tmp4_;
			_selected_corner_size = _tmp5_;
			_selected_corner_index = -1;
			while (TRUE) {
				gint _tmp6_;
				gint _tmp7_;
				BirdFontPointSelection* selected_corner = NULL;
				GeeArrayList* _tmp8_;
				gpointer _tmp9_;
				BirdFontPointSelection* _tmp10_;
				BirdFontEditPoint* _tmp11_;
				_selected_corner_index = _selected_corner_index + 1;
				_tmp6_ = _selected_corner_index;
				_tmp7_ = _selected_corner_size;
				if (!(_tmp6_ < _tmp7_)) {
					break;
				}
				_tmp8_ = _selected_corner_list;
				_tmp9_ = gee_abstract_list_get ((GeeAbstractList*) _tmp8_, _selected_corner_index);
				selected_corner = (BirdFontPointSelection*) _tmp9_;
				_tmp10_ = selected_corner;
				_tmp11_ = _tmp10_->point;
				if (bird_font_pen_tool_is_close_to_handle (self, _tmp11_, event_x, event_y, distance_to_edit_point)) {
					result = TRUE;
					_g_object_unref0 (selected_corner);
					_g_object_unref0 (g);
					return result;
				}
				_g_object_unref0 (selected_corner);
			}
		}
	} else {
		{
			GeeArrayList* _p_list = NULL;
			BirdFontGlyph* _tmp12_;
			GeeArrayList* _tmp13_;
			gint _p_size = 0;
			GeeArrayList* _tmp14_;
			gint _tmp15_;
			gint _tmp16_;
			gint _p_index = 0;
			_tmp12_ = g;
			_tmp13_ = bird_font_glyph_get_visible_paths (_tmp12_);
			_p_list = _tmp13_;
			_tmp14_ = _p_list;
			_tmp15_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp14_);
			_tmp16_ = _tmp15_;
			_p_size = _tmp16_;
			_p_index = -1;
			while (TRUE) {
				gint _tmp17_;
				gint _tmp18_;
				BirdFontPath* p = NULL;
				GeeArrayList* _tmp19_;
				gpointer _tmp20_;
				_p_index = _p_index + 1;
				_tmp17_ = _p_index;
				_tmp18_ = _p_size;
				if (!(_tmp17_ < _tmp18_)) {
					break;
				}
				_tmp19_ = _p_list;
				_tmp20_ = gee_abstract_list_get ((GeeAbstractList*) _tmp19_, _p_index);
				p = (BirdFontPath*) _tmp20_;
				{
					GeeArrayList* _ep_list = NULL;
					BirdFontPath* _tmp21_;
					GeeArrayList* _tmp22_;
					GeeArrayList* _tmp23_;
					gint _ep_size = 0;
					GeeArrayList* _tmp24_;
					gint _tmp25_;
					gint _tmp26_;
					gint _ep_index = 0;
					_tmp21_ = p;
					_tmp22_ = bird_font_path_get_points (_tmp21_);
					_tmp23_ = _tmp22_;
					_ep_list = _tmp23_;
					_tmp24_ = _ep_list;
					_tmp25_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp24_);
					_tmp26_ = _tmp25_;
					_ep_size = _tmp26_;
					_ep_index = -1;
					while (TRUE) {
						gint _tmp27_;
						gint _tmp28_;
						BirdFontEditPoint* ep = NULL;
						GeeArrayList* _tmp29_;
						gpointer _tmp30_;
						BirdFontEditPoint* _tmp31_;
						_ep_index = _ep_index + 1;
						_tmp27_ = _ep_index;
						_tmp28_ = _ep_size;
						if (!(_tmp27_ < _tmp28_)) {
							break;
						}
						_tmp29_ = _ep_list;
						_tmp30_ = gee_abstract_list_get ((GeeAbstractList*) _tmp29_, _ep_index);
						ep = (BirdFontEditPoint*) _tmp30_;
						_tmp31_ = ep;
						if (bird_font_pen_tool_is_close_to_handle (self, _tmp31_, event_x, event_y, distance_to_edit_point)) {
							result = TRUE;
							_g_object_unref0 (ep);
							_g_object_unref0 (p);
							_g_object_unref0 (_p_list);
							_g_object_unref0 (g);
							return result;
						}
						_g_object_unref0 (ep);
					}
				}
				_g_object_unref0 (p);
			}
			_g_object_unref0 (_p_list);
		}
	}
	result = FALSE;
	_g_object_unref0 (g);
	return result;
}

static gboolean
bird_font_pen_tool_is_close_to_path (BirdFontPenTool* self,
                                     BirdFontPath* p,
                                     gdouble event_x,
                                     gdouble event_y)
{
	gdouble c = 0.0;
	gdouble _tmp0_;
	gdouble _tmp1_;
	gdouble x = 0.0;
	gdouble y = 0.0;
	gboolean _tmp14_ = FALSE;
	gdouble _tmp15_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (p != NULL, FALSE);
	_tmp0_ = bird_font_pen_tool_get_contact_surface ();
	_tmp1_ = _tmp0_;
	c = _tmp1_ * bird_font_glyph_ivz ();
	x = bird_font_glyph_path_coordinate_x (event_x);
	y = bird_font_glyph_path_coordinate_y (event_y);
	if (G_UNLIKELY (!bird_font_path_has_region_boundaries (p))) {
		GeeArrayList* _tmp2_;
		GeeArrayList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		_tmp2_ = bird_font_path_get_points (p);
		_tmp3_ = _tmp2_;
		_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
		_tmp5_ = _tmp4_;
		if (_tmp5_ > 0) {
			GeeArrayList* _tmp6_;
			GeeArrayList* _tmp7_;
			gint _tmp8_;
			gint _tmp9_;
			gchar* _tmp10_;
			gchar* _tmp11_;
			gchar* _tmp12_;
			gchar* _tmp13_;
			_tmp6_ = bird_font_path_get_points (p);
			_tmp7_ = _tmp6_;
			_tmp8_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp7_);
			_tmp9_ = _tmp8_;
			_tmp10_ = g_strdup_printf ("%i", _tmp9_);
			_tmp11_ = _tmp10_;
			_tmp12_ = g_strconcat ("No bounding box. ", _tmp11_, NULL);
			_tmp13_ = _tmp12_;
			g_warning ("PenTool.vala:1931: %s", _tmp13_);
			_g_free0 (_tmp13_);
			_g_free0 (_tmp11_);
			bird_font_path_update_region_boundaries (p);
		}
	}
	_tmp15_ = x;
	if ((((p->xmin - c) - 10) <= _tmp15_) && (_tmp15_ <= ((p->xmax + c) + 10))) {
		gdouble _tmp16_;
		_tmp16_ = y;
		_tmp14_ = (((p->ymin - c) - 10) <= _tmp16_) && (_tmp16_ <= ((p->ymax + c) + 10));
	} else {
		_tmp14_ = FALSE;
	}
	result = _tmp14_;
	return result;
}

static gboolean
bird_font_pen_tool_is_close_to_handle (BirdFontPenTool* self,
                                       BirdFontEditPoint* selected_corner,
                                       gdouble event_x,
                                       gdouble event_y,
                                       gdouble distance_to_edit_point)
{
	gdouble x = 0.0;
	gdouble y = 0.0;
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	gdouble d_point = 0.0;
	gdouble dl = 0.0;
	gdouble dr = 0.0;
	BirdFontGlyph* _tmp1_;
	BirdFontEditPointHandle* _tmp2_;
	BirdFontEditPoint* _tmp3_;
	BirdFontEditPoint* _tmp4_;
	BirdFontGlyph* _tmp5_;
	BirdFontEditPointHandle* _tmp6_;
	BirdFontEditPoint* _tmp7_;
	BirdFontEditPoint* _tmp8_;
	gboolean _tmp9_ = FALSE;
	gdouble _tmp10_;
	gdouble _tmp11_;
	gboolean _tmp12_ = FALSE;
	gdouble _tmp13_;
	gdouble _tmp14_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (selected_corner != NULL, FALSE);
	x = bird_font_glyph_path_coordinate_x (event_x);
	y = bird_font_glyph_path_coordinate_y (event_y);
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	d_point = distance_to_edit_point;
	_tmp1_ = g;
	_tmp2_ = bird_font_edit_point_get_left_handle (selected_corner);
	_tmp3_ = bird_font_edit_point_handle_get_point (_tmp2_);
	_tmp4_ = _tmp3_;
	dl = _tmp1_->view_zoom * bird_font_edit_point_get_distance (_tmp4_, x, y);
	_g_object_unref0 (_tmp4_);
	_tmp5_ = g;
	_tmp6_ = bird_font_edit_point_get_right_handle (selected_corner);
	_tmp7_ = bird_font_edit_point_handle_get_point (_tmp6_);
	_tmp8_ = _tmp7_;
	dr = _tmp5_->view_zoom * bird_font_edit_point_get_distance (_tmp8_, x, y);
	_g_object_unref0 (_tmp8_);
	_tmp10_ = bird_font_pen_tool_get_contact_surface ();
	_tmp11_ = _tmp10_;
	if (dl < _tmp11_) {
		_tmp9_ = dl < d_point;
	} else {
		_tmp9_ = FALSE;
	}
	if (_tmp9_) {
		result = TRUE;
		_g_object_unref0 (g);
		return result;
	}
	_tmp13_ = bird_font_pen_tool_get_contact_surface ();
	_tmp14_ = _tmp13_;
	if (dr < _tmp14_) {
		_tmp12_ = dr < d_point;
	} else {
		_tmp12_ = FALSE;
	}
	if (_tmp12_) {
		result = TRUE;
		_g_object_unref0 (g);
		return result;
	}
	result = FALSE;
	_g_object_unref0 (g);
	return result;
}

static BirdFontPointSelection*
bird_font_pen_tool_get_closest_handle (BirdFontPenTool* self,
                                       gdouble event_x,
                                       gdouble event_y)
{
	BirdFontEditPointHandle* left = NULL;
	BirdFontEditPointHandle* right = NULL;
	gdouble x = 0.0;
	gdouble y = 0.0;
	BirdFontEditPointHandle* eh = NULL;
	BirdFontEditPointHandle* _tmp0_;
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp1_;
	gdouble d = 0.0;
	gdouble dn = 0.0;
	BirdFontPath* path = NULL;
	BirdFontPath* _tmp2_;
	gboolean left_handle = FALSE;
	BirdFontEditPoint* parent_point = NULL;
	BirdFontEditPoint* tied_point = NULL;
	BirdFontEditPointHandle* _tmp44_;
	BirdFontEditPointHandle* _tmp69_;
	BirdFontPath* _tmp70_;
	BirdFontPointSelection* _tmp71_;
	BirdFontPointSelection* result;
	g_return_val_if_fail (self != NULL, NULL);
	x = bird_font_glyph_path_coordinate_x (event_x);
	y = bird_font_glyph_path_coordinate_y (event_y);
	_tmp0_ = bird_font_edit_point_handle_new_empty ();
	eh = _tmp0_;
	_tmp1_ = bird_font_main_window_get_current_glyph ();
	g = _tmp1_;
	d = DBL_MAX;
	_tmp2_ = bird_font_path_new ();
	path = _tmp2_;
	left_handle = FALSE;
	{
		GeeArrayList* _p_list = NULL;
		BirdFontGlyph* _tmp3_;
		GeeArrayList* _tmp4_;
		gint _p_size = 0;
		GeeArrayList* _tmp5_;
		gint _tmp6_;
		gint _tmp7_;
		gint _p_index = 0;
		_tmp3_ = g;
		_tmp4_ = bird_font_glyph_get_paths_in_current_layer (_tmp3_);
		_p_list = _tmp4_;
		_tmp5_ = _p_list;
		_tmp6_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp5_);
		_tmp7_ = _tmp6_;
		_p_size = _tmp7_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp8_;
			gint _tmp9_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp10_;
			gpointer _tmp11_;
			_p_index = _p_index + 1;
			_tmp8_ = _p_index;
			_tmp9_ = _p_size;
			if (!(_tmp8_ < _tmp9_)) {
				break;
			}
			_tmp10_ = _p_list;
			_tmp11_ = gee_abstract_list_get ((GeeAbstractList*) _tmp10_, _p_index);
			p = (BirdFontPath*) _tmp11_;
			{
				GeeArrayList* _ep_list = NULL;
				BirdFontPath* _tmp12_;
				GeeArrayList* _tmp13_;
				GeeArrayList* _tmp14_;
				gint _ep_size = 0;
				GeeArrayList* _tmp15_;
				gint _tmp16_;
				gint _tmp17_;
				gint _ep_index = 0;
				_tmp12_ = p;
				_tmp13_ = bird_font_path_get_points (_tmp12_);
				_tmp14_ = _tmp13_;
				_ep_list = _tmp14_;
				_tmp15_ = _ep_list;
				_tmp16_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp15_);
				_tmp17_ = _tmp16_;
				_ep_size = _tmp17_;
				_ep_index = -1;
				while (TRUE) {
					gint _tmp18_;
					gint _tmp19_;
					BirdFontEditPoint* ep = NULL;
					GeeArrayList* _tmp20_;
					gpointer _tmp21_;
					gboolean _tmp22_ = FALSE;
					BirdFontEditPoint* _tmp23_;
					_ep_index = _ep_index + 1;
					_tmp18_ = _ep_index;
					_tmp19_ = _ep_size;
					if (!(_tmp18_ < _tmp19_)) {
						break;
					}
					_tmp20_ = _ep_list;
					_tmp21_ = gee_abstract_list_get ((GeeAbstractList*) _tmp20_, _ep_index);
					ep = (BirdFontEditPoint*) _tmp21_;
					_tmp23_ = ep;
					if (bird_font_edit_point_is_selected (_tmp23_)) {
						_tmp22_ = TRUE;
					} else {
						_tmp22_ = bird_font_path_show_all_line_handles;
					}
					if (_tmp22_) {
						BirdFontEditPoint* _tmp24_;
						BirdFontEditPointHandle* _tmp25_;
						BirdFontEditPointHandle* _tmp26_;
						BirdFontEditPoint* _tmp27_;
						BirdFontEditPointHandle* _tmp28_;
						BirdFontEditPointHandle* _tmp29_;
						BirdFontEditPointHandle* _tmp30_;
						BirdFontEditPoint* _tmp31_;
						BirdFontEditPoint* _tmp32_;
						BirdFontEditPointHandle* _tmp37_;
						BirdFontEditPoint* _tmp38_;
						BirdFontEditPoint* _tmp39_;
						_tmp24_ = ep;
						_tmp25_ = bird_font_edit_point_get_left_handle (_tmp24_);
						_tmp26_ = _g_object_ref0 (_tmp25_);
						_g_object_unref0 (left);
						left = _tmp26_;
						_tmp27_ = ep;
						_tmp28_ = bird_font_edit_point_get_right_handle (_tmp27_);
						_tmp29_ = _g_object_ref0 (_tmp28_);
						_g_object_unref0 (right);
						right = _tmp29_;
						_tmp30_ = left;
						_tmp31_ = bird_font_edit_point_handle_get_point (_tmp30_);
						_tmp32_ = _tmp31_;
						dn = bird_font_edit_point_get_distance (_tmp32_, x, y);
						_g_object_unref0 (_tmp32_);
						if (dn < d) {
							BirdFontEditPointHandle* _tmp33_;
							BirdFontEditPointHandle* _tmp34_;
							BirdFontPath* _tmp35_;
							BirdFontPath* _tmp36_;
							_tmp33_ = left;
							_tmp34_ = _g_object_ref0 (_tmp33_);
							_g_object_unref0 (eh);
							eh = _tmp34_;
							d = dn;
							_tmp35_ = p;
							_tmp36_ = _g_object_ref0 (_tmp35_);
							_g_object_unref0 (path);
							path = _tmp36_;
							left_handle = TRUE;
						}
						_tmp37_ = right;
						_tmp38_ = bird_font_edit_point_handle_get_point (_tmp37_);
						_tmp39_ = _tmp38_;
						dn = bird_font_edit_point_get_distance (_tmp39_, x, y);
						_g_object_unref0 (_tmp39_);
						if (dn < d) {
							BirdFontEditPointHandle* _tmp40_;
							BirdFontEditPointHandle* _tmp41_;
							BirdFontPath* _tmp42_;
							BirdFontPath* _tmp43_;
							_tmp40_ = right;
							_tmp41_ = _g_object_ref0 (_tmp40_);
							_g_object_unref0 (eh);
							eh = _tmp41_;
							d = dn;
							_tmp42_ = p;
							_tmp43_ = _g_object_ref0 (_tmp42_);
							_g_object_unref0 (path);
							path = _tmp43_;
							left_handle = FALSE;
						}
					}
					_g_object_unref0 (ep);
				}
			}
			_g_object_unref0 (p);
		}
		_g_object_unref0 (_p_list);
	}
	_tmp44_ = eh;
	if (_tmp44_->type == BIRD_FONT_POINT_TYPE_QUADRATIC) {
		BirdFontEditPointHandle* _tmp45_;
		BirdFontEditPoint* _tmp46_;
		_tmp45_ = eh;
		_tmp46_ = bird_font_edit_point_handle_get_parent (_tmp45_);
		_g_object_unref0 (parent_point);
		parent_point = _tmp46_;
		if (left_handle) {
			BirdFontEditPoint* _tmp47_;
			BirdFontEditPoint* _tmp48_;
			_tmp47_ = parent_point;
			_tmp48_ = _tmp47_->prev;
			if (_tmp48_ != NULL) {
				BirdFontEditPoint* _tmp49_;
				BirdFontEditPoint* _tmp50_;
				BirdFontEditPoint* _tmp51_;
				BirdFontEditPoint* _tmp52_;
				gboolean _tmp53_;
				gboolean _tmp54_;
				_tmp49_ = parent_point;
				_tmp50_ = bird_font_edit_point_get_prev (_tmp49_);
				_tmp51_ = _g_object_ref0 (_tmp50_);
				_g_object_unref0 (tied_point);
				tied_point = _tmp51_;
				_tmp52_ = tied_point;
				_tmp53_ = bird_font_edit_point_get_selected_point (_tmp52_);
				_tmp54_ = _tmp53_;
				if (_tmp54_) {
					BirdFontEditPoint* _tmp55_;
					BirdFontEditPointHandle* _tmp56_;
					BirdFontEditPointHandle* _tmp57_;
					_tmp55_ = tied_point;
					_tmp56_ = bird_font_edit_point_get_right_handle (_tmp55_);
					_tmp57_ = _g_object_ref0 (_tmp56_);
					_g_object_unref0 (eh);
					eh = _tmp57_;
				}
			}
		} else {
			BirdFontEditPoint* _tmp58_;
			BirdFontEditPoint* _tmp59_;
			_tmp58_ = parent_point;
			_tmp59_ = _tmp58_->next;
			if (_tmp59_ != NULL) {
				BirdFontEditPoint* _tmp60_;
				BirdFontEditPoint* _tmp61_;
				BirdFontEditPoint* _tmp62_;
				BirdFontEditPoint* _tmp63_;
				gboolean _tmp64_;
				gboolean _tmp65_;
				_tmp60_ = parent_point;
				_tmp61_ = bird_font_edit_point_get_next (_tmp60_);
				_tmp62_ = _g_object_ref0 (_tmp61_);
				_g_object_unref0 (tied_point);
				tied_point = _tmp62_;
				_tmp63_ = tied_point;
				_tmp64_ = bird_font_edit_point_get_selected_point (_tmp63_);
				_tmp65_ = _tmp64_;
				if (_tmp65_) {
					BirdFontEditPoint* _tmp66_;
					BirdFontEditPointHandle* _tmp67_;
					BirdFontEditPointHandle* _tmp68_;
					_tmp66_ = tied_point;
					_tmp67_ = bird_font_edit_point_get_left_handle (_tmp66_);
					_tmp68_ = _g_object_ref0 (_tmp67_);
					_g_object_unref0 (eh);
					eh = _tmp68_;
				}
			}
		}
	}
	_tmp69_ = eh;
	_tmp70_ = path;
	_tmp71_ = bird_font_point_selection_new_handle_selection (_tmp69_, _tmp70_);
	result = _tmp71_;
	_g_object_unref0 (tied_point);
	_g_object_unref0 (parent_point);
	_g_object_unref0 (path);
	_g_object_unref0 (g);
	_g_object_unref0 (eh);
	_g_object_unref0 (right);
	_g_object_unref0 (left);
	return result;
}

static void
bird_font_pen_tool_curve_active_corner_event (BirdFontPenTool* self,
                                              gdouble event_x,
                                              gdouble event_y)
{
	BirdFontPointSelection* eh = NULL;
	BirdFontGlyph* glyph = NULL;
	BirdFontGlyph* _tmp0_;
	BirdFontEditPointHandle* _tmp1_;
	BirdFontPointSelection* _tmp2_;
	BirdFontPointSelection* _tmp3_;
	BirdFontEditPointHandle* _tmp4_;
	BirdFontEditPointHandle* _tmp5_;
	BirdFontPointSelection* _tmp6_;
	BirdFontEditPointHandle* _tmp7_;
	BirdFontPointSelection* _tmp8_;
	BirdFontEditPointHandle* _tmp9_;
	BirdFontEditPointHandle* _tmp10_;
	g_return_if_fail (self != NULL);
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	_g_object_unref0 (glyph);
	glyph = _tmp0_;
	_tmp1_ = bird_font_pen_tool_active_handle;
	_tmp1_->active = FALSE;
	if (!bird_font_pen_tool_is_over_handle (self, event_x, event_y)) {
		_g_object_unref0 (glyph);
		_g_object_unref0 (eh);
		return;
	}
	_tmp2_ = bird_font_pen_tool_get_closest_handle (self, event_x, event_y);
	_g_object_unref0 (eh);
	eh = _tmp2_;
	_tmp3_ = eh;
	_tmp4_ = _tmp3_->handle;
	_tmp4_->active = TRUE;
	_tmp5_ = bird_font_pen_tool_active_handle;
	_tmp6_ = eh;
	_tmp7_ = _tmp6_->handle;
	if (_tmp5_ != _tmp7_) {
		bird_font_glyph_canvas_redraw ();
	}
	_tmp8_ = eh;
	_tmp9_ = _tmp8_->handle;
	_tmp10_ = _g_object_ref0 (_tmp9_);
	_g_object_unref0 (bird_font_pen_tool_active_handle);
	bird_font_pen_tool_active_handle = _tmp10_;
	_g_object_unref0 (glyph);
	_g_object_unref0 (eh);
}

static void
bird_font_pen_tool_curve_corner_event (BirdFontPenTool* self,
                                       gdouble event_x,
                                       gdouble event_y)
{
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	BirdFontGlyph* _tmp1_;
	BirdFontPointSelection* p = NULL;
	BirdFontEditPointHandle* _tmp2_;
	BirdFontPointSelection* _tmp3_;
	BirdFontPointSelection* _tmp4_;
	BirdFontEditPointHandle* _tmp5_;
	BirdFontEditPointHandle* _tmp6_;
	BirdFontPointSelection* _tmp7_;
	BirdFontPointSelection* _tmp8_;
	BirdFontEditPointHandle* _tmp9_;
	BirdFontPointSelection* _tmp10_;
	BirdFontPath* _tmp11_;
	BirdFontPath* _tmp12_;
	BirdFontGlyph* _tmp13_;
	BirdFontPath* _tmp14_;
	g_return_if_fail (self != NULL);
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	_tmp1_ = g;
	bird_font_glyph_open_path (_tmp1_);
	if (!bird_font_pen_tool_is_over_handle (self, event_x, event_y)) {
		_g_object_unref0 (p);
		_g_object_unref0 (g);
		return;
	}
	bird_font_pen_tool_move_selected_handle = TRUE;
	self->priv->last_selected_is_handle = TRUE;
	_tmp2_ = bird_font_pen_tool_selected_handle;
	_tmp2_->selected = FALSE;
	_tmp3_ = bird_font_pen_tool_get_closest_handle (self, event_x, event_y);
	_g_object_unref0 (p);
	p = _tmp3_;
	_tmp4_ = p;
	_tmp5_ = _tmp4_->handle;
	_tmp6_ = _g_object_ref0 (_tmp5_);
	_g_object_unref0 (bird_font_pen_tool_selected_handle);
	bird_font_pen_tool_selected_handle = _tmp6_;
	_tmp7_ = p;
	_tmp8_ = _g_object_ref0 (_tmp7_);
	_g_object_unref0 (bird_font_pen_tool_handle_selection);
	bird_font_pen_tool_handle_selection = _tmp8_;
	_tmp9_ = bird_font_pen_tool_selected_handle;
	_tmp9_->selected = TRUE;
	_tmp10_ = p;
	_tmp11_ = _tmp10_->path;
	_tmp12_ = _g_object_ref0 (_tmp11_);
	_g_object_unref0 (bird_font_pen_tool_active_path);
	bird_font_pen_tool_active_path = _tmp12_;
	_tmp13_ = g;
	_tmp14_ = bird_font_pen_tool_active_path;
	bird_font_glyph_add_active_path (_tmp13_, NULL, _tmp14_);
	_g_object_unref0 (p);
	_g_object_unref0 (g);
}

void
bird_font_pen_tool_add_selected_point (BirdFontEditPoint* p,
                                       BirdFontPath* path)
{
	gboolean in_path = FALSE;
	GeeArrayList* _tmp20_;
	BirdFontPointSelection* _tmp21_;
	BirdFontPointSelection* _tmp22_;
	g_return_if_fail (p != NULL);
	g_return_if_fail (path != NULL);
	in_path = FALSE;
	{
		GeeArrayList* _e_list = NULL;
		GeeArrayList* _tmp0_;
		GeeArrayList* _tmp1_;
		gint _e_size = 0;
		GeeArrayList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _e_index = 0;
		_tmp0_ = bird_font_path_get_points (path);
		_tmp1_ = _tmp0_;
		_e_list = _tmp1_;
		_tmp2_ = _e_list;
		_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_e_size = _tmp4_;
		_e_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			BirdFontEditPoint* e = NULL;
			GeeArrayList* _tmp7_;
			gpointer _tmp8_;
			BirdFontEditPoint* _tmp9_;
			_e_index = _e_index + 1;
			_tmp5_ = _e_index;
			_tmp6_ = _e_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _e_list;
			_tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, _e_index);
			e = (BirdFontEditPoint*) _tmp8_;
			_tmp9_ = e;
			if (_tmp9_ == p) {
				in_path = TRUE;
				_g_object_unref0 (e);
				break;
			}
			_g_object_unref0 (e);
		}
	}
	if (!in_path) {
		g_warning ("PenTool.vala:2078: Point is not in path.");
	}
	{
		GeeArrayList* _ep_list = NULL;
		GeeArrayList* _tmp10_;
		gint _ep_size = 0;
		GeeArrayList* _tmp11_;
		gint _tmp12_;
		gint _tmp13_;
		gint _ep_index = 0;
		_tmp10_ = bird_font_pen_tool_selected_points;
		_ep_list = _tmp10_;
		_tmp11_ = _ep_list;
		_tmp12_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp11_);
		_tmp13_ = _tmp12_;
		_ep_size = _tmp13_;
		_ep_index = -1;
		while (TRUE) {
			gint _tmp14_;
			gint _tmp15_;
			BirdFontPointSelection* ep = NULL;
			GeeArrayList* _tmp16_;
			gpointer _tmp17_;
			BirdFontPointSelection* _tmp18_;
			BirdFontEditPoint* _tmp19_;
			_ep_index = _ep_index + 1;
			_tmp14_ = _ep_index;
			_tmp15_ = _ep_size;
			if (!(_tmp14_ < _tmp15_)) {
				break;
			}
			_tmp16_ = _ep_list;
			_tmp17_ = gee_abstract_list_get ((GeeAbstractList*) _tmp16_, _ep_index);
			ep = (BirdFontPointSelection*) _tmp17_;
			_tmp18_ = ep;
			_tmp19_ = _tmp18_->point;
			if (p == _tmp19_) {
				_g_object_unref0 (ep);
				return;
			}
			_g_object_unref0 (ep);
		}
	}
	_tmp20_ = bird_font_pen_tool_selected_points;
	_tmp21_ = bird_font_point_selection_new (p, path);
	_tmp22_ = _tmp21_;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp20_, _tmp22_);
	_g_object_unref0 (_tmp22_);
}

void
bird_font_pen_tool_remove_all_selected_points (void)
{
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	GeeArrayList* _tmp13_;
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	{
		GeeArrayList* _ep_list = NULL;
		GeeArrayList* _tmp1_;
		gint _ep_size = 0;
		GeeArrayList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _ep_index = 0;
		_tmp1_ = bird_font_pen_tool_selected_points;
		_ep_list = _tmp1_;
		_tmp2_ = _ep_list;
		_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_ep_size = _tmp4_;
		_ep_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			BirdFontPointSelection* ep = NULL;
			GeeArrayList* _tmp7_;
			gpointer _tmp8_;
			BirdFontPointSelection* _tmp9_;
			BirdFontEditPoint* _tmp10_;
			BirdFontPointSelection* _tmp11_;
			BirdFontEditPoint* _tmp12_;
			_ep_index = _ep_index + 1;
			_tmp5_ = _ep_index;
			_tmp6_ = _ep_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _ep_list;
			_tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, _ep_index);
			ep = (BirdFontPointSelection*) _tmp8_;
			_tmp9_ = ep;
			_tmp10_ = _tmp9_->point;
			bird_font_edit_point_set_active (_tmp10_, FALSE);
			_tmp11_ = ep;
			_tmp12_ = _tmp11_->point;
			bird_font_edit_point_set_selected (_tmp12_, FALSE);
			_g_object_unref0 (ep);
		}
	}
	_tmp13_ = bird_font_pen_tool_selected_points;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp13_);
	{
		GeeArrayList* _p_list = NULL;
		BirdFontGlyph* _tmp14_;
		GeeArrayList* _tmp15_;
		gint _p_size = 0;
		GeeArrayList* _tmp16_;
		gint _tmp17_;
		gint _tmp18_;
		gint _p_index = 0;
		_tmp14_ = g;
		_tmp15_ = bird_font_glyph_get_visible_paths (_tmp14_);
		_p_list = _tmp15_;
		_tmp16_ = _p_list;
		_tmp17_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp16_);
		_tmp18_ = _tmp17_;
		_p_size = _tmp18_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp19_;
			gint _tmp20_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp21_;
			gpointer _tmp22_;
			_p_index = _p_index + 1;
			_tmp19_ = _p_index;
			_tmp20_ = _p_size;
			if (!(_tmp19_ < _tmp20_)) {
				break;
			}
			_tmp21_ = _p_list;
			_tmp22_ = gee_abstract_list_get ((GeeAbstractList*) _tmp21_, _p_index);
			p = (BirdFontPath*) _tmp22_;
			{
				GeeArrayList* _e_list = NULL;
				BirdFontPath* _tmp23_;
				GeeArrayList* _tmp24_;
				GeeArrayList* _tmp25_;
				gint _e_size = 0;
				GeeArrayList* _tmp26_;
				gint _tmp27_;
				gint _tmp28_;
				gint _e_index = 0;
				_tmp23_ = p;
				_tmp24_ = bird_font_path_get_points (_tmp23_);
				_tmp25_ = _tmp24_;
				_e_list = _tmp25_;
				_tmp26_ = _e_list;
				_tmp27_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp26_);
				_tmp28_ = _tmp27_;
				_e_size = _tmp28_;
				_e_index = -1;
				while (TRUE) {
					gint _tmp29_;
					gint _tmp30_;
					BirdFontEditPoint* e = NULL;
					GeeArrayList* _tmp31_;
					gpointer _tmp32_;
					BirdFontEditPoint* _tmp33_;
					BirdFontEditPoint* _tmp34_;
					_e_index = _e_index + 1;
					_tmp29_ = _e_index;
					_tmp30_ = _e_size;
					if (!(_tmp29_ < _tmp30_)) {
						break;
					}
					_tmp31_ = _e_list;
					_tmp32_ = gee_abstract_list_get ((GeeAbstractList*) _tmp31_, _e_index);
					e = (BirdFontEditPoint*) _tmp32_;
					_tmp33_ = e;
					bird_font_edit_point_set_active (_tmp33_, FALSE);
					_tmp34_ = e;
					bird_font_edit_point_set_selected (_tmp34_, FALSE);
					_g_object_unref0 (e);
				}
			}
			_g_object_unref0 (p);
		}
		_g_object_unref0 (_p_list);
	}
	_g_object_unref0 (g);
}

static void
bird_font_pen_tool_move_select_next_point (guint keyval)
{
	BirdFontPointSelection* next = NULL;
	BirdFontPointSelection* _tmp0_;
	GeeArrayList* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	BirdFontPointSelection* _tmp8_;
	BirdFontEditPoint* _tmp9_;
	BirdFontPointSelection* _tmp10_;
	BirdFontPath* _tmp11_;
	_tmp0_ = bird_font_point_selection_new_empty ();
	next = _tmp0_;
	_tmp1_ = bird_font_pen_tool_selected_points;
	_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
	_tmp3_ = _tmp2_;
	if (_tmp3_ == 0) {
		_g_object_unref0 (next);
		return;
	}
	bird_font_pen_tool_cancel_stroke_creator ();
	switch (keyval) {
		case BIRD_FONT_KEY_UP:
		{
			BirdFontPointSelection* _tmp4_;
			_tmp4_ = bird_font_pen_tool_get_next_point_up ();
			_g_object_unref0 (next);
			next = _tmp4_;
			break;
		}
		case BIRD_FONT_KEY_DOWN:
		{
			BirdFontPointSelection* _tmp5_;
			_tmp5_ = bird_font_pen_tool_get_next_point_down ();
			_g_object_unref0 (next);
			next = _tmp5_;
			break;
		}
		case BIRD_FONT_KEY_LEFT:
		{
			BirdFontPointSelection* _tmp6_;
			_tmp6_ = bird_font_pen_tool_get_next_point_left ();
			_g_object_unref0 (next);
			next = _tmp6_;
			break;
		}
		case BIRD_FONT_KEY_RIGHT:
		{
			BirdFontPointSelection* _tmp7_;
			_tmp7_ = bird_font_pen_tool_get_next_point_right ();
			_g_object_unref0 (next);
			next = _tmp7_;
			break;
		}
		default:
		{
			break;
		}
	}
	_tmp8_ = next;
	_tmp9_ = _tmp8_->point;
	_tmp10_ = next;
	_tmp11_ = _tmp10_->path;
	bird_font_pen_tool_set_selected_point (_tmp9_, _tmp11_);
	bird_font_glyph_canvas_redraw ();
	_g_object_unref0 (next);
}

static BirdFontPointSelection*
bird_font_pen_tool_get_next_point (gdouble angle)
{
	GeeArrayList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	BirdFontPointSelection* e = NULL;
	GeeArrayList* _tmp3_;
	GeeArrayList* _tmp4_;
	gint _tmp5_;
	gint _tmp6_;
	gpointer _tmp7_;
	gdouble right_angle = 0.0;
	BirdFontPointSelection* _tmp8_;
	BirdFontEditPoint* _tmp9_;
	BirdFontEditPointHandle* _tmp10_;
	gdouble left_angle = 0.0;
	BirdFontPointSelection* _tmp11_;
	BirdFontEditPoint* _tmp12_;
	BirdFontEditPointHandle* _tmp13_;
	gdouble min_right = 0.0;
	gdouble min_left = 0.0;
	gdouble min = 0.0;
	BirdFontPointSelection* _tmp14_;
	BirdFontEditPoint* _tmp15_;
	BirdFontEditPoint* _tmp16_;
	BirdFontEditPoint* _tmp17_;
	BirdFontEditPoint* _tmp18_;
	BirdFontPointSelection* _tmp19_;
	BirdFontEditPoint* _tmp20_;
	BirdFontEditPoint* _tmp21_;
	BirdFontEditPoint* _tmp22_;
	BirdFontEditPoint* _tmp23_;
	BirdFontPointSelection* _tmp31_;
	BirdFontEditPoint* _tmp32_;
	BirdFontEditPoint* _tmp33_;
	BirdFontPointSelection* _tmp34_;
	BirdFontPath* _tmp35_;
	BirdFontPointSelection* _tmp36_;
	BirdFontPointSelection* result;
	_tmp0_ = bird_font_pen_tool_selected_points;
	_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	_vala_return_val_if_fail (_tmp2_ != 0, "selected_points.size != 0", NULL);
	_tmp3_ = bird_font_pen_tool_selected_points;
	_tmp4_ = bird_font_pen_tool_selected_points;
	_tmp5_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp3_, _tmp6_ - 1);
	e = (BirdFontPointSelection*) _tmp7_;
	_tmp8_ = e;
	_tmp9_ = _tmp8_->point;
	_tmp10_ = _tmp9_->right_handle;
	right_angle = _tmp10_->angle;
	_tmp11_ = e;
	_tmp12_ = _tmp11_->point;
	_tmp13_ = _tmp12_->left_handle;
	left_angle = _tmp13_->angle;
	_tmp14_ = e;
	_tmp15_ = _tmp14_->point;
	_tmp16_ = _tmp15_->next;
	_tmp17_ = bird_font_edit_point_new ((gdouble) 0, (gdouble) 0, BIRD_FONT_POINT_TYPE_NONE);
	_tmp18_ = _tmp17_;
	g_return_val_if_fail (_tmp16_ != NULL, _tmp18_);
	_g_object_unref0 (_tmp18_);
	_tmp19_ = e;
	_tmp20_ = _tmp19_->point;
	_tmp21_ = _tmp20_->prev;
	_tmp22_ = bird_font_edit_point_new ((gdouble) 0, (gdouble) 0, BIRD_FONT_POINT_TYPE_NONE);
	_tmp23_ = _tmp22_;
	g_return_val_if_fail (_tmp21_ != NULL, _tmp23_);
	_g_object_unref0 (_tmp23_);
	min_right = DBL_MAX;
	min_left = DBL_MAX;
	{
		gdouble i = 0.0;
		i = -2 * G_PI;
		{
			gboolean _tmp24_ = FALSE;
			_tmp24_ = TRUE;
			while (TRUE) {
				if (!_tmp24_) {
					i += 2 * G_PI;
				}
				_tmp24_ = FALSE;
				if (!(i <= (2 * G_PI))) {
					break;
				}
				min = fabs (right_angle - (angle + i));
				if (min < min_right) {
					min_right = min;
				}
				min = fabs (left_angle - (angle + i));
				if (min < min_left) {
					min_left = min;
				}
			}
		}
	}
	if (min_right < min_left) {
		BirdFontPointSelection* _tmp25_;
		BirdFontEditPoint* _tmp26_;
		BirdFontEditPoint* _tmp27_;
		BirdFontPointSelection* _tmp28_;
		BirdFontPath* _tmp29_;
		BirdFontPointSelection* _tmp30_;
		_tmp25_ = e;
		_tmp26_ = _tmp25_->point;
		_tmp27_ = bird_font_edit_point_get_next (_tmp26_);
		_tmp28_ = e;
		_tmp29_ = _tmp28_->path;
		_tmp30_ = bird_font_point_selection_new (_tmp27_, _tmp29_);
		result = _tmp30_;
		_g_object_unref0 (e);
		return result;
	}
	_tmp31_ = e;
	_tmp32_ = _tmp31_->point;
	_tmp33_ = bird_font_edit_point_get_prev (_tmp32_);
	_tmp34_ = e;
	_tmp35_ = _tmp34_->path;
	_tmp36_ = bird_font_point_selection_new (_tmp33_, _tmp35_);
	result = _tmp36_;
	_g_object_unref0 (e);
	return result;
}

static BirdFontPointSelection*
bird_font_pen_tool_get_next_point_up (void)
{
	BirdFontPointSelection* _tmp0_;
	BirdFontPointSelection* result;
	_tmp0_ = bird_font_pen_tool_get_next_point (G_PI / 2);
	result = _tmp0_;
	return result;
}

static BirdFontPointSelection*
bird_font_pen_tool_get_next_point_down (void)
{
	BirdFontPointSelection* _tmp0_;
	BirdFontPointSelection* result;
	_tmp0_ = bird_font_pen_tool_get_next_point (G_PI + (G_PI / 2));
	result = _tmp0_;
	return result;
}

static BirdFontPointSelection*
bird_font_pen_tool_get_next_point_left (void)
{
	BirdFontPointSelection* _tmp0_;
	BirdFontPointSelection* result;
	_tmp0_ = bird_font_pen_tool_get_next_point (G_PI);
	result = _tmp0_;
	return result;
}

static BirdFontPointSelection*
bird_font_pen_tool_get_next_point_right (void)
{
	BirdFontPointSelection* _tmp0_;
	BirdFontPointSelection* result;
	_tmp0_ = bird_font_pen_tool_get_next_point ((gdouble) 0);
	result = _tmp0_;
	return result;
}

static void
bird_font_pen_tool_set_selected_point (BirdFontEditPoint* ep,
                                       BirdFontPath* p)
{
	g_return_if_fail (ep != NULL);
	g_return_if_fail (p != NULL);
	bird_font_pen_tool_remove_all_selected_points ();
	bird_font_pen_tool_add_selected_point (ep, p);
	bird_font_pen_tool_set_active_edit_point (ep, p);
	bird_font_pen_tool_edit_active_corner = TRUE;
	bird_font_edit_point_set_selected (ep, TRUE);
	bird_font_pen_tool_set_default_handle_positions ();
}

void
bird_font_pen_tool_select_point_up (void)
{
	bird_font_pen_tool_move_select_next_point ((guint) BIRD_FONT_KEY_UP);
}

void
bird_font_pen_tool_select_point_down (void)
{
	bird_font_pen_tool_move_select_next_point ((guint) BIRD_FONT_KEY_DOWN);
}

void
bird_font_pen_tool_select_point_right (void)
{
	bird_font_pen_tool_move_select_next_point ((guint) BIRD_FONT_KEY_RIGHT);
}

void
bird_font_pen_tool_select_point_left (void)
{
	bird_font_pen_tool_move_select_next_point ((guint) BIRD_FONT_KEY_LEFT);
}

/**
 * Move the selected editpoint one pixel with keyboard irrespectivly of 
 * current zoom.
 */
static void
bird_font_pen_tool_move_selected_points (BirdFontPenTool* self,
                                         guint keyval)
{
	BirdFontPath* last_path = NULL;
	g_return_if_fail (self != NULL);
	last_path = NULL;
	bird_font_pen_tool_cancel_stroke_creator ();
	bird_font_pen_tool_update_selected_points ();
	if (!self->priv->last_selected_is_handle) {
		if (keyval == ((guint) BIRD_FONT_KEY_UP)) {
			{
				GeeArrayList* _e_list = NULL;
				GeeArrayList* _tmp0_;
				gint _e_size = 0;
				GeeArrayList* _tmp1_;
				gint _tmp2_;
				gint _tmp3_;
				gint _e_index = 0;
				_tmp0_ = bird_font_pen_tool_selected_points;
				_e_list = _tmp0_;
				_tmp1_ = _e_list;
				_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
				_tmp3_ = _tmp2_;
				_e_size = _tmp3_;
				_e_index = -1;
				while (TRUE) {
					gint _tmp4_;
					gint _tmp5_;
					BirdFontPointSelection* e = NULL;
					GeeArrayList* _tmp6_;
					gpointer _tmp7_;
					BirdFontPointSelection* _tmp8_;
					BirdFontEditPoint* _tmp9_;
					BirdFontPointSelection* _tmp10_;
					BirdFontEditPoint* _tmp11_;
					BirdFontPointSelection* _tmp12_;
					BirdFontEditPoint* _tmp13_;
					BirdFontPointSelection* _tmp14_;
					BirdFontPath* _tmp15_;
					BirdFontPointSelection* _tmp16_;
					BirdFontEditPoint* _tmp17_;
					_e_index = _e_index + 1;
					_tmp4_ = _e_index;
					_tmp5_ = _e_size;
					if (!(_tmp4_ < _tmp5_)) {
						break;
					}
					_tmp6_ = _e_list;
					_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _e_index);
					e = (BirdFontPointSelection*) _tmp7_;
					_tmp8_ = e;
					_tmp9_ = _tmp8_->point;
					_tmp10_ = e;
					_tmp11_ = _tmp10_->point;
					_tmp12_ = e;
					_tmp13_ = _tmp12_->point;
					bird_font_edit_point_set_position (_tmp9_, _tmp11_->x, _tmp13_->y + bird_font_glyph_ivz ());
					_tmp14_ = e;
					_tmp15_ = _tmp14_->path;
					_tmp16_ = e;
					_tmp17_ = _tmp16_->point;
					bird_font_path_recalculate_linear_handles_for_point (_tmp15_, _tmp17_);
					_g_object_unref0 (e);
				}
			}
		}
		if (keyval == ((guint) BIRD_FONT_KEY_DOWN)) {
			{
				GeeArrayList* _e_list = NULL;
				GeeArrayList* _tmp18_;
				gint _e_size = 0;
				GeeArrayList* _tmp19_;
				gint _tmp20_;
				gint _tmp21_;
				gint _e_index = 0;
				_tmp18_ = bird_font_pen_tool_selected_points;
				_e_list = _tmp18_;
				_tmp19_ = _e_list;
				_tmp20_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp19_);
				_tmp21_ = _tmp20_;
				_e_size = _tmp21_;
				_e_index = -1;
				while (TRUE) {
					gint _tmp22_;
					gint _tmp23_;
					BirdFontPointSelection* e = NULL;
					GeeArrayList* _tmp24_;
					gpointer _tmp25_;
					BirdFontPointSelection* _tmp26_;
					BirdFontEditPoint* _tmp27_;
					BirdFontPointSelection* _tmp28_;
					BirdFontEditPoint* _tmp29_;
					BirdFontPointSelection* _tmp30_;
					BirdFontEditPoint* _tmp31_;
					BirdFontPointSelection* _tmp32_;
					BirdFontPath* _tmp33_;
					BirdFontPointSelection* _tmp34_;
					BirdFontEditPoint* _tmp35_;
					_e_index = _e_index + 1;
					_tmp22_ = _e_index;
					_tmp23_ = _e_size;
					if (!(_tmp22_ < _tmp23_)) {
						break;
					}
					_tmp24_ = _e_list;
					_tmp25_ = gee_abstract_list_get ((GeeAbstractList*) _tmp24_, _e_index);
					e = (BirdFontPointSelection*) _tmp25_;
					_tmp26_ = e;
					_tmp27_ = _tmp26_->point;
					_tmp28_ = e;
					_tmp29_ = _tmp28_->point;
					_tmp30_ = e;
					_tmp31_ = _tmp30_->point;
					bird_font_edit_point_set_position (_tmp27_, _tmp29_->x, _tmp31_->y - bird_font_glyph_ivz ());
					_tmp32_ = e;
					_tmp33_ = _tmp32_->path;
					_tmp34_ = e;
					_tmp35_ = _tmp34_->point;
					bird_font_path_recalculate_linear_handles_for_point (_tmp33_, _tmp35_);
					_g_object_unref0 (e);
				}
			}
		}
		if (keyval == ((guint) BIRD_FONT_KEY_LEFT)) {
			{
				GeeArrayList* _e_list = NULL;
				GeeArrayList* _tmp36_;
				gint _e_size = 0;
				GeeArrayList* _tmp37_;
				gint _tmp38_;
				gint _tmp39_;
				gint _e_index = 0;
				_tmp36_ = bird_font_pen_tool_selected_points;
				_e_list = _tmp36_;
				_tmp37_ = _e_list;
				_tmp38_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp37_);
				_tmp39_ = _tmp38_;
				_e_size = _tmp39_;
				_e_index = -1;
				while (TRUE) {
					gint _tmp40_;
					gint _tmp41_;
					BirdFontPointSelection* e = NULL;
					GeeArrayList* _tmp42_;
					gpointer _tmp43_;
					BirdFontPointSelection* _tmp44_;
					BirdFontEditPoint* _tmp45_;
					BirdFontPointSelection* _tmp46_;
					BirdFontEditPoint* _tmp47_;
					BirdFontPointSelection* _tmp48_;
					BirdFontEditPoint* _tmp49_;
					BirdFontPointSelection* _tmp50_;
					BirdFontPath* _tmp51_;
					BirdFontPointSelection* _tmp52_;
					BirdFontEditPoint* _tmp53_;
					_e_index = _e_index + 1;
					_tmp40_ = _e_index;
					_tmp41_ = _e_size;
					if (!(_tmp40_ < _tmp41_)) {
						break;
					}
					_tmp42_ = _e_list;
					_tmp43_ = gee_abstract_list_get ((GeeAbstractList*) _tmp42_, _e_index);
					e = (BirdFontPointSelection*) _tmp43_;
					_tmp44_ = e;
					_tmp45_ = _tmp44_->point;
					_tmp46_ = e;
					_tmp47_ = _tmp46_->point;
					_tmp48_ = e;
					_tmp49_ = _tmp48_->point;
					bird_font_edit_point_set_position (_tmp45_, _tmp47_->x - bird_font_glyph_ivz (), _tmp49_->y);
					_tmp50_ = e;
					_tmp51_ = _tmp50_->path;
					_tmp52_ = e;
					_tmp53_ = _tmp52_->point;
					bird_font_path_recalculate_linear_handles_for_point (_tmp51_, _tmp53_);
					_g_object_unref0 (e);
				}
			}
		}
		if (keyval == ((guint) BIRD_FONT_KEY_RIGHT)) {
			{
				GeeArrayList* _e_list = NULL;
				GeeArrayList* _tmp54_;
				gint _e_size = 0;
				GeeArrayList* _tmp55_;
				gint _tmp56_;
				gint _tmp57_;
				gint _e_index = 0;
				_tmp54_ = bird_font_pen_tool_selected_points;
				_e_list = _tmp54_;
				_tmp55_ = _e_list;
				_tmp56_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp55_);
				_tmp57_ = _tmp56_;
				_e_size = _tmp57_;
				_e_index = -1;
				while (TRUE) {
					gint _tmp58_;
					gint _tmp59_;
					BirdFontPointSelection* e = NULL;
					GeeArrayList* _tmp60_;
					gpointer _tmp61_;
					BirdFontPointSelection* _tmp62_;
					BirdFontEditPoint* _tmp63_;
					BirdFontPointSelection* _tmp64_;
					BirdFontEditPoint* _tmp65_;
					BirdFontPointSelection* _tmp66_;
					BirdFontEditPoint* _tmp67_;
					BirdFontPointSelection* _tmp68_;
					BirdFontPath* _tmp69_;
					BirdFontPointSelection* _tmp70_;
					BirdFontEditPoint* _tmp71_;
					_e_index = _e_index + 1;
					_tmp58_ = _e_index;
					_tmp59_ = _e_size;
					if (!(_tmp58_ < _tmp59_)) {
						break;
					}
					_tmp60_ = _e_list;
					_tmp61_ = gee_abstract_list_get ((GeeAbstractList*) _tmp60_, _e_index);
					e = (BirdFontPointSelection*) _tmp61_;
					_tmp62_ = e;
					_tmp63_ = _tmp62_->point;
					_tmp64_ = e;
					_tmp65_ = _tmp64_->point;
					_tmp66_ = e;
					_tmp67_ = _tmp66_->point;
					bird_font_edit_point_set_position (_tmp63_, _tmp65_->x + bird_font_glyph_ivz (), _tmp67_->y);
					_tmp68_ = e;
					_tmp69_ = _tmp68_->path;
					_tmp70_ = e;
					_tmp71_ = _tmp70_->point;
					bird_font_path_recalculate_linear_handles_for_point (_tmp69_, _tmp71_);
					_g_object_unref0 (e);
				}
			}
		}
		_g_object_unref0 (last_path);
		last_path = NULL;
		{
			GeeArrayList* _e_list = NULL;
			GeeArrayList* _tmp72_;
			gint _e_size = 0;
			GeeArrayList* _tmp73_;
			gint _tmp74_;
			gint _tmp75_;
			gint _e_index = 0;
			_tmp72_ = bird_font_pen_tool_selected_points;
			_e_list = _tmp72_;
			_tmp73_ = _e_list;
			_tmp74_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp73_);
			_tmp75_ = _tmp74_;
			_e_size = _tmp75_;
			_e_index = -1;
			while (TRUE) {
				gint _tmp76_;
				gint _tmp77_;
				BirdFontPointSelection* e = NULL;
				GeeArrayList* _tmp78_;
				gpointer _tmp79_;
				BirdFontPointSelection* _tmp80_;
				BirdFontPath* _tmp81_;
				BirdFontPath* _tmp82_;
				_e_index = _e_index + 1;
				_tmp76_ = _e_index;
				_tmp77_ = _e_size;
				if (!(_tmp76_ < _tmp77_)) {
					break;
				}
				_tmp78_ = _e_list;
				_tmp79_ = gee_abstract_list_get ((GeeAbstractList*) _tmp78_, _e_index);
				e = (BirdFontPointSelection*) _tmp79_;
				_tmp80_ = e;
				_tmp81_ = _tmp80_->path;
				_tmp82_ = last_path;
				if (_tmp81_ != _tmp82_) {
					BirdFontPointSelection* _tmp83_;
					BirdFontPath* _tmp84_;
					BirdFontPointSelection* _tmp85_;
					BirdFontPath* _tmp86_;
					BirdFontPath* _tmp87_;
					_tmp83_ = e;
					_tmp84_ = _tmp83_->path;
					bird_font_path_update_region_boundaries (_tmp84_);
					_tmp85_ = e;
					_tmp86_ = _tmp85_->path;
					_tmp87_ = _g_object_ref0 (_tmp86_);
					_g_object_unref0 (last_path);
					last_path = _tmp87_;
				}
				_g_object_unref0 (e);
			}
		}
	} else {
		BirdFontEditPointHandle* _tmp88_;
		BirdFontEditPointHandle* _tmp89_;
		bird_font_pen_tool_set_type_for_moving_handle (self);
		_tmp88_ = bird_font_pen_tool_active_handle;
		_tmp88_->active = FALSE;
		_tmp89_ = bird_font_edit_point_handle_new_empty ();
		_g_object_unref0 (bird_font_pen_tool_active_handle);
		bird_font_pen_tool_active_handle = _tmp89_;
		if (keyval == ((guint) BIRD_FONT_KEY_UP)) {
			BirdFontEditPointHandle* _tmp90_;
			_tmp90_ = bird_font_pen_tool_selected_handle;
			bird_font_edit_point_handle_move_delta_coordinate (_tmp90_, (gdouble) 0, 1 * bird_font_glyph_ivz ());
		}
		if (keyval == ((guint) BIRD_FONT_KEY_DOWN)) {
			BirdFontEditPointHandle* _tmp91_;
			_tmp91_ = bird_font_pen_tool_selected_handle;
			bird_font_edit_point_handle_move_delta_coordinate (_tmp91_, (gdouble) 0, -1 * bird_font_glyph_ivz ());
		}
		if (keyval == ((guint) BIRD_FONT_KEY_LEFT)) {
			BirdFontEditPointHandle* _tmp92_;
			_tmp92_ = bird_font_pen_tool_selected_handle;
			bird_font_edit_point_handle_move_delta_coordinate (_tmp92_, -1 * bird_font_glyph_ivz (), (gdouble) 0);
		}
		if (keyval == ((guint) BIRD_FONT_KEY_RIGHT)) {
			BirdFontEditPointHandle* _tmp93_;
			_tmp93_ = bird_font_pen_tool_selected_handle;
			bird_font_edit_point_handle_move_delta_coordinate (_tmp93_, 1 * bird_font_glyph_ivz (), (gdouble) 0);
		}
	}
	bird_font_pen_tool_reset_stroke ();
	bird_font_glyph_canvas_redraw ();
	_g_object_unref0 (last_path);
}

void
bird_font_pen_tool_convert_point_to_line (BirdFontEditPoint* ep,
                                          gboolean both)
{
	BirdFontEditPoint* _tmp0_;
	BirdFontEditPoint* _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp23_ = FALSE;
	g_return_if_fail (ep != NULL);
	bird_font_edit_point_set_tie_handle (ep, FALSE);
	bird_font_edit_point_set_reflective_handles (ep, FALSE);
	_tmp0_ = ep->next;
	if (_tmp0_ == NULL) {
	}
	_tmp1_ = ep->prev;
	if (_tmp1_ == NULL) {
		g_warning ("PenTool.vala:2298: Prev is null.");
	}
	if (ep->type == BIRD_FONT_POINT_TYPE_CUBIC) {
		_tmp2_ = TRUE;
	} else {
		_tmp2_ = ep->type == BIRD_FONT_POINT_TYPE_LINE_CUBIC;
	}
	if (_tmp2_) {
		gboolean _tmp5_ = FALSE;
		BirdFontEditPoint* _tmp6_;
		gboolean _tmp9_ = FALSE;
		BirdFontEditPoint* _tmp10_;
		ep->type = BIRD_FONT_POINT_TYPE_LINE_CUBIC;
		if (both) {
			BirdFontEditPointHandle* _tmp3_;
			BirdFontEditPointHandle* _tmp4_;
			_tmp3_ = bird_font_edit_point_get_left_handle (ep);
			_tmp3_->type = BIRD_FONT_POINT_TYPE_LINE_CUBIC;
			_tmp4_ = bird_font_edit_point_get_right_handle (ep);
			_tmp4_->type = BIRD_FONT_POINT_TYPE_LINE_CUBIC;
		}
		_tmp6_ = ep->next;
		if (_tmp6_ != NULL) {
			BirdFontEditPoint* _tmp7_;
			_tmp7_ = bird_font_edit_point_get_next (ep);
			_tmp5_ = bird_font_edit_point_is_selected (_tmp7_);
		} else {
			_tmp5_ = FALSE;
		}
		if (_tmp5_) {
			BirdFontEditPointHandle* _tmp8_;
			_tmp8_ = bird_font_edit_point_get_right_handle (ep);
			_tmp8_->type = BIRD_FONT_POINT_TYPE_LINE_CUBIC;
		}
		_tmp10_ = ep->prev;
		if (_tmp10_ != NULL) {
			BirdFontEditPoint* _tmp11_;
			_tmp11_ = bird_font_edit_point_get_prev (ep);
			_tmp9_ = bird_font_edit_point_is_selected (_tmp11_);
		} else {
			_tmp9_ = FALSE;
		}
		if (_tmp9_) {
			BirdFontEditPointHandle* _tmp12_;
			_tmp12_ = bird_font_edit_point_get_left_handle (ep);
			_tmp12_->type = BIRD_FONT_POINT_TYPE_LINE_CUBIC;
		}
	}
	if ((ep->type == BIRD_FONT_POINT_TYPE_DOUBLE_CURVE) | (ep->type == BIRD_FONT_POINT_TYPE_LINE_DOUBLE_CURVE)) {
		gboolean _tmp15_ = FALSE;
		BirdFontEditPoint* _tmp16_;
		gboolean _tmp19_ = FALSE;
		BirdFontEditPoint* _tmp20_;
		ep->type = BIRD_FONT_POINT_TYPE_LINE_DOUBLE_CURVE;
		if (both) {
			BirdFontEditPointHandle* _tmp13_;
			BirdFontEditPointHandle* _tmp14_;
			_tmp13_ = bird_font_edit_point_get_left_handle (ep);
			_tmp13_->type = BIRD_FONT_POINT_TYPE_LINE_DOUBLE_CURVE;
			_tmp14_ = bird_font_edit_point_get_right_handle (ep);
			_tmp14_->type = BIRD_FONT_POINT_TYPE_LINE_DOUBLE_CURVE;
		}
		_tmp16_ = ep->next;
		if (_tmp16_ != NULL) {
			BirdFontEditPoint* _tmp17_;
			_tmp17_ = bird_font_edit_point_get_next (ep);
			_tmp15_ = bird_font_edit_point_is_selected (_tmp17_);
		} else {
			_tmp15_ = FALSE;
		}
		if (_tmp15_) {
			BirdFontEditPointHandle* _tmp18_;
			_tmp18_ = bird_font_edit_point_get_right_handle (ep);
			_tmp18_->type = BIRD_FONT_POINT_TYPE_LINE_DOUBLE_CURVE;
		}
		_tmp20_ = ep->prev;
		if (_tmp20_ != NULL) {
			BirdFontEditPoint* _tmp21_;
			_tmp21_ = bird_font_edit_point_get_prev (ep);
			_tmp19_ = bird_font_edit_point_is_selected (_tmp21_);
		} else {
			_tmp19_ = FALSE;
		}
		if (_tmp19_) {
			BirdFontEditPointHandle* _tmp22_;
			_tmp22_ = bird_font_edit_point_get_left_handle (ep);
			_tmp22_->type = BIRD_FONT_POINT_TYPE_LINE_DOUBLE_CURVE;
		}
	}
	if (ep->type == BIRD_FONT_POINT_TYPE_QUADRATIC) {
		_tmp23_ = TRUE;
	} else {
		_tmp23_ = ep->type == BIRD_FONT_POINT_TYPE_LINE_QUADRATIC;
	}
	if (_tmp23_) {
		gboolean _tmp32_ = FALSE;
		BirdFontEditPoint* _tmp33_;
		gboolean _tmp38_ = FALSE;
		BirdFontEditPoint* _tmp39_;
		ep->type = BIRD_FONT_POINT_TYPE_LINE_QUADRATIC;
		if (both) {
			BirdFontEditPointHandle* _tmp24_;
			BirdFontEditPointHandle* _tmp25_;
			BirdFontEditPoint* _tmp26_;
			BirdFontEditPoint* _tmp29_;
			_tmp24_ = bird_font_edit_point_get_left_handle (ep);
			_tmp24_->type = BIRD_FONT_POINT_TYPE_LINE_QUADRATIC;
			_tmp25_ = bird_font_edit_point_get_right_handle (ep);
			_tmp25_->type = BIRD_FONT_POINT_TYPE_LINE_QUADRATIC;
			_tmp26_ = ep->next;
			if (_tmp26_ != NULL) {
				BirdFontEditPoint* _tmp27_;
				BirdFontEditPointHandle* _tmp28_;
				_tmp27_ = bird_font_edit_point_get_next (ep);
				_tmp28_ = bird_font_edit_point_get_left_handle (_tmp27_);
				_tmp28_->type = BIRD_FONT_POINT_TYPE_LINE_QUADRATIC;
			}
			_tmp29_ = ep->prev;
			if (_tmp29_ != NULL) {
				BirdFontEditPoint* _tmp30_;
				BirdFontEditPointHandle* _tmp31_;
				_tmp30_ = bird_font_edit_point_get_prev (ep);
				_tmp31_ = bird_font_edit_point_get_right_handle (_tmp30_);
				_tmp31_->type = BIRD_FONT_POINT_TYPE_LINE_QUADRATIC;
			}
		}
		_tmp33_ = ep->next;
		if (_tmp33_ != NULL) {
			BirdFontEditPoint* _tmp34_;
			_tmp34_ = bird_font_edit_point_get_next (ep);
			_tmp32_ = bird_font_edit_point_is_selected (_tmp34_);
		} else {
			_tmp32_ = FALSE;
		}
		if (_tmp32_) {
			BirdFontEditPointHandle* _tmp35_;
			BirdFontEditPoint* _tmp36_;
			BirdFontEditPointHandle* _tmp37_;
			_tmp35_ = bird_font_edit_point_get_right_handle (ep);
			_tmp35_->type = BIRD_FONT_POINT_TYPE_LINE_QUADRATIC;
			_tmp36_ = bird_font_edit_point_get_next (ep);
			_tmp37_ = bird_font_edit_point_get_left_handle (_tmp36_);
			_tmp37_->type = BIRD_FONT_POINT_TYPE_LINE_QUADRATIC;
		}
		_tmp39_ = ep->prev;
		if (_tmp39_ != NULL) {
			BirdFontEditPoint* _tmp40_;
			_tmp40_ = bird_font_edit_point_get_prev (ep);
			_tmp38_ = bird_font_edit_point_is_selected (_tmp40_);
		} else {
			_tmp38_ = FALSE;
		}
		if (_tmp38_) {
			BirdFontEditPointHandle* _tmp41_;
			BirdFontEditPoint* _tmp42_;
			BirdFontEditPointHandle* _tmp43_;
			_tmp41_ = bird_font_edit_point_get_left_handle (ep);
			_tmp41_->type = BIRD_FONT_POINT_TYPE_LINE_QUADRATIC;
			_tmp42_ = bird_font_edit_point_get_prev (ep);
			_tmp43_ = bird_font_edit_point_get_right_handle (_tmp42_);
			_tmp43_->type = BIRD_FONT_POINT_TYPE_LINE_QUADRATIC;
		}
	}
}

void
bird_font_pen_tool_convert_segment_to_line (void)
{
	GeeArrayList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	GeeArrayList* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	_tmp0_ = bird_font_pen_tool_selected_points;
	_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == 0) {
		return;
	}
	_tmp3_ = bird_font_pen_tool_selected_points;
	_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
	_tmp5_ = _tmp4_;
	if (_tmp5_ == 1) {
		GeeArrayList* _tmp6_;
		gpointer _tmp7_;
		BirdFontPointSelection* _tmp8_;
		BirdFontEditPoint* _tmp9_;
		_tmp6_ = bird_font_pen_tool_selected_points;
		_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, 0);
		_tmp8_ = (BirdFontPointSelection*) _tmp7_;
		_tmp9_ = _tmp8_->point;
		bird_font_pen_tool_convert_point_to_line (_tmp9_, TRUE);
		_g_object_unref0 (_tmp8_);
	} else {
		{
			GeeArrayList* _p_list = NULL;
			GeeArrayList* _tmp10_;
			gint _p_size = 0;
			GeeArrayList* _tmp11_;
			gint _tmp12_;
			gint _tmp13_;
			gint _p_index = 0;
			_tmp10_ = bird_font_pen_tool_selected_points;
			_p_list = _tmp10_;
			_tmp11_ = _p_list;
			_tmp12_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp11_);
			_tmp13_ = _tmp12_;
			_p_size = _tmp13_;
			_p_index = -1;
			while (TRUE) {
				gint _tmp14_;
				gint _tmp15_;
				BirdFontPointSelection* p = NULL;
				GeeArrayList* _tmp16_;
				gpointer _tmp17_;
				BirdFontPointSelection* _tmp18_;
				BirdFontEditPoint* _tmp19_;
				_p_index = _p_index + 1;
				_tmp14_ = _p_index;
				_tmp15_ = _p_size;
				if (!(_tmp14_ < _tmp15_)) {
					break;
				}
				_tmp16_ = _p_list;
				_tmp17_ = gee_abstract_list_get ((GeeAbstractList*) _tmp16_, _p_index);
				p = (BirdFontPointSelection*) _tmp17_;
				_tmp18_ = p;
				_tmp19_ = _tmp18_->point;
				bird_font_pen_tool_convert_point_to_line (_tmp19_, FALSE);
				_g_object_unref0 (p);
			}
		}
	}
	{
		GeeArrayList* _p_list = NULL;
		GeeArrayList* _tmp20_;
		gint _p_size = 0;
		GeeArrayList* _tmp21_;
		gint _tmp22_;
		gint _tmp23_;
		gint _p_index = 0;
		_tmp20_ = bird_font_pen_tool_selected_points;
		_p_list = _tmp20_;
		_tmp21_ = _p_list;
		_tmp22_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp21_);
		_tmp23_ = _tmp22_;
		_p_size = _tmp23_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp24_;
			gint _tmp25_;
			BirdFontPointSelection* p = NULL;
			GeeArrayList* _tmp26_;
			gpointer _tmp27_;
			BirdFontPointSelection* _tmp28_;
			BirdFontPath* _tmp29_;
			BirdFontPointSelection* _tmp30_;
			BirdFontEditPoint* _tmp31_;
			_p_index = _p_index + 1;
			_tmp24_ = _p_index;
			_tmp25_ = _p_size;
			if (!(_tmp24_ < _tmp25_)) {
				break;
			}
			_tmp26_ = _p_list;
			_tmp27_ = gee_abstract_list_get ((GeeAbstractList*) _tmp26_, _p_index);
			p = (BirdFontPointSelection*) _tmp27_;
			_tmp28_ = p;
			_tmp29_ = _tmp28_->path;
			_tmp30_ = p;
			_tmp31_ = _tmp30_->point;
			bird_font_path_recalculate_linear_handles_for_point (_tmp29_, _tmp31_);
			_g_object_unref0 (p);
		}
	}
}

gboolean
bird_font_pen_tool_is_line (BirdFontPointType t)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean result;
	if (t == BIRD_FONT_POINT_TYPE_LINE_QUADRATIC) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = t == BIRD_FONT_POINT_TYPE_LINE_DOUBLE_CURVE;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = t == BIRD_FONT_POINT_TYPE_LINE_CUBIC;
	}
	result = _tmp0_;
	return result;
}

BirdFontPointType
bird_font_pen_tool_to_line (BirdFontPointType t)
{
	BirdFontPointType result;
	switch (t) {
		case BIRD_FONT_POINT_TYPE_QUADRATIC:
		{
			result = BIRD_FONT_POINT_TYPE_LINE_QUADRATIC;
			return result;
		}
		case BIRD_FONT_POINT_TYPE_DOUBLE_CURVE:
		{
			result = BIRD_FONT_POINT_TYPE_LINE_DOUBLE_CURVE;
			return result;
		}
		case BIRD_FONT_POINT_TYPE_CUBIC:
		{
			result = BIRD_FONT_POINT_TYPE_LINE_CUBIC;
			return result;
		}
		default:
		{
			break;
		}
	}
	result = t;
	return result;
}

BirdFontPointType
bird_font_pen_tool_to_curve (BirdFontPointType t)
{
	BirdFontPointType result;
	switch (t) {
		case BIRD_FONT_POINT_TYPE_LINE_QUADRATIC:
		{
			result = BIRD_FONT_POINT_TYPE_QUADRATIC;
			return result;
		}
		case BIRD_FONT_POINT_TYPE_LINE_DOUBLE_CURVE:
		{
			result = BIRD_FONT_POINT_TYPE_DOUBLE_CURVE;
			return result;
		}
		case BIRD_FONT_POINT_TYPE_LINE_CUBIC:
		{
			result = BIRD_FONT_POINT_TYPE_CUBIC;
			return result;
		}
		default:
		{
			break;
		}
	}
	if (G_UNLIKELY (t == BIRD_FONT_POINT_TYPE_NONE)) {
		g_warning ("PenTool.vala:2417: Type is not set.");
	}
	result = t;
	return result;
}

void
bird_font_pen_tool_set_converted_handle_length (BirdFontEditPointHandle* e,
                                                BirdFontPointType pt)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	gboolean _tmp5_ = FALSE;
	g_return_if_fail (e != NULL);
	if (e->type == BIRD_FONT_POINT_TYPE_QUADRATIC) {
		_tmp0_ = pt == BIRD_FONT_POINT_TYPE_DOUBLE_CURVE;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		e->length = e->length * 2;
		e->length = e->length / 4;
	}
	if (e->type == BIRD_FONT_POINT_TYPE_QUADRATIC) {
		_tmp1_ = pt == BIRD_FONT_POINT_TYPE_CUBIC;
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		e->length = e->length * 2;
		e->length = e->length / 3;
	}
	if (e->type == BIRD_FONT_POINT_TYPE_DOUBLE_CURVE) {
		_tmp2_ = pt == BIRD_FONT_POINT_TYPE_QUADRATIC;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		e->length = e->length * 4;
		e->length = e->length / 2;
	}
	if (e->type == BIRD_FONT_POINT_TYPE_DOUBLE_CURVE) {
		_tmp3_ = pt == BIRD_FONT_POINT_TYPE_CUBIC;
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		e->length = e->length * 4;
		e->length = e->length / 3;
	}
	if (e->type == BIRD_FONT_POINT_TYPE_CUBIC) {
		_tmp4_ = pt == BIRD_FONT_POINT_TYPE_QUADRATIC;
	} else {
		_tmp4_ = FALSE;
	}
	if (_tmp4_) {
		e->length = e->length * 3;
		e->length = e->length / 2;
	}
	if (e->type == BIRD_FONT_POINT_TYPE_CUBIC) {
		_tmp5_ = pt == BIRD_FONT_POINT_TYPE_DOUBLE_CURVE;
	} else {
		_tmp5_ = FALSE;
	}
	if (_tmp5_) {
		e->length = e->length * 3;
		e->length = e->length / 4;
	}
}

void
bird_font_pen_tool_convert_point_segment_type (BirdFontEditPoint* first,
                                               BirdFontEditPoint* next,
                                               BirdFontPointType point_type)
{
	gboolean line = FALSE;
	BirdFontEditPointHandle* _tmp0_;
	BirdFontEditPointHandle* _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	g_return_if_fail (first != NULL);
	g_return_if_fail (next != NULL);
	_tmp0_ = bird_font_edit_point_get_right_handle (first);
	bird_font_pen_tool_set_converted_handle_length (_tmp0_, point_type);
	_tmp1_ = bird_font_edit_point_get_left_handle (next);
	bird_font_pen_tool_set_converted_handle_length (_tmp1_, point_type);
	if (bird_font_pen_tool_is_line (first->type)) {
		BirdFontEditPointHandle* _tmp4_;
		_tmp4_ = bird_font_edit_point_get_right_handle (first);
		_tmp3_ = bird_font_pen_tool_is_line (_tmp4_->type);
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		BirdFontEditPointHandle* _tmp5_;
		_tmp5_ = bird_font_edit_point_get_left_handle (next);
		_tmp2_ = bird_font_pen_tool_is_line (_tmp5_->type);
	} else {
		_tmp2_ = FALSE;
	}
	line = _tmp2_;
	if (!line) {
		first->type = point_type;
	} else {
		first->type = bird_font_pen_tool_to_line (point_type);
	}
	if (!line) {
		BirdFontEditPointHandle* _tmp6_;
		_tmp6_ = bird_font_edit_point_get_right_handle (first);
		_tmp6_->type = point_type;
	} else {
		BirdFontEditPointHandle* _tmp7_;
		_tmp7_ = bird_font_edit_point_get_right_handle (first);
		_tmp7_->type = bird_font_pen_tool_to_line (point_type);
	}
	if (!line) {
		BirdFontEditPointHandle* _tmp8_;
		_tmp8_ = bird_font_edit_point_get_left_handle (next);
		_tmp8_->type = point_type;
	} else {
		BirdFontEditPointHandle* _tmp9_;
		_tmp9_ = bird_font_edit_point_get_left_handle (next);
		_tmp9_->type = bird_font_pen_tool_to_line (point_type);
	}
	if (point_type == BIRD_FONT_POINT_TYPE_QUADRATIC) {
		bird_font_edit_point_set_position (first, first->x, first->y);
	}
}

void
bird_font_pen_tool_convert_point_type (BirdFontEditPoint* first,
                                       BirdFontPointType point_type)
{
	BirdFontEditPoint* _tmp0_;
	g_return_if_fail (first != NULL);
	_tmp0_ = bird_font_edit_point_get_next (first);
	bird_font_pen_tool_convert_point_segment_type (first, _tmp0_, point_type);
}

void
bird_font_pen_tool_convert_point_types (void)
{
	BirdFontGlyph* glyph = NULL;
	BirdFontGlyph* _tmp0_;
	BirdFontGlyph* _tmp1_;
	BirdFontPointSelection* selected = NULL;
	BirdFontPointSelection* _tmp2_;
	gboolean reset_selected = FALSE;
	BirdFontEditPoint* e = NULL;
	GeeArrayList* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	glyph = _tmp0_;
	_tmp1_ = glyph;
	bird_font_glyph_store_undo_state (_tmp1_, FALSE);
	_tmp2_ = bird_font_point_selection_new_empty ();
	selected = _tmp2_;
	reset_selected = FALSE;
	_tmp3_ = bird_font_pen_tool_selected_points;
	_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
	_tmp5_ = _tmp4_;
	if (_tmp5_ == 1) {
		GeeArrayList* _tmp6_;
		gpointer _tmp7_;
		BirdFontPointSelection* _tmp8_;
		BirdFontEditPoint* _tmp9_;
		BirdFontEditPoint* _tmp10_;
		BirdFontPointSelection* _tmp22_;
		BirdFontEditPoint* _tmp23_;
		BirdFontEditPoint* _tmp24_;
		_tmp6_ = bird_font_pen_tool_selected_points;
		_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, 0);
		_g_object_unref0 (selected);
		selected = (BirdFontPointSelection*) _tmp7_;
		_tmp8_ = selected;
		_tmp9_ = _tmp8_->point;
		_tmp10_ = _tmp9_->next;
		if (_tmp10_ != NULL) {
			GeeArrayList* _tmp11_;
			BirdFontPointSelection* _tmp12_;
			BirdFontEditPoint* _tmp13_;
			BirdFontEditPoint* _tmp14_;
			BirdFontPointSelection* _tmp15_;
			BirdFontPath* _tmp16_;
			BirdFontPointSelection* _tmp17_;
			BirdFontPointSelection* _tmp18_;
			BirdFontPointSelection* _tmp19_;
			BirdFontEditPoint* _tmp20_;
			BirdFontEditPoint* _tmp21_;
			_tmp11_ = bird_font_pen_tool_selected_points;
			_tmp12_ = selected;
			_tmp13_ = _tmp12_->point;
			_tmp14_ = bird_font_edit_point_get_next (_tmp13_);
			_tmp15_ = selected;
			_tmp16_ = _tmp15_->path;
			_tmp17_ = bird_font_point_selection_new (_tmp14_, _tmp16_);
			_tmp18_ = _tmp17_;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp11_, _tmp18_);
			_g_object_unref0 (_tmp18_);
			_tmp19_ = selected;
			_tmp20_ = _tmp19_->point;
			_tmp21_ = bird_font_edit_point_get_next (_tmp20_);
			bird_font_edit_point_set_selected (_tmp21_, TRUE);
		}
		_tmp22_ = selected;
		_tmp23_ = _tmp22_->point;
		_tmp24_ = _tmp23_->prev;
		if (_tmp24_ != NULL) {
			GeeArrayList* _tmp25_;
			BirdFontPointSelection* _tmp26_;
			BirdFontEditPoint* _tmp27_;
			BirdFontEditPoint* _tmp28_;
			BirdFontPointSelection* _tmp29_;
			BirdFontPath* _tmp30_;
			BirdFontPointSelection* _tmp31_;
			BirdFontPointSelection* _tmp32_;
			BirdFontPointSelection* _tmp33_;
			BirdFontEditPoint* _tmp34_;
			BirdFontEditPoint* _tmp35_;
			_tmp25_ = bird_font_pen_tool_selected_points;
			_tmp26_ = selected;
			_tmp27_ = _tmp26_->point;
			_tmp28_ = bird_font_edit_point_get_prev (_tmp27_);
			_tmp29_ = selected;
			_tmp30_ = _tmp29_->path;
			_tmp31_ = bird_font_point_selection_new (_tmp28_, _tmp30_);
			_tmp32_ = _tmp31_;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp25_, _tmp32_);
			_g_object_unref0 (_tmp32_);
			_tmp33_ = selected;
			_tmp34_ = _tmp33_->point;
			_tmp35_ = bird_font_edit_point_get_next (_tmp34_);
			bird_font_edit_point_set_selected (_tmp35_, TRUE);
		}
		reset_selected = TRUE;
	}
	{
		GeeArrayList* _ps_list = NULL;
		GeeArrayList* _tmp36_;
		gint _ps_size = 0;
		GeeArrayList* _tmp37_;
		gint _tmp38_;
		gint _tmp39_;
		gint _ps_index = 0;
		_tmp36_ = bird_font_pen_tool_selected_points;
		_ps_list = _tmp36_;
		_tmp37_ = _ps_list;
		_tmp38_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp37_);
		_tmp39_ = _tmp38_;
		_ps_size = _tmp39_;
		_ps_index = -1;
		while (TRUE) {
			gint _tmp40_;
			gint _tmp41_;
			BirdFontPointSelection* ps = NULL;
			GeeArrayList* _tmp42_;
			gpointer _tmp43_;
			BirdFontPointSelection* _tmp44_;
			BirdFontEditPoint* _tmp45_;
			BirdFontEditPoint* _tmp46_;
			gboolean _tmp47_ = FALSE;
			BirdFontEditPoint* _tmp48_;
			BirdFontEditPoint* _tmp49_;
			BirdFontEditPoint* _tmp52_;
			BirdFontPointSelection* _tmp53_;
			BirdFontPath* _tmp54_;
			BirdFontPointSelection* _tmp55_;
			BirdFontEditPoint* _tmp56_;
			_ps_index = _ps_index + 1;
			_tmp40_ = _ps_index;
			_tmp41_ = _ps_size;
			if (!(_tmp40_ < _tmp41_)) {
				break;
			}
			_tmp42_ = _ps_list;
			_tmp43_ = gee_abstract_list_get ((GeeAbstractList*) _tmp42_, _ps_index);
			ps = (BirdFontPointSelection*) _tmp43_;
			_tmp44_ = ps;
			_tmp45_ = _tmp44_->point;
			_tmp46_ = _g_object_ref0 (_tmp45_);
			_g_object_unref0 (e);
			e = _tmp46_;
			_tmp48_ = e;
			_tmp49_ = _tmp48_->next;
			if (_tmp49_ == NULL) {
				_tmp47_ = TRUE;
			} else {
				BirdFontEditPoint* _tmp50_;
				BirdFontEditPoint* _tmp51_;
				_tmp50_ = e;
				_tmp51_ = bird_font_edit_point_get_next (_tmp50_);
				_tmp47_ = !bird_font_edit_point_is_selected (_tmp51_);
			}
			if (_tmp47_) {
				_g_object_unref0 (ps);
				continue;
			}
			_tmp52_ = e;
			bird_font_pen_tool_convert_point_type (_tmp52_, bird_font_drawing_tools_point_type);
			_tmp53_ = ps;
			_tmp54_ = _tmp53_->path;
			_tmp55_ = ps;
			_tmp56_ = _tmp55_->point;
			bird_font_path_recalculate_linear_handles_for_point (_tmp54_, _tmp56_);
			_g_object_unref0 (ps);
		}
	}
	if (reset_selected) {
		GeeArrayList* _tmp57_;
		BirdFontPointSelection* _tmp58_;
		BirdFontPointSelection* _tmp59_;
		BirdFontEditPoint* _tmp60_;
		bird_font_pen_tool_remove_all_selected_points ();
		_tmp57_ = bird_font_pen_tool_selected_points;
		_tmp58_ = selected;
		gee_abstract_collection_add ((GeeAbstractCollection*) _tmp57_, _tmp58_);
		_tmp59_ = selected;
		_tmp60_ = _tmp59_->point;
		bird_font_edit_point_set_selected (_tmp60_, TRUE);
	}
	{
		GeeArrayList* _p_list = NULL;
		BirdFontGlyph* _tmp61_;
		GeeArrayList* _tmp62_;
		gint _p_size = 0;
		GeeArrayList* _tmp63_;
		gint _tmp64_;
		gint _tmp65_;
		gint _p_index = 0;
		_tmp61_ = glyph;
		_tmp62_ = bird_font_glyph_get_visible_paths (_tmp61_);
		_p_list = _tmp62_;
		_tmp63_ = _p_list;
		_tmp64_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp63_);
		_tmp65_ = _tmp64_;
		_p_size = _tmp65_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp66_;
			gint _tmp67_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp68_;
			gpointer _tmp69_;
			BirdFontPath* _tmp70_;
			_p_index = _p_index + 1;
			_tmp66_ = _p_index;
			_tmp67_ = _p_size;
			if (!(_tmp66_ < _tmp67_)) {
				break;
			}
			_tmp68_ = _p_list;
			_tmp69_ = gee_abstract_list_get ((GeeAbstractList*) _tmp68_, _p_index);
			p = (BirdFontPath*) _tmp69_;
			_tmp70_ = p;
			bird_font_path_update_region_boundaries (_tmp70_);
			_g_object_unref0 (p);
		}
		_g_object_unref0 (_p_list);
	}
	_g_object_unref0 (e);
	_g_object_unref0 (selected);
	_g_object_unref0 (glyph);
}

void
bird_font_pen_tool_update_selected_points (void)
{
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	GeeArrayList* _tmp1_;
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	_tmp1_ = bird_font_pen_tool_selected_points;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp1_);
	{
		GeeArrayList* _p_list = NULL;
		BirdFontGlyph* _tmp2_;
		GeeArrayList* _tmp3_;
		gint _p_size = 0;
		GeeArrayList* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		gint _p_index = 0;
		_tmp2_ = g;
		_tmp3_ = bird_font_glyph_get_visible_paths (_tmp2_);
		_p_list = _tmp3_;
		_tmp4_ = _p_list;
		_tmp5_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp4_);
		_tmp6_ = _tmp5_;
		_p_size = _tmp6_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp7_;
			gint _tmp8_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp9_;
			gpointer _tmp10_;
			_p_index = _p_index + 1;
			_tmp7_ = _p_index;
			_tmp8_ = _p_size;
			if (!(_tmp7_ < _tmp8_)) {
				break;
			}
			_tmp9_ = _p_list;
			_tmp10_ = gee_abstract_list_get ((GeeAbstractList*) _tmp9_, _p_index);
			p = (BirdFontPath*) _tmp10_;
			{
				GeeArrayList* _ep_list = NULL;
				BirdFontPath* _tmp11_;
				GeeArrayList* _tmp12_;
				GeeArrayList* _tmp13_;
				gint _ep_size = 0;
				GeeArrayList* _tmp14_;
				gint _tmp15_;
				gint _tmp16_;
				gint _ep_index = 0;
				_tmp11_ = p;
				_tmp12_ = bird_font_path_get_points (_tmp11_);
				_tmp13_ = _tmp12_;
				_ep_list = _tmp13_;
				_tmp14_ = _ep_list;
				_tmp15_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp14_);
				_tmp16_ = _tmp15_;
				_ep_size = _tmp16_;
				_ep_index = -1;
				while (TRUE) {
					gint _tmp17_;
					gint _tmp18_;
					BirdFontEditPoint* ep = NULL;
					GeeArrayList* _tmp19_;
					gpointer _tmp20_;
					BirdFontEditPoint* _tmp21_;
					_ep_index = _ep_index + 1;
					_tmp17_ = _ep_index;
					_tmp18_ = _ep_size;
					if (!(_tmp17_ < _tmp18_)) {
						break;
					}
					_tmp19_ = _ep_list;
					_tmp20_ = gee_abstract_list_get ((GeeAbstractList*) _tmp19_, _ep_index);
					ep = (BirdFontEditPoint*) _tmp20_;
					_tmp21_ = ep;
					if (bird_font_edit_point_is_selected (_tmp21_)) {
						GeeArrayList* _tmp22_;
						BirdFontEditPoint* _tmp23_;
						BirdFontPath* _tmp24_;
						BirdFontPointSelection* _tmp25_;
						BirdFontPointSelection* _tmp26_;
						_tmp22_ = bird_font_pen_tool_selected_points;
						_tmp23_ = ep;
						_tmp24_ = p;
						_tmp25_ = bird_font_point_selection_new (_tmp23_, _tmp24_);
						_tmp26_ = _tmp25_;
						gee_abstract_collection_add ((GeeAbstractCollection*) _tmp22_, _tmp26_);
						_g_object_unref0 (_tmp26_);
					}
					_g_object_unref0 (ep);
				}
			}
			_g_object_unref0 (p);
		}
		_g_object_unref0 (_p_list);
	}
	_g_object_unref0 (g);
}

void
bird_font_pen_tool_select_all_points (BirdFontPenTool* self)
{
	BirdFontGlyph* g = NULL;
	BirdFontGlyph* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = bird_font_main_window_get_current_glyph ();
	g = _tmp0_;
	{
		GeeArrayList* _p_list = NULL;
		BirdFontGlyph* _tmp1_;
		GeeArrayList* _tmp2_;
		gint _p_size = 0;
		GeeArrayList* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		gint _p_index = 0;
		_tmp1_ = g;
		_tmp2_ = bird_font_glyph_get_visible_paths (_tmp1_);
		_p_list = _tmp2_;
		_tmp3_ = _p_list;
		_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
		_tmp5_ = _tmp4_;
		_p_size = _tmp5_;
		_p_index = -1;
		while (TRUE) {
			gint _tmp6_;
			gint _tmp7_;
			BirdFontPath* p = NULL;
			GeeArrayList* _tmp8_;
			gpointer _tmp9_;
			_p_index = _p_index + 1;
			_tmp6_ = _p_index;
			_tmp7_ = _p_size;
			if (!(_tmp6_ < _tmp7_)) {
				break;
			}
			_tmp8_ = _p_list;
			_tmp9_ = gee_abstract_list_get ((GeeAbstractList*) _tmp8_, _p_index);
			p = (BirdFontPath*) _tmp9_;
			{
				GeeArrayList* _ep_list = NULL;
				BirdFontPath* _tmp10_;
				GeeArrayList* _tmp11_;
				GeeArrayList* _tmp12_;
				gint _ep_size = 0;
				GeeArrayList* _tmp13_;
				gint _tmp14_;
				gint _tmp15_;
				gint _ep_index = 0;
				_tmp10_ = p;
				_tmp11_ = bird_font_path_get_points (_tmp10_);
				_tmp12_ = _tmp11_;
				_ep_list = _tmp12_;
				_tmp13_ = _ep_list;
				_tmp14_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp13_);
				_tmp15_ = _tmp14_;
				_ep_size = _tmp15_;
				_ep_index = -1;
				while (TRUE) {
					gint _tmp16_;
					gint _tmp17_;
					BirdFontEditPoint* ep = NULL;
					GeeArrayList* _tmp18_;
					gpointer _tmp19_;
					BirdFontEditPoint* _tmp20_;
					BirdFontEditPoint* _tmp21_;
					BirdFontPath* _tmp22_;
					_ep_index = _ep_index + 1;
					_tmp16_ = _ep_index;
					_tmp17_ = _ep_size;
					if (!(_tmp16_ < _tmp17_)) {
						break;
					}
					_tmp18_ = _ep_list;
					_tmp19_ = gee_abstract_list_get ((GeeAbstractList*) _tmp18_, _ep_index);
					ep = (BirdFontEditPoint*) _tmp19_;
					_tmp20_ = ep;
					bird_font_edit_point_set_selected (_tmp20_, TRUE);
					_tmp21_ = ep;
					_tmp22_ = p;
					bird_font_pen_tool_add_selected_point (_tmp21_, _tmp22_);
					_g_object_unref0 (ep);
				}
			}
			_g_object_unref0 (p);
		}
		_g_object_unref0 (_p_list);
	}
	_g_object_unref0 (g);
}

BirdFontPath*
bird_font_pen_tool_simplify (BirdFontPath* path,
                             gboolean selected_segments,
                             gdouble threshold)
{
	BirdFontPointSelection* ps = NULL;
	BirdFontEditPoint* ep = NULL;
	BirdFontPath* p1 = NULL;
	BirdFontPath* new_path = NULL;
	gdouble d = 0.0;
	gdouble sumd = 0.0;
	gint i = 0;
	BirdFontPath* _tmp0_;
	BirdFontPath* _tmp1_;
	BirdFontPath* _tmp2_;
	BirdFontPath* _tmp21_;
	BirdFontPath* result;
	g_return_val_if_fail (path != NULL, NULL);
	_tmp0_ = bird_font_path_copy (path);
	_g_object_unref0 (p1);
	p1 = _tmp0_;
	_tmp1_ = p1;
	_tmp2_ = bird_font_path_copy (_tmp1_);
	_g_object_unref0 (new_path);
	new_path = _tmp2_;
	i = 0;
	sumd = (gdouble) 0;
	while (TRUE) {
		BirdFontPath* _tmp3_;
		GeeArrayList* _tmp4_;
		GeeArrayList* _tmp5_;
		gint _tmp6_;
		gint _tmp7_;
		BirdFontPath* _tmp8_;
		GeeArrayList* _tmp9_;
		GeeArrayList* _tmp10_;
		gpointer _tmp11_;
		BirdFontEditPoint* _tmp12_;
		BirdFontPath* _tmp13_;
		BirdFontPointSelection* _tmp14_;
		BirdFontPointSelection* _tmp15_;
		_tmp3_ = new_path;
		_tmp4_ = bird_font_path_get_points (_tmp3_);
		_tmp5_ = _tmp4_;
		_tmp6_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp5_);
		_tmp7_ = _tmp6_;
		if (!(i < _tmp7_)) {
			break;
		}
		_tmp8_ = new_path;
		_tmp9_ = bird_font_path_get_points (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp11_ = gee_abstract_list_get ((GeeAbstractList*) _tmp10_, i);
		_g_object_unref0 (ep);
		ep = (BirdFontEditPoint*) _tmp11_;
		_tmp12_ = ep;
		_tmp13_ = new_path;
		_tmp14_ = bird_font_point_selection_new (_tmp12_, _tmp13_);
		_g_object_unref0 (ps);
		ps = _tmp14_;
		_tmp15_ = ps;
		d = bird_font_pen_tool_remove_point_simplify (_tmp15_, 0.6);
		sumd += d;
		if (sumd < threshold) {
			BirdFontPath* _tmp16_;
			BirdFontPath* _tmp17_;
			_tmp16_ = new_path;
			_tmp17_ = bird_font_path_copy (_tmp16_);
			_g_object_unref0 (p1);
			p1 = _tmp17_;
		} else {
			BirdFontPath* _tmp18_;
			BirdFontPath* _tmp19_;
			gint _tmp20_;
			_tmp18_ = p1;
			_tmp19_ = bird_font_path_copy (_tmp18_);
			_g_object_unref0 (new_path);
			new_path = _tmp19_;
			sumd = (gdouble) 0;
			_tmp20_ = i;
			i = _tmp20_ + 1;
		}
	}
	_tmp21_ = new_path;
	bird_font_path_update_region_boundaries (_tmp21_);
	result = new_path;
	_g_object_unref0 (p1);
	_g_object_unref0 (ep);
	_g_object_unref0 (ps);
	return result;
}

void
bird_font_pen_tool_set_simplification_threshold (BirdFontPenTool* self,
                                                 gdouble t)
{
	g_return_if_fail (self != NULL);
	bird_font_pen_tool_simplification_threshold = t;
}

void
bird_font_pen_tool_move_handle_on_axis (void)
{
	bird_font_pen_tool_on_axis = TRUE;
}

static gdouble
bird_font_pen_tool_get_contact_surface (void)
{
	gdouble result;
	result = bird_font_main_window_units * 20;
	return result;
}

static void
bird_font_pen_tool_class_init (BirdFontPenToolClass * klass,
                               gpointer klass_data)
{
	bird_font_pen_tool_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BirdFontPenTool_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_bird_font_pen_tool_get_property;
	G_OBJECT_CLASS (klass)->finalize = bird_font_pen_tool_finalize;
}

static void
bird_font_pen_tool_instance_init (BirdFontPenTool * self,
                                  gpointer klass)
{
	self->priv = bird_font_pen_tool_get_instance_private (self);
	self->priv->first_move_action = FALSE;
	self->priv->last_selected_is_handle = FALSE;
}

static void
bird_font_pen_tool_finalize (GObject * obj)
{
	BirdFontPenTool * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_PEN_TOOL, BirdFontPenTool);
	G_OBJECT_CLASS (bird_font_pen_tool_parent_class)->finalize (obj);
}

/** Create new points. */
static GType
bird_font_pen_tool_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontPenToolClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_pen_tool_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontPenTool), 0, (GInstanceInitFunc) bird_font_pen_tool_instance_init, NULL };
	GType bird_font_pen_tool_type_id;
	bird_font_pen_tool_type_id = g_type_register_static (BIRD_FONT_TYPE_TOOL, "BirdFontPenTool", &g_define_type_info, 0);
	BirdFontPenTool_private_offset = g_type_add_instance_private (bird_font_pen_tool_type_id, sizeof (BirdFontPenToolPrivate));
	return bird_font_pen_tool_type_id;
}

GType
bird_font_pen_tool_get_type (void)
{
	static volatile gsize bird_font_pen_tool_type_id__once = 0;
	if (g_once_init_enter (&bird_font_pen_tool_type_id__once)) {
		GType bird_font_pen_tool_type_id;
		bird_font_pen_tool_type_id = bird_font_pen_tool_get_type_once ();
		g_once_init_leave (&bird_font_pen_tool_type_id__once, bird_font_pen_tool_type_id);
	}
	return bird_font_pen_tool_type_id__once;
}

static void
_vala_bird_font_pen_tool_get_property (GObject * object,
                                       guint property_id,
                                       GValue * value,
                                       GParamSpec * pspec)
{
	BirdFontPenTool * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, BIRD_FONT_TYPE_PEN_TOOL, BirdFontPenTool);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

