Clone in a terminal:
Commit c106d62
Johan Mattsson - 2014-06-07T17:16:41+00:00
c106d62d0362f0b578397cfec5a9731312589835johan.mattsson.m@gmail.com

Add new points on path from end point to start point

Changed files (3)

Diff

diff --git a/libbirdfont/OpenFontFormat/OpenFontFormatReader.vala b/libbirdfont/OpenFontFormat/OpenFontFormatReader.valaindex 23c2470..035575f 100644--- a/libbirdfont/OpenFontFormat/OpenFontFormatReader.vala+++ b/libbirdfont/OpenFontFormat/OpenFontFormatReader.vala@@ -147,7 +147,7 @@ public class OpenFontFormatReader : Object { 		return directory_table.head_table.get_adjusted_checksum (); 	} 	-	public static StringBuilder parse_kerning (string file_name) {+	public static string parse_kerning (string file_name) { 		KernTable kern_table; 		CmapTable cmap_table; 		HeadTable head_table;@@ -195,8 +195,8 @@ public class OpenFontFormatReader : Object { 		} catch (GLib.Error e) { 			warning (@"Failed to parse font. $(e.message)"); 		}-		-		return bf_kerning;+				+		return bf_kerning.str; 	} } }diff --git a/libbirdfont/OpenFontFormat/load_font.c b/libbirdfont/OpenFontFormat/load_font.cindex d0451f0..b7ceb24 100644--- a/libbirdfont/OpenFontFormat/load_font.c+++ b/libbirdfont/OpenFontFormat/load_font.c@@ -658,7 +658,7 @@ void append_description (GString* str, FT_SfntName* name_table_data) { GString* get_bf_font (FT_Face face, char* file, int* err) { 	GString* bf = g_string_new (""); 	GString* bf_data;-	GString* kerning;+	gchar* kerning; 	GString* glyph; 	FT_Error error; 	FT_Long i;@@ -674,6 +674,10 @@ GString* get_bf_font (FT_Face face, char* file, int* err) { 	units_per_em = face->units_per_EM; 	units = get_units (units_per_em); 	+	if (face == NULL) {+		return  bf;+	}+	 	g_string_append (bf, "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n"); 	 	// libxml2 fails on doctype declaration in windows.@@ -717,7 +721,7 @@ GString* get_bf_font (FT_Face face, char* file, int* err) { 		append_description (bf, &name_table_data); 		g_string_append (bf, "</copyright>\n"); 	}-		+	 	g_string_append_printf (bf, "<backup>%s</backup>\n", file);  @@ -780,12 +784,15 @@ GString* get_bf_font (FT_Face face, char* file, int* err) { 		bird_font_tool_yield (); 	} 	-	kerning = (GString*) bird_font_open_font_format_reader_parse_kerning (file); -	g_string_append (bf, kerning->str);-	g_string_free (kerning, 0);	+	kerning = bird_font_open_font_format_reader_parse_kerning (file); +	+	if (kerning != NULL) {+		printf (kerning);+		g_string_append (bf, kerning);+		g_free (kerning);	+	}  	g_string_append (bf, "</font>\n");-	 	bird_font_tool_yield (); 	 	return bf;diff --git a/libbirdfont/Path.vala b/libbirdfont/Path.valaindex 203f016..a19ca7d 100644--- a/libbirdfont/Path.vala+++ b/libbirdfont/Path.vala@@ -1361,7 +1361,7 @@ public class Path { 			 	/** Get a point on the this path closest to x and y coordinates. */ 	public void get_closest_point_on_path (EditPoint edit_point, double x, double y) {-		return_if_fail (points.size != 0);+		return_if_fail (points.size >= 1); 		 		double min = double.MAX; 		double n = 0;@@ -1373,14 +1373,15 @@ public class Path { 		double handle_x0, handle_x1; 		double handle_y0, handle_y1; 		-		unowned EditPoint prev = points.get (0).get_link_item ();-		unowned EditPoint i = prev.get_next ();+		EditPoint prev = points.get (points.size - 1).get_link_item ();+		EditPoint i = points.get (0).get_link_item ();  		bool done = false; 		bool exit = false;+		bool first = true; 		-		unowned EditPoint? previous_point = null;-		unowned EditPoint? next_point = null;+		EditPoint? previous_point = null;+		EditPoint? next_point = null;  		EditPoint previous; 		EditPoint next;@@ -1397,20 +1398,16 @@ public class Path { 			 			edit_point.prev = i; 			edit_point.next = i;-			-			exit = true; 			return; 		} 		-		if (points.size != 1) {-			edit_point.x = i.x;-			edit_point.y = i.y;-		}+		edit_point.x = i.x;+		edit_point.y = i.y; 		 		create_list (); 		 		while (!exit) {-			if (i == points.get (points.size - 1)) {+			if (!first && i == points.get (points.size - 1)) { 				done = true; 			} 			@@ -1444,6 +1441,8 @@ public class Path { 				 				return true; 			});+			+			first = false; 		}  		if (previous_point == null && is_open ()) {@@ -1463,7 +1462,7 @@ public class Path { 		previous = (!) previous_point; 		next = (!) next_point; -		// FIXME: delete+// 		// FIXME: delete 		bezier_vector (step, previous.x, previous.get_right_handle ().x (), next.get_left_handle ().x (), next.x, out handle_x0, out handle_x1); 		bezier_vector (step, previous.y, previous.get_right_handle ().y (), next.get_left_handle ().y (), next.y, out handle_y0, out handle_y1); @@ -2374,30 +2373,29 @@ public class Path { 			return true; 		}); 		-		insert_new_point_on_path_at (x0 - 1, y0);-		insert_new_point_on_path_at (x1 + 1, y1);-		insert_new_point_on_path_at (x2, y2 - 1);-		insert_new_point_on_path_at (x3, y3 + 1);+		insert_new_point_on_path_at (x0 - 0.001, y0);+		insert_new_point_on_path_at (x1 + 0.001, y1);+		insert_new_point_on_path_at (x2, y2 - 0.001);+		insert_new_point_on_path_at (x3, y3 + 0.001); 	} 	 	void insert_new_point_on_path_at (double x, double y) { 		EditPoint ep = new EditPoint ();+		EditPoint prev, next; 		bool exists; 		-		get_closest_point_on_path (ep, x, y);--		if (unlikely (ep.next == null)) {-			warning ("No next point");+		if (points.size < 2) {+			warning ("Can't add extrema to jut one point."); 			return; 		} 		-		if (unlikely (ep.prev == null)) {-			warning ("No previous point");-			return;-		}+		get_closest_point_on_path (ep, x, y);++		next = (ep.next == null) ? points.get (0) : ep.get_next ();+		prev = (ep.prev == null) ? points.get (points.size - 1) : ep.get_prev (); 		-		exists = ep.get_prev ().x == ep.x && ep.get_prev ().y == ep.y;-		exists |= ep.get_next ().x == ep.x && ep.get_next ().y == ep.y;+		exists = prev.x == ep.x && prev.y == ep.y;+		exists |= next.x == ep.x && next.y == ep.y; 		 		if (!exists) { 			insert_new_point_on_path (ep);

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112