Clone in a terminal:
Commit e92398f
Johan Mattsson - 2015-12-18T18:05:08+00:00
e92398f7debf208f717009aa3f8c94848026c378johan.mattsson.m@gmail.com

Use roboto as the default fallback font

Changed files (3)

Diff

diff --git a/libbirdfont/OverViewItem.vala b/libbirdfont/OverViewItem.valaindex 20ff667..8ec374f 100644--- a/libbirdfont/OverViewItem.vala+++ b/libbirdfont/OverViewItem.vala@@ -16,7 +16,7 @@ using Cairo; using Math;  [CCode (cname = "draw_overview_glyph")]-public extern void draw_overview_glyph (Context context, string font_file, double width, double height, unichar character);+public extern bool draw_overview_glyph (Context context, string font_file, double width, double height, unichar character);  namespace BirdFont { 	@@ -167,22 +167,25 @@ public class OverViewItem : GLib.Object { 			 			c.save (); 			-			string? font_file = find_font (FallbackFont.font_config, (!) character.to_string ());-			if (font_file != null) {-				draw_overview_glyph (c, (!) font_file, width, height, character);+			bool glyph_found;+			string? font_file;+			+			Test t1 = new Test.time("both");+			font_file = FontCache.fallback_font.get_default_font_file ();	+			glyph_found = draw_overview_glyph (c, (!) font_file, width, height, character);+			+			Test t2 = new Test.time("fall");+			if (!glyph_found) {+				font_file = find_font (FallbackFont.font_config, (!) character.to_string ());+				+				if (font_file != null) {+					draw_overview_glyph (c, (!) font_file, width, height, character);+				} 			} 			-			/*-			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;-			fallback.set_font_size (font_size);-			gx = (width - fallback.get_extent ()) / 2.0;-			gy = height - 30;-			fallback.draw_at_baseline (c, gx, gy);-			*/+			t2.print();+			t1.print();+			 			c.restore (); 			 			cache = s;diff --git a/libbirdfont/Renderer/FallbackFont.vala b/libbirdfont/Renderer/FallbackFont.valaindex 2b0b889..5e58281 100644--- a/libbirdfont/Renderer/FallbackFont.vala+++ b/libbirdfont/Renderer/FallbackFont.vala@@ -49,6 +49,8 @@ public class FallbackFont : GLib.Object {  	public int max_cached_fonts = 300; 	+	string? default_font_file = null;+	 	public FallbackFont () { 		string home = Environment.get_home_dir (); 		font_directories = new Gee.ArrayList<File> ();@@ -243,10 +245,14 @@ public class FallbackFont : GLib.Object { 		return File.new_for_path (font_file); 	} -	void open_default_font () {+	public string? get_default_font_file () { 		File font_file; 		string? fn = null; 		+		if (likely (default_font_file != null)) {+			return default_font_file;+		}+		 		font_file = SearchPaths.search_file (null, default_font_file_name); 		 		if (font_file.query_exists ()) {@@ -261,6 +267,18 @@ public class FallbackFont : GLib.Object { 			} 		} 			+		if (likely (fn != null)) {+			default_font_file = fn;+			return fn;+		}+		+		warning(default_font_family_name + " not found");+		return null;+	}+	+	void open_default_font () {+		string? fn = get_default_font_file ();+		 		if (fn != null) { 			default_font = open_font ((!) fn); 		}diff --git a/libbirdfont/overview_glyph.c b/libbirdfont/overview_glyph.cindex 1d079aa..b30d617 100644--- a/libbirdfont/overview_glyph.c+++ b/libbirdfont/overview_glyph.c@@ -21,7 +21,7 @@ #include FT_FREETYPE_H
 #include FT_GLYPH_H
 
-void draw_overview_glyph (cairo_t* context, const char* font_file, gdouble width, gdouble height, gunichar character) {
+gboolean draw_overview_glyph (cairo_t* context, const char* font_file, gdouble width, gdouble height, gunichar character) {
 	FT_Library library;
 	FT_Face face;
 	int error;
@@ -34,24 +34,24 @@ void draw_overview_glyph (cairo_t* context, const char* font_file, gdouble width 
 	// private use area
 	if (0xe000 <= character && character <= 0xf8ff) {
-		return;
+		return FALSE;
 	}
 	
 	// control characters
 	if (character <= 0x001f || (0x007f <= character && character <= 0x008d)) {
-		return;
+		return FALSE;
 	}
 
 	error = FT_Init_FreeType (&library);
 	if (error) {
 		g_warning ("Freetype init error %d.\n", error);
-		return;
+		return FALSE;
 	}
 
 	error = FT_New_Face (library, font_file, 0, &face);
 	if (error) {
 		g_warning ("Freetype font face error %d\n", error);
-		return;
+		return FALSE;
 	}
 
 	units_per_em = face->units_per_EM;
@@ -60,19 +60,19 @@ void draw_overview_glyph (cairo_t* context, const char* font_file, gdouble width 	error = FT_Select_Charmap (face , FT_ENCODING_UNICODE);
 	if (error) {
 		g_warning ("Freetype can not use Unicode, error: %d\n", error);
-		return;
+		return FALSE;
 	}
 
 	error = FT_Set_Char_Size (face, 0, 64, (int) height, (int) height);
 	if (error) {
 		g_warning ("FT_Set_Char_Size, error: %d.\n", error);
-		return;
+		return FALSE;
 	}
 
 	error = FT_Set_Pixel_Sizes (face, 0, (int) (height * 0.5));
 	if (error) {
 		g_warning ("FT_Set_Pixel_Sizes, error: %d.\n", error);
-		return;
+		return FALSE;
 	}
 
 	gchar text[7];
@@ -87,7 +87,7 @@ void draw_overview_glyph (cairo_t* context, const char* font_file, gdouble width 		advance *= units;
 	} else {
 		g_warning("Glyph not found: %s", text);
-		return;
+		return FALSE;
 	}
 
 	cairo_save (context);
@@ -110,4 +110,6 @@ void draw_overview_glyph (cairo_t* context, const char* font_file, gdouble width 	
 	FT_Done_Face (face);
 	FT_Done_FreeType (library);
+	
+	return TRUE;
 }

Contact

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