[pango/simple-fontmap: 13/16] Implement a new fontconfig fontmap
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/simple-fontmap: 13/16] Implement a new fontconfig fontmap
- Date: Thu, 23 Dec 2021 17:20:14 +0000 (UTC)
commit 5d2ff6022f5854a019c637a0d2a25c6e9e52dc98
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Nov 1 22:04:14 2021 -0400
Implement a new fontconfig fontmap
This is a new fontmap implementation that
is populated from fontconfig data, but uses
PangoSimpleFamily, PangoHbFace and PangoHbFont.
After the initial population of the fontmap,
no fontconfig data of apis are used.
pango/meson.build | 1 +
pango/pangofc-fontmap2.c | 696 +++++++++++++++++++++++++++++++++++++++++++++++
pango/pangofc-fontmap2.h | 42 +++
3 files changed, 739 insertions(+)
---
diff --git a/pango/meson.build b/pango/meson.build
index dfc997ef..6451f46c 100644
--- a/pango/meson.build
+++ b/pango/meson.build
@@ -208,6 +208,7 @@ if build_pangoft2
pangofc_public_sources = [
'pangofc-font.c',
'pangofc-fontmap.c',
+ 'pangofc-fontmap2.c',
'pangofc-decoder.c',
'pango-trace.c',
]
diff --git a/pango/pangofc-fontmap2.c b/pango/pangofc-fontmap2.c
new file mode 100644
index 00000000..ef2c0621
--- /dev/null
+++ b/pango/pangofc-fontmap2.c
@@ -0,0 +1,696 @@
+/* Pango
+ *
+ * Copyright (C) 2021 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+#include <math.h>
+
+#include <gio/gio.h>
+
+#include "pangofc-fontmap2.h"
+#include "pango-simple-family-private.h"
+#include "pango-simple-fontmap-private.h"
+#include "pango-hbface-private.h"
+#include "pango-hbfont-private.h"
+#include "pango-context.h"
+#include "pango-impl-utils.h"
+
+#include <fontconfig/fontconfig.h>
+#include <hb-ot.h>
+
+struct _PangoFcFontMap2
+{
+ PangoSimpleFontMap parent_instance;
+
+ FcConfig *config;
+};
+
+struct _PangoFcFontMap2Class
+{
+ PangoSimpleFontMapClass parent_class;
+};
+
+/* {{{ Fontconfig utilities */
+
+static gboolean
+pango_fc_is_supported_font_format (FcPattern *pattern)
+{
+ FcResult res;
+ const char *fontformat;
+ const char *file;
+
+ /* Harfbuzz loads woff fonts, but we don't get any glyphs */
+ res = FcPatternGetString (pattern, FC_FILE, 0, (FcChar8 **)(void*)&file);
+ if (res == FcResultMatch &&
+ (g_str_has_suffix (file, ".woff") || g_str_has_suffix (file, ".woff2")))
+ return FALSE;
+
+ res = FcPatternGetString (pattern, FC_FONTFORMAT, 0, (FcChar8 **)(void*)&fontformat);
+ if (res != FcResultMatch)
+ return FALSE;
+
+ /* Harfbuzz supports only SFNT fonts */
+
+ /* FIXME: "CFF" is used for both CFF in OpenType and bare CFF files, but
+ * HarfBuzz does not support the later and FontConfig does not seem
+ * to have a way to tell them apart.
+ */
+ if (g_ascii_strcasecmp (fontformat, "TrueType") == 0 ||
+ g_ascii_strcasecmp (fontformat, "CFF") == 0)
+ return TRUE;
+
+ return FALSE;
+}
+
+static PangoStyle
+pango_fc_convert_slant_to_pango (int fc_style)
+{
+ switch (fc_style)
+ {
+ case FC_SLANT_ROMAN:
+ return PANGO_STYLE_NORMAL;
+ case FC_SLANT_ITALIC:
+ return PANGO_STYLE_ITALIC;
+ case FC_SLANT_OBLIQUE:
+ return PANGO_STYLE_OBLIQUE;
+ default:
+ return PANGO_STYLE_NORMAL;
+ }
+}
+
+static PangoStretch
+pango_fc_convert_width_to_pango (int fc_stretch)
+{
+ switch (fc_stretch)
+ {
+ case FC_WIDTH_NORMAL:
+ return PANGO_STRETCH_NORMAL;
+ case FC_WIDTH_ULTRACONDENSED:
+ return PANGO_STRETCH_ULTRA_CONDENSED;
+ case FC_WIDTH_EXTRACONDENSED:
+ return PANGO_STRETCH_EXTRA_CONDENSED;
+ case FC_WIDTH_CONDENSED:
+ return PANGO_STRETCH_CONDENSED;
+ case FC_WIDTH_SEMICONDENSED:
+ return PANGO_STRETCH_SEMI_CONDENSED;
+ case FC_WIDTH_SEMIEXPANDED:
+ return PANGO_STRETCH_SEMI_EXPANDED;
+ case FC_WIDTH_EXPANDED:
+ return PANGO_STRETCH_EXPANDED;
+ case FC_WIDTH_EXTRAEXPANDED:
+ return PANGO_STRETCH_EXTRA_EXPANDED;
+ case FC_WIDTH_ULTRAEXPANDED:
+ return PANGO_STRETCH_ULTRA_EXPANDED;
+ default:
+ return PANGO_STRETCH_NORMAL;
+ }
+}
+
+static PangoWeight
+pango_fc_convert_weight_to_pango (double fc_weight)
+{
+ return FcWeightToOpenTypeDouble (fc_weight);
+}
+
+#define PANGO_FC_GRAVITY "gravity"
+
+static PangoFontDescription *
+pango_font_description_from_pattern (FcPattern *pattern,
+ gboolean include_size)
+{
+ PangoFontDescription *desc;
+ PangoStyle style;
+ PangoWeight weight;
+ PangoStretch stretch;
+ double size;
+ PangoGravity gravity;
+ PangoVariant variant;
+ gboolean all_caps;
+
+ FcChar8 *s;
+ int i;
+ double d;
+ FcResult res;
+
+ desc = pango_font_description_new ();
+
+ res = FcPatternGetString (pattern, FC_FAMILY, 0, (FcChar8 **) &s);
+ g_assert (res == FcResultMatch);
+
+ pango_font_description_set_family (desc, (gchar *)s);
+
+ if (FcPatternGetInteger (pattern, FC_SLANT, 0, &i) == FcResultMatch)
+ style = pango_fc_convert_slant_to_pango (i);
+ else
+ style = PANGO_STYLE_NORMAL;
+
+ pango_font_description_set_style (desc, style);
+
+ if (FcPatternGetDouble (pattern, FC_WEIGHT, 0, &d) == FcResultMatch)
+ weight = pango_fc_convert_weight_to_pango (d);
+ else
+ weight = PANGO_WEIGHT_NORMAL;
+
+ pango_font_description_set_weight (desc, weight);
+
+ if (FcPatternGetInteger (pattern, FC_WIDTH, 0, &i) == FcResultMatch)
+ stretch = pango_fc_convert_width_to_pango (i);
+ else
+ stretch = PANGO_STRETCH_NORMAL;
+
+ pango_font_description_set_stretch (desc, stretch);
+
+ variant = PANGO_VARIANT_NORMAL;
+ all_caps = FALSE;
+
+ for (int i = 0; i < 32; i++)
+ {
+ const char *s;
+
+ if (FcPatternGetString (pattern, FC_FONT_FEATURES, i, (FcChar8 **)&s) == FcResultMatch)
+ {
+ if (strcmp (s, "smcp=1") == 0)
+ {
+ if (all_caps)
+ variant = PANGO_VARIANT_ALL_SMALL_CAPS;
+ else
+ variant = PANGO_VARIANT_SMALL_CAPS;
+ }
+ else if (strcmp (s, "c2sc=1") == 0)
+ {
+ if (variant == PANGO_VARIANT_SMALL_CAPS)
+ variant = PANGO_VARIANT_ALL_SMALL_CAPS;
+ else
+ all_caps = TRUE;
+ }
+ else if (strcmp (s, "pcap=1") == 0)
+ {
+ if (all_caps)
+ variant = PANGO_VARIANT_ALL_PETITE_CAPS;
+ else
+ variant = PANGO_VARIANT_PETITE_CAPS;
+ }
+ else if (strcmp (s, "c2pc=1") == 0)
+ {
+ if (variant == PANGO_VARIANT_PETITE_CAPS)
+ variant = PANGO_VARIANT_ALL_PETITE_CAPS;
+ else
+ all_caps = TRUE;
+ }
+ else if (strcmp (s, "unic=1") == 0)
+ {
+ variant = PANGO_VARIANT_UNICASE;
+ }
+ else if (strcmp (s, "titl=1") == 0)
+ {
+ variant = PANGO_VARIANT_TITLE_CAPS;
+ }
+ }
+ else
+ break;
+ }
+
+ pango_font_description_set_variant (desc, variant);
+
+ if (include_size && FcPatternGetDouble (pattern, FC_SIZE, 0, &size) == FcResultMatch)
+ {
+ FcMatrix *fc_matrix;
+ double scale_factor = 1;
+ volatile double scaled_size;
+
+ if (FcPatternGetMatrix (pattern, FC_MATRIX, 0, &fc_matrix) == FcResultMatch)
+ {
+ PangoMatrix mat = PANGO_MATRIX_INIT;
+
+ mat.xx = fc_matrix->xx;
+ mat.xy = fc_matrix->xy;
+ mat.yx = fc_matrix->yx;
+ mat.yy = fc_matrix->yy;
+
+ scale_factor = pango_matrix_get_font_scale_factor (&mat);
+ }
+
+ /* We need to use a local variable to ensure that the compiler won't
+ * implicitly cast it to integer while the result is kept in registers,
+ * leading to a wrong approximation in i386 (with 387 FPU)
+ */
+ scaled_size = scale_factor * size * PANGO_SCALE;
+ pango_font_description_set_size (desc, scaled_size);
+ }
+
+ /* gravity is a bit different. we don't want to set it if it was not set on the pattern */
+ if (FcPatternGetString (pattern, PANGO_FC_GRAVITY, 0, (FcChar8 **)&s) == FcResultMatch)
+ {
+ GEnumClass *class = g_type_class_ref (PANGO_TYPE_GRAVITY);
+ GEnumValue *value = g_enum_get_value_by_nick (class, (char *)s);
+ gravity = value->value;
+ pango_font_description_set_gravity (desc, gravity);
+ g_type_class_unref (class);
+ }
+
+ if (FcPatternGetString (pattern, FC_FONT_VARIATIONS, 0, (FcChar8 **)&s) == FcResultMatch)
+ {
+ if (s && *s)
+ pango_font_description_set_variations (desc, (char *)s);
+ }
+
+ return desc;
+}
+
+static const char *
+style_name_from_pattern (FcPattern *pattern)
+{
+ const char *font_style;
+ int weight, slant;
+
+ if (FcPatternGetString (pattern, FC_STYLE, 0, (FcChar8 **)(void*)&font_style) == FcResultMatch)
+ return font_style;
+
+ if (FcPatternGetInteger(pattern, FC_WEIGHT, 0, &weight) != FcResultMatch)
+ weight = FC_WEIGHT_MEDIUM;
+
+ if (FcPatternGetInteger(pattern, FC_SLANT, 0, &slant) != FcResultMatch)
+ slant = FC_SLANT_ROMAN;
+
+ if (weight <= FC_WEIGHT_MEDIUM)
+ {
+ if (slant == FC_SLANT_ROMAN)
+ return "Regular";
+ else
+ return "Italic";
+ }
+ else
+ {
+ if (slant == FC_SLANT_ROMAN)
+ return "Bold";
+ else
+ return "Bold Italic";
+ }
+
+ return "Normal";
+}
+
+static gboolean
+get_font_matrix_from_pattern (FcPattern *pattern,
+ PangoMatrix *matrix)
+{
+ FcMatrix fc_matrix, *fc_matrix_val;
+ int i;
+
+ FcMatrixInit (&fc_matrix);
+ for (i = 0; FcPatternGetMatrix (pattern, FC_MATRIX, i, &fc_matrix_val) == FcResultMatch; i++)
+ FcMatrixMultiply (&fc_matrix, &fc_matrix, fc_matrix_val);
+
+ if (i > 0)
+ {
+ matrix->xx = fc_matrix.xx;
+ matrix->yx = fc_matrix.yx;
+ matrix->xy = - fc_matrix.xy;
+ matrix->yy = - fc_matrix.yy;
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static PangoLanguage **
+get_languages_from_pattern (FcPattern *pattern,
+ gsize *n_languages)
+{
+ GPtrArray *langs;
+ FcLangSet *langset;
+ FcStrSet *strset;
+ FcStrList *list;
+ FcChar8 *s;
+
+ if (FcPatternGetLangSet (pattern, FC_LANG, 0, &langset) != FcResultMatch)
+ {
+ *n_languages = 0;
+ return NULL;
+ }
+
+ langs = g_ptr_array_new ();
+
+ strset = FcLangSetGetLangs (langset);
+ list = FcStrListCreate (strset);
+
+ FcStrListFirst (list);
+ while ((s = FcStrListNext (list)))
+ {
+ PangoLanguage *l = pango_language_from_string ((const char *)s);
+ g_ptr_array_add (langs, l);
+ }
+
+ FcStrListDone (list);
+ FcStrSetDestroy (strset);
+
+ g_ptr_array_add (langs, NULL);
+
+ *n_languages = langs->len;
+
+ return (PangoLanguage **) g_ptr_array_free (langs, FALSE);
+}
+
+static PangoHbFace *
+pango_hb_face_from_pattern (FcPattern *pattern)
+{
+ const char *family_name, *file;
+ int index;
+ int instance_id;
+ PangoFontDescription *description;
+ const char *name;
+ PangoHbFace *face;
+ PangoMatrix font_matrix;
+ PangoLanguage **languages;
+ gsize n_languages;
+
+ if (!pango_fc_is_supported_font_format (pattern))
+ return NULL;
+
+ if (FcPatternGetString (pattern, FC_FAMILY, 0, (FcChar8 **)(void*)&family_name) != FcResultMatch)
+ return NULL;
+
+ if (FcPatternGetString (pattern, FC_FILE, 0, (FcChar8 **)(void*)&file) != FcResultMatch)
+ return NULL;
+
+ if (FcPatternGetInteger (pattern, FC_INDEX, 0, &index) != FcResultMatch)
+ index = 0;
+
+ instance_id = (index >> 16) - 1;
+ index = index & 0xffff;
+
+ name = style_name_from_pattern (pattern);
+ description = pango_font_description_from_pattern (pattern, FALSE);
+
+ face = pango_hb_face_new_from_file (file, index, instance_id, name, description);
+
+ pango_font_description_free (description);
+
+ if (get_font_matrix_from_pattern (pattern, &font_matrix))
+ pango_hb_face_set_matrix (face, &font_matrix);
+
+ languages = get_languages_from_pattern (pattern, &n_languages);
+ pango_hb_face_set_languages (face, languages, n_languages);
+ g_free (languages);
+
+ return face;
+}
+
+#define DONTCARE 2
+
+static PangoSimpleFamily *
+find_family (PangoFcFontMap2 *self,
+ const char *family_name,
+ gboolean variable)
+{
+ PangoSimpleFontMap *simple = PANGO_SIMPLE_FONT_MAP (self);
+
+ for (int i = 0; i < simple->families->len; i++)
+ {
+ PangoSimpleFamily *family = g_ptr_array_index (simple->families, i);
+
+ if (g_ascii_strcasecmp (family->name, family_name) == 0 &&
+ (variable == DONTCARE || variable == family->variable))
+ return family;
+ }
+
+ return NULL;
+}
+
+static void
+pango_fc_font_map2_populate (PangoSimpleFontMap *simple)
+{
+ PangoFcFontMap2 *self = PANGO_FC_FONT_MAP2 (simple);
+
+ FcObjectSet *os = FcObjectSetBuild (FC_FAMILY,
+ FC_SPACING,
+ FC_STYLE,
+ FC_WEIGHT,
+ FC_WIDTH,
+ FC_SLANT,
+ FC_VARIABLE,
+ FC_FONTFORMAT,
+ FC_FILE,
+ FC_INDEX,
+ NULL);
+ FcPattern *pat;
+ FcFontSet *fontset;
+ int k;
+
+ pat = FcPatternCreate ();
+ fontset = FcFontList (self->config, pat, os);
+ FcPatternDestroy (pat);
+
+ for (k = 0; k < fontset->nfont; k++)
+ {
+ PangoHbFace *face = pango_hb_face_from_pattern (fontset->fonts[k]);
+ if (!face)
+ continue;
+
+ pango_simple_font_map_add_face (PANGO_SIMPLE_FONT_MAP (self), face);
+ g_object_unref (face);
+ }
+
+ FcFontSetDestroy (fontset);
+
+ /* Add alias families */
+ const char *alias_names[] = {
+ "monospace", "sans", "serif", "cursive", "fantasy" "system-ui"
+ };
+
+ for (int i = 0; i < G_N_ELEMENTS (alias_names); i++)
+ {
+ FcPattern *pattern;
+ FcPattern *ret;
+ FcResult res;
+ PangoSimpleFamily *alias_family;
+ const char *family_name;
+
+ alias_family = find_family (self, alias_names[i], FALSE);
+ if (alias_family)
+ continue;
+
+ pattern = FcPatternCreate ();
+ FcPatternAddString (pattern, FC_FAMILY, (FcChar8 *) alias_names[i]);
+
+ FcConfigSubstitute (self->config, pattern, FcMatchPattern);
+ FcDefaultSubstitute (pattern);
+
+ ret = FcFontMatch (self->config, pattern, &res);
+ if (ret && FcPatternGetString (ret, FC_FAMILY, 0, (FcChar8 **)(void*)&family_name) == FcResultMatch)
+ {
+ PangoSimpleFamily *family;
+
+ family = find_family (self, family_name, DONTCARE);
+ if (!family)
+ {
+ g_warning ("Ignoring alias family %s", alias_names[i]);
+ continue;
+ }
+
+ alias_family = pango_simple_family_new (PANGO_FONT_MAP (self),
+ alias_names[i],
+ family->monospace,
+ FALSE);
+ g_ptr_array_add (PANGO_SIMPLE_FONT_MAP (self)->families, alias_family);
+
+ for (int j = 0; j < g_list_model_get_n_items (G_LIST_MODEL (family)); j++)
+ {
+ PangoFontFace *face = g_list_model_get_item (G_LIST_MODEL (family), j);
+ PangoFontFace *alias_face;
+ char *fullname;
+
+ fullname = g_strdup_printf ("%s %s", alias_names[i], pango_font_face_get_face_name (face));
+ alias_face = PANGO_FONT_FACE (pango_hb_face_new_alias (PANGO_HB_FACE (face), fullname));
+ pango_simple_family_add_face (alias_family, alias_face);
+ g_object_unref (alias_face);
+ g_free (fullname);
+
+ g_object_unref (face);
+ }
+ }
+ FcPatternDestroy (ret);
+ FcPatternDestroy (pattern);
+ }
+
+ FcObjectSetDestroy (os);
+
+ /* Synthesize missing Bold and Italics */
+ for (int i = 0; i < PANGO_SIMPLE_FONT_MAP (self)->families->len; i++)
+ {
+ PangoSimpleFamily *family = g_ptr_array_index (PANGO_SIMPLE_FONT_MAP (self)->families, i);
+ PangoHbFace *regular_face = NULL;
+ PangoHbFace *bold_face = NULL;
+ int regular_weight = 0;
+ int bold_weight = 1000;
+ gboolean has_italic = FALSE;
+ gboolean has_bold_italic = FALSE;
+
+ for (int j = 0; j < g_list_model_get_n_items (G_LIST_MODEL (family)); j++)
+ {
+ PangoFontFace *face = g_list_model_get_item (G_LIST_MODEL (family), j);
+ PangoFontDescription *desc;
+ PangoWeight weight;
+ PangoStyle style;
+
+ desc = pango_font_face_describe (face);
+ weight = pango_font_description_get_weight (desc);
+ style = pango_font_description_get_style (desc);
+ pango_font_description_free (desc);
+
+ if (style == PANGO_STYLE_NORMAL)
+ {
+ if (abs (weight - PANGO_WEIGHT_NORMAL) < abs (regular_weight - PANGO_WEIGHT_NORMAL))
+ {
+ regular_weight = weight;
+ regular_face = PANGO_HB_FACE (face);
+ }
+ if (abs (weight - PANGO_WEIGHT_BOLD) < abs (bold_weight - PANGO_WEIGHT_BOLD))
+ {
+ bold_weight = weight;
+ bold_face = PANGO_HB_FACE (face);
+ }
+ }
+ else
+ {
+ if (weight < PANGO_WEIGHT_SEMIBOLD)
+ has_italic = TRUE;
+ else
+ has_bold_italic = TRUE;
+ }
+
+ g_object_unref (face);
+ }
+
+ if (regular_face && !has_italic)
+ {
+ PangoHbFace *face = pango_hb_face_new_transformed (regular_face,
+ &(PangoMatrix) { 1, 0.2, 0, 1, 0, 0 },
+ "Italic");
+ pango_simple_family_add_face (family, PANGO_FONT_FACE (face));
+ g_object_unref (face);
+ }
+
+ if (regular_face && !bold_face)
+ {
+ PangoHbFace *face = pango_hb_face_new_emboldened (regular_face);
+ pango_simple_family_add_face (family, PANGO_FONT_FACE (face));
+ bold_face = face;
+ g_object_unref (face);
+ }
+
+ if (bold_face && !has_bold_italic)
+ {
+ PangoHbFace *face = pango_hb_face_new_transformed (bold_face,
+ &(PangoMatrix) { 1, 0.2, 0, 1, 0, 0 },
+ "Bold Italic");
+ pango_simple_family_add_face (family, PANGO_FONT_FACE (face));
+ g_object_unref (face);
+ }
+ }
+}
+
+/* }}} */
+/* {{{ PangoFontMap implementation */
+
+G_DEFINE_TYPE (PangoFcFontMap2, pango_fc_font_map2, PANGO_TYPE_SIMPLE_FONT_MAP)
+
+static void
+pango_fc_font_map2_init (PangoFcFontMap2 *self)
+{
+}
+
+static void
+pango_fc_font_map2_finalize (GObject *object)
+{
+ PangoFcFontMap2 *self = PANGO_FC_FONT_MAP2 (object);
+
+ if (self->config)
+ FcConfigDestroy (self->config);
+
+ G_OBJECT_CLASS (pango_fc_font_map2_parent_class)->finalize (object);
+}
+
+static void
+pango_fc_font_map2_class_init (PangoFcFontMap2Class *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ PangoSimpleFontMapClass *simple_map_class = PANGO_SIMPLE_FONT_MAP_CLASS (class);
+
+ FcInit ();
+
+ object_class->finalize = pango_fc_font_map2_finalize;
+
+ simple_map_class->populate = pango_fc_font_map2_populate;
+}
+
+/* }}} */
+/* {{{ Public API */
+
+/**
+ * pango_fc_font_map2_new:
+ *
+ * Creates a new `PangoFcFontMap2` object.
+ *
+ * Unless overridden by [method@PangoFc.FontMap2.set_config],
+ * this font map uses the default fontconfig configuration.
+ *
+ * Returns: a new `PangoFcFontMap2`
+ */
+PangoFcFontMap2 *
+pango_fc_font_map2_new (void)
+{
+ PangoFcFontMap2 *self = g_object_new (PANGO_TYPE_FC_FONT_MAP2, NULL);
+
+ pango_simple_font_map_cache_clear (PANGO_SIMPLE_FONT_MAP (self));
+
+ return self;
+}
+
+/**
+ * pango_fc_Font_map2_set_config:
+ * @self: a `PangoFcFontMap2`
+ * @config: (nullable): the `FcConfig` to use, or `NULL` to use
+ * the default configuration
+ *
+ * Sets the fontconfig configuration to use.
+ *
+ * Note that changing the fontconfig configuration
+ * removes all cached font families, faces and fonts,
+ * including manually added ones.
+ */
+void
+pango_fc_font_map2_set_config (PangoFcFontMap2 *self,
+ FcConfig *config)
+{
+ if (self->config)
+ FcConfigDestroy (self->config);
+
+ self->config = config;
+
+ if (self->config)
+ FcConfigReference (self->config);
+
+ pango_simple_font_map_cache_clear (PANGO_SIMPLE_FONT_MAP (self));
+}
+
+/* }}} */
+
+/* vim:set foldmethod=marker expandtab: */
diff --git a/pango/pangofc-fontmap2.h b/pango/pangofc-fontmap2.h
new file mode 100644
index 00000000..1fa63918
--- /dev/null
+++ b/pango/pangofc-fontmap2.h
@@ -0,0 +1,42 @@
+/* Pango
+ * pangofc-fontmap2.h: Base fontmap type for fontconfig-based backends
+ *
+ * Copyright (C) 2021 Red Hat, Inc
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#pragma once
+
+#include <pango/pango.h>
+#include <pango/pango-simple-fontmap.h>
+#include <fontconfig/fontconfig.h>
+
+G_BEGIN_DECLS
+
+#define PANGO_TYPE_FC_FONT_MAP2 (pango_fc_font_map2_get_type ())
+
+PANGO_AVAILABLE_IN_1_50
+PANGO_DECLARE_INTERNAL_TYPE (PangoFcFontMap2, pango_fc_font_map2, PANGO, FC_FONT_MAP2, PangoSimpleFontMap)
+
+PANGO_AVAILABLE_IN_1_50
+PangoFcFontMap2 * pango_fc_font_map2_new (void);
+
+PANGO_AVAILABLE_IN_1_50
+void pango_fc_font_map2_set_config (PangoFcFontMap2 *self,
+ FcConfig *config);
+
+G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]