rendernodeparser: Implement font loading on Windows
This commit is contained in:
@@ -55,6 +55,9 @@
|
||||
#ifdef HAVE_PANGOFT
|
||||
#include <pango/pangofc-fontmap.h>
|
||||
#endif
|
||||
#ifdef HAVE_PANGOWIN32
|
||||
#include <pango/pangowin32.h>
|
||||
#endif
|
||||
|
||||
#include <hb-subset.h>
|
||||
|
||||
@@ -1135,7 +1138,6 @@ create_ascii_glyphs (PangoFont *font)
|
||||
}
|
||||
|
||||
#ifdef HAVE_PANGOFT
|
||||
|
||||
static void
|
||||
delete_file (gpointer data)
|
||||
{
|
||||
@@ -1144,25 +1146,31 @@ delete_file (gpointer data)
|
||||
g_remove (path);
|
||||
g_free (path);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
ensure_fontmap (Context *context)
|
||||
{
|
||||
FcConfig *config;
|
||||
GPtrArray *files;
|
||||
|
||||
if (context->fontmap)
|
||||
return;
|
||||
|
||||
context->fontmap = pango_cairo_font_map_new ();
|
||||
|
||||
config = FcConfigCreate ();
|
||||
pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (context->fontmap), config);
|
||||
FcConfigDestroy (config);
|
||||
#ifdef HAVE_PANGOFT
|
||||
if (PANGO_IS_FC_FONT_MAP (context->fontmap))
|
||||
{
|
||||
FcConfig *config;
|
||||
GPtrArray *files;
|
||||
|
||||
files = g_ptr_array_new_with_free_func (delete_file);
|
||||
config = FcConfigCreate ();
|
||||
pango_fc_font_map_set_config (PANGO_FC_FONT_MAP (context->fontmap), config);
|
||||
FcConfigDestroy (config);
|
||||
|
||||
g_object_set_data_full (G_OBJECT (context->fontmap), "font-files", files, (GDestroyNotify) g_ptr_array_unref);
|
||||
files = g_ptr_array_new_with_free_func (delete_file);
|
||||
|
||||
g_object_set_data_full (G_OBJECT (context->fontmap), "font-files", files, (GDestroyNotify) g_ptr_array_unref);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -1170,37 +1178,53 @@ add_font_from_file (Context *context,
|
||||
const char *path,
|
||||
GError **error)
|
||||
{
|
||||
FcConfig *config;
|
||||
GPtrArray *files;
|
||||
|
||||
ensure_fontmap (context);
|
||||
|
||||
if (!PANGO_IS_FC_FONT_MAP (context->fontmap))
|
||||
#ifdef HAVE_PANGOFT
|
||||
if (PANGO_IS_FC_FONT_MAP (context->fontmap))
|
||||
{
|
||||
FcConfig *config;
|
||||
GPtrArray *files;
|
||||
|
||||
config = pango_fc_font_map_get_config (PANGO_FC_FONT_MAP (context->fontmap));
|
||||
|
||||
if (!FcConfigAppFontAddFile (config, (FcChar8 *) path))
|
||||
{
|
||||
g_set_error (error,
|
||||
GTK_CSS_PARSER_ERROR,
|
||||
GTK_CSS_PARSER_ERROR_UNKNOWN_VALUE,
|
||||
"Failed to load font");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
files = (GPtrArray *) g_object_get_data (G_OBJECT (context->fontmap), "font-files");
|
||||
g_ptr_array_add (files, g_strdup (path));
|
||||
|
||||
pango_fc_font_map_config_changed (PANGO_FC_FONT_MAP (context->fontmap));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#ifdef HAVE_PANGOWIN32
|
||||
if (g_type_is_a (G_OBJECT_TYPE (context->fontmap), g_type_from_name ("PangoWin32FontMap")))
|
||||
{
|
||||
gboolean result;
|
||||
|
||||
result = pango_win32_font_map_add_font_file (context->fontmap, path, error);
|
||||
g_remove (path);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
g_remove (path);
|
||||
g_set_error (error,
|
||||
GTK_CSS_PARSER_ERROR,
|
||||
GTK_CSS_PARSER_ERROR_FAILED,
|
||||
"Custom fonts are not implemented for %s", G_OBJECT_TYPE_NAME (context->fontmap));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
config = pango_fc_font_map_get_config (PANGO_FC_FONT_MAP (context->fontmap));
|
||||
|
||||
if (!FcConfigAppFontAddFile (config, (FcChar8 *) path))
|
||||
{
|
||||
g_set_error (error,
|
||||
GTK_CSS_PARSER_ERROR,
|
||||
GTK_CSS_PARSER_ERROR_UNKNOWN_VALUE,
|
||||
"Failed to load font");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
files = (GPtrArray *) g_object_get_data (G_OBJECT (context->fontmap), "font-files");
|
||||
g_ptr_array_add (files, g_strdup (path));
|
||||
|
||||
pango_fc_font_map_config_changed (PANGO_FC_FONT_MAP (context->fontmap));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -1236,22 +1260,6 @@ add_font_from_bytes (Context *context,
|
||||
return result;
|
||||
}
|
||||
|
||||
#else /* !HAVE_PANGOFT */
|
||||
|
||||
static gboolean
|
||||
add_font_from_bytes (Context *context,
|
||||
GBytes *bytes,
|
||||
GError **error)
|
||||
{
|
||||
g_set_error (error,
|
||||
GTK_CSS_PARSER_ERROR,
|
||||
GTK_CSS_PARSER_ERROR_FAILED,
|
||||
"Not implemented");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static gboolean
|
||||
parse_font (GtkCssParser *parser,
|
||||
Context *context,
|
||||
|
@@ -501,6 +501,9 @@ if have_egl
|
||||
endif
|
||||
cdata.set('HAVE_HARFBUZZ', harfbuzz_dep.found())
|
||||
cdata.set('HAVE_PANGOFT', pangoft_dep.found())
|
||||
if win32_enabled
|
||||
cdata.set('HAVE_PANGOWIN32', pangowin32_dep.found())
|
||||
endif
|
||||
|
||||
wayland_pkgs = []
|
||||
if wayland_enabled
|
||||
|
Reference in New Issue
Block a user