Clone in a terminal:
Commit 283d911
Johan Mattsson - 2015-12-14T14:08:12+00:00
283d91133b7d32c875aeeff95d1d67d933a4367ejohan.mattsson.m@gmail.com

Don't put overview glyphs in cache The cache does become large and it slows down rendering.

Changed files (9)

Diff

diff --git a/libbirdfont/CharacterInfo.vala b/libbirdfont/CharacterInfo.valaindex acbc715..9eff97d 100644--- a/libbirdfont/CharacterInfo.vala+++ b/libbirdfont/CharacterInfo.vala@@ -21,6 +21,7 @@ public class CharacterInfo : GLib.Object { 	 	public unichar unicode; +	private static Text? info_icon = null; 	Text icon; 	double x = 0; 	double y = 0;@@ -29,13 +30,17 @@ public class CharacterInfo : GLib.Object { 	 	public CharacterInfo (unichar c, GlyphCollection? gc) { 		unicode = c;-		icon = new Text ("info_icon", 22);-		icon.load_font ("icons.bf");+		+		if (info_icon == null) {+			info_icon= new Text ("info_icon", 22);+			((!) info_icon).load_font ("icons.bf");+		}+		+		icon = (!) info_icon; 		 		if (gc != null) { 			ligature = ((!) gc).is_unassigned (); 			name = ((!) gc).get_name ();-			icon.load_font ("icons.bf"); 		} 	} 	diff --git a/libbirdfont/OpenFontFormat/Os2Table.vala b/libbirdfont/OpenFontFormat/Os2Table.valaindex e424367..4308069 100644--- a/libbirdfont/OpenFontFormat/Os2Table.vala+++ b/libbirdfont/OpenFontFormat/Os2Table.vala@@ -61,7 +61,7 @@ public class Os2Table : OtfTable { 		uint32 codepage1, codepage2; 		int16 win_descent; 		-		fd.add_u16 (0x0004); // version+		fd.add_u16 (0x0002); // version  		fd.add_16 (hmtx_table.get_average_width ()); // xAvgCharWidth 		@@ -104,6 +104,7 @@ public class Os2Table : OtfTable { 			fd.add_u32 (0); // ulUnicodeRange3 Bits 64-95 			fd.add_u32 (0); // ulUnicodeRange4 Bits 96-127 		} else {+			warning(@"unicodeRange1: $unicodeRange1 unicodeRange2: $unicodeRange2 unicodeRange3 $unicodeRange3 unicodeRange4: $unicodeRange4"); 			fd.add_u32 (unicodeRange1); // ulUnicodeRange1 Bits 0-31 			fd.add_u32 (unicodeRange2); // ulUnicodeRange2 Bits 32-63 			fd.add_u32 (unicodeRange3); // ulUnicodeRange3 Bits 64-95diff --git a/libbirdfont/OpenFontFormat/load_font.c b/libbirdfont/OpenFontFormat/load_font.cindex 513da74..323dc62 100644--- a/libbirdfont/OpenFontFormat/load_font.c+++ b/libbirdfont/OpenFontFormat/load_font.c@@ -1,15 +1,15 @@ /*-    Copyright (C) 2013 2014 2015 Johan Mattsson+	Copyright (C) 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 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.+	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 <assert.h>diff --git a/libbirdfont/OverView.vala b/libbirdfont/OverView.valaindex 089d152..1ff2261 100644--- a/libbirdfont/OverView.vala+++ b/libbirdfont/OverView.vala@@ -1455,6 +1455,7 @@ public class OverView : FontDisplay { 		 		cr.save (); 		Text character = new Text ();+		character.set_use_cache (false); 		Theme.text_color (character, "Foreground 1"); 		character.set_text ((!) c.to_string ()); 		character.set_font_size (height);diff --git a/libbirdfont/OverViewItem.vala b/libbirdfont/OverViewItem.valaindex ed3458d..bc251c9 100644--- a/libbirdfont/OverViewItem.vala+++ b/libbirdfont/OverViewItem.vala@@ -233,9 +233,10 @@ public class OverViewItem : GLib.Object { 			c.restore (); 		} else { 			c.scale (Screen.get_scale (), Screen.get_scale ());-+			 			c.save (); 			Text fallback = new Text ();+			fallback.set_use_cache (false); 			Theme.text_color (fallback, "Overview Glyph"); 			fallback.set_text ((!) character.to_string ()); 			double font_size = height * 0.8;diff --git a/libbirdfont/Renderer/CachedFont.vala b/libbirdfont/Renderer/CachedFont.valaindex f341970..d93368a 100644--- a/libbirdfont/Renderer/CachedFont.vala+++ b/libbirdfont/Renderer/CachedFont.vala@@ -33,7 +33,7 @@ public class CachedFont : GLib.Object { 	double _top_limit = 92.77; // FIXME: load before first glyph 	double _bottom_limit = -24.4; 	-	FallbackFont fallback_font {+	static FallbackFont fallback_font { 		get { 			if (_fallback_font == null) { 				_fallback_font = new FallbackFont ();diff --git a/libbirdfont/Renderer/FallbackFont.vala b/libbirdfont/Renderer/FallbackFont.valaindex 32d484a..2b0b889 100644--- a/libbirdfont/Renderer/FallbackFont.vala+++ b/libbirdfont/Renderer/FallbackFont.vala@@ -16,17 +16,20 @@ using Gee;  [SimpleType] [CCode (has_type_id = false)]-extern struct FcConfig {+public extern struct FcConfig { }  [CCode (cname = "FcInitLoadConfigAndFonts")]-extern FcConfig* FcInitLoadConfigAndFonts ();+public extern FcConfig* FcInitLoadConfigAndFonts ();  [CCode (cname = "find_font")]-extern string? find_font (FcConfig* font_config, string characters);+public extern string? find_font (FcConfig* font_config, string characters);++[CCode (cname = "find_font_family")]+public extern string? find_font_family (FcConfig* font_config, string characters);  [CCode (cname = "find_font_file")]-extern string? find_font_file (FcConfig* font_config, string font_name);+public extern string? find_font_file (FcConfig* font_config, string font_name);  namespace BirdFont { @@ -35,7 +38,7 @@ public class FallbackFont : GLib.Object { 	Gee.ArrayList<File> font_directories; 	 	FontFace* default_font = null;-	static FcConfig* font_config = null;+	public static FcConfig* font_config = null; 	static bool font_config_stated = false; 	 	string default_font_file_name = "Roboto-Regular.ttf";diff --git a/libbirdfont/Renderer/Text.vala b/libbirdfont/Renderer/Text.valaindex 94e7a83..2121e5f 100644--- a/libbirdfont/Renderer/Text.vala+++ b/libbirdfont/Renderer/Text.vala@@ -26,6 +26,8 @@ public class Text : Widget { 	 	public string text; 	+	private bool use_cache = true;+	 	GlyphSequence glyph_sequence { 		get { 			if (gs == null) {@@ -60,6 +62,10 @@ public class Text : Widget { 		set_font_size (size); 	} 	+	public void set_use_cache (bool cache) {+		use_cache = cache;+	}+	 	public string get_text () { 		return text; 	}@@ -432,6 +438,7 @@ public class Text : Widget { 		 		double lsb; 		Surface cache;+		Surface cached_glyph; 		Context cc; 		string cache_id; 		double glyph_margin_left = glyph.get_left_side_bearing ();@@ -472,13 +479,19 @@ public class Text : Widget { 			cc.fill (); 			cc.restore (); -			glyph.set_cache (cache_id, cache);+			if (use_cache) {+				glyph.set_cache (cache_id, cache);+			}+			+			cached_glyph = cache;+		} else {+			cached_glyph = glyph.get_cache (cache_id); 		}  		cr.save (); 		cr.set_antialias (Cairo.Antialias.NONE); 		cr.scale(1 / Screen.get_scale (), 1 / Screen.get_scale ());-		cr.set_source_surface (glyph.get_cache (cache_id),+		cr.set_source_surface (cached_glyph, 			(int) (xp * Screen.get_scale ()), 			(int) (yp * Screen.get_scale ())); 		cr.paint ();diff --git a/libbirdfont/Renderer/fontconfig.c b/libbirdfont/Renderer/fontconfig.cindex 7cb6304..0ae4dca 100644--- a/libbirdfont/Renderer/fontconfig.c+++ b/libbirdfont/Renderer/fontconfig.c@@ -1,25 +1,22 @@ /*-    Copyright (C) 2015 Johan Mattsson+	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 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.+	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 <stdio.h> #include <glib.h> #include <fontconfig/fontconfig.h> -/** Find a fallback font for a set of characters.- * @return A path to the font file.- */-gchar* find_font (FcConfig* fontconfig, const gchar* characters) {+gchar* find_font_with_property (FcConfig* fontconfig, const gchar* characters, const gchar* property) { 	FcPattern* pattern; 	FcCharSet* character_set; 	FcObjectSet* font_properties;@@ -58,12 +55,12 @@ gchar* find_font (FcConfig* fontconfig, const gchar* characters) { 	FcPatternAddInteger (pattern, FC_SLANT, FC_SLANT_ROMAN); 	 	FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);-	font_properties = FcObjectSetBuild (FC_FILE, NULL);	+	font_properties = FcObjectSetBuild (property, NULL);	 	fonts = FcFontList (fontconfig, pattern, font_properties);  	if (fonts && fonts->nfont > 0) { 		font = fonts->fonts[0];-		if (FcPatternGetString(font, FC_FILE, 0, &path) == FcResultMatch) {+		if (FcPatternGetString(font, property, 0, &path) == FcResultMatch) { 			result = g_strdup ((gchar*) path); 		} 	}@@ -79,6 +76,20 @@ gchar* find_font (FcConfig* fontconfig, const gchar* characters) { 	return result; } +/** Find a fallback font for a set of characters.+ * @return A path to the font file.+ */+gchar* find_font (FcConfig* fontconfig, const gchar* characters) {+	return find_font_with_property (fontconfig, characters, FC_FILE);+}++/** Find a fallback font for a set of characters.+ * @return Family name of the font.+ */+gchar* find_font_family (FcConfig* fontconfig, const gchar* characters) {+	return find_font_with_property (fontconfig, characters, FC_FAMILY);+}+ /** Find a font file from its family name.  * @param font_config fontconfig instance  * @param font_name name of the font

Contact

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