diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-09-18 19:17:32 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-09-18 19:17:32 +0000 |
commit | 3d1240ae397d1637be6887815221bc17112ad4ce (patch) | |
tree | 1d71eb13e526ac0b3a19b2aaba0610160976c81e | |
parent | d3d211a0e8ce537da876ddce7c442b2d4a6197a6 (diff) | |
parent | e023cf0d66b323359740c453481507ab91005a34 (diff) | |
download | pango-3d1240ae397d1637be6887815221bc17112ad4ce.tar.gz |
Merge branch 'ch/83' into 'master'
Add pango_fc_font_map_set_default_substitute
Closes #83
See merge request GNOME/pango!191
-rw-r--r-- | docs/pango-sections.txt | 3 | ||||
-rw-r--r-- | pango/pangocairo-fcfontmap.c | 2 | ||||
-rw-r--r-- | pango/pangofc-fontmap-private.h | 16 | ||||
-rw-r--r-- | pango/pangofc-fontmap.c | 25 | ||||
-rw-r--r-- | pango/pangofc-fontmap.h | 46 | ||||
-rw-r--r-- | pango/pangoft2-fontmap.c | 39 | ||||
-rw-r--r-- | pango/pangoft2.h | 6 | ||||
-rw-r--r-- | pango/pangoxft-fontmap.c | 39 | ||||
-rw-r--r-- | pango/pangoxft.h | 6 |
9 files changed, 118 insertions, 64 deletions
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt index 062b1bb4..3d45510d 100644 --- a/docs/pango-sections.txt +++ b/docs/pango-sections.txt @@ -980,6 +980,9 @@ pango_fc_font_map_config_changed pango_fc_font_map_shutdown pango_fc_font_map_set_config pango_fc_font_map_get_config +PangoFcSubstituteFunc +pango_fc_font_map_set_default_substitute +pango_fc_font_map_substitute_changed pango_fc_font_description_from_pattern PANGO_FC_FONT_FEATURES PANGO_FC_GRAVITY diff --git a/pango/pangocairo-fcfontmap.c b/pango/pangocairo-fcfontmap.c index 015b8170..dec59c8b 100644 --- a/pango/pangocairo-fcfontmap.c +++ b/pango/pangocairo-fcfontmap.c @@ -105,6 +105,8 @@ pango_cairo_fc_font_map_fontset_key_substitute (PangoFcFontMap *fcfontmap G_G { FcConfigSubstitute (pango_fc_font_map_get_config (fcfontmap), pattern, FcMatchPattern); + if (fcfontmap->substitute_func) + fcfontmap->substitute_func (pattern, fcfontmap->substitute_data); if (fontkey) cairo_ft_font_options_substitute (pango_fc_fontset_key_get_context_key (fontkey), pattern); diff --git a/pango/pangofc-fontmap-private.h b/pango/pangofc-fontmap-private.h index 131f7266..b32982f2 100644 --- a/pango/pangofc-fontmap-private.h +++ b/pango/pangofc-fontmap-private.h @@ -94,14 +94,23 @@ struct _PangoFcFontMap PangoFontMap parent_instance; PangoFcFontMapPrivate *priv; + + /* Function to call on prepared patterns to do final + * config tweaking. + */ + PangoFcSubstituteFunc substitute_func; + gpointer substitute_data; + GDestroyNotify substitute_destroy; }; /** * PangoFcFontMapClass: * @default_substitute: (nullable): Substitutes in default * values for unspecified fields in a #FcPattern. This will - * be called prior to creating a font for the pattern. May be - * %NULL. Deprecated in favor of @font_key_substitute(). + * be called prior to creating a font for the pattern. + * Implementations must call substitute_func if it is + * defined. May be %NULL. Deprecated in favor of + * @font_key_substitute(). * @new_font: Creates a new #PangoFcFont for the specified * pattern of the appropriate type for this font map. The * @pattern argument must be passed to the "pattern" property @@ -127,7 +136,8 @@ struct _PangoFcFontMap * @fontset_key_substitute: (nullable): Substitutes in * default values for unspecified fields in a * #FcPattern. This will be called prior to creating a font - * for the pattern. May be %NULL. (Since: 1.24) + * for the pattern. Implementations must call substitute_func + * if it is defined. May be %NULL. (Since: 1.24) * @create_font: (nullable): Creates a new #PangoFcFont for * the specified pattern of the appropriate type for this * font map using information from the font key that is diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c index bd15bf2a..e120d305 100644 --- a/pango/pangofc-fontmap.c +++ b/pango/pangofc-fontmap.c @@ -1340,6 +1340,9 @@ pango_fc_font_map_finalize (GObject *object) pango_fc_font_map_shutdown (fcfontmap); + if (fcfontmap->substitute_destroy) + fcfontmap->substitute_destroy (fcfontmap->substitute_data); + G_OBJECT_CLASS (pango_fc_font_map_parent_class)->finalize (object); } @@ -1801,6 +1804,28 @@ pango_fc_default_substitute (PangoFcFontMap *fontmap, PANGO_FC_FONT_MAP_GET_CLASS (fontmap)->default_substitute (fontmap, pattern); } +void +pango_fc_font_map_set_default_substitute (PangoFcFontMap *fontmap, + PangoFcSubstituteFunc func, + gpointer data, + GDestroyNotify notify) +{ + if (fontmap->substitute_destroy) + fontmap->substitute_destroy (fontmap->substitute_data); + + fontmap->substitute_func = func; + fontmap->substitute_data = data; + fontmap->substitute_destroy = notify; + + pango_fc_font_map_substitute_changed (fontmap); +} + +void +pango_fc_font_map_substitute_changed (PangoFcFontMap *fontmap) { + pango_fc_font_map_cache_clear(fontmap); + pango_font_map_changed(PANGO_FONT_MAP (fontmap)); +} + static double pango_fc_font_map_get_resolution (PangoFcFontMap *fcfontmap, PangoContext *context) diff --git a/pango/pangofc-fontmap.h b/pango/pangofc-fontmap.h index a41ae1d9..c20bde60 100644 --- a/pango/pangofc-fontmap.h +++ b/pango/pangofc-fontmap.h @@ -106,6 +106,52 @@ hb_face_t * pango_fc_font_map_get_hb_face (PangoFcFontMap *fcfontmap, PangoFcFont *fcfont); /** + * PangoFcSubstituteFunc: + * @pattern: the FcPattern to tweak. + * @data: user data. + * + * Function type for doing final config tweaking on prepared FcPatterns. + */ +typedef void (*PangoFcSubstituteFunc) (FcPattern *pattern, + gpointer data); + +/** + * pango_fc_font_map_set_default_substitute: + * @fontmap: a #PangoFcFontMap + * @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 antialiasing options. + * + * Since: 1.46 + */ +PANGO_AVAILABLE_IN_1_46 +void pango_fc_font_map_set_default_substitute (PangoFcFontMap *fontmap, + PangoFcSubstituteFunc func, + gpointer data, + GDestroyNotify notify); + +/** + * pango_fc_font_map_substitute_changed: + * @fontmap: a #PangoFcFontMap + * + * Call this function any time the results of the + * default substitution function set with + * pango_fc_font_map_set_default_substitute() change. + * That is, if your substitution function will return different + * results for the same input pattern, you must call this function. + * + * Since: 1.46 + */ +PANGO_AVAILABLE_IN_1_46 +void pango_fc_font_map_substitute_changed (PangoFcFontMap *fontmap); + +/** * PANGO_FC_GRAVITY: * * String representing a fontconfig property name that Pango sets on any diff --git a/pango/pangoft2-fontmap.c b/pango/pangoft2-fontmap.c index 60ca3e79..4fb64616 100644 --- a/pango/pangoft2-fontmap.c +++ b/pango/pangoft2-fontmap.c @@ -52,13 +52,6 @@ struct _PangoFT2FontMap 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; - PangoRenderer *renderer; }; @@ -117,9 +110,6 @@ pango_ft2_font_map_finalize (GObject *object) if (ft2fontmap->renderer) g_object_unref (ft2fontmap->renderer); - if (ft2fontmap->substitute_destroy) - ft2fontmap->substitute_destroy (ft2fontmap->substitute_data); - G_OBJECT_CLASS (pango_ft2_font_map_parent_class)->finalize (object); FT_Done_FreeType (ft2fontmap->library); @@ -176,6 +166,9 @@ pango_ft2_font_map_changed (PangoFontMap *fontmap) * the font. This function can be used to do things like set * hinting and antialiasing options. * + * Deprecated: 1.46: Use pango_fc_font_map_set_default_substitute() + * instead. + * * Since: 1.2 **/ void @@ -184,18 +177,8 @@ pango_ft2_font_map_set_default_substitute (PangoFT2FontMap *fontmap, gpointer data, GDestroyNotify notify) { - fontmap->serial++; - if (fontmap->serial == 0) - fontmap->serial++; - - if (fontmap->substitute_destroy) - fontmap->substitute_destroy (fontmap->substitute_data); - - fontmap->substitute_func = func; - fontmap->substitute_data = data; - fontmap->substitute_destroy = notify; - - pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap)); + PangoFcFontMap *fcfontmap = PANGO_FC_FONT_MAP (fontmap); + pango_fc_font_map_set_default_substitute(fcfontmap, func, data, notify); } /** @@ -208,15 +191,15 @@ pango_ft2_font_map_set_default_substitute (PangoFT2FontMap *fontmap, * That is, if your substitution function will return different * results for the same input pattern, you must call this function. * + * Deprecated: 1.46: Use pango_fc_font_map_substitute_changed() + * instead. + * * Since: 1.2 **/ void pango_ft2_font_map_substitute_changed (PangoFT2FontMap *fontmap) { - fontmap->serial++; - if (fontmap->serial == 0) - fontmap->serial++; - pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap)); + pango_fc_font_map_substitute_changed(PANGO_FC_FONT_MAP (fontmap)); } /** @@ -363,8 +346,8 @@ _pango_ft2_font_map_default_substitute (PangoFcFontMap *fcfontmap, FcConfigSubstitute (NULL, pattern, FcMatchPattern); - if (ft2fontmap->substitute_func) - ft2fontmap->substitute_func (pattern, ft2fontmap->substitute_data); + if (fcfontmap->substitute_func) + fcfontmap->substitute_func (pattern, fcfontmap->substitute_data); if (FcPatternGet (pattern, FC_DPI, 0, &v) == FcResultNoMatch) FcPatternAddDouble (pattern, FC_DPI, ft2fontmap->dpi_y); diff --git a/pango/pangoft2.h b/pango/pangoft2.h index 483bc366..cda3b51e 100644 --- a/pango/pangoft2.h +++ b/pango/pangoft2.h @@ -28,6 +28,7 @@ #include <ft2build.h> #include FT_FREETYPE_H +#include <pango/pangofc-fontmap.h> #include <pango/pango-layout.h> #include <pango/pangofc-font.h> @@ -66,8 +67,7 @@ typedef struct _PangoFT2FontMap PangoFT2FontMap; * * Function type for doing final config tweaking on prepared FcPatterns. */ -typedef void (*PangoFT2SubstituteFunc) (FcPattern *pattern, - gpointer data); +typedef PangoFcSubstituteFunc PangoFT2SubstituteFunc; /* Calls for applications */ @@ -115,6 +115,7 @@ PANGO_AVAILABLE_IN_1_2 void pango_ft2_font_map_set_resolution (PangoFT2FontMap *fontmap, double dpi_x, double dpi_y); +#ifndef PANGO_DISABLE_DEPRECATED PANGO_AVAILABLE_IN_1_2 void pango_ft2_font_map_set_default_substitute (PangoFT2FontMap *fontmap, PangoFT2SubstituteFunc func, @@ -122,7 +123,6 @@ void pango_ft2_font_map_set_default_substitute (PangoFT2FontMap GDestroyNotify notify); PANGO_AVAILABLE_IN_1_2 void pango_ft2_font_map_substitute_changed (PangoFT2FontMap *fontmap); -#ifndef PANGO_DISABLE_DEPRECATED PANGO_DEPRECATED_IN_1_22_FOR(pango_font_map_create_context) PangoContext *pango_ft2_font_map_create_context (PangoFT2FontMap *fontmap); #endif diff --git a/pango/pangoxft-fontmap.c b/pango/pangoxft-fontmap.c index fce8c665..82955165 100644 --- a/pango/pangoxft-fontmap.c +++ b/pango/pangoxft-fontmap.c @@ -46,13 +46,6 @@ struct _PangoXftFontMap Display *display; int screen; - /* Function to call on prepared patterns to do final - * config tweaking. - */ - PangoXftSubstituteFunc substitute_func; - gpointer substitute_data; - GDestroyNotify substitute_destroy; - PangoRenderer *renderer; }; @@ -108,9 +101,6 @@ pango_xft_font_map_finalize (GObject *object) fontmaps = g_slist_remove (fontmaps, object); G_UNLOCK (fontmaps); - if (xftfontmap->substitute_destroy) - xftfontmap->substitute_destroy (xftfontmap->substitute_data); - G_OBJECT_CLASS (pango_xft_font_map_parent_class)->finalize (object); } @@ -297,6 +287,9 @@ pango_xft_shutdown_display (Display *display, * the font. This function can be used to do things like set * hinting and antialiasing options. * + * Deprecated: 1.46: Use pango_fc_font_map_set_default_substitute() + * instead. + * * Since: 1.2 **/ void @@ -308,18 +301,8 @@ pango_xft_set_default_substitute (Display *display, { PangoXftFontMap *xftfontmap = (PangoXftFontMap *)pango_xft_get_font_map (display, screen); - xftfontmap->serial++; - if (xftfontmap->serial == 0) - xftfontmap->serial++; - - if (xftfontmap->substitute_destroy) - xftfontmap->substitute_destroy (xftfontmap->substitute_data); - - xftfontmap->substitute_func = func; - xftfontmap->substitute_data = data; - xftfontmap->substitute_destroy = notify; - - pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (xftfontmap)); + PangoFcFontMap *fcfontmap = PANGO_FC_FONT_MAP (xftfontmap); + pango_fc_font_map_set_default_substitute(fcfontmap, func, data, notify); } /** @@ -333,6 +316,9 @@ pango_xft_set_default_substitute (Display *display, * That is, if your substitution function will return different * results for the same input pattern, you must call this function. * + * Deprecated: 1.46: Use pango_fc_font_map_substitute_changed() + * instead. + * * Since: 1.2 **/ void @@ -341,10 +327,7 @@ pango_xft_substitute_changed (Display *display, { PangoXftFontMap *xftfontmap = (PangoXftFontMap *)pango_xft_get_font_map (display, screen); - xftfontmap->serial++; - if (xftfontmap->serial == 0) - xftfontmap->serial++; - pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (xftfontmap)); + pango_fc_font_map_substitute_changed(PANGO_FC_FONT_MAP (xftfontmap)); } void @@ -408,8 +391,8 @@ pango_xft_font_map_default_substitute (PangoFcFontMap *fcfontmap, double d; FcConfigSubstitute (NULL, pattern, FcMatchPattern); - if (xftfontmap->substitute_func) - xftfontmap->substitute_func (pattern, xftfontmap->substitute_data); + if (fcfontmap->substitute_func) + fcfontmap->substitute_func (pattern, fcfontmap->substitute_data); XftDefaultSubstitute (xftfontmap->display, xftfontmap->screen, pattern); if (FcPatternGetDouble (pattern, FC_PIXEL_SIZE, 0, &d) == FcResultMatch && d == 0.0) { diff --git a/pango/pangoxft.h b/pango/pangoxft.h index f14b89c9..708629cc 100644 --- a/pango/pangoxft.h +++ b/pango/pangoxft.h @@ -23,6 +23,7 @@ #ifndef __PANGOXFT_H__ #define __PANGOXFT_H__ +#include <pango/pangofc-fontmap.h> #include <pango/pango-context.h> #include <pango/pango-ot.h> #include <pango/pangofc-font.h> @@ -84,8 +85,7 @@ typedef struct _PangoXftFont PangoXftFont; * * Function type for doing final config tweaking on prepared FcPatterns. */ -typedef void (*PangoXftSubstituteFunc) (FcPattern *pattern, - gpointer data); +typedef PangoFcSubstituteFunc PangoXftSubstituteFunc; /* Calls for applications */ @@ -101,6 +101,7 @@ PANGO_AVAILABLE_IN_1_2 void pango_xft_shutdown_display (Display *display, int screen); +#ifndef PANGO_DISABLE_DEPRECATED PANGO_AVAILABLE_IN_1_2 void pango_xft_set_default_substitute (Display *display, int screen, @@ -110,6 +111,7 @@ void pango_xft_set_default_substitute (Display *display, PANGO_AVAILABLE_IN_1_2 void pango_xft_substitute_changed (Display *display, int screen); +#endif PANGO_AVAILABLE_IN_ALL GType pango_xft_font_map_get_type (void) G_GNUC_CONST; |