The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Remove old fallback fonts

These changes was commited to the Birdfont repository Sat, 23 May 2015 20:08:59 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Sat, 23 May 2015 20:08:59 +0000 (22:08 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sat, 23 May 2015 20:08:59 +0000 (22:08 +0200)
commit 4318ff58ce4f8646fb538b42ab88e2fe7e8889ef
tree 81f590dd8d310bf7fce463bce6a0f42bfd816baf
parent 05ab74c607ec7be417b9d21b4ea718d86d0ad8bb
Remove old fallback fonts

libbirdfont/Renderer/FallbackFont.vala
--- a/libbirdfont/Renderer/FallbackFont.vala +++ b/libbirdfont/Renderer/FallbackFont.vala @@ -31,102 +31,10 @@ // TODO: use font config public class FallbackFont : GLib.Object { - static unowned Database db; - static Database? database = null; - - Gee.ArrayList<File> fallback_fonts; - Gee.ArrayList<File> font_directories; - FcConfig* font_config; public FallbackFont () { - string home = Environment.get_home_dir (); - - fallback_fonts = new Gee.ArrayList<File> (); - font_directories = new Gee.ArrayList<File> (); - font_config = FcInitLoadConfigAndFonts (); - - open_database (); - - 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 - - add_fallback_fonts (); - } - - void add_fallback_fonts () { - add_font ("times.ttf"); - add_font ("arial.ttf"); - add_font ("verdana.ttf"); - add_font ("calibri.ttf"); - - add_font ("DejaVuSans.ttf"); - add_font ("Ubuntu-R.ttf"); - - add_font ("DroidKufi.ttf"); - add_font ("DroidSansGeorgian.ttf"); - add_font ("DroidSansHebrew.ttf"); - add_font ("DroidNaskh.ttf"); - add_font ("DroidSansJapanese.ttf"); - add_font ("DroidSansArabic.ttf"); - add_font ("DroidSansArmenian.ttf"); - add_font ("DroidSans.ttf"); - add_font ("DroidSansEthiopic.ttf"); - add_font ("DroidSansFallbackFull.ttf"); - - add_font ("Roboto-Regular.ttf"); - } - - void add_font (string font) { - File f = find_font_file (font); - - if (f.query_exists ()) { - fallback_fonts.add (f); - } - } - - File find_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; - } - } - - return File.new_for_path (font_file); - } - - void add_font_folder (string f) { - File folder = File.new_for_path (f); - FileInfo? file_info; - string fn; - - try { - if (folder.query_exists ()) { - font_directories.add (folder); - - var enumerator = folder.enumerate_children (FileAttribute.STANDARD_NAME + "," + FileAttribute.STANDARD_TYPE, 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); - } } public Font get_single_glyph_font (unichar c) { @@ -140,14 +48,10 @@ font_file = find_font (font_config, (!) c.to_string ()); if (font_file == null) { - warning ("No font returned from fontconfig."); - return get_single_glyph_font_without_font_config (c); + font_file = (!) SearchPaths.find_file (null, "Roboto-Regular.ttf").get_path (); } file = (!) font_file; - print (@"font_file: $(file)\n"); - - print (@"Load from TTF $((!) c.to_string ())\n"); font = open_font (file); glyph_data = get_glyph_in_font (font, c); @@ -161,70 +65,8 @@ return bf_font; } - - // FIXME: remove after fixing the windows version - public Font get_single_glyph_font_without_font_config (unichar c) { - BirdFontFile bf_parser; - Font bf_font; - StringBuilder? glyph_data; - string data; - - glyph_data = find_cached_glyph (c); - - if (glyph_data == null) { - print (@"Load from TTF $((!) c.to_string ())\n"); - glyph_data = load_glyph_from_ttf (c); - } else print (@"Found cached gd $((!) c.to_string ())\n"); - - bf_font = new Font (); - - if (glyph_data != null) { - bf_parser = new BirdFontFile (bf_font); - data = ((!) glyph_data).str; - - if (data != "") { - bf_parser.load_data (data); - } - } - return bf_font; - } - - public StringBuilder? load_glyph_from_ttf (unichar c) { - StringBuilder? glyph_data; - - glyph_data = load_glyph_data_from_ttf (c); - - if (glyph_data != null) { - cache_glyph (c, ((!) glyph_data).str); - } else { - cache_glyph (c, ""); - } - - return glyph_data; - } - - public StringBuilder? load_glyph_data_from_ttf (unichar c) { - File f; - FontFace* font; - StringBuilder? data = null; - - for (int i = fallback_fonts.size - 1; i >= 0; i--) { - f = fallback_fonts.get (i); - - font = open_font ((!) f.get_path ()); - data = get_glyph_in_font (font, c); - close_font (font); - - if (data != null) { - return data; - } - } - - return null; - } - - public StringBuilder? get_glyph_in_font (FontFace font, unichar c) { + public StringBuilder? get_glyph_in_font (FontFace* font, unichar c) { StringBuilder? glyph_data = null; GlyphCollection gc; @@ -232,100 +74,8 @@ glyph_data = load_glyph (font, (uint) c); return glyph_data; - } - - File get_fallback_database () { - File f = BirdFont.get_settings_directory (); - return get_child (f, "fallback_font.sqlite"); - } - - public void open_database () { - File db_file = get_fallback_database (); - bool create_table = !db_file.query_exists (); - int rc = Database.open ((!) db_file.get_path (), out database); - - db = (!) database; - - if (rc != Sqlite.OK) { - stderr.printf ("Can't open database: %d, %s\n", rc, db.errmsg ()); - } - - if (create_table) { - create_tables (); - } - } - - public void create_tables () { - int ec; - string? errmsg; - string create_font_table = """ - CREATE TABLE FallbackFont ( - unicode INTEGER PRIMARY KEY NOT NULL, - font_data TEXT NOT NULL - ); - """; - - ec = db.exec (create_font_table, null, out errmsg); - if (ec != Sqlite.OK) { - warning ("Error: %s\n", (!) errmsg); - } - } - - void cache_glyph (unichar c, string glyph_data) { - int64 character; - int ec; - string? errmsg; - string insert; - - character = (int64) c; - insert = "INSERT INTO FallbackFont (unicode, font_data) " - + @"VALUES ('$character', '" + glyph_data.replace ("'", "''") + "');"; - - ec = db.exec (insert, null, out errmsg); - if (ec != Sqlite.OK) { - warning ("Error: %s\n", (!) errmsg); - } - } - - StringBuilder? find_cached_glyph (unichar c) { - int rc, cols; - Statement statement; - string select; - StringBuilder? font_data = null; - - select = "SELECT font_data FROM FallbackFont " - + "WHERE unicode = '" + @"$((int64) c)" + "';"; - - rc = db.prepare_v2 (select, select.length, out statement, null); - - if (rc == Sqlite.OK) { - cols = statement.column_count(); - - if (cols != 1) { - warning ("Expecting one column."); - return font_data; - } - - while (true) { - rc = statement.step (); - - if (rc == Sqlite.DONE) { - break; - } else if (rc == Sqlite.ROW) { - font_data = new StringBuilder (); - ((!) font_data).append (statement.column_text (0)); - } else { - warning ("Error: %d, %s\n", rc, db.errmsg ()); - break; - } - } - } else { - warning ("SQL error: %d, %s\n", rc, db.errmsg ()); - } - - return font_data; } } }