The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Cache glyphs in fallback font

These changes was commited to the Birdfont repository Thu, 28 May 2015 10:44:36 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Thu, 28 May 2015 10:44:36 +0000]

Updated Files

libbirdfont/BirdFontFile.vala
libbirdfont/Font.vala
libbirdfont/Glyph.vala
libbirdfont/Renderer/FallbackFont.vala
--- a/libbirdfont/BirdFontFile.vala +++ b/libbirdfont/BirdFontFile.vala @@ -1516,7 +1516,7 @@ } } - path.update_region_boundaries (); + path.update_region_boundaries (); } private static double parse_double (string p) {
--- a/libbirdfont/Font.vala +++ b/libbirdfont/Font.vala @@ -37,10 +37,10 @@ public Gee.ArrayList<BackgroundImage> background_images; public string background_scale = "1"; - + /** Top margin */ public double top_limit; - + /** Height of upper case letters. */ public double top_position; @@ -787,7 +787,7 @@ BirdFontFile bf_font = new BirdFontFile (this); data = load_freetype_font (path, out error); - + if (error != 0) { warning ("Failed to load freetype font."); return false;
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -1247,11 +1247,6 @@ if (p.is_editable ()) { r = true; p.set_editable (false); - } - - if (p.is_open ()) { - // FIXME: this distorts ttf paths - //p.convert_path_ending_to_line (); } p.create_full_stroke (); // cache stroke
--- a/libbirdfont/Renderer/FallbackFont.vala +++ b/libbirdfont/Renderer/FallbackFont.vala @@ -39,6 +39,9 @@ string default_font_file_name = "Roboto-Regular.ttf"; string default_font_family_name = "Roboto"; + + Gee.HashMap<unichar, Font> glyphs; + Gee.ArrayList<unichar> cached; public FallbackFont () { string home = Environment.get_home_dir (); @@ -56,6 +59,9 @@ add_font_folder ("/Network/Library/Fonts"); add_font_folder ("/System/Library/Fonts"); add_font_folder ("/System Folder/Fonts"); + + glyphs = new Gee.HashMap<unichar, Font> (); + cached = new Gee.ArrayList<unichar> (); open_default_font (); } @@ -67,6 +73,29 @@ } public Font get_single_glyph_font (unichar c) { + Font f; + + // remove glyphs from cache if it is full + if (cached.size > 300) { + for (int i = 0; i < 100 && cached.size > 0; i++) { + glyphs.unset (cached.get (cached.size - 1)); + cached.remove_at (cached.size - 1); + } + } + + if (glyphs.has_key (c)) { + f = glyphs.get (c); + return f; + } + + f = get_single_fallback_glyph_font (c); + glyphs.set (c, f); + cached.add (c); + + return f; + } + + Font get_single_fallback_glyph_font (unichar c) { string? font_file; BirdFontFile bf_parser; Font bf_font;