Commit d3d211a0 authored by Matthias Clasen's avatar Matthias Clasen

Merge branch 'preferred-languages' into 'master'

Preferred languages

See merge request !232
parents 29671113 87b99bbb
Pipeline #214883 passed with stages
in 1 minute and 40 seconds
......@@ -644,6 +644,7 @@ pango_language_matches
pango_language_includes_script
pango_language_get_scripts
pango_language_get_default
pango_language_get_preferred
pango_language_get_sample_string
<SUBSECTION Private>
......@@ -1010,6 +1011,7 @@ pango_fc_font_has_char
pango_fc_font_get_glyph
pango_fc_font_get_unknown_glyph
pango_fc_font_kern_glyphs
pango_fc_font_get_languages
<SUBSECTION Standard>
PANGO_FC_FONT
PANGO_IS_FC_FONT
......
project('pango', 'c', 'cpp',
version: '1.46.2',
version: '1.47.0',
license: 'LGPLv2.1+',
default_options: [
'buildtype=debugoptimized',
......
......@@ -791,13 +791,14 @@ parse_default_languages (void)
return (PangoLanguage **) g_array_free (langs, FALSE);
}
G_LOCK_DEFINE_STATIC (languages);
static gboolean initialized = FALSE; /* MT-safe */
static PangoLanguage * const * languages = NULL; /* MT-safe */
static GHashTable *hash = NULL; /* MT-safe */
static PangoLanguage *
_pango_script_get_default_language (PangoScript script)
{
G_LOCK_DEFINE_STATIC (languages);
static gboolean initialized = FALSE; /* MT-safe */
static PangoLanguage * const * languages = NULL; /* MT-safe */
static GHashTable *hash = NULL; /* MT-safe */
PangoLanguage *result, * const * p;
G_LOCK (languages);
......@@ -834,6 +835,33 @@ out:
return result;
}
/**
* pango_language_get_preferred:
*
* Returns the list of languages that the user prefers, as specified
* by the PANGO_LANGUAGE or LANGUAGE environment variables, in order
* of preference. Note that this list does not necessarily include
* the language returned by pango_language_get_default().
*
* When choosing language-specific resources, such as the sample
* text returned by pango_language_get_sample_string(), you should
* first try the default language, followed by the languages returned
* by this function.
*
* Returns: (transfer none) (nullable): a %NULL-terminated array of
* PangoLanguage*
*
* Since: 1.48
*/
PangoLanguage **
pango_language_get_preferred (void)
{
/* We call this just for its side-effect of initializing languages */
_pango_script_get_default_language (PANGO_SCRIPT_COMMON);
return languages;
}
/**
* pango_script_get_sample_language:
* @script: a #PangoScript
......
......@@ -53,6 +53,9 @@ const char *pango_language_get_sample_string (PangoLanguage *language) G_GNUC
PANGO_AVAILABLE_IN_1_16
PangoLanguage *pango_language_get_default (void) G_GNUC_CONST;
PANGO_AVAILABLE_IN_1_48
PangoLanguage **pango_language_get_preferred (void) G_GNUC_CONST;
PANGO_AVAILABLE_IN_ALL
gboolean pango_language_matches (PangoLanguage *language,
const char *range_list) G_GNUC_PURE;
......
......@@ -262,6 +262,16 @@
*/
#define PANGO_VERSION_1_46 (G_ENCODE_VERSION (1, 46))
/**
* PANGO_VERSION_1_48:
*
* A macro that evaluates to the 1.48 version of Pango, in a format
* that can be used by the C pre-processor.
*
* Since: 1.48
*/
#define PANGO_VERSION_1_48 (G_ENCODE_VERSION (1, 48))
/* evaluates to the current stable version; for development cycles,
* this means the next stable target
*/
......@@ -681,4 +691,18 @@
# define PANGO_AVAILABLE_IN_1_46 _PANGO_EXTERN
#endif
#if PANGO_VERSION_MIN_REQUIRED >= PANGO_VERSION_1_48
# define PANGO_DEPRECATED_IN_1_48 PANGO_DEPRECATED
# define PANGO_DEPRECATED_IN_1_48_FOR(f) PANGO_DEPRECATED_FOR(f)
#else
# define PANGO_DEPRECATED_IN_1_48 _PANGO_EXTERN
# define PANGO_DEPRECATED_IN_1_48_FOR(f) _PANGO_EXTERN
#endif
#if PANGO_VERSION_MAX_ALLOWED < PANGO_VERSION_1_48
# define PANGO_AVAILABLE_IN_1_48 PANGO_UNAVAILABLE(1, 48)
#else
# define PANGO_AVAILABLE_IN_1_48 _PANGO_EXTERN
#endif
#endif /* __PANGO_VERSION_H__ */
......@@ -1035,3 +1035,35 @@ pango_fc_font_create_hb_font (PangoFont *font)
done:
return hb_font;
}
/**
* pango_fc_font_get_languages:
* @font: a #PangoFcFont
*
* Returns the languages that are supported by @font.
*
* This corresponds to the FC_LANG member of the FcPattern.
*
* The returned array is only valid as long as the font
* and its fontmap are valid.
*
* Returns: (transfer none) (nullable): a %NULL-terminated
* array of PangoLanguage*
*
* Since: 1.48
*/
PangoLanguage **
pango_fc_font_get_languages (PangoFcFont *font)
{
PangoFcFontMap *fontmap;
PangoLanguage **languages;
fontmap = g_weak_ref_get ((GWeakRef *) &font->fontmap);
if (!fontmap)
return NULL;
languages = _pango_fc_font_map_get_languages (fontmap, font);
g_object_unref (fontmap);
return languages;
}
......@@ -94,6 +94,10 @@ gboolean pango_fc_font_has_char (PangoFcFont *font,
PANGO_AVAILABLE_IN_1_4
guint pango_fc_font_get_glyph (PangoFcFont *font,
gunichar wc);
PANGO_AVAILABLE_IN_1_48
PangoLanguage **
pango_fc_font_get_languages (PangoFcFont *font);
PANGO_DEPRECATED_FOR(PANGO_GET_UNKNOWN_GLYPH)
PangoGlyph pango_fc_font_get_unknown_glyph (PangoFcFont *font,
gunichar wc);
......
......@@ -166,8 +166,9 @@ struct _PangoFcFontFaceData
int id; /* needed to handle TTC files with multiple faces */
/* Data */
FcPattern *pattern; /* Referenced pattern that owns filename */
FcPattern *pattern; /* Referenced pattern that owns filename */
PangoCoverage *coverage;
PangoLanguage **languages;
hb_face_t *hb_face;
};
......@@ -307,6 +308,8 @@ pango_fc_font_face_data_free (PangoFcFontFaceData *data)
if (data->coverage)
pango_coverage_unref (data->coverage);
g_free (data->languages);
hb_face_destroy (data->hb_face);
g_slice_free (PangoFcFontFaceData, data);
......@@ -2245,6 +2248,57 @@ _pango_fc_font_map_fc_to_coverage (FcCharSet *charset)
return (PangoCoverage *)coverage;
}
static PangoLanguage **
_pango_fc_font_map_fc_to_languages (FcLangSet *langset)
{
FcStrSet *strset;
FcStrList *list;
FcChar8 *s;
GArray *langs;
langs = g_array_new (TRUE, FALSE, sizeof (PangoLanguage *));
strset = FcLangSetGetLangs (langset);
list = FcStrListCreate (strset);
FcStrListFirst (list);
while ((s = FcStrListNext (list)))
{
PangoLanguage *l = pango_language_from_string ((const char *)s);
g_array_append_val (langs, l);
}
FcStrListDone (list);
FcStrSetDestroy (strset);
return (PangoLanguage **) g_array_free (langs, FALSE);
}
PangoLanguage **
_pango_fc_font_map_get_languages (PangoFcFontMap *fcfontmap,
PangoFcFont *fcfont)
{
PangoFcFontFaceData *data;
FcLangSet *langset;
data = pango_fc_font_map_get_font_face_data (fcfontmap, fcfont->font_pattern);
if (G_UNLIKELY (!data))
return NULL;
if (G_UNLIKELY (data->languages == NULL))
{
/*
* Pull the languages out of the pattern, this
* doesn't require loading the font
*/
if (FcPatternGetLangSet (fcfont->font_pattern, FC_LANG, 0, &langset) != FcResultMatch)
return NULL;
data->languages = _pango_fc_font_map_fc_to_languages (langset);
}
return data->languages;
}
/**
* pango_fc_font_map_create_context:
* @fcfontmap: a #PangoFcFontMap
......
......@@ -78,6 +78,9 @@ _PANGO_EXTERN
PangoFontMetrics *pango_fc_font_create_base_metrics_for_context (PangoFcFont *font,
PangoContext *context);
PangoLanguage **_pango_fc_font_map_get_languages (PangoFcFontMap *fcfontmap,
PangoFcFont *fcfont);
G_END_DECLS
#endif /* __PANGOFC_PRIVATE_H__ */
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