Commit 606b8e3
Look for Roboto in default font locations
Changed files (3)
modifiedlibbirdfont/Renderer/FallbackFont.valamodifiedlibbirdfont/Renderer/FontCache.valamodifiedlibbirdfont/Renderer/Text.vala
Diff
@@ -34,7 +34,11 @@ namespace BirdFont { public class FallbackFont : GLib.Object { Gee.ArrayList<File> font_directories; - FcConfig* font_config;+ FcConfig* font_config = null;+ FontFace* default_font = null;+ + string default_font_file_name = "Roboto-Regular.ttf";+ string default_font_family_name = "Roboto"; public FallbackFont () { string home = Environment.get_home_dir ();@@ -46,66 +50,34 @@ public class FallbackFont : GLib.Object { 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+ add_font_folder ("C:\\Windows\\Fonts");+ add_font_folder (home + "/Library/Fonts");+ add_font_folder ("/Library/Fonts");+ add_font_folder ("/Network/Library/Fonts");+ add_font_folder ("/System/Library/Fonts");+ add_font_folder ("/System Folder/Fonts");+ + open_default_font (); } - 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);+ ~FallbackFont () {+ if (default_font != null) {+ close_font (default_font); } } - 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; BirdFontFile bf_parser; Font bf_font; StringBuilder? glyph_data; FontFace* font;- File roboto; bf_font = new Font (); font_file = null; glyph_data = null; - // don't use fallback font for private use area+ // don't use fallback font in private use area if (0xe000 <= c <= 0xf8ff) { return bf_font; }@@ -116,28 +88,10 @@ public class FallbackFont : GLib.Object { } // check if glyph is available in roboto- if (font_file == null) {- 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");- }- }- }- - if (font_file != null) {- font = open_font ((!) font_file);- glyph_data = get_glyph_in_font (font, c);- close_font (font);+ if (default_font != null) {+ glyph_data = get_glyph_in_font ((!) default_font, c); }- + // use fontconfig to find a fallback font if (glyph_data == null) { font_file = find_font (font_config, (!) c.to_string ());@@ -165,6 +119,72 @@ public class FallbackFont : GLib.Object { return glyph_data; }+ + 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);+ }++ void open_default_font () {+ File font_file;+ string? fn = null;+ + font_file = SearchPaths.search_file (null, default_font_file_name);+ + if (font_file.query_exists ()) {+ fn = (!) font_file.get_path ();+ } else {+ font_file = search_font_file (default_font_file_name);+ + if (font_file.query_exists ()) {+ fn = (!) font_file.get_path ();+ } else {+ fn = find_font_file (font_config, default_font_family_name);+ }+ }+ + if (fn != null) {+ default_font = open_font ((!) fn);+ }+ } } }@@ -40,8 +40,8 @@ public class FontCache { if (f != null) { ((!) f).load (); }- }- + } + public CachedFont get_font (string file_name) { CachedFont c; Font f;@@ -68,7 +68,7 @@ public class FontCache { return c; }- + public static FontCache get_default_cache () { if (default_cache == null) { default_cache = new FontCache ();@@ -76,66 +76,11 @@ public class FontCache { return (!) default_cache; }- + public CachedFont get_fallback () { return fallback; }- - 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;- - public static int cached = 0; - - public CachedFont (Font? font) {- this.font = font;- cached++;- }- - ~CachedFont () {- cached--;- }- - 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;- }- - public GlyphCollection get_not_def_character () {- Font f;- - if (font != null) {- return ((!) font).get_not_def_character ();- }- - f = new Font ();- - return f.get_not_def_character ();- }- } } }@@ -19,7 +19,7 @@ namespace BirdFont { /** Test implementation of a birdfont rendering engine. */ public class Text : Widget { FontCache font_cache;- public FontCache.CachedFont cached_font;+ public CachedFont cached_font; public string text;