Clone in a terminal:
Commit a0831ba
Johan Mattsson - 2012-08-10T18:38:15+00:00
a0831ba39020ccb9f37ecbe19e1f47dea34c544ejohan.mattsson.m@gmail.com

load glyph as they are requested, rather slow

Changed files (8)

Diff

diff --git a/src/Font.vala b/src/Font.valaindex c172495..39d2ff6 100644--- a/src/Font.vala+++ b/src/Font.vala@@ -27,6 +27,8 @@ class Font : GLib.Object { 	/** Glyphs that not are tied to a unichar value. */ 	GlyphTable unassigned_glyphs = new GlyphTable (); +	List<string> glyph_names = new List<string> ();+ 	/** Last unassigned index */ 	int next_unindexed = 0; 		@@ -61,6 +63,9 @@ class Font : GLib.Object { 	 	bool ttf_export = true; 	bool svg_export = true;++	bool loading = false;+	OpenFontFormatReader otf; 	 	public Font () { 		// positions in pixels at first zoom level@@ -100,7 +105,7 @@ class Font : GLib.Object { 	}  	public uint get_length () {-		return glyph_cache.length () + unassigned_glyphs.length ();+		return glyph_names.length (); 	}  	/** Retuns true if the current font has be modified */@@ -195,16 +200,7 @@ class Font : GLib.Object {  	public GlyphRange get_available_glyph_ranges () { 		GlyphRange gr = new GlyphRange ();-		-		Glyph? g = null;-		unichar i = 0;-		-		while ((g = get_glyph_indice (i++)) != null) {-			gr.add_single (((!) g).get_unichar ());-		}-		-		gr.set_unassigned (unassigned_glyphs);-		+		gr.unassigned = glyph_names; 		return gr; 	} @@ -330,7 +326,10 @@ class Font : GLib.Object { 	}  	public void add_glyph_collection (GlyphCollection glyph_collection) {-		GlyphCollection? gc = get_glyph_collection (glyph_collection.get_name ());+		GlyphCollection? gc = get_cached_glyph_collection (glyph_collection.get_name ());+		unowned List<string>? nl;+		+		print (@"Adding: $(glyph_collection.get_name ())\n"); 		 		if (glyph_collection.get_name () == "") { 			warning ("Refusing to insert glyph with name \"\", null character should be named null.");@@ -338,7 +337,8 @@ class Font : GLib.Object { 		} 		 		if (gc != null) {-			warning ("glyph has been inserted");+			warning ("glyph has already been added");+			return; 		} 		 		if (glyph_collection.get_current ().is_unassigned ()) {@@ -346,23 +346,55 @@ class Font : GLib.Object { 		} else { 			glyph_cache.insert (glyph_collection); 		}++		if (!has_name (glyph_collection.get_name ())) {+			glyph_names.append (glyph_collection.get_name ());+			glyph_names.sort (strcmp);+		} 	}+	+	bool has_name (string name) {+		foreach (string n in glyph_names) {+			if (n == name) {+				return true;+			}+		} 		+		return false;+	}+	 	public void delete_glyph (string glyph) {+		glyph_names.remove_all (glyph); 		glyph_cache.remove (glyph); 	} 	 	/** Obtain all versions and alterntes for this glyph. */ 	public GlyphCollection? get_glyph_collection (string glyph) {-		GlyphCollection? gc = glyph_cache.get (glyph);+		GlyphCollection? gc = get_cached_glyph_collection (glyph);+		Glyph? g; 		 		if (gc == null) {-			gc = unassigned_glyphs.get (glyph);+			// load it from otf file if we need to+			g = otf.read_glyph (glyph); 			-			if (gc == null) {			-				return null;+			if (g != null) {+				add_glyph_callback ((!) g);+				return get_cached_glyph_collection (glyph); 			} 		}+			+		return gc;+	}++	public GlyphCollection? get_cached_glyph_collection (string glyph) {+		GlyphCollection? gc = null;+		Glyph? new_glyph;+		+		gc = glyph_cache.get (glyph);+		+		if (gc == null) {+			gc = unassigned_glyphs.get (glyph);+		} 		 		return gc; 	}@@ -384,20 +416,22 @@ class Font : GLib.Object { 	} 	 	public Glyph? get_glyph_indice (unichar glyph_indice) {-		GlyphCollection gc;+		GlyphCollection? gc;+		string n; 		-		if (glyph_indice >= length ()) {+		if (!(0 <= glyph_indice < glyph_names.length ())) {+			warning ("glyph_indice is out of range"); 			return null;-		} +		} 		-		if (glyph_indice >= glyph_cache.length ()) {-			glyph_indice -= glyph_cache.length ();-			gc = (!) unassigned_glyphs.nth (glyph_indice);-		} else {-			gc = (!) glyph_cache.nth (glyph_indice);+		n = glyph_names.nth (glyph_indice).data;+		gc = get_glyph_collection (n);+		+		if (gc != null) {+			return ((!) gc).get_current (); 		}-				-		return gc.get_current ();+		+		return null; 	} 	 	public void add_background_image (string file) {@@ -632,11 +666,11 @@ class Font : GLib.Object { 	}  	public uint length () {-		return glyph_cache.length () + unassigned_glyphs.length ();+		return glyph_names.length (); 	}  	public bool is_empty () {-		return (glyph_cache.length () == 0 && unassigned_glyphs.length () == 0);+		return (glyph_names.length () == 0); 	}  	public bool load (string path) {@@ -663,8 +697,6 @@ class Font : GLib.Object { 		Context cr; 		double scale; 		-		Font font = Supplement.get_current_font ();- 		if (gl == null) { 			gl = get_glyph_indice (4); 		}		@@ -703,6 +735,7 @@ class Font : GLib.Object { 	public void loading_finished_callback () { 		add_thumbnail (); 		Preferences.add_recent_files (get_path ());+		loading = false; 		print ("Done Loading.\n"); 	} @@ -711,7 +744,7 @@ class Font : GLib.Object { 		GlyphCollection? gcl; 		GlyphCollection gc; 		-		gcl = get_glyph_collection (g.get_name ());+		gcl = get_cached_glyph_collection (g.get_name ()); 		 		if (gcl != null) { 			warning (@"glyph \"$(g.get_name ())\" does already exist");@@ -721,7 +754,9 @@ class Font : GLib.Object { 			gc = new GlyphCollection (g); 			 			if (g.name == "") {+				warning ("refusing to insert glyph without name"); 				g.name = @"($(++next_unindexed))";+				return; 			} 			 			// del: print (@"added name: $(g.name)\n");@@ -742,14 +777,34 @@ class Font : GLib.Object { 	}  	public bool parse_otf_file (string path) {+		otf = new OpenFontFormatReader ();+		loading = true;+		+		while (glyph_names.length () > 0) {+			glyph_names.remove_link (glyph_names.first ());+		}+		 		glyph_cache.remove_all (); 		unassigned_glyphs.remove_all (); 		 		font_file = path; 		+		otf.parse_index (path);+		+		foreach (string n in otf.get_all_names ()) {+			glyph_names.append (n);+		}+				+		/* 		ThreadFunc<void*> run = () => { 			string file = (!) font_file;-			parse_otf_file_async (file);++			try {+				parse_otf_async ((!) font_file);+			} catch (GLib.Error e) {+				stderr.printf (e.message);+			}+ 			return null; 		}; 		@@ -759,12 +814,12 @@ class Font : GLib.Object { 		} catch (ThreadError e) { 			stderr.printf ("Thread error: %s\n", e.message); 		}-		+		*/ 		return true; 	}-		-	public static void parse_otf_file_async (string path) {-		OpenFontFormatReader otf = new OpenFontFormatReader (path);+	+	void parse_otf_async (string fn) {+		// otf.parse (fn); 	} 	 	/** Measure height of x or other lower case letter. */diff --git a/src/GlyphRange.vala b/src/GlyphRange.valaindex 90d3e7b..c9bc5d4 100644--- a/src/GlyphRange.vala+++ b/src/GlyphRange.vala@@ -20,18 +20,14 @@ namespace Supplement { class GlyphRange { 	 	List<UniRange> ranges;--	GlyphTable unassigned = new GlyphTable ();+	+	public unowned List<string> unassigned = new List<string> (); 	 	uint32 len = 0; 	 	public GlyphRange () { 	}-	-	public void set_unassigned (GlyphTable unassigned) {-		this.unassigned = unassigned;-	}-	+		 	public unowned List<UniRange> get_ranges () { 		return ranges; 	}@@ -77,7 +73,6 @@ class GlyphRange { 	} 	 	public void use_full_unicode_range () {-		// add_range ('\0', (unichar) 0xA868FE00); 		add_range ('\0', (unichar) 0xFFF8); 	} 	@@ -192,7 +187,7 @@ class GlyphRange { 				return "\0".dup(); 			}  			-			chr = ((!) unassigned.nth (index - len)).get_name ();+			chr = ((!) unassigned.nth (index - len)).data; 			return chr; 		} diff --git a/src/MainWindow.vala b/src/MainWindow.valaindex 95f727c..c8dae2a 100644--- a/src/MainWindow.vala+++ b/src/MainWindow.vala@@ -25,9 +25,10 @@ public class MainWindow : Gtk.Window { 
 	HBox list_box;
 	HBox canvas_box;
+	
 	WebView html_canvas;
 	ScrolledWindow html_box;
-	
+		
 	static TabBar tabs;
 	VBox tab_box;
 	
@@ -75,6 +76,7 @@ public class MainWindow : Gtk.Window { 		
 		html_box = new ScrolledWindow (null, null);
 		html_box.set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC);
+		
 		html_box.add (html_canvas);
 		
 		tabs.signal_tab_selected.connect ((f, tab) => {
@@ -105,7 +107,7 @@ public class MainWindow : Gtk.Window { 			} else {
 				html_box.set_visible (false);
 				glyph_canvas.set_visible (true);
-			}
+			} 
 		});
 
 		// Hide this canvas when window is realized and flip canvas 
@@ -114,7 +116,7 @@ public class MainWindow : Gtk.Window { 			glyph_canvas.set_visible (false);
 			return false;
 		});
-        
+
 		over_view = new OverView();
 				
 		tabs.add_unique_tab (content, 60, true);
@@ -123,7 +125,7 @@ public class MainWindow : Gtk.Window { 		tabs.select_tab_name ("Menu");
 
 		canvas_box = new HBox (false, 0);
-		canvas_box.child = (glyph_canvas);
+		canvas_box.pack_start (glyph_canvas, true, true, 0);
 		canvas_box.pack_start (html_box, true, true, 0);
 		
 		tab_box = new VBox (false, 0);
@@ -152,7 +154,7 @@ public class MainWindow : Gtk.Window { 		
 		show_all ();
 	}
-
+	
 	public static WebView get_webview () {
 		return singleton.html_canvas;
 	}
diff --git a/src/MenuTab.vala b/src/MenuTab.valaindex 11a4da4..81a905b 100644--- a/src/MenuTab.vala+++ b/src/MenuTab.vala@@ -97,10 +97,6 @@ class MenuTab : FontDisplay { 		});	  	}--	public override void selected_canvas () {-		MainWindow.get_webview ().reload ();-	} 		 	public override string get_name () { 		return "Menu";diff --git a/src/OpenFontFormatReader.vala b/src/OpenFontFormatReader.valaindex e492588..9f6365a 100644--- a/src/OpenFontFormatReader.vala+++ b/src/OpenFontFormatReader.vala@@ -52,15 +52,15 @@ class OpenFontFormatReader : Object { 	DirectoryTable directory_table; 	File file; 	-	public OpenFontFormatReader (string file_name) {-		try {-			parse (file_name);-		} catch (Error e) {-			stderr.printf (e.message);-		}+	public OpenFontFormatReader () {+		directory_table = new DirectoryTable ();+	}+	+	public Glyph? read_glyph (string name) {+		return directory_table.glyf_table.read_glyph (name); 	} 	-	void parse (string file_name) throws Error {+	public void parse_index (string file_name) throws Error { 		file = File.new_for_path (file_name); 		if (!file.query_exists ()) { 			throw new FileError.EXIST(@"OpenFontFormatReader: file does not exist. $((!) file.get_path ())");@@ -68,7 +68,7 @@ class OpenFontFormatReader : Object { 			 		dis = new OtfInputStream (file.read ()); 		-		parse_index ();+		parse_index_tables (); 		done (); 	} 	@@ -84,11 +84,9 @@ class OpenFontFormatReader : Object { 		idle.attach (null);		 	} 	-	void parse_index () throws Error {+	void parse_index_tables () throws Error { 		OffsetTable offset_table;-		-		directory_table = new DirectoryTable ();-		+ 		offset_table = new OffsetTable (directory_table); 		offset_table.parse (dis); 		@@ -122,6 +120,10 @@ class OpenFontFormatReader : Object { 	 	public double get_descender () { 		return directory_table.hhea_table.get_descender ();-	}}+	} +	public unowned List<string> get_all_names () {+		return directory_table.post_table.get_all_names ();+	}+} }diff --git a/src/OpenFontFormatWriter.vala b/src/OpenFontFormatWriter.valaindex 63becd5..8feb88c 100644--- a/src/OpenFontFormatWriter.vala+++ b/src/OpenFontFormatWriter.vala@@ -680,8 +680,13 @@ class GlyfTable : Table { 	public int16 ymin = 0;
 	public int16 xmax = 0;
 	public int16 ymax = 0;
-	
+
+	public OtfInputStream dis;
+	public HeadTable head_table;
+	public HmtxTable hmtx_table;
 	public LocaTable loca_table;
+	public CmapTable cmap_table; // hack, hack, hack. cmap and post is null when inistialized and set in parse method
+	public PostTable post_table;
 	
 	public List<uint32> location_offsets; 
 
@@ -696,12 +701,17 @@ class GlyfTable : Table { 	
 	double total_width = 0;
 	int non_zero_glyphs = 0;
+
+	Mutex read_lock;
+	int64 next_index = -1;
+	List<int> loca_index = new List<int> ();
 	
 	public GlyfTable (LocaTable l) {
 		id = "glyf";
 		loca_table = l;
 		location_offsets = new List<uint32> ();
 		glyphs = new List<Glyph> ();
+		read_lock = new Mutex ();
 	}	
 
 	public int16 get_space_gid () {
@@ -757,6 +767,22 @@ class GlyfTable : Table { 		
 		return (uint16)g.unichar_code; 
 	}
+	
+	int x = 0;
+	public Glyph? read_glyph (string name) {
+		Glyph glyph;
+		int i;
+		
+		i = post_table.get_gid (name);
+		
+		print (@"Parse index $i, name $name\n");
+		
+		if (i == -1) {
+			return null;
+		}
+		
+		return parse_index (i, dis, loca_table, hmtx_table, head_table, post_table);
+	}
 			
 	/** Add this glyph from thread safe callback to the running gui. */
 	void add_glyph (Glyph g) {
@@ -771,98 +797,126 @@ class GlyfTable : Table { 		idle.attach (null);
 	}
 	
-	public void parse (OtfInputStream dis, CmapTable cmap, LocaTable loca, HmtxTable hmtx_table, HeadTable head_table, PostTable post_table) throws GLib.Error {
-		uint32 glyph_offset;
-		Glyph glyph = new Glyph ("");
-		double xmin, xmax;
-		double units_per_em = head_table.get_units_per_em ();
-		unichar character = 0;
-		string name;	
-
+	public void parse (OtfInputStream dis, CmapTable cmap_table, LocaTable loca, HmtxTable hmtx_table, HeadTable head_table, PostTable post_table) throws GLib.Error {
 		printd (@"loca.size: $(loca.size)\n");
-		// post_table.print_all ();
-		
-		// notdef character:
-		character = cmap.get_char (0);
-
-		if (character != 0) {
-			warning ("notdef has a another value in cmap table");
-		}
+			
+		Glyph glyph;
+		unowned List<int> ind;
+		int i;
+			
+		// read_lock.lock ();
+		this.cmap_table = cmap_table;
+		this.post_table = post_table;
+		this.loca_table = loca;
+		this.hmtx_table = hmtx_table;
+		this.head_table = head_table;
+		this.dis = dis;
 		
-		glyph = parse_next_glyf (dis, 0, 0, out xmin, out xmax, units_per_em);
-		glyph.left_limit = 0;
-		glyph.right_limit = glyph.left_limit + hmtx_table.get_advance (0);
-		glyph.name = post_table.get_name (0);
-		glyph.set_unassigned (true);		
-		add_glyph (glyph);				
+		// post_table.print_all ();
 		
-		if (glyph.name != ".notdef") {
-			warning ("First glyph must be .notdef");
+		// create a list of indices since we might read them in a different order
+		for (i = 0; i < loca.size; i++) {
+			loca_index.append (i);
 		}
-		
-		for (int i = 1; i < loca.size; i++) {
-			try {
-				character = cmap.get_char (i);
-				name = post_table.get_name (i);
-				
-				if (name == "") {
-					StringBuilder name_c = new StringBuilder ();
-					name_c.append_unichar (character);
-					name = name_c.str;
-				}
+		// read_lock.unlock ();
+/*				
+		while (true) {
+			read_lock.lock ();
+			
+			if (loca_index.length () == 0) {
+				break;
+			}
 
-				printd (@"name: $(name)\n");
-				
-				if (!loca.is_empty (i)) {	
-					glyph_offset = loca.get_offset(i);
-					
-					glyph = parse_next_glyf (dis, character, glyph_offset, out xmin, out xmax, units_per_em);
-					
-					glyph.left_limit = xmin - hmtx_table.get_lsb (i);
-					glyph.left_limit = 0;
-					glyph.right_limit = glyph.left_limit + hmtx_table.get_advance (i);
-					
-					printd (@"$(glyph.right_limit) = $(glyph.left_limit) + $(hmtx_table.get_advance (i))\n");
-					
-					if (xmin > glyph.right_limit || xmax < glyph.left_limit) {
-						warning (@"Glyph $(name) is outside of it's box.");
-						glyph.left_limit = xmin;
-						glyph.right_limit = xmax;
-					}
-					
-				} else {
-					// add empty glyph
-					glyph = new Glyph (name, character);
-					glyph.left_limit = -hmtx_table.get_lsb (i);
-					glyph.right_limit = hmtx_table.get_advance (i) - hmtx_table.get_lsb (i);				
-				}
-				
-				glyph.name = name;
+			ind = loca_index.first ();
+			i = ind.data;
 
-				if (character == 0) {
-					glyph.set_unassigned (true);
-				}
+			try {
+				glyph = parse_index (i, dis, loca, hmtx_table, head_table, post_table);
+				add_glyph (glyph);
 				
-				if (character == 0 && name != "") {
-					stderr.printf (@"gid: $i\n");
-					stderr.printf (@"char: $((uint) character)\n");
-					stderr.printf (@"name: $(name)\n");
+				if (next_index != -1) {
+					i = (int) next_index;
 				}
-								
-				add_glyph (glyph);
 				
+				glyph = parse_index (i, dis, loca, hmtx_table, head_table, post_table);
+				add_glyph (glyph);				
 			} catch (Error e) {
-				stderr.printf (@"Cmap length $(cmap.get_length ()) glyfs\n");
+				stderr.printf (@"Cmap length $(cmap_table.get_length ()) glyfs\n");
 				stderr.printf (@"Loca size: $(loca.size)\n");
-				stderr.printf (@"Loca offset at $i: $glyph_offset\n");
-				stderr.printf (@"Glyph name: $(name)\n");
-				stderr.printf (@"Unicode character: $((uint64)character)\n");
+				stderr.printf (@"Glyph name: $(post_table.get_name (i))\n");
 				stderr.printf (@"\n");
 				stderr.printf (@"Falied to parse glyf: $(e.message)\n");
 				
 				break;
 			}
+
+			if (i == next_index) {
+				next_index = -1;
+			}
+			
+			loca_index.remove_all (i);
+			read_lock.unlock ();
+		}
+		*/
+	}
+	
+	Glyph parse_index (int index, OtfInputStream dis, LocaTable loca, HmtxTable hmtx_table, HeadTable head_table, PostTable post_table) throws GLib.Error {
+		uint32 glyph_offset;
+		Glyph glyph = new Glyph ("");
+		double xmin, xmax;
+		double units_per_em = head_table.get_units_per_em ();
+		unichar character = 0;
+		string name;	
+		
+		character = cmap_table.get_char (index);
+		name = post_table.get_name (index);
+		
+		if (name == "") {
+			StringBuilder name_c = new StringBuilder ();
+			name_c.append_unichar (character);
+			name = name_c.str;
+		}
+
+		printd (@"name: $(name)\n");
+
+		if (!loca.is_empty (index)) {	
+			glyph_offset = loca.get_offset(index);
+			
+			glyph = parse_next_glyf (dis, character, glyph_offset, out xmin, out xmax, units_per_em);
+			
+			glyph.left_limit = xmin - hmtx_table.get_lsb (index);
+			glyph.left_limit = 0;
+			glyph.right_limit = glyph.left_limit + hmtx_table.get_advance (index);
+			
+			// DEL: printd (@"$(glyph.right_limit) = $(glyph.left_limit) + $(hmtx_table.get_advance (i))\n");
+			
+			if (xmin > glyph.right_limit || xmax < glyph.left_limit) {
+				warning (@"Glyph $(name) is outside of it's box.");
+				glyph.left_limit = xmin;
+				glyph.right_limit = xmax;
+			}
+			
+		} else {
+			// add empty glyph
+			glyph = new Glyph (name, character);
+			glyph.left_limit = -hmtx_table.get_lsb (index);
+			glyph.right_limit = hmtx_table.get_advance (index) - hmtx_table.get_lsb (index);				
 		}
+		
+		glyph.name = name;
+
+		if (character == 0) {
+			glyph.set_unassigned (true);
+		}
+		
+		if (character == 0 && name != "") {
+			stderr.printf (@"Got null character\n");
+			stderr.printf (@"gid: $index\n");
+			stderr.printf (@"char: $((uint) character)\n");
+			stderr.printf (@"name: $(name)\n");
+		}
+		
+		return glyph;
 	}
 	
 	Glyph parse_next_composite_glyf (OtfInputStream dis, unichar character) throws Error {
@@ -2700,18 +2754,48 @@ class PostTable : Table { 	List<uint16> index = new List<uint16> ();
 	List<string> names = new List<string> ();
 
+	List<string> available_names = new List<string> ();
+	
 	public PostTable (GlyfTable g) {
 		id = "post";
 		glyf_table = g;
 	}
 
+	public unowned List<string> get_all_names () {
+		return available_names;
+	}
+		
+	public int get_gid (string name) { // fixa do fast lookup
+		int i = 0;
+		int j = 0;
+		foreach (string n in names) {
+			if (n == name) {
+				print (@"found name $name == $n at $i\n");
+				
+				j = 0;
+				foreach (uint16 k in index) {
+					if (k == i) {
+						return j;
+					}
+					j++;
+				}
+								
+				return i;
+			}
+			i++;
+		}
+		
+		warn_if_reached ();
+		return -1;
+	}
+
 	public string get_name (int gid) {
 		uint16 i;
 		int k;
 		
-		if (!(0 <= gid <= index.length ())) {
+		if (!(0 <= gid < index.length ())) {
 			warning ("gid is out of range.");
-			return "INVALID";
+			return "";
 		}
 				
 		k = (!) index.nth (gid).data;
@@ -2721,9 +2805,9 @@ class PostTable : Table { 			return "";
 		}
 		
-		if (!(0 <= k <= names.length ())) {
+		if (!(0 <= k < names.length ())) {
 			warning ("k is out of range.");
-			return "INVALID";
+			return "";
 		}
 				
 		return (!) names.nth (k).data;
@@ -2790,9 +2874,17 @@ class PostTable : Table { 			// print (@"Name gid: $gid len: $len: $(name.str)\n");
 			
 			names.append (name.str);
-		}		
+		}
+		
+		populate_available ();
 	}
-	
+
+	void populate_available () {
+		for (int i = 0; i < index.length (); i++) {
+			available_names.append (get_name (i));
+		}
+	}
+		
 	public void print_all () {
 		print (@"PostScript glyph mapping:\n");
 		for (int i = 0; i < index.length (); i++) {
@@ -2800,7 +2892,7 @@ class PostTable : Table { 		}
 	}
 	
-	public void print_avaliable_names () {
+	public void print_all_names () {
 		print (@"Post table names:\n");
 		foreach (var n in names) {
 			print (@"$n\n");
@@ -4431,8 +4523,6 @@ class DirectoryTable : Table { 		
 		if (!validate_tables (dis, file)) {
 			warning ("Missing required table or bad checksum.");
-			// Fixa: stop processing here, if we want to avoid loading bad fonts
-			return;
 		}
 		
 		hhea_table.parse (dis);
diff --git a/src/OverView.vala b/src/OverView.valaindex 36218b0..deb3286 100644--- a/src/OverView.vala+++ b/src/OverView.vala@@ -53,6 +53,8 @@ class OverView : FontDisplay {  	Scrollbar scrollbar; 	+	bool all_avail = true;+	 	public OverView (GlyphRange? range = null) { 		GlyphRange gr; 		@@ -128,6 +130,10 @@ class OverView : FontDisplay { 	} 	 	public double get_height () {+		if (rows == 0) {+			return 0;+		}+				 		return 2.0 * nail_height * (glyph_range.length () / rows); 	} @@ -271,6 +277,14 @@ class OverView : FontDisplay { 		return "Overview"; 	} 	+	public void display_all_available_glyphs () {+		all_avail = true;+		+		first_character = 0;+		first_visible = 0;+		selected = 0;+	}+	 	private unowned List<GlyphCollection> get_visible_glyphs () { 		return visible_characters; 	}@@ -280,6 +294,8 @@ class OverView : FontDisplay { 		double left_margin, x, caption_y; // for glyph caption 		uint64 index = index_begin; 		int i = row * items_per_row;+		Font f = Supplement.get_current_font ();+		 		cr.save (); 		cr.set_line_width (1); 		@@ -288,24 +304,22 @@ class OverView : FontDisplay { 		cr.set_font_size (14);  		left_margin = 0;-		-		if (nail_width >= 70)-			left_margin = 14;-		else if (nail_width >= 60)-			left_margin = 9;-		else if (nail_width >= 36)-			left_margin = -2;-		else if (nail_width >= 26)-			left_margin = -8;-		else-			warning ("Max zoom level reached"); 					 		while (x < width) {-			if (! (0 <= index < glyph_range.get_length ())) {-				break;-			} 			-			character_string = glyph_range.get_char ((uint32) index);+			if (all_avail) {+				if (! (0 <= index < f.length ())) {+					break;+				}+				+				character_string = ((!) f.get_glyph_indice ((uint32) index)).get_name ();+			} else {+				if (!(0 <= index < glyph_range.get_length ())) {+					break;+				}+				+				character_string = glyph_range.get_char ((uint32) index);+			} 			 			if (character_string == "") { 				warning (@"Got null character as name for glyph. Index: $index");@@ -368,11 +382,12 @@ class OverView : FontDisplay { 	private bool draw_thumbnail (Context cr, string name, double x, double y) { 		Glyph? gl = Supplement.get_current_font ().get_glyph (name); 		Glyph g;+		 		double gx, gy; 		double x1, x2, y1, y2; 		double scale = nail_zoom_width / 150.0; 		double w, h, m;-		+ 		w = nail_width  - 19; 		h = nail_height - 22; 		@@ -388,7 +403,7 @@ class OverView : FontDisplay { 		g.boundries (out x1, out y1, out x2, out y2); 		 		if (g.get_width () > w) {-			m = ((g.get_width () - w) / 2.0) / scale;+			m = 0; 		} else { 			m = ((w - g.get_width ()) / 2.0) / scale; 		}@@ -398,13 +413,11 @@ class OverView : FontDisplay { 		 		Surface s = new Surface.similar (cr.get_target (), Content.COLOR_ALPHA, (int) w, (int) h); 		Context c = new Context (s);-		-		/*+/* 		c.set_source_rgb (200/255.0, 200/255.0, 229/255.0); 		c.rectangle (0, 0, w, h);	 		c.fill ();-		*/-		+*/ 		c.scale (scale, scale);				 		Svg.draw_svg_path (c, g.get_svg_data (), gx, gy, 1.0); 		@@ -691,11 +704,19 @@ class OverView : FontDisplay { 				key_up (); 			} 		}-		-		print (@"selected: $(selected)\n"); 	} 	 	public string get_selected_char () {+		Font f;+		Glyph? g;+		+		if (all_avail) {+			f = Supplement.get_current_font ();+			g = f.get_glyph_indice (selected);+			return_val_if_fail (g != null, "");+			return ((!) g).get_name ();+		}+		 		return glyph_range.get_char (selected); 	} 	@@ -878,7 +899,7 @@ class OverView : FontDisplay { 		selected--; 		 		if (current == selected && !menu_action) {-			open_glyph_signal (glyph_range.get_char (selected));+			open_glyph_signal (get_selected_char ()); 		} 		 		adjust_scroll ();@@ -897,7 +918,15 @@ class OverView : FontDisplay {  	/** Returns true if overview shows the last character. */ 	private bool at_bottom () {-		return (rows * items_per_row + items_per_row + first_visible >= glyph_range.length ());+		Font f;+		double t = rows * items_per_row + items_per_row + first_visible;+		+		if (all_avail) {+			f = Supplement.get_current_font ();+			return t >= f.length ();+		}+		+		return t >= glyph_range.length (); 	}  	public void set_glyph_range (GlyphRange range) {@@ -906,8 +935,10 @@ class OverView : FontDisplay { 		uint32 i; 		uint32 len = 0; 		-		glyph_range = range;+		all_avail = false; 		+		glyph_range = range;+ 		// Todo: optimized search when full range is selected. 		 		// scroll to the selected characterdiff --git a/src/Toolbox.vala b/src/Toolbox.valaindex 311473a..b2a7e39 100644--- a/src/Toolbox.vala+++ b/src/Toolbox.vala@@ -248,9 +248,7 @@ class Toolbox : DrawingArea { 		avalilable_characters.select_action.connect((self) => { 				MainWindow.get_tab_bar ().add_unique_tab (new OverView (), 75, false); 				OverView o = MainWindow.get_overview ();-				Font f = Supplement.get_current_font ();-				GlyphRange gr = f.get_available_glyph_ranges ();-				o.set_glyph_range (gr);+				o.display_all_available_glyphs (); 				MainWindow.get_tab_bar ().select_tab_name ("Overview"); 			}); 		characterset_tools.add_tool (avalilable_characters);

Contact

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