summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-12-29 13:41:12 -0500
committerMatthias Clasen <mclasen@redhat.com>2022-01-28 09:03:03 -0500
commit0c5b714c17ef5efa6d8e19592cb30f0b9a608402 (patch)
tree3b384c32e7c4d45040ee777ff08cf96ffd953cc5
parent98fafa7c500a87f50d77e472153ee08806282414 (diff)
downloadpango-0c5b714c17ef5efa6d8e19592cb30f0b9a608402.tar.gz
font: Add pango_font_face_is_variable/monospace
These are really properties of the individual faces, not the family. The default implementations of these functions simply return the corresponding family value. Add some tests for the new api.
-rw-r--r--pango/fonts.c80
-rw-r--r--pango/pango-font.h12
-rw-r--r--tests/test-font.c13
3 files changed, 91 insertions, 14 deletions
diff --git a/pango/fonts.c b/pango/fonts.c
index e502d2b3..3afc8f27 100644
--- a/pango/fonts.c
+++ b/pango/fonts.c
@@ -2520,18 +2520,24 @@ pango_font_family_get_face (PangoFontFamily *family,
* A monospace font is a font designed for text display where the the
* characters form a regular grid.
*
- * For Western languages this would
- * mean that the advance width of all characters are the same, but
- * this categorization also includes Asian fonts which include
- * double-width characters: characters that occupy two grid cells.
- * g_unichar_iswide() returns a result that indicates whether a
- * character is typically double-width in a monospace font.
+ * For Western languages this would mean that the advance width of all
+ * characters are the same, but this categorization also includes Asian
+ * fonts which include double-width characters: characters that occupy
+ * two grid cells. [function@GLib.unichar_iswide] returns a result that
+ * indicates whether a character is typically double-width in a monospace
+ * font.
*
* The best way to find out the grid-cell size is to call
* [method@Pango.FontMetrics.get_approximate_digit_width], since the
* results of [method@Pango.FontMetrics.get_approximate_char_width] may
* be affected by double-width characters.
*
+ * Note that a font family can in principle contain a mixture of
+ * monospace and non-monospace faces (although well-behaved families
+ * won't). Use [method@Pango.FontFace.is_monospace] to examine individual
+ * faces. This function will return `TRUE` as long as the family contains
+ * any monospace faces.
+ *
* Return value: %TRUE if the family is monospace.
*
* Since: 1.4
@@ -2554,6 +2560,12 @@ pango_font_family_is_monospace (PangoFontFamily *family)
* Such axes are also known as _variations_; see
* [method@Pango.FontDescription.set_variations] for more information.
*
+ * Note that a font family can in principle contain a mixture of
+ * variable and non-variable faces, and even variable and non-variable
+ * versions of the same face. Use [method@Pango.FontFace.is_variable]
+ * to examine individual faces. This function will return `TRUE` as
+ * long as the family contains any variable faces.
+ *
* Return value: %TRUE if the family is variable
*
* Since: 1.44
@@ -2572,9 +2584,23 @@ pango_font_family_is_variable (PangoFontFamily *family)
G_DEFINE_ABSTRACT_TYPE (PangoFontFace, pango_font_face, G_TYPE_OBJECT)
+static gboolean
+pango_font_face_default_is_monospace (PangoFontFace *face)
+{
+ return pango_font_family_is_monospace (pango_font_face_get_family (face));
+}
+
+static gboolean
+pango_font_face_default_is_variable (PangoFontFace *face)
+{
+ return pango_font_family_is_variable (pango_font_face_get_family (face));
+}
+
static void
pango_font_face_class_init (PangoFontFaceClass *class G_GNUC_UNUSED)
{
+ class->is_monospace = pango_font_face_default_is_monospace;
+ class->is_variable = pango_font_face_default_is_variable;
}
static void
@@ -2707,6 +2733,48 @@ pango_font_face_get_family (PangoFontFace *face)
}
/**
+ * pango_font_face_is_monospace:
+ * @face: a `PangoFontFace`
+ *
+ * A monospace font is a font designed for text display where the the
+ * characters form a regular grid.
+ *
+ * See [method@Pango.FontFamily.is_monospace] for more details.
+ *
+ * Returns: `TRUE` if @face is monospace
+ *
+ * Since: 1.52
+ */
+gboolean
+pango_font_face_is_monospace (PangoFontFace *face)
+{
+ g_return_val_if_fail (PANGO_IS_FONT_FACE (face), FALSE);
+
+ return PANGO_FONT_FACE_GET_CLASS (face)->is_monospace (face);
+}
+
+/**
+ * pango_font_face_is_variable:
+ * @face: a `PangoFontFace`
+ *
+ * A variable font is a font which has axes that can be modified
+ * to produce variations.
+ *
+ * See [method@Pango.FontFamily.is_variable] for more details.
+ *
+ * Returns: `TRUE` if @face is variable
+ *
+ * Since: 1.52
+ */
+gboolean
+pango_font_face_is_variable (PangoFontFace *face)
+{
+ g_return_val_if_fail (PANGO_IS_FONT_FACE (face), FALSE);
+
+ return PANGO_FONT_FACE_GET_CLASS (face)->is_variable (face);
+}
+
+/**
* pango_font_has_char:
* @font: a `PangoFont`
* @wc: a Unicode character
diff --git a/pango/pango-font.h b/pango/pango-font.h
index 350e4e29..d54dd820 100644
--- a/pango/pango-font.h
+++ b/pango/pango-font.h
@@ -506,11 +506,8 @@ struct _PangoFontFaceClass
gboolean (*is_synthesized) (PangoFontFace *face);
PangoFontFamily * (*get_family) (PangoFontFace *face);
- /*< private >*/
-
- /* Padding for future expansion */
- void (*_pango_reserved3) (void);
- void (*_pango_reserved4) (void);
+ gboolean (*is_monospace) (PangoFontFace *face);
+ gboolean (*is_variable) (PangoFontFace *face);
};
#endif /* PANGO_DISABLE_DEPRECATED */
@@ -532,6 +529,11 @@ gboolean pango_font_face_is_synthesized (PangoFontFace *face) G_GN
PANGO_AVAILABLE_IN_1_46
PangoFontFamily * pango_font_face_get_family (PangoFontFace *face);
+PANGO_AVAILABLE_IN_1_52
+gboolean pango_font_face_is_monospace (PangoFontFace *face);
+PANGO_AVAILABLE_IN_1_52
+gboolean pango_font_face_is_variable (PangoFontFace *face);
+
/*
* PangoFont
diff --git a/tests/test-font.c b/tests/test-font.c
index 2eef4396..2fa54cdf 100644
--- a/tests/test-font.c
+++ b/tests/test-font.c
@@ -455,6 +455,15 @@ test_font_models (void)
g_assert_true (pango_font_face_get_family (PANGO_FONT_FACE (obj2)) == (PangoFontFamily *)obj);
+ if (g_ascii_strcasecmp (pango_font_family_get_name (PANGO_FONT_FAMILY (obj)), "monospace") == 0)
+ g_assert_true (pango_font_face_is_monospace (PANGO_FONT_FACE (obj2)));
+
+ if (pango_font_face_is_monospace (PANGO_FONT_FACE (obj2)))
+ g_assert_true (pango_font_family_is_monospace (PANGO_FONT_FAMILY (obj)));
+
+ if (pango_font_face_is_variable (PANGO_FONT_FACE (obj2)))
+ g_assert_true (pango_font_family_is_variable (PANGO_FONT_FAMILY (obj)));
+
pango_font_face_list_sizes (PANGO_FONT_FACE (obj2), &sizes, &n_sizes);
g_assert_true ((sizes == NULL) == (n_sizes == 0));
g_free (sizes);
@@ -462,9 +471,7 @@ test_font_models (void)
if (pango_font_family_is_monospace (PANGO_FONT_FAMILY (obj)))
{
if (pango_font_face_is_synthesized (PANGO_FONT_FACE (obj2)))
- {
- monospace_found = TRUE;
- }
+ monospace_found = TRUE;
}
g_object_unref (obj2);