[pango: 2/3] add pango_fc_font_map_set_default_substitute




commit e023cf0d66b323359740c453481507ab91005a34
Author: Caleb Hearon <crh0872 gmail com>
Date:   Mon Jun 8 22:22:55 2020 +0000

    add pango_fc_font_map_set_default_substitute
    
    added:
    pango_fc_font_map_set_default_substitute
    pango_fc_font_map_default_substitute_changed
    
    deprecated:
    pango_ft2_font_map_set_default_substitute
    pango_ft2_font_map_changed
    pango_xft_font_map_set_default_substitute
    pango_xft_font_map_changed
    
    Now PangoCairoFcFontMap will call what is passed to
    pango_fc_font_map_set_default_substitute when it is time.
    
    The deprecated functions make calls to the parent (FC) class now.
    The user-supplied callbacks are executed in the exact same places as
    before.

 docs/pango-sections.txt         |  2 ++
 pango/pangocairo-fcfontmap.c    |  2 ++
 pango/pangofc-fontmap-private.h | 16 +++++++++++++---
 pango/pangofc-fontmap.c         | 25 +++++++++++++++++++++++++
 pango/pangofc-fontmap.h         | 37 +++++++++++++++++++++++++++++++++++++
 pango/pangoft2-fontmap.c        | 39 +++++++++++----------------------------
 pango/pangoft2.h                |  2 +-
 pango/pangoxft-fontmap.c        | 39 +++++++++++----------------------------
 pango/pangoxft.h                |  2 ++
 9 files changed, 104 insertions(+), 60 deletions(-)
---
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index 1a9aede9..81a83b81 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -979,6 +979,8 @@ 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 bd3a8583..5fe61f54 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 (NULL, 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 8aa27c1e..41da194d 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -1328,6 +1328,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);
 }
 
@@ -1790,6 +1793,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 f7cc88b4..c20bde60 100644
--- a/pango/pangofc-fontmap.h
+++ b/pango/pangofc-fontmap.h
@@ -114,6 +114,43 @@ hb_face_t * pango_fc_font_map_get_hb_face (PangoFcFontMap *fcfontmap,
  */
 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:
  *
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 2f45c9e3..cda3b51e 100644
--- a/pango/pangoft2.h
+++ b/pango/pangoft2.h
@@ -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 95898f80..708629cc 100644
--- a/pango/pangoxft.h
+++ b/pango/pangoxft.h
@@ -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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]