Updated Files
libbirdfont/OverViewItem.vala |
libbirdfont/Renderer/FallbackFont.vala |
libbirdfont/Renderer/fontconfig.c |
libbirdfont/overview_glyph.c |
--- a/libbirdfont/OverViewItem.vala
+++ b/libbirdfont/OverViewItem.vala
@@ -180,7 +180,7 @@
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);
}
}
}
--- a/libbirdfont/Renderer/FallbackFont.vala
+++ b/libbirdfont/Renderer/FallbackFont.vala
@@ -21,6 +21,24 @@
[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 @@
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 @@
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 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);
--- a/libbirdfont/Renderer/fontconfig.c
+++ b/libbirdfont/Renderer/fontconfig.c
@@ -57,7 +57,7 @@
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) {
--- a/libbirdfont/overview_glyph.c
+++ b/libbirdfont/overview_glyph.c
@@ -42,6 +42,11 @@
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 @@
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;