Commit 3d1240ae authored by Matthias Clasen's avatar Matthias Clasen

Merge branch 'ch/83' into 'master'

Add pango_fc_font_map_set_default_substitute

Closes #83

See merge request !191
parents d3d211a0 e023cf0d
Pipeline #214884 passed with stages
in 1 minute and 50 seconds
......@@ -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
......
......@@ -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);
......
......@@ -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
......
......@@ -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)
......
......@@ -105,6 +105,52 @@ PANGO_AVAILABLE_IN_1_44
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:
*
......
......@@ -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);
......
......@@ -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
......
......@@ -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)
{
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment