Commit fc73ec7
Fix fontconfig issues connected to sandboxing
Changed files (4)
modifiedlibbirdfont/OverViewItem.valamodifiedlibbirdfont/Renderer/FallbackFont.valamodifiedlibbirdfont/Renderer/fontconfig.cmodifiedlibbirdfont/overview_glyph.c
Diff
@@ -180,7 +180,7 @@ public class OverViewItem : GLib.Object { string path = (!) font_file; if (!path.has_suffix("LastResort.ttf")) {- draw_overview_glyph (c, (!) font_file, width, height, character);+ draw_overview_glyph (c, path, width, height, character); } } }@@ -22,6 +22,24 @@ public extern struct FcConfig { [CCode (cname = "FcInitLoadConfigAndFonts")] public extern FcConfig* FcInitLoadConfigAndFonts (); +[CCode (cname = "FcConfigAppFontAddDir")]+public extern string* FcConfigAppFontAddDir (FcConfig* config, string path);++[CCode (cname = "FcConfigSetSysRoot")]+public extern void FcConfigSetSysRoot (FcConfig* config, string path);++[CCode (cname = "FcConfigParseAndLoad")]+public extern bool FcConfigParseAndLoad (FcConfig* config, string path, bool complain);++[CCode (cname = "FcConfigSetCurrent")]+public extern void FcConfigSetCurrent (FcConfig* config);++[CCode (cname = "FcConfigCreate")]+public extern FcConfig* FcConfigCreate ();++[CCode (cname = "FcConfigFilename")]+public extern string FcConfigFilename (string path);+ [CCode (cname = "find_font")] public extern string? find_font (FcConfig* font_config, string characters); @@ -39,7 +57,7 @@ public class FallbackFont : GLib.Object { FontFace* default_font = null; public static FcConfig* font_config = null;- static bool font_config_stated = false;+ static bool font_config_started = false; string default_font_file_name = "Roboto-Regular.ttf"; string default_font_family_name = "Roboto";@@ -55,9 +73,9 @@ public class FallbackFont : GLib.Object { string home = Environment.get_home_dir (); font_directories = new Gee.ArrayList<File> (); - if (!font_config_stated) {- font_config_stated = true;-+ if (!font_config_started) {+ font_config_started = true;+ IdleSource idle = new IdleSource (); idle.set_callback (() => { Task t = new Task (init_font_config);@@ -91,11 +109,32 @@ public class FallbackFont : GLib.Object { } public void init_font_config () {- FcConfig* fc = FcInitLoadConfigAndFonts ();+ print("init_font_config\n");+ FcConfig* config;+ +#if MAC+ config = FcConfigCreate();+ + string bundle = (!) BirdFont.get_settings_directory ().get_path ();+ FcConfigSetSysRoot(config, bundle);+ + string path = FcConfigFilename((!) SearchPaths.search_file(null, "fontconfig.settings").get_path ());+ bool loaded = FcConfigParseAndLoad(config, path, true);+ + if (!loaded) {+ warning ("Cannot load fontconfig.");+ }+ + FcConfigSetCurrent (config);+#else+ config = FcInitLoadConfigAndFonts ();+#endif+ IdleSource idle = new IdleSource (); idle.set_callback (() => {- font_config = fc;+ font_config = config;+ print("Fontconfog loaded."); return false; }); idle.attach (null);@@ -57,7 +57,7 @@ gchar* find_font_with_property (FcConfig* fontconfig, const gchar* characters, c FcPatternAddBool(pattern, FC_SCALABLE, FcTrue); font_properties = FcObjectSetBuild (property, NULL); fonts = FcFontList (fontconfig, pattern, font_properties);-+ if (fonts && fonts->nfont > 0) { font = fonts->fonts[0]; if (FcPatternGetString(font, property, 0, &path) == FcResultMatch) {@@ -42,6 +42,11 @@ gboolean draw_overview_glyph (cairo_t* context, const char* font_file, gdouble w return FALSE; } + if (font_file == NULL) { + g_warning("font_file is null"); + return FALSE; + } + gchar text[7]; int length = g_unichar_to_utf8 (character, text); text[length] = '\0'; @@ -53,13 +58,13 @@ gboolean draw_overview_glyph (cairo_t* context, const char* font_file, gdouble w return FALSE; } } - + error = FT_New_Face (freetype_library, font_file, 0, &face); if (error) { g_warning ("Freetype font face error %d\n", error); return FALSE; } - + units_per_em = face->units_per_EM; units = (height * 0.5) / units_per_em;