Clone in a terminal:
Commit 05e1c36
Johan Mattsson - 2014-07-27T22:55:21+00:00
05e1c363c0da0d74daab31ec169e9b488d8c33c5johan.mattsson.m@gmail.com

Faster TTF export Cache quadratic paths for TTF export

Changed files (5)

Diff

diff --git a/fonts/BetecknaBirdfont.bf b/fonts/BetecknaBirdfont.bfindex eb9077e..04b0fad 100644--- a/fonts/BetecknaBirdfont.bf+++ b/fonts/BetecknaBirdfont.bf@@ -193,7 +193,7 @@ 	</glyph> 	<glyph id="4" left="-113.13516137095797" right="-58.135161370957974"> 		<path stroke="0" data="S -98.1881051176,45.9398340249 D -100.0968188105,45.9398340249 -101.8782849239,45.9398340249 -103.9142461964,45.9398340249 L -104.0414937759,19.7268326418 D -101.0838981475,19.7181113303 -97.9336099585,19.7268326418 -95.8976486860,19.7268326418 T D -89.5205574787,19.7268326418 -81.1369294606,26.9799446750 -81.1369294606,32.9605809129 T D -81.1369294606,37.0325034578 -85.1843017118,43.2261299803 -88.5580318367,44.8847694921 D -90.4071575536,45.7939802934 -95.3496926019,45.9398340249 -98.1881051176,45.9398340249" />-		<path stroke="0" data="S -93.0982019364,11.9647302905 D -95.2191815139,11.9306450369 -102.0479285751,12.0079659660 -104.1687413555,11.9647302905 L -104.1687413555,-17.9384508990 L -113.0760719225,-17.9384508990 L -113.0411866766,53.6702485545 D -107.2594926875,53.6673414507 -98.8653536700,53.9564315353 -97.4246196404,53.9564315353 T D -94.4630348458,53.9564315353 -85.7792540446,53.4580203647 -83.4934235298,52.4507876740 D -78.1180590433,50.0824853746 -71.7755738350,39.5638307526 -71.7206085754,32.3243430152 T D -71.6627971811,24.8394383262 -84.2995622027,12.1082039786 -93.0982019364,11.9647302905 T" />+		<path stroke="0" data="S -93.0982019364,11.9647302905 D -95.2191815139,11.9306450369 -102.0479285751,12.0079659660 -104.1687413555,11.9647302905 L -104.1687413555,-17.9384508990 L -113.0760719225,-17.9384508990 L -113.0411866766,53.6702485545 D -107.2594926875,53.6673414507 -98.8653536700,53.9564315353 -97.4246196404,53.9564315353 T D -94.4630348458,53.9564315353 -85.7792540446,53.4580203647 -83.4934235298,52.4507876740 D -78.1180590433,50.0824853746 -71.7765243788,39.5638234733 -71.7206085754,32.3243430152 T D -71.6627971811,24.8394383262 -84.2995622027,12.1082039786 -93.0982019364,11.9647302905 T" /> 	</glyph> </collection> <collection unicode="U+72">@@ -269,9 +269,9 @@ 		<path stroke="0" data="B -2.1474926254,-21.0737463127 M -25.7699115044,53.7581120944 M -15.1976401180,53.7581120944 M -15.1976401180,53.7581120944 M 0.0000000000,6.1828908555 M 21.2820849094,53.5929203540 M 41.7935103245,6.1828908555 M 59.6342182891,53.5929203540 M 68.5545722714,53.5929203540 M 42.6471186304,-20.5781710914 M 20.9793510324,32.1456437042 M -2.1474926254,-21.0737463127" /> 	</glyph> </collection>+<kerning left="t" right="a" hadjustment="17.0000000000" /> <kerning left="F" right="a" hadjustment="0.0000000000" /> <kerning left="e" right="l" hadjustment="-1.0000000000" />-<kerning left="t" right="a" hadjustment="17.0000000000" /> <kerning left="S" right="a" hadjustment="9.0000000000" /> <kerning left="o" right="n" hadjustment="-5.0000000000" /> <kerning left="a" right="n" hadjustment="0.0000000000" />diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex d50b400..44ef44e 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -94,6 +94,9 @@ public class Glyph : FontDisplay { 	/** Id in the version list. */ 	public int version_id = 1; 	+	/** Cache quadratic form on export. */+	GlyfData? ttf_data = null;+	 	public Glyph (string name, unichar unichar_code = 0) { 		this.name = name; 		this.unichar_code = unichar_code;@@ -113,6 +116,27 @@ public class Glyph : FontDisplay { 		path_list.add (new Path ()); 	} +	public GlyfData get_ttf_data () {+		if (ttf_data == null) {+			ttf_data =  new GlyfData (this);+		}+		+		return (!) ttf_data;+	}++	public PathList get_quadratic_paths () {+		PointConverter pc;+		PathList pl;++		pl = new PathList ();+		foreach (Path p in path_list) {+			pc = new PointConverter (p);+			pl.add (pc.get_quadratic_path ());+		}++		return pl;+	}+ 	public override void close () { 		undo_list.clear (); 	}@@ -362,6 +386,8 @@ public class Glyph : FontDisplay { 	public override void selected_canvas () { 		TimeoutSource input_delay; 		+		ttf_data = null; // recreate quatradic path on export+		 		ignore_input = true; // make sure that tripple clicks in overview are ignored  		input_delay = new TimeoutSource (250);diff --git a/libbirdfont/KerningDisplay.vala b/libbirdfont/KerningDisplay.valaindex 1190594..dffa4aa 100644--- a/libbirdfont/KerningDisplay.vala+++ b/libbirdfont/KerningDisplay.vala@@ -234,7 +234,11 @@ public class KerningDisplay : FontDisplay { 						 			y += row_height + 20; 			x = 20;-			first_row = false;	+			first_row = false;+			+			if (y > allocation.height) {+				break;+			} 		} 		 		for (int j = row.size - 1; j > 30; j--) {diff --git a/libbirdfont/OpenFontFormat/GlyfData.vala b/libbirdfont/OpenFontFormat/GlyfData.valaindex 1f64404..51e1c31 100644--- a/libbirdfont/OpenFontFormat/GlyfData.vala+++ b/libbirdfont/OpenFontFormat/GlyfData.vala@@ -1,5 +1,5 @@ /*-    Copyright (C) 2012, 2013 Johan Mattsson+    Copyright (C) 2012, 2013, 2014 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 @@ -34,12 +34,12 @@ public class CoordinateFlags { }  /** Data for one entry in the glyf table. */-class GlyfData : GLib.Object {		-	public List<Path> paths = new List<Path> ();-	public List<uint16> end_points = new List<uint16> ();-	public List<uint8> flags = new List<uint8> ();-	public List<int16> coordinate_x = new List<int16> ();-	public List<int16> coordinate_y = new List<int16> ();+public class GlyfData : GLib.Object {		+	public Gee.ArrayList<Path> paths = new Gee.ArrayList<Path> ();+	public Gee.ArrayList<uint16> end_points = new Gee.ArrayList<uint16> ();+	public Gee.ArrayList<uint8> flags = new Gee.ArrayList<uint8> ();+	public Gee.ArrayList<int16> coordinate_x = new Gee.ArrayList<int16> ();+	public Gee.ArrayList<int16> coordinate_y = new Gee.ArrayList<int16> (); 	 	uint16 end_point = 0; 	int16 nflags = 0;@@ -56,23 +56,19 @@ class GlyfData : GLib.Object { 	} 		 	public GlyfData (Glyph g) {	-		Path q;-		 		glyph = g; 						-		foreach (Path p in g.path_list) {+		foreach (Path p in g.get_quadratic_paths ().paths) { 			if (p.points.size > 0) {-				q = p.get_quadratic_points ();--				if (!is_empty (q)) {-					// Add point at extrema-					q.add_extrema ();-					paths.append (q);+				if (!is_empty (p)) {+					// Add points at extrema+					p.add_extrema ();+					paths.add (p); 				} 			} 		} 		-		if (paths.length () > 0) {+		if (paths.size > 0) { 			process_end_points (); 			process_flags (); 			process_x ();@@ -105,7 +101,7 @@ class GlyfData : GLib.Object { 	} 			 	public int16 get_ncontours () {-		return (int16) paths.length ();+		return (int16) paths.size; 	}  	public int16 get_nflags () {@@ -140,7 +136,7 @@ class GlyfData : GLib.Object { 					warning ("Too many points"); 				} 			}-			end_points.append (end_point - 1);+			end_points.add (end_point - 1); 			 			if (unlikely (end_point - 1 < last_end_point)) { 				warning (@"Next endpoint has bad value. (end_point - 1 < last_end_point)  ($(end_point - 1) < $last_end_point)");@@ -157,18 +153,18 @@ class GlyfData : GLib.Object { 	void process_flags () { 		PointType type; 		-		flags = new List<uint8> ();+		flags = new Gee.ArrayList<uint8> (); 		nflags = 0; 		 		foreach (Path p in paths) { 			foreach (EditPoint e in p.points) {-				flags.append (CoordinateFlags.ON_PATH);+				flags.add (CoordinateFlags.ON_PATH); 				nflags++; 				 				type = e.get_right_handle ().type; 				 				// off curve-				flags.append (CoordinateFlags.NONE);+				flags.add (CoordinateFlags.NONE); 				nflags++; 			} 		}@@ -194,7 +190,7 @@ class GlyfData : GLib.Object { 		foreach (Path p in paths) { 			foreach (EditPoint e in p.points) { 				x = rint (e.x * UNITS - prev - glyph.left_limit * UNITS);-				coordinate_x.append ((int16) x);+				coordinate_x.add ((int16) x); 				 				prev = rint (e.x * UNITS - glyph.left_limit * UNITS); 				@@ -202,7 +198,7 @@ class GlyfData : GLib.Object { 				 				// off curve 				x = rint (e.get_right_handle ().x * UNITS - prev - glyph.left_limit * UNITS);-				coordinate_x.append ((int16) x);+				coordinate_x.add ((int16) x); 				 				prev = rint (e.get_right_handle ().x * UNITS - glyph.left_limit * UNITS); 			}@@ -218,7 +214,7 @@ class GlyfData : GLib.Object { 		foreach (Path p in paths) { 			foreach (EditPoint e in p.points) { 				y = rint (e.y * UNITS - prev - font.base_line  * UNITS);-				coordinate_y.append ((int16) y);+				coordinate_y.add ((int16) y); 				 				prev = rint (e.y * UNITS - font.base_line * UNITS); 				@@ -226,7 +222,7 @@ class GlyfData : GLib.Object { 				 				// off curve 				y = rint (e.get_right_handle ().y * UNITS - prev - font.base_line * UNITS);-				coordinate_y.append ((int16) y);+				coordinate_y.add ((int16) y); 			 				prev = rint (e.get_right_handle ().y * UNITS - font.base_line  * UNITS); 			}@@ -242,7 +238,7 @@ class GlyfData : GLib.Object { 		bounding_box_xmax = int16.MIN; 		bounding_box_ymax = int16.MIN; 				-		if (coordinate_x.length () == 0) {+		if (coordinate_x.size == 0) { 			warning ("no points in coordinate_y"); 		} 		@@ -261,7 +257,7 @@ class GlyfData : GLib.Object { 			i++; 		} -		if (coordinate_y.length () == 0) {+		if (coordinate_y.size == 0) { 			warning ("no points in coordinate_y"); 		} 		diff --git a/libbirdfont/OpenFontFormat/GlyfTable.vala b/libbirdfont/OpenFontFormat/GlyfTable.valaindex eb49eaf..56c2873 100644--- a/libbirdfont/OpenFontFormat/GlyfTable.vala+++ b/libbirdfont/OpenFontFormat/GlyfTable.vala@@ -204,9 +204,9 @@ public class GlyfTable : Table { 		printd (@"glyph_offset: $(glyph_offset)\n"); 		 		g.remove_empty_paths ();-		glyf_data = new GlyfData (g);+		glyf_data = g.get_ttf_data (); 		-		if (g.path_list.size == 0 || glyf_data.paths.length () == 0 || glyf_data.get_ncontours () == 0) {+		if (g.path_list.size == 0 || glyf_data.paths.size == 0 || glyf_data.get_ncontours () == 0) { 			// location_offsets will be equal to location_offset + 1 for 			// all empty glyphs 			g.set_empty_ttf (true);@@ -219,7 +219,7 @@ public class GlyfTable : Table { 			warning (@"No paths in $(g.get_name ()) ($(g.get_hex ())) can be exported."); 		} 		-		ncontours = (int16) glyf_data.paths.length ();+		ncontours = (int16) glyf_data.paths.size; 		fd.add_short (ncontours);  		// bounding box

Contact

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