The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Look for Roboto in default font locations

These changes was commited to the Birdfont repository Mon, 25 May 2015 03:27:16 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Mon, 25 May 2015 03:27:16 +0000]

Updated Files

libbirdfont/Renderer/FallbackFont.vala
libbirdfont/Renderer/FontCache.vala
libbirdfont/Renderer/Text.vala
--- a/libbirdfont/Renderer/FallbackFont.vala +++ b/libbirdfont/Renderer/FallbackFont.vala @@ -34,7 +34,11 @@ 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 @@ 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 @@ } // 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 (default_font != null) { + glyph_data = get_glyph_in_font ((!) default_font, c); } - - 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 ()); @@ -164,8 +118,74 @@ glyph_data = load_glyph (font, (uint) c); 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); + } } } }
--- a/libbirdfont/Renderer/FontCache.vala +++ b/libbirdfont/Renderer/FontCache.vala @@ -40,8 +40,8 @@ if (f != null) { ((!) f).load (); } - } - + } + public CachedFont get_font (string file_name) { CachedFont c; Font f; @@ -68,7 +68,7 @@ return c; } - + public static FontCache get_default_cache () { if (default_cache == null) { default_cache = new FontCache (); @@ -76,67 +76,12 @@ 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 (); - } - } } }
--- a/libbirdfont/Renderer/Text.vala +++ b/libbirdfont/Renderer/Text.vala @@ -19,7 +19,7 @@ /** 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;