diff options
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | ChangeLog.pre-1-10 | 15 | ||||
-rw-r--r-- | ChangeLog.pre-1-2 | 15 | ||||
-rw-r--r-- | ChangeLog.pre-1-4 | 15 | ||||
-rw-r--r-- | ChangeLog.pre-1-6 | 15 | ||||
-rw-r--r-- | ChangeLog.pre-1-8 | 15 | ||||
-rw-r--r-- | pango/pangoft2-fontmap.c | 240 | ||||
-rw-r--r-- | pango/pangoft2-private.h | 2 | ||||
-rw-r--r-- | pango/pangoft2.c | 44 | ||||
-rw-r--r-- | pango/pangoft2.h | 36 | ||||
-rw-r--r-- | pango/pangoxft-fontmap.c | 111 | ||||
-rw-r--r-- | pango/pangoxft.h | 11 |
12 files changed, 433 insertions, 101 deletions
@@ -1,3 +1,18 @@ +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() + 2002-07-02 Matthias Warkus <mawarkus@gnome.org> * pango/pango-markup.c (span_parse_func): Fixed typo that was diff --git a/ChangeLog.pre-1-10 b/ChangeLog.pre-1-10 index 257de9d6..ef84f6cf 100644 --- a/ChangeLog.pre-1-10 +++ b/ChangeLog.pre-1-10 @@ -1,3 +1,18 @@ +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() + 2002-07-02 Matthias Warkus <mawarkus@gnome.org> * pango/pango-markup.c (span_parse_func): Fixed typo that was diff --git a/ChangeLog.pre-1-2 b/ChangeLog.pre-1-2 index 257de9d6..ef84f6cf 100644 --- a/ChangeLog.pre-1-2 +++ b/ChangeLog.pre-1-2 @@ -1,3 +1,18 @@ +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() + 2002-07-02 Matthias Warkus <mawarkus@gnome.org> * pango/pango-markup.c (span_parse_func): Fixed typo that was diff --git a/ChangeLog.pre-1-4 b/ChangeLog.pre-1-4 index 257de9d6..ef84f6cf 100644 --- a/ChangeLog.pre-1-4 +++ b/ChangeLog.pre-1-4 @@ -1,3 +1,18 @@ +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() + 2002-07-02 Matthias Warkus <mawarkus@gnome.org> * pango/pango-markup.c (span_parse_func): Fixed typo that was diff --git a/ChangeLog.pre-1-6 b/ChangeLog.pre-1-6 index 257de9d6..ef84f6cf 100644 --- a/ChangeLog.pre-1-6 +++ b/ChangeLog.pre-1-6 @@ -1,3 +1,18 @@ +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() + 2002-07-02 Matthias Warkus <mawarkus@gnome.org> * pango/pango-markup.c (span_parse_func): Fixed typo that was diff --git a/ChangeLog.pre-1-8 b/ChangeLog.pre-1-8 index 257de9d6..ef84f6cf 100644 --- a/ChangeLog.pre-1-8 +++ b/ChangeLog.pre-1-8 @@ -1,3 +1,18 @@ +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() + 2002-07-02 Matthias Warkus <mawarkus@gnome.org> * pango/pango-markup.c (span_parse_func): Fixed typo that was diff --git a/pango/pangoft2-fontmap.c b/pango/pangoft2-fontmap.c index 3d172b39..0e29b31d 100644 --- a/pango/pangoft2-fontmap.c +++ b/pango/pangoft2-fontmap.c @@ -31,22 +31,18 @@ #include <dirent.h> #endif +#include <fontconfig/fontconfig.h> + #include "pango-fontmap.h" #include "pango-utils.h" #include "pangoft2-private.h" - -#include <fontconfig/fontconfig.h> +#include "modules.h" #ifdef G_OS_WIN32 #define STRICT #include <windows.h> #endif -#define PANGO_TYPE_FT2_FONT_MAP (pango_ft2_font_map_get_type ()) -#define PANGO_FT2_FONT_MAP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_FT2_FONT_MAP, PangoFT2FontMap)) -#define PANGO_FT2_IS_FONT_MAP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_FT2_FONT_MAP)) - -typedef struct _PangoFT2FontMap PangoFT2FontMap; typedef struct _PangoFT2SizeInfo PangoFT2SizeInfo; typedef struct _PangoFT2PatternSet PangoFT2PatternSet; @@ -80,6 +76,16 @@ struct _PangoFT2FontMap /* List of all families availible */ PangoFT2Family **families; int n_families; /* -1 == uninitialized */ + + double dpi_x; + double dpi_y; + + /* Function to call on prepared patterns to do final + * config tweaking. + */ + PangoFT2SubstituteFunc substitute_func; + gpointer substitute_data; + GDestroyNotify substitute_destroy; }; struct _PangoFT2PatternSet @@ -96,7 +102,6 @@ struct _PangoFT2PatternSet #define PANGO_FT2_FACE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_FT2_TYPE_FACE, PangoFT2Face)) #define PANGO_FT2_IS_FACE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_FT2_TYPE_FACE)) -static GType pango_ft2_font_map_get_type (void); GType pango_ft2_family_get_type (void); GType pango_ft2_face_get_type (void); @@ -124,7 +129,7 @@ static PangoFontClass *parent_class; /* Parent class structure for PangoFT2Font static PangoFT2FontMap *pango_ft2_global_fontmap = NULL; -static GType +GType pango_ft2_font_map_get_type (void) { static GType object_type = 0; @@ -190,6 +195,18 @@ pango_ft2_pattern_equal (FcPattern *pattern1, return FcPatternEqual (pattern1, pattern2); } +static void +pango_ft2_init_fontset_hash (PangoFT2FontMap *ft2fontmap) +{ + if (ft2fontmap->fontset_hash) + g_hash_table_destroy (ft2fontmap->fontset_hash); + + ft2fontmap->fontset_hash = + g_hash_table_new_full ((GHashFunc)pango_font_description_hash, + (GEqualFunc)pango_font_description_equal, + (GDestroyNotify)pango_font_description_free, + (GDestroyNotify)pango_ft2_font_set_free); +} static void pango_ft2_font_map_init (PangoFT2FontMap *ft2fontmap) @@ -199,12 +216,9 @@ pango_ft2_font_map_init (PangoFT2FontMap *ft2fontmap) ft2fontmap->fonts = g_hash_table_new ((GHashFunc)pango_ft2_pattern_hash, (GEqualFunc)pango_ft2_pattern_equal); - ft2fontmap->fontset_hash = - g_hash_table_new_full ((GHashFunc)pango_font_description_hash, - (GEqualFunc)pango_font_description_equal, - (GDestroyNotify)pango_font_description_free, - (GDestroyNotify)pango_ft2_font_set_free); - + + pango_ft2_init_fontset_hash (ft2fontmap); + ft2fontmap->coverage_hash = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, @@ -226,28 +240,40 @@ pango_ft2_font_map_class_init (PangoFontMapClass *class) } /** - * pango_ft2_font_map_for_display: - * - * Returns a #PangoFT2FontMap. Font maps are cached and should - * not be freed. If the font map is no longer needed, it can - * be released with pango_ft2_shutdown_display(). - * - * Returns: a #PangoFT2FontMap. + * pango_ft2_font_map_new: + * + * Create a new #PangoFT2FontMap object; a fontmap is used + * to cache information about available fonts, and holds + * certain global parameters such as the resolution and + * the default substitute function (see + * pango_font_map_set_default_substitute ()). + * + * Return value: the newly created fontmap object. Unref + * with g_object_unref when you are finished with it. **/ PangoFontMap * -pango_ft2_font_map_for_display (void) +pango_ft2_font_map_new (void) { + static gboolean registered_modules = FALSE; + PangoFT2FontMap *ft2fontmap; FT_Error error; - - /* Make sure that the type system is initialized */ - g_type_init (); - if (pango_ft2_global_fontmap != NULL) - return PANGO_FONT_MAP (pango_ft2_global_fontmap); + if (!registered_modules) + { + int i; + + registered_modules = TRUE; + + /* Make sure that the type system is initialized */ + g_type_init (); + + for (i = 0; _pango_included_ft2_modules[i].list; i++) + pango_module_register (&_pango_included_ft2_modules[i]); + } - pango_ft2_global_fontmap = (PangoFT2FontMap *)g_object_new (PANGO_TYPE_FT2_FONT_MAP, NULL); + ft2fontmap = g_object_new (PANGO_TYPE_FT2_FONT_MAP, NULL); - error = FT_Init_FreeType (&pango_ft2_global_fontmap->library); + error = FT_Init_FreeType (&ft2fontmap->library); if (error != FT_Err_Ok) { g_warning ("Error from FT_Init_FreeType: %s", @@ -255,13 +281,147 @@ pango_ft2_font_map_for_display (void) return NULL; } + return (PangoFontMap *)ft2fontmap; +} + +/** + * pango_ft2_font_map_set_resolution: + * @fontmap: a #PangoFT2Fontmap + * @dpi_x: dots per inch in the X direction + * @dpi_y: dots per inch in the Y direction + * + * Sets the horizontal and vertical resolutions for the fontmap. + **/ +void +pango_ft2_font_map_set_resolution (PangoFT2FontMap *fontmap, + double dpi_x, + double dpi_y) +{ + g_return_if_fail (PANGO_FT2_IS_FONT_MAP (fontmap)); + + fontmap->dpi_x = dpi_x; + fontmap->dpi_y = dpi_y; + + pango_ft2_font_map_substitute_changed (fontmap); +} + +/** + * pango_ft2_font_map_set_default_substitute: + * @fontmap: a #PangoFT2Fontmap + * @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_ft2_font_map_set_default_substitute (PangoFT2FontMap *fontmap, + PangoFT2SubstituteFunc func, + gpointer data, + GDestroyNotify notify) +{ + g_return_if_fail (PANGO_FT2_IS_FONT_MAP (fontmap)); + + if (fontmap->substitute_destroy) + fontmap->substitute_destroy (fontmap->substitute_data); + + fontmap->substitute_func = func; + fontmap->substitute_data = data; + fontmap->substitute_destroy = notify; + + pango_ft2_font_map_substitute_changed (fontmap); +} + +/** + * pango_ft2_font_map_substitute_changed: + * @fontmap: a #PangoFT2Fontmap + * + * Call this function any time the results of the + * default substitution function set with + * pango_ft2_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_ft2_font_map_substitute_changed (PangoFT2FontMap *fontmap) +{ + pango_ft2_init_fontset_hash (fontmap); +} + +/** + * pango_ft2_font_map_create_context: + * @fontmap: a #PangoFT2Fontmap + * + * Create a #PangoContext for the given fontmap. + * + * Return value: the newly created context; free with g_object_unref(). + **/ +PangoContext * +pango_ft2_font_map_create_context (PangoFT2FontMap *fontmap) +{ + PangoContext *context; + + g_return_val_if_fail (PANGO_FT2_IS_FONT_MAP (fontmap), NULL); + + context = pango_context_new (); + pango_context_set_font_map (context, PANGO_FONT_MAP (fontmap)); + + return context; +} + +/** + * pango_ft2_font_map_for_display: + * + * Returns a #PangoFT2FontMap. This font map is cached and should + * not be freed. If the font map is no longer needed, it can + * be released with pango_ft2_shutdown_display(). + * + * Returns: a #PangoFT2FontMap. + **/ +PangoFontMap * +pango_ft2_font_map_for_display (void) +{ + if (pango_ft2_global_fontmap != NULL) + return PANGO_FONT_MAP (pango_ft2_global_fontmap); + + pango_ft2_global_fontmap = (PangoFT2FontMap *)pango_ft2_font_map_new (); + return PANGO_FONT_MAP (pango_ft2_global_fontmap); } /** + * pango_ft2_get_context: + * @dpi_x: the horizontal dpi of the target device + * @dpi_y: the vertical dpi of the target device + * + * Retrieves a #PangoContext for the default PangoFT2 fontmap + * (see pango_ft2_fontmap_get_for_display()) and sets the resolution + * for the default fontmap to @dpi_x by @dpi_y. + * + * Use of this function is discouraged, see pango_ft2_fontmap_create_context() + * instead. + * + * Return value: the new #PangoContext + **/ +PangoContext * +pango_ft2_get_context (double dpi_x, double dpi_y) +{ + PangoFontMap *fontmap; + + fontmap = pango_ft2_font_map_for_display (); + pango_ft2_font_map_set_resolution (PANGO_FT2_FONT_MAP (fontmap), dpi_x, dpi_y); + + return pango_ft2_font_map_create_context (PANGO_FT2_FONT_MAP (fontmap)); +} + +/** * pango_ft2_shutdown_display: * - * Free cached resources. + * Free the global fontmap. (See pango_ft2_font_map_for_display()) **/ void pango_ft2_shutdown_display (void) @@ -283,6 +443,9 @@ pango_ft2_font_map_finalize (GObject *object) g_hash_table_destroy (ft2fontmap->fontset_hash); g_hash_table_destroy (ft2fontmap->coverage_hash); + if (ft2fontmap->substitute_destroy) + ft2fontmap->substitute_destroy (ft2fontmap->substitute_data); + FT_Done_FreeType (ft2fontmap->library); G_OBJECT_CLASS (parent_class)->finalize (object); @@ -510,6 +673,19 @@ pango_ft2_font_map_load_font (PangoFontMap *fontmap, return font; } +static void +pango_ft2_default_substitute (PangoFT2FontMap *fontmap, + FcPattern *pattern) +{ + FcValue v; + + if (fontmap->substitute_func) + fontmap->substitute_func (pattern, fontmap->substitute_data); + + if (FcPatternGet (pattern, FC_DPI, 0, &v) == FcResultNoMatch) + FcPatternAddDouble (pattern, FC_DPI, fontmap->dpi_y); +} + static PangoFontset * pango_ft2_font_map_load_fontset (PangoFontMap *fontmap, PangoContext *context, @@ -540,7 +716,7 @@ pango_ft2_font_map_load_fontset (PangoFontMap *fontmap, } FcConfigSubstitute (0, pattern, FcMatchPattern); FcDefaultSubstitute (pattern); - pango_ft2_default_substitute (pattern); + pango_ft2_default_substitute (ft2fontmap, pattern); pattern_copy = FcPatternDuplicate (pattern); diff --git a/pango/pangoft2-private.h b/pango/pangoft2-private.h index 6865a8db..16938c5a 100644 --- a/pango/pangoft2-private.h +++ b/pango/pangoft2-private.h @@ -127,6 +127,4 @@ void pango_ft2_font_set_cache_glyph_data (PangoFont *font, void pango_ft2_font_set_glyph_cache_destroy (PangoFont *font, GDestroyNotify destroy_notify); -void pango_ft2_default_substitute (FcPattern *pattern); - #endif /* __PANGOFT2_PRIVATE_H__ */ diff --git a/pango/pangoft2.c b/pango/pangoft2.c index cd60be74..d18f3b7a 100644 --- a/pango/pangoft2.c +++ b/pango/pangoft2.c @@ -33,7 +33,6 @@ #include "pango-utils.h" #include "pangoft2.h" #include "pangoft2-private.h" -#include "modules.h" #define PANGO_TYPE_FT2_FONT (pango_ft2_font_get_type ()) #define PANGO_FT2_FONT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_FT2_FONT, PangoFT2Font)) @@ -218,49 +217,6 @@ pango_ft2_font_get_face (PangoFont *font) return face; } -static double pango_ft2_resolution = 75.0; - -void -pango_ft2_default_substitute (FcPattern *pattern) -{ - FcValue v; - if (FcPatternGet (pattern, FC_DPI, 0, &v) == FcResultNoMatch) - FcPatternAddDouble (pattern, FC_DPI, pango_ft2_resolution); -} - -/** - * pango_ft2_get_context: - * @dpi_x: the horizontal dpi of the target device - * @dpi_y: the vertical dpi of the target device - * - * Retrieves a #PangoContext appropriate for rendering with the PangoFT2 - * backend. - * - * Return value: the new #PangoContext - **/ -PangoContext * -pango_ft2_get_context (double dpi_x, double dpi_y) -{ - PangoContext *result; - static gboolean registered_modules = FALSE; - int i; - - if (!registered_modules) - { - registered_modules = TRUE; - - for (i = 0; _pango_included_ft2_modules[i].list; i++) - pango_module_register (&_pango_included_ft2_modules[i]); - } - - pango_ft2_resolution = dpi_y; - - result = pango_context_new (); - pango_context_set_font_map (result, pango_ft2_font_map_for_display ()); - - return result; -} - static GType pango_ft2_font_get_type (void) { diff --git a/pango/pangoft2.h b/pango/pangoft2.h index 1eaeda05..10dc143c 100644 --- a/pango/pangoft2.h +++ b/pango/pangoft2.h @@ -23,16 +23,31 @@ #ifndef __PANGOFT2_H__ #define __PANGOFT2_H__ -#include <pango/pango-layout.h> - #include <freetype/freetype.h> +#include <fontconfig/fontconfig.h> + +#include <pango/pango-layout.h> + G_BEGIN_DECLS #define PANGO_RENDER_TYPE_FT2 "PangoRenderFT2" +#define PANGO_TYPE_FT2_FONT_MAP (pango_ft2_font_map_get_type ()) +#define PANGO_FT2_FONT_MAP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_FT2_FONT_MAP, PangoFT2FontMap)) +#define PANGO_FT2_IS_FONT_MAP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_FT2_FONT_MAP)) + +typedef struct _PangoFT2FontMap PangoFT2FontMap; + +typedef void (*PangoFT2SubstituteFunc) (FcPattern *pattern, + gpointer data); + /* Calls for applications */ -PangoContext *pango_ft2_get_context (double dpi_x, double dpi_y); +PangoContext *pango_ft2_get_context (double dpi_x, + double dpi_y); +PangoFontMap *pango_ft2_font_map_for_display (void); +void pango_ft2_shutdown_display (void); + void pango_ft2_render (FT_Bitmap *bitmap, PangoFont *font, @@ -48,8 +63,19 @@ void pango_ft2_render_layout (FT_Bitmap *bitmap, int x, int y); -PangoFontMap *pango_ft2_font_map_for_display (void); -void pango_ft2_shutdown_display (void); +GType pango_ft2_font_map_get_type (void); + +PangoFontMap *pango_ft2_font_map_new (void); +void pango_ft2_font_map_set_resolution (PangoFT2FontMap *fontmap, + double dpi_x, + double dpi_y); +void pango_ft2_font_map_set_default_substitute (PangoFT2FontMap *fontmap, + PangoFT2SubstituteFunc func, + gpointer data, + GDestroyNotify notify); +void pango_ft2_font_map_substitute_changed (PangoFT2FontMap *fontmap); +PangoContext *pango_ft2_font_map_create_context (PangoFT2FontMap *fontmap); + /* API for rendering modules */ 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); diff --git a/pango/pangoxft.h b/pango/pangoxft.h index a268351f..24f14b7e 100644 --- a/pango/pangoxft.h +++ b/pango/pangoxft.h @@ -39,6 +39,9 @@ G_BEGIN_DECLS #define PANGO_RENDER_TYPE_XFT "PangoRenderXft" +typedef void (*PangoXftSubstituteFunc) (FcPattern *pattern, + gpointer data); + /* Calls for applications */ PangoContext *pango_xft_get_context (Display *display, @@ -57,6 +60,14 @@ void pango_xft_picture_render (Display *display, gint x, gint y); +void pango_xft_set_default_substitute (Display *display, + int screen, + PangoXftSubstituteFunc func, + gpointer data, + GDestroyNotify notify); +void pango_xft_substitute_changed (Display *display, + int screen); + #define PANGO_TYPE_XFT_FONT (pango_xft_font_get_type ()) #define PANGO_XFT_IS_FONT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_XFT_FONT)) |