enum {
PROP_0,
- PROP_PATTERN
+ PROP_PATTERN,
+ PROP_FONTMAP
};
typedef struct _GUnicharToGlyphCacheEntry GUnicharToGlyphCacheEntry;
"The fontconfig pattern for this font",
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_FONTMAP,
+ g_param_spec_object ("fontmap",
+ "Font Map",
+ "The PangoFc font map this font is associated with (Since: 1.26)",
+ PANGO_TYPE_FC_FONT_MAP,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
g_type_class_add_private (object_class, sizeof (PangoFcFontPrivate));
}
const GValue *value,
GParamSpec *pspec)
{
+ PangoFcFont *fcfont = PANGO_FC_FONT (object);
+
switch (prop_id)
{
case PROP_PATTERN:
{
- PangoFcFont *fcfont = PANGO_FC_FONT (object);
FcPattern *pattern = g_value_get_pointer (value);
g_return_if_fail (pattern != NULL);
fcfont->is_hinted = pattern_is_hinted (pattern);
fcfont->is_transformed = pattern_is_transformed (pattern);
}
- break;
+ goto set_decoder;
+
+ case PROP_FONTMAP:
+ {
+ PangoFcFontMap *fcfontmap = PANGO_FC_FONT_MAP (g_value_get_object (value));
+
+ g_return_if_fail (fcfont->fontmap == NULL);
+ fcfont->fontmap = (PangoFontMap *) fcfontmap;
+ if (fcfont->fontmap)
+ g_object_add_weak_pointer (G_OBJECT (fcfont->fontmap), (gpointer *) (gpointer) &fcfont->fontmap);
+ }
+ goto set_decoder;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
+ return;
}
+
+set_decoder:
+ /* set decoder if both pattern and fontmap are set now */
+ if (fcfont->font_pattern && fcfont->fontmap)
+ _pango_fc_font_set_decoder (fcfont,
+ pango_fc_font_map_find_decoder ((PangoFcFontMap *) fcfont->fontmap,
+ fcfont->font_pattern));
}
static void
g_value_set_pointer (value, fcfont->font_pattern);
}
break;
+ case PROP_FONTMAP:
+ {
+ PangoFcFont *fcfont = PANGO_FC_FONT (object);
+ g_value_set_object (value, fcfont->fontmap);
+ }
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
gpointer user_data,
GDestroyNotify dnotify)
{
- PangoFcFontMapPrivate *priv = fcfontmap->priv;
+ PangoFcFontMapPrivate *priv;
PangoFcFindFuncInfo *info;
+ g_return_val_if_fail (PANGO_IS_FC_FONT_MAP (fcfontmap), NULL);
+
+ priv = fcfontmap->priv;
+
info = g_slice_new (PangoFcFindFuncInfo);
info->findfunc = findfunc;
priv->findfuncs = g_slist_append (priv->findfuncs, info);
}
+/**
+ * pango_fc_font_map_find_decoder:
+ * @fcfontmap: The #PangoFcFontMap to use.
+ * @pattern: The #FcPattern to find the decoder for.
+ *
+ * Finds the decoder to use for @pattern. Decoders can be added to
+ * a font map using pango_fc_font_map_add_decoder_find_func().
+ *
+ * Returns: a newly created #PangoFcDecoder object or %NULL if
+ * no decoder is set for @pattern.
+ *
+ * Since: 1.26.
+ **/
+PangoFcDecoder *
+pango_fc_font_map_find_decoder (PangoFcFontMap *fcfontmap,
+ FcPattern *pattern)
+{
+ GSList *l;
+
+ g_return_val_if_fail (PANGO_IS_FC_FONT_MAP (fcfontmap), NULL);
+ g_return_val_if_fail (pattern != NULL, NULL);
+
+ for (l = fcfontmap->priv->findfuncs; l && l->data; l = l->next)
+ {
+ PangoFcFindFuncInfo *info = l->data;
+ PangoFcDecoder *decoder;
+
+ decoder = info->findfunc (pattern, info->user_data);
+ if (decoder)
+ return decoder;
+ }
+
+ return NULL;
+}
+
static void
pango_fc_font_map_finalize (GObject *object)
{
PangoFcFontMapPrivate *priv = fcfontmap->priv;
PangoFcFontKey *key_copy;
- g_assert (fcfont->fontmap == NULL);
- fcfont->fontmap = (PangoFontMap *) fcfontmap;
- /* In other fontmaps we add a weak pointer on ->fontmap so the
- * field is unset when fontmap is finalized. We don't need it
- * here though as PangoFcFontMap already cleans up fcfont->fontmap
- * as part of it's caching scheme. */
-
key_copy = pango_fc_font_key_copy (key);
_pango_fc_font_set_font_key (fcfont, key_copy);
g_hash_table_insert (priv->font_hash, key_copy, fcfont);
PangoFcFontMapPrivate *priv = fcfontmap->priv;
PangoFcFontKey *key;
- fcfont->fontmap = NULL;
-
key = _pango_fc_font_get_font_key (fcfont);
if (key)
{
PangoFcFontMapPrivate *priv = fcfontmap->priv;
FcPattern *pattern;
PangoFcFont *fcfont;
- GSList *l;
PangoFcFontKey key;
if (priv->closed)
fcfont->matrix = key.matrix;
+ /* cache it on fontmap */
pango_fc_font_map_add (fcfontmap, &key, fcfont);
- /*
- * Give any custom decoders a crack at this font now that it's been
- * created.
- */
- for (l = priv->findfuncs; l && l->data; l = l->next)
- {
- PangoFcFindFuncInfo *info = l->data;
- PangoFcDecoder *decoder;
-
- decoder = info->findfunc (match, info->user_data);
- if (decoder)
- {
- _pango_fc_font_set_decoder (fcfont, decoder);
- break;
- }
- }
-
return (PangoFont *)fcfont;
}
static void
shutdown_font (gpointer key G_GNUC_UNUSED,
- PangoFcFont *fcfont)
+ PangoFcFont *fcfont,
+ PangoFcFontMap *fcfontmap)
{
_pango_fc_font_shutdown (fcfont);
+
+ /* While _pango_fc_font_shutdown() tries to call the following
+ * function, it's too late as the fontmap weakref has already
+ * NULL'ed fcfont->fontmap, so we do it ourselves. */
+ _pango_fc_font_map_remove (fcfontmap, fcfont);
}
/**
if (priv->closed)
return;
- g_hash_table_foreach (priv->font_hash, (GHFunc) shutdown_font, NULL);
+ g_hash_table_foreach (priv->font_hash, (GHFunc) shutdown_font, fcfontmap);
for (i = 0; i < priv->n_families; i++)
priv->families[i]->fontmap = NULL;