summaryrefslogtreecommitdiff
path: root/pango/pangoxft-fontmap.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2002-07-03 22:30:36 +0000
committerOwen Taylor <otaylor@src.gnome.org>2002-07-03 22:30:36 +0000
commit145341236ea2dad9e5a0e7270d0b6dc7d9b09770 (patch)
tree0b915833a0191f13c8b410de1db69a50928f471c /pango/pangoxft-fontmap.c
parent325238c642d9f89a4e46df6cf1bd6c9942097c1b (diff)
downloadpango-145341236ea2dad9e5a0e7270d0b6dc7d9b09770.tar.gz
New function to allow tweaking of FcPattern default substitution (for
Mon Jul 1 19:45:10 2002 Owen Taylor <otaylor@redhat.com> * pango/pangoxft-fontmap.c (pango_xft_set_default_substitute): New function to allow tweaking of FcPattern default substitution (for XSETTINGS support.) * pango/pangoft2-fontmap.c pango/pangoft2.[ch] pango/pangoft2-private.h: Rationalize DPI and context creation by adding: pango_ft2_font_map_new() pango_ft2_font_map_set_resolution() pango_ft2_font_map_set_default_substitute() pango_ft2_font_map_create_context()
Diffstat (limited to 'pango/pangoxft-fontmap.c')
-rw-r--r--pango/pangoxft-fontmap.c111
1 files changed, 93 insertions, 18 deletions
diff --git a/pango/pangoxft-fontmap.c b/pango/pangoxft-fontmap.c
index fc765e47..5fd75b3d 100644
--- a/pango/pangoxft-fontmap.c
+++ b/pango/pangoxft-fontmap.c
@@ -56,7 +56,14 @@ struct _PangoXftFontMap
/* FcFontSet *font_set; */
Display *display;
- int screen;
+ int screen;
+
+ /* Function to call on prepared patterns to do final
+ * config tweaking.
+ */
+ PangoXftSubstituteFunc substitute_func;
+ gpointer substitute_data;
+ GDestroyNotify substitute_destroy;
};
#define PANGO_XFT_TYPE_FAMILY (pango_xft_family_get_type ())
@@ -196,18 +203,43 @@ pango_xft_pattern_equal (FcPattern *pattern1,
return FcPatternEqual (pattern1, pattern2);
}
+static void
+pango_xft_init_fontset_hash (PangoXftFontMap *xfontmap)
+{
+ if (xfontmap->fontset_hash)
+ g_hash_table_destroy (xfontmap->fontset_hash);
+
+ xfontmap->fontset_hash =
+ g_hash_table_new_full ((GHashFunc)pango_font_description_hash,
+ (GEqualFunc)pango_font_description_equal,
+ (GDestroyNotify)pango_font_description_free,
+ (GDestroyNotify)pango_xft_font_set_free);
+}
+
static PangoFontMap *
pango_xft_get_font_map (Display *display,
int screen)
{
+ static gboolean registered_modules = FALSE;
PangoXftFontMap *xfontmap;
- GSList *tmp_list = fontmaps;
+ GSList *tmp_list;
g_return_val_if_fail (display != NULL, NULL);
- /* Make sure that the type system is initialized */
- g_type_init ();
+ if (!registered_modules)
+ {
+ int i;
+
+ registered_modules = TRUE;
+
+ /* Make sure that the type system is initialized */
+ g_type_init ();
+ for (i = 0; _pango_included_xft_modules[i].list; i++)
+ pango_module_register (&_pango_included_xft_modules[i]);
+ }
+
+ tmp_list = fontmaps;
while (tmp_list)
{
xfontmap = tmp_list->data;
@@ -226,10 +258,7 @@ pango_xft_get_font_map (Display *display,
xfontmap->fonts = g_hash_table_new ((GHashFunc)pango_xft_pattern_hash,
(GEqualFunc)pango_xft_pattern_equal);
- xfontmap->fontset_hash = g_hash_table_new_full ((GHashFunc)pango_font_description_hash,
- (GEqualFunc)pango_font_description_equal,
- (GDestroyNotify)pango_font_description_free,
- (GDestroyNotify)pango_xft_font_set_free);
+ pango_xft_init_fontset_hash (xfontmap);
xfontmap->coverage_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify)g_free,
(GDestroyNotify)pango_coverage_unref);
@@ -241,6 +270,57 @@ pango_xft_get_font_map (Display *display,
}
/**
+ * pango_xft_font_map_set_default_substitute:
+ * @fontmap: a #PangoXFTFontmap
+ * @func: function to call to to do final config tweaking
+ * on #FcPattern objects.
+ * @data: data to pass to @func
+ * @notify: function to call when @data is no longer used.
+ *
+ * Sets a function that will be called to do final configuration
+ * substitution on a #FcPattern before it is used to load
+ * the font. This function can be used to do things like set
+ * hinting and antiasing options.
+ **/
+void
+pango_xft_set_default_substitute (Display *display,
+ int screen,
+ PangoXftSubstituteFunc func,
+ gpointer data,
+ GDestroyNotify notify)
+{
+ PangoXftFontMap *xfontmap = (PangoXftFontMap *)pango_xft_get_font_map (display, screen);
+
+ if (xfontmap->substitute_destroy)
+ xfontmap->substitute_destroy (xfontmap->substitute_data);
+
+ xfontmap->substitute_func = func;
+ xfontmap->substitute_data = data;
+ xfontmap->substitute_destroy = notify;
+
+ pango_xft_init_fontset_hash (xfontmap);
+}
+
+/**
+ * pango_substitute_changed:
+ * @fontmap: a #PangoXftFontmap
+ *
+ * Call this function any time the results of the
+ * default substitution function set with
+ * pango_xft_font_map_set_default_substitute() change.
+ * That is, if your subsitution function will return different
+ * results for the same input pattern, you must call this function.
+ **/
+void
+pango_xft_substitute_changed (Display *display,
+ int screen)
+{
+ PangoXftFontMap *xfontmap = (PangoXftFontMap *)pango_xft_get_font_map (display, screen);
+
+ pango_xft_init_fontset_hash (xfontmap);
+}
+
+/**
* pango_xft_get_context:
* @display: an X display.
* @screen: an X screen.
@@ -255,19 +335,9 @@ pango_xft_get_context (Display *display,
int screen)
{
PangoContext *result;
- int i;
- static gboolean registered_modules = FALSE;
g_return_val_if_fail (display != NULL, NULL);
- if (!registered_modules)
- {
- registered_modules = TRUE;
-
- for (i = 0; _pango_included_xft_modules[i].list; i++)
- pango_module_register (&_pango_included_xft_modules[i]);
- }
-
result = pango_context_new ();
pango_context_set_font_map (result, pango_xft_get_font_map (display, screen));
@@ -281,6 +351,9 @@ pango_xft_font_map_finalize (GObject *object)
fontmaps = g_slist_remove (fontmaps, object);
+ if (xfontmap->substitute_destroy)
+ xfontmap->substitute_destroy (xfontmap->substitute_data);
+
g_queue_free (xfontmap->freed_fonts);
g_hash_table_destroy (xfontmap->fontset_hash);
g_hash_table_destroy (xfontmap->coverage_hash);
@@ -502,6 +575,8 @@ pango_xft_font_map_get_patterns (PangoFontMap *fontmap,
pattern = pango_xft_make_pattern (desc);
FcConfigSubstitute (0, pattern, FcMatchPattern);
+ if (xfontmap->substitute_func)
+ xfontmap->substitute_func (pattern, xfontmap->substitute_data);
XftDefaultSubstitute (xfontmap->display, xfontmap->screen, pattern);
pattern_copy = FcPatternDuplicate (pattern);