Issue #1211: Load fonts in background after startup.

Fonts should not be blocking startup as this provides a very bad
experience when people have a lot of fonts. This was experienced even
more on Windows where loading time are often excessively long.
We were already running font loading in a thread, yet were still
blocking startup (thread was only so that the loading status GUI could
get updated as a feedback). Now we will only start loading and proceed
directly to next steps.
While fonts are not loaded, the text tool will not be usable, yet all
other activities can be performed.

(cherry picked from commit 2484dec7d5)
This commit is contained in:
Jehan
2018-05-27 02:13:33 +02:00
parent 117beee244
commit 89c829a242
6 changed files with 31 additions and 44 deletions

View File

@ -39,5 +39,5 @@ fonts_refresh_cmd_callback (GtkAction *action,
GimpContext *context = action_data_get_context (data);
if (context)
gimp_fonts_load (context->gimp, NULL, NULL);
gimp_fonts_load (context->gimp, NULL);
}

View File

@ -799,8 +799,8 @@ gimp_restore (Gimp *gimp,
/* initialize the list of fonts */
if (! gimp->no_fonts)
{
status_callback (NULL, _("Fonts (this may take a while)"), 0.7);
gimp_fonts_load (gimp, status_callback, error);
status_callback (NULL, _("Fonts"), 0.7);
gimp_fonts_load (gimp, error);
}
/* initialize the template list */

View File

@ -46,7 +46,7 @@ fonts_refresh_invoker (GimpProcedure *procedure,
const GimpValueArray *args,
GError **error)
{
gimp_fonts_load (gimp, NULL, error);
gimp_fonts_load (gimp, error);
return gimp_procedure_get_return_values (procedure, TRUE, NULL);
}

View File

@ -110,14 +110,22 @@ gimp_fonts_load_async (GimpAsync *async,
gimp_async_finish (async, NULL);
}
void
gimp_fonts_load (Gimp *gimp,
GimpInitStatusFunc status_callback,
GError **error)
static void
gimp_fonts_load_async_callback (GimpAsync *async,
GimpFontList *fonts)
{
FcConfig *config;
GFile *fonts_conf;
GList *path;
if (gimp_async_is_finished (async))
gimp_font_list_restore (fonts);
}
void
gimp_fonts_load (Gimp *gimp,
GError **error)
{
FcConfig *config;
GFile *fonts_conf;
GList *path;
GimpAsync *async;
g_return_if_fail (GIMP_IS_FONT_LIST (gimp->fonts));
@ -147,36 +155,16 @@ gimp_fonts_load (Gimp *gimp,
gimp_fonts_add_directories (gimp, config, path, error);
g_list_free_full (path, (GDestroyNotify) g_object_unref);
if (status_callback)
{
GimpAsync *async;
gint64 end_time;
/* We perform font cache initialization in a separate thread, so
* in the case a cache rebuild is to be done it will not block
* the UI.
*/
async = gimp_parallel_run_async (
(GimpParallelRunAsyncFunc) gimp_fonts_load_async,
config);
do
{
status_callback (NULL, NULL, 0.6);
end_time = g_get_monotonic_time () + 0.1 * G_TIME_SPAN_SECOND;
}
while (! gimp_async_wait_until (async, end_time));
g_object_unref (async);
}
else
{
gimp_fonts_load_func (config);
}
gimp_font_list_restore (GIMP_FONT_LIST (gimp->fonts));
/* We perform font cache initialization in a separate thread, so
* in the case a cache rebuild is to be done it will not block
* the UI.
*/
async = gimp_parallel_run_async ((GimpParallelRunAsyncFunc) gimp_fonts_load_async,
config);
gimp_async_add_callback (async,
(GimpAsyncCallback) gimp_fonts_load_async_callback,
gimp->fonts);
g_object_unref (async);
cleanup:
gimp_container_thaw (GIMP_CONTAINER (gimp->fonts));
@ -364,7 +352,7 @@ gimp_fonts_notify_font_path (GObject *gobject,
{
GError *error = NULL;
gimp_fonts_load (gimp, NULL, &error);
gimp_fonts_load (gimp, &error);
if (error)
{

View File

@ -24,7 +24,6 @@ void gimp_fonts_set_config (Gimp *gimp);
void gimp_fonts_exit (Gimp *gimp);
void gimp_fonts_load (Gimp *gimp,
GimpInitStatusFunc status_callback,
GError **error);
void gimp_fonts_reset (Gimp *gimp);

View File

@ -30,7 +30,7 @@ HELP
%invoke = (
code => <<'CODE'
{
gimp_fonts_load (gimp, NULL, error);
gimp_fonts_load (gimp, error);
}
CODE
);