Clone in a terminal:
Commit c8fcf94
Johan Mattsson - 2015-05-28T12:11:08+00:00
c8fcf94fb9617ef7374d4b2b6dd50268a9ba4be2johan.mattsson.m@gmail.com

Cached font

Changed files (3)

Diff

diff --git a/libbirdfont/Renderer/CachedFont.vala b/libbirdfont/Renderer/CachedFont.valanew file mode 100644index 0000000..d291b96--- /dev/null+++ b/libbirdfont/Renderer/CachedFont.vala@@ -0,0 +1,67 @@+/*+    Copyright (C) 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.+*/++using Gee;++namespace BirdFont {+	+public class CachedFont : GLib.Object {+	public Font? font;++	// FIXME: move fallback glyphs in to fond boundaries+	public double top_limit = 84;+	public double base_line = 0;+	public double bottom_limit = -27;+	+	FallbackFont fallback_font {+		get {+			if (_fallback_font == null) {+				_fallback_font = new FallbackFont ();+			}+			+			return (!) _fallback_font;+		}+	}+	static FallbackFont? _fallback_font = null;++	public CachedFont (Font? font) {+		this.font = font;+	}+	+	public Glyph? get_glyph_by_name (string name) {+		Font f = new Font ();+		Glyph? g = null;+		+		if (font != null) {+			g = ((!) font).get_glyph_by_name (name);+		}+		+		if (g == null && name.char_count () == 1) {+			f = fallback_font.get_single_glyph_font (name.get_char (0));+			g = f.get_glyph_by_name (name);+			+			if (g == null) {+				return null;+			}+			+			top_limit = f.top_limit;+			base_line = f.base_line;+			bottom_limit = f.bottom_limit;	+		}+				+		return g;+	}+}++}diff --git a/libbirdfont/Renderer/Text.vala b/libbirdfont/Renderer/Text.valaindex fe85ad1..c1bf3b6 100644--- a/libbirdfont/Renderer/Text.vala+++ b/libbirdfont/Renderer/Text.vala@@ -48,8 +48,6 @@ public class Text : Widget { 	bool use_cached_glyphs = true; 	double truncated_width = -1; 	-	static int ntext = 0;-	 	public Text (string text = "", double size = 17, double margin_bottom = 0) { 		this.margin_bottom = margin_bottom; 		font_cache = FontCache.get_default_cache ();@@ -57,12 +55,6 @@ public class Text : Widget { 		 		set_font_size (size); 		set_text (text);-		-		ntext++;-	}- -	~Text () {-		ntext--; 	} 	 	public void use_cache (bool cache) {@@ -343,6 +335,10 @@ public class Text : Widget { 		y = py; 		x = px; +		if (unlikely (cached_font.base_line != 0)) {+			warning ("Base line not zero.");+		}+ 		if (use_cached_glyphs) { 			iterate ((glyph, kerning, last) => { 				double end;@@ -390,7 +386,7 @@ public class Text : Widget { 		lsb = glyph.left_limit;  		foreach (Path path in glyph.path_list) {-			draw_path (cr, path, lsb, x, y, ratio);+			draw_path (cr, glyph, path, lsb, x, y, ratio); 		}  		cr.fill ();@@ -426,7 +422,7 @@ public class Text : Widget { 			cc.new_path ();  			foreach (Path path in glyph.path_list) {-				draw_path (cc, path, lsb, offset_x / 10.0, cc_y + offset_y / 10.0, ratio);+				draw_path (cc, glyph, path, lsb, offset_x / 10.0, cc_y + offset_y / 10.0, ratio); 			} 			 			cc.fill ();@@ -442,12 +438,18 @@ public class Text : Widget { 		cr.restore (); 	} 	-	void draw_path (Context cr, Path path, double lsb, double x, double y, double scale) {+	void draw_path (Context cr, Glyph glyph, Path path,+		double lsb, double x, double y, double scale) {+			 		EditPoint e, prev; 		double xa, ya, xb, yb, xc, yc, xd, yd; 		double by;-		+ 		if (path.points.size > 0) {+			if (unlikely (path.is_open ())) {+				warning (@"Path is open in $(glyph.get_name ()).");+			}+			 			path.add_hidden_double_points (); 			 			prev = path.points.get (path.points.size - 1);diff --git a/libbirdfont/VersionList.vala b/libbirdfont/VersionList.valaindex 18dc51b..b43d837 100644--- a/libbirdfont/VersionList.vala+++ b/libbirdfont/VersionList.vala@@ -27,8 +27,6 @@ public class VersionList : GLib.Object { 	GlyphCollection glyph_collection; 	 	public Gee.ArrayList<Glyph> glyphs;-	-	static int n_lists = 0;  	public delegate void Selected (MenuAction self); 	public signal void selected (VersionList self);@@ -74,15 +72,6 @@ public class VersionList : GLib.Object { 		} 		 		set_selected_version (gc.get_current ().version_id, false);-		n_lists++;-	}-	-	~VersionList () {-		n_lists--;--		if (menu_visible) {-			warning ("menu is visible");-		} 	} 	 	private void delete_item (int index) {@@ -92,7 +81,7 @@ public class VersionList : GLib.Object { 		 		font.touch (); 		-		index--; // first item is the add new action+		index--; // first item adds new glyphs to the list 		 		// delete the entire glyph if the last remaining version is removed 		if (glyphs.size == 1) {

Contact

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