Clone in a terminal:
Commit 2f8aa2e
Johan Mattsson - 2015-05-24T12:19:17+00:00
2f8aa2e962a382745feb34640b2b602ac18b8b31johan.mattsson.m@gmail.com

Use Roboto as the default font for the application

Changed files (5)

Diff

diff --git a/README.md b/README.mdindex 16ae001..2ccea37 100644--- a/README.md+++ b/README.md@@ -16,6 +16,7 @@ Install vala and all required libraries, they are most likely in packages with a -dev or -devel affix:      valac+    font-roboto     libgee-dev     libglib2.0-dev      libgtk-3-dev diff --git a/libbirdfont/Expander.vala b/libbirdfont/Expander.valaindex 6dc553e..17f2edc 100644--- a/libbirdfont/Expander.vala+++ b/libbirdfont/Expander.vala@@ -53,9 +53,6 @@ public class Expander : GLib.Object {  		if (headline != null) { 			title.set_text ((!) headline);-			title.use_cache (true);-			Theme.text_color (title, "Text Tool Box");-			title.set_font_size (17 * Toolbox.get_scale ()); 		} 				 		tool = new Gee.ArrayList<Tool> ();@@ -139,6 +136,10 @@ public class Expander : GLib.Object { 		}  		if (headline != null && tool.size > 0) {+			Theme.text_color (title, "Text Tool Box");+			title.use_cache (true);+			title.set_font_size (17 * Toolbox.get_scale ());+ 			yt += 17 * scale + HEADLINE_MARGIN; 			content_height += 17 * scale + HEADLINE_MARGIN; 		}diff --git a/libbirdfont/OverView.vala b/libbirdfont/OverView.valaindex 0f53e5a..389a111 100644--- a/libbirdfont/OverView.vala+++ b/libbirdfont/OverView.vala@@ -46,7 +46,18 @@ public class OverView : FontDisplay { 	Gee.ArrayList<OverViewUndoItem> redo_items = new Gee.ArrayList<OverViewUndoItem> (); 	 	/** Show all characters that has been drawn. */-	public bool all_available = true;+	public bool all_available {+		set {+			_all_available = value;+			update_item_list ();+		}+		+		get {+			return _all_available;+		}+	}+	+	bool _all_available = false; 	 	/** Show unicode database info. */ 	CharacterInfo? character_info = null;diff --git a/libbirdfont/Renderer/FallbackFont.vala b/libbirdfont/Renderer/FallbackFont.valaindex fec5799..d2c384d 100644--- a/libbirdfont/Renderer/FallbackFont.vala+++ b/libbirdfont/Renderer/FallbackFont.vala@@ -13,8 +13,6 @@ */  using Gee;-using Sqlite;-using Bird;  [SimpleType] [CCode (has_type_id = false)]@@ -27,37 +25,119 @@ extern FcConfig* FcInitLoadConfigAndFonts (); [CCode (cname = "find_font")] extern string? find_font (FcConfig* font_config, string characters); +[CCode (cname = "find_font_file")]+extern string? find_font_file (FcConfig* font_config, string font_name);+ namespace BirdFont {  // TODO: use font config public class FallbackFont : GLib.Object {+	Gee.ArrayList<File> font_directories;+	 	FcConfig* font_config; -	public FallbackFont () {	+	public FallbackFont () {+		string home = Environment.get_home_dir ();+		+		font_directories = new Gee.ArrayList<File> (); 		font_config = FcInitLoadConfigAndFonts ();++		add_font_folder ("/usr/share/fonts/");+		add_font_folder ("/usr/local/share/fonts/");+		add_font_folder (home + "/.local/share/fonts");+		add_font_folder (home + "/.fonts");+		add_font_folder ("C:\\Windows\\Fonts");	+		//FIXME: MAC 	} 	+	void add_font_folder (string f) {+		File folder = File.new_for_path (f);+		FileInfo? file_info;+		string fn;+		string file_attributes;+		try {+			if (folder.query_exists ()) {+				font_directories.add (folder);+				+				file_attributes = FileAttribute.STANDARD_NAME;+				file_attributes += ",";+				file_attributes += FileAttribute.STANDARD_TYPE;+				var enumerator = folder.enumerate_children (file_attributes, 0);+				+				while ((file_info = enumerator.next_file ()) != null) {+					fn = ((!) file_info).get_name ();++					if (((!)file_info).get_file_type () == FileType.DIRECTORY) {+						add_font_folder ((!) get_child (folder, fn).get_path ());+					}+				}+			}+		} catch (GLib.Error e) {+			warning (e.message);+		}+	}++	File search_font_file (string font_file) {+		File d, f;+		+		for (int i = font_directories.size - 1; i >= 0; i--) {+			d = font_directories.get (i);+			f = get_child (d, font_file);+			+			if (f.query_exists ()) {+				return f;+			}+		}+		+		warning (@"The font $font_file not found");+		return File.new_for_path (font_file);+	}+			 	public Font get_single_glyph_font (unichar c) { 		string? font_file;-		string file; 		BirdFontFile bf_parser; 		Font bf_font; 		StringBuilder? glyph_data; 		FontFace* font;+		File roboto; -		font_file = find_font (font_config, (!) c.to_string ());-		+		bf_font = new Font ();+		font_file = null;+		glyph_data = null;++		// check if glyph is available in roboto 		if (font_file == null) {-			font_file = (!) SearchPaths.find_file (null, "Roboto-Regular.ttf").get_path ();+			roboto = SearchPaths.search_file (null, "Roboto-Regular.ttf");+			+			if (roboto.query_exists ()) {+				font_file = (!) roboto.get_path ();+			} else {+				roboto = search_font_file ("Roboto-Regular.ttf");+		+				if (roboto.query_exists ()) {+					font_file = (!) roboto.get_path ();+				} else {+					font_file = find_font_file (font_config, "Roboto");+				}+			} 		} 		-		file = (!) font_file;--		font = open_font (file);-		glyph_data = get_glyph_in_font (font, c);-		close_font (font);+		if (font_file != null) {+			font = open_font ((!) font_file);+			glyph_data = get_glyph_in_font (font, c);+			close_font (font);+		}+		+		// use fontconfig to find a fallback font+		if (glyph_data == null) {+			font_file = find_font (font_config, (!) c.to_string ());+			if (font_file != null) {+				font = open_font ((!) font_file);+				glyph_data = get_glyph_in_font (font, c);+				close_font (font);+			}+		} 		-		bf_font = new Font (); 		if (glyph_data != null) { 			bf_parser = new BirdFontFile (bf_font); 			bf_parser.load_data (((!) glyph_data).str);diff --git a/libbirdfont/Renderer/fontconfig.c b/libbirdfont/Renderer/fontconfig.cindex 15e2498..7281410 100644--- a/libbirdfont/Renderer/fontconfig.c+++ b/libbirdfont/Renderer/fontconfig.c@@ -35,7 +35,7 @@ gchar* find_font (FcConfig* fontconfig, const gchar* characters) { 	 	character_set = FcCharSetCreate (); 	-	remaining_characters = characters;+	remaining_characters = (gchar*) characters; 	while (TRUE) { 		character = g_utf8_get_char (remaining_characters); 		@@ -50,12 +50,13 @@ gchar* find_font (FcConfig* fontconfig, const gchar* characters) {  	FcPatternAddCharSet (pattern, FC_CHARSET, character_set); 	FcCharSetDestroy (character_set);+	FcPatternAddInteger (pattern, FC_SLANT, FC_SLANT_ROMAN); 	 	FcPatternAddBool(pattern, FC_SCALABLE, FcTrue); 	font_properties = FcObjectSetBuild (FC_FILE, NULL);	 	fonts = FcFontList (fontconfig, pattern, font_properties); -	if (fonts->nfont > 0) {+	if (fonts && fonts->nfont > 0) { 		font = fonts->fonts[0]; 		if (FcPatternGetString(font, FC_FILE, 0, &path) == FcResultMatch) { 			result = g_strdup ((gchar*) path);@@ -66,5 +67,53 @@ gchar* find_font (FcConfig* fontconfig, const gchar* characters) { 		FcFontSetDestroy(fonts); 	} +	if (pattern) {+		FcPatternDestroy(pattern);+	}+ 	return result; }++/** Find a font file from its family name.+ * @param font_config fontconfig instance+ * @param font_name name of the font+ * @return full path to the font file+ */+gchar* find_font_file (FcConfig* font_config, const gchar* font_name) {+	const FcChar8* name;+	FcPattern* search_pattern;+	FcPattern* font;+	FcChar8* file;+	gchar* path;+	FcObjectSet* font_properties;+	FcFontSet* fonts;+	int i;+	+	path = NULL;+	name = font_name;++	search_pattern = FcPatternCreate ();+	FcPatternAddString (search_pattern, FC_FAMILY, name);+	FcPatternAddBool (search_pattern, FC_SCALABLE, FcTrue);+	FcPatternAddInteger (search_pattern, FC_WEIGHT, FC_WEIGHT_MEDIUM);+	FcPatternAddInteger (search_pattern, FC_SLANT, FC_SLANT_ROMAN);+		+	font_properties = FcObjectSetBuild (FC_FILE, NULL);+	fonts = FcFontList (font_config, search_pattern, font_properties);+	+	if (fonts->nfont > 0) {+		for (i = 0; i < fonts->nfont; i++) {+			font = fonts->fonts[i];+			+			if (FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch) {+				path = g_strdup ((gchar*) file);+				break;+			}+		}+		FcPatternDestroy (font);+	}++	FcPatternDestroy (search_pattern);+	+	return path;+}

Contact

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