The Birdfont Source Code
Create fontconfig cache in a background thread
These changes was commited to the Birdfont repository Fri, 18 Sep 2015 18:11:10 +0000.
Contributing
Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
Create fontconfig cache in a background thread
--- a/birdfont/GtkWindow.vala
+++ b/birdfont/GtkWindow.vala
@@ -483,6 +483,16 @@
}
}
+ public void run_non_blocking_background_thread (Task t) {
+ unowned Thread<void*> bg;
+
+ try {
+ bg = Thread.create<void> (t.perform_task, true);
+ } catch (GLib.Error e) {
+ warning (e.message);
+ }
+ }
+
public void* background_thread () {
background_task.run ();
MenuTab.stop_background_thread ();
--- a/libbirdfont/NativeWindow.vala
+++ b/libbirdfont/NativeWindow.vala
@@ -51,8 +51,11 @@
/** Load images in a background thread. */
public abstract void load_background_image ();
- /** Load images in a background thread. */
+ /** Run a background thread and block the gui. */
public abstract void run_background_thread (Task t);
+
+ /** Run a background thread without blocking the gui. */
+ public abstract void run_non_blocking_background_thread (Task t);
/** Copy text to clipboard. */
public abstract void set_clipboard_text (string text);
--- a/libbirdfont/Renderer/FallbackFont.vala
+++ b/libbirdfont/Renderer/FallbackFont.vala
@@ -36,6 +36,7 @@
FcConfig* font_config = null;
FontFace* default_font = null;
+ static bool font_config_stated = false;
string default_font_file_name = "Roboto-Regular.ttf";
string default_font_family_name = "Roboto";
@@ -49,8 +50,20 @@
string home = Environment.get_home_dir ();
font_directories = new Gee.ArrayList<File> ();
- font_config = FcInitLoadConfigAndFonts ();
+ if (!font_config_stated) {
+ font_config_stated = true;
+
+ IdleSource idle = new IdleSource ();
+ idle.set_callback (() => {
+ Task t = new Task ();
+ t.task.connect (init_font_config);
+ MainWindow.native_window.run_non_blocking_background_thread (t);
+ return false;
+ });
+ idle.attach (null);
+ }
+
add_font_folder ("/usr/share/fonts/");
add_font_folder ("/usr/local/share/fonts/");
add_font_folder (home + "/.local/share/fonts");
@@ -72,6 +85,17 @@
if (default_font != null) {
close_font (default_font);
}
+ }
+
+ public void init_font_config () {
+ FcConfig* fc = FcInitLoadConfigAndFonts ();
+ IdleSource idle = new IdleSource ();
+
+ idle.set_callback (() => {
+ font_config = fc;
+ return false;
+ });
+ idle.attach (null);
}
public Font get_single_glyph_font (unichar c) {
--- a/libbirdfont/Renderer/fontconfig.c
+++ b/libbirdfont/Renderer/fontconfig.c
@@ -29,6 +29,11 @@
gchar* result;
gchar* remaining_characters;
gunichar character;
+
+ if (fontconfig == NULL) {
+ g_warning("Font config not loaded.");
+ return NULL;
+ }
result = NULL;
pattern = FcPatternCreate ();
@@ -88,6 +93,11 @@
FcObjectSet* font_properties;
FcFontSet* fonts;
int i;
+
+ if (font_config == NULL) {
+ g_warning("Font config not loaded.");
+ return NULL;
+ }
path = NULL;
name = font_name;
--- a/libbirdfont/Task.vala
+++ b/libbirdfont/Task.vala
@@ -23,8 +23,13 @@
public void run () {
task ();
+ }
+
+ public void* perform_task() {
+ run ();
+ return null;
}
}
}
--- a/scripts/builder.py
+++ b/scripts/builder.py
@@ -66,12 +66,12 @@
'basename': 'mkdir ' + build_directory,
'actions': ['mkdir -p ' + path.join('build', 'bin'),
'mkdir -p ' + build_directory,
- 'touch ' + build_file],
+ '[ -e "' + build_file + '" ] || touch "' + build_file + '"'],
'targets': [build_file],
}
copied_csources = []
- copied_cheader = []
+ copied_cheader = []
for csource in copied_cheader_paths + copied_csource_paths:
dest = path.join(build_directory, path.basename(csource))
@@ -82,7 +82,7 @@
yield {
'basename': 'copy ' + csource,
- 'file_dep': [build_file] + bindep,
+ 'file_dep': [build_file] + [csource],
'actions': ['cp ' + csource + ' ' + build_directory],
'targets': [dest]
}
@@ -155,7 +155,7 @@
if len(dependency_times) == 0 or len(target_times) == 0:
return False
- return dependency_times[-1] > target_times[0]
+ return dependency_times[-1] <= target_times[0]
def execute_task(task):
if is_up_to_date(task):