[pango/pango2: 31/37] font: Redo feature api
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/pango2: 31/37] font: Redo feature api
- Date: Tue, 21 Jun 2022 18:11:34 +0000 (UTC)
commit b6d40b5f3a577426eecfe04f0239c4717de1b34e
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jun 20 09:26:25 2022 -0700
font: Redo feature api
Move this to PangoHbFont.
pango/pango-font-private.h | 4 ---
pango/pango-font.c | 89 ----------------------------------------------
pango/pango-font.h | 6 ----
pango/pango-hbfont.c | 42 +++++++++++++++-------
pango/pango-hbfont.h | 3 ++
pango/pango-item.c | 11 +++++-
pango/serializer.c | 6 ++--
tests/test-font.c | 8 ++---
tests/testhbfont.c | 3 +-
9 files changed, 51 insertions(+), 121 deletions(-)
---
diff --git a/pango/pango-font-private.h b/pango/pango-font-private.h
index 5644f591..db4720dc 100644
--- a/pango/pango-font-private.h
+++ b/pango/pango-font-private.h
@@ -59,10 +59,6 @@ struct _PangoFontClass
PangoRectangle *logical_rect);
PangoFontMetrics * (* get_metrics) (PangoFont *font,
PangoLanguage *language);
- void (* get_features) (PangoFont *font,
- hb_feature_t *features,
- guint len,
- guint *num_features);
hb_font_t * (* create_hb_font) (PangoFont *font);
gboolean (* is_hinted) (PangoFont *font);
void (* get_scale_factors) (PangoFont *font,
diff --git a/pango/pango-font.c b/pango/pango-font.c
index e180c3af..9552b786 100644
--- a/pango/pango-font.c
+++ b/pango/pango-font.c
@@ -41,28 +41,6 @@
* rendering-system-independent manner.
*/
-/* {{{ Utilities */
-
-static char *
-features_to_string (hb_feature_t *features,
- unsigned int n_features)
-{
- GString *s;
- char buf[128];
-
- s = g_string_new ("");
-
- for (unsigned int i = 0; i < n_features; i++)
- {
- hb_feature_to_string (&features[i], buf, sizeof (buf));
- if (s->len > 0)
- g_string_append_c (s, ',');
- g_string_append (s, buf);
- }
-
- return g_string_free (s, FALSE);
-}
-
/* }}} */
/* {{{ PangoFont implementation */
@@ -72,7 +50,6 @@ enum {
PROP_SIZE,
PROP_DPI,
PROP_GRAVITY,
- PROP_FEATURES,
N_PROPERTIES
};
@@ -121,19 +98,6 @@ pango_font_get_property (GObject *object,
g_value_set_enum (value, font->gravity);
break;
- case PROP_FEATURES:
- {
- hb_feature_t features[64];
- guint n_features;
- char *s;
-
- pango_font_get_features (font, features, sizeof (features), &n_features);
- s = features_to_string (features, n_features);
- g_value_set_string (value, s);
- g_free (s);
- }
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -160,15 +124,6 @@ pango_font_default_get_transform (PangoFont *font,
*matrix = (PangoMatrix) PANGO_MATRIX_INIT;
}
-static void
-pango_font_default_get_features (PangoFont *font,
- hb_feature_t *features,
- guint len,
- guint *num_features)
-{
- *num_features = 0;
-}
-
static void
pango_font_class_init (PangoFontClass *class G_GNUC_UNUSED)
{
@@ -177,7 +132,6 @@ pango_font_class_init (PangoFontClass *class G_GNUC_UNUSED)
object_class->finalize = pango_font_finalize;
object_class->get_property = pango_font_get_property;
- class->get_features = pango_font_default_get_features;
class->is_hinted = pango_font_default_is_hinted;
class->get_scale_factors = pango_font_default_get_scale_factors;
class->get_transform = pango_font_default_get_transform;
@@ -232,23 +186,6 @@ pango_font_class_init (PangoFontClass *class G_GNUC_UNUSED)
PANGO_GRAVITY_AUTO,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
- /**
- * PangoFont:features: (attributes org.gtk.Property.get=pango_font_get_features)
- *
- * OpenType features that are provided by the font.
- *
- * These are passed to the rendering system, together with features
- * that have been explicitly set via attributes.
- *
- * Note that this does not include OpenType features which the
- * rendering system enables by default.
- *
- * This property holds a string representation of the features.
- */
- properties[PROP_FEATURES] =
- g_param_spec_string ("features", NULL, NULL, NULL,
- G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
-
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
}
@@ -536,32 +473,6 @@ pango_font_get_gravity (PangoFont *font)
return font->gravity;
}
-/**
- * pango_font_get_features:
- * @font: a `PangoFont`
- * @features: (out caller-allocates) (array length=len): Array to features in
- * @len: the length of @features
- * @num_features: (inout): the number of used items in @features
- *
- * Obtain the OpenType features that are provided by the font.
- *
- * These are passed to the rendering system, together with features
- * that have been explicitly set via attributes.
- *
- * Note that this does not include OpenType features which the
- * rendering system enables by default.
- */
-void
-pango_font_get_features (PangoFont *font,
- hb_feature_t *features,
- guint len,
- guint *num_features)
-{
- g_return_if_fail (PANGO_IS_FONT (font));
-
- PANGO_FONT_GET_CLASS (font)->get_features (font, features, len, num_features);
-}
-
/* }}} */
/* vim:set foldmethod=marker expandtab: */
diff --git a/pango/pango-font.h b/pango/pango-font.h
index 878aa2b9..e5f6ca3d 100644
--- a/pango/pango-font.h
+++ b/pango/pango-font.h
@@ -63,12 +63,6 @@ double pango_font_get_absolute_size (PangoFont *font);
PANGO_AVAILABLE_IN_ALL
PangoGravity pango_font_get_gravity (PangoFont *font);
-PANGO_AVAILABLE_IN_ALL
-void pango_font_get_features (PangoFont *font,
- hb_feature_t *features,
- guint len,
- guint *num_features);
-
PANGO_AVAILABLE_IN_ALL
GBytes * pango_font_serialize (PangoFont *font);
diff --git a/pango/pango-hbfont.c b/pango/pango-hbfont.c
index 751a2c38..d9fe88cc 100644
--- a/pango/pango-hbfont.c
+++ b/pango/pango-hbfont.c
@@ -893,18 +893,6 @@ pango_hb_font_get_transform (PangoFont *font,
*matrix = (PangoMatrix) PANGO_MATRIX_INIT;
}
-static void
-pango_hb_font_get_features (PangoFont *font,
- hb_feature_t *features,
- guint len,
- guint *num_features)
-{
- PangoHbFont *self = PANGO_HB_FONT (font);
-
- *num_features = MIN (len, self->n_features);
- memcpy (features, self->features, sizeof (hb_feature_t) * *num_features);
-}
-
static void
pango_hb_font_class_init (PangoHbFontClass *class)
{
@@ -918,7 +906,6 @@ pango_hb_font_class_init (PangoHbFontClass *class)
font_class->get_glyph_extents = pango_hb_font_get_glyph_extents;
font_class->get_metrics = pango_hb_font_get_metrics;
font_class->create_hb_font = pango_hb_font_create_hb_font;
- font_class->get_features = pango_hb_font_get_features;
font_class->get_transform = pango_hb_font_get_transform;
/**
@@ -1054,6 +1041,35 @@ pango_hb_font_new_for_description (PangoHbFace *face,
return pango_hb_font_new (face, size, features, n_features, variations, n_variations, gravity, dpi, ctm);
}
+/**
+ * pango_hb_font_get_features:
+ * @self: a `PangoFont`
+ * @n_features: (nullable) (out caller-allocates): return location for
+ * the length of the returned array
+ *
+ * Obtain the OpenType features that are provided by the font.
+ *
+ * These are passed to the rendering system, together with features
+ * that have been explicitly set via attributes.
+ *
+ * Note that this does not include OpenType features which the
+ * rendering system enables by default.
+ *
+ * Returns: (nullable) (transfer none): the features
+ */
+const hb_feature_t *
+pango_hb_font_get_features (PangoHbFont *self,
+ unsigned int *n_features)
+{
+ g_return_val_if_fail (PANGO_IS_HB_FONT (self), NULL);
+
+ if (n_features)
+ *n_features = self->n_features;
+
+ return self->features;
+}
+
+
/**
* pango_hb_font_get_variations:
* @self: a `PangoHbFont`
diff --git a/pango/pango-hbfont.h b/pango/pango-hbfont.h
index fe7f14d9..ec9eac7c 100644
--- a/pango/pango-hbfont.h
+++ b/pango/pango-hbfont.h
@@ -48,6 +48,9 @@ PangoHbFont * pango_hb_font_new_for_description (PangoHbFace
float dpi,
const PangoMatrix *ctm);
+PANGO_AVAILABLE_IN_ALL
+const hb_feature_t * pango_hb_font_get_features (PangoHbFont *self,
+ unsigned int *n_features);
PANGO_AVAILABLE_IN_ALL
const hb_variation_t * pango_hb_font_get_variations (PangoHbFont *self,
diff --git a/pango/pango-item.c b/pango/pango-item.c
index 952cab05..f5c9df85 100644
--- a/pango/pango-item.c
+++ b/pango/pango-item.c
@@ -277,7 +277,16 @@ pango_analysis_collect_features (const PangoAnalysis *analysis,
{
GSList *l;
- pango_font_get_features (analysis->font, features, length, num_features);
+ if (PANGO_IS_HB_FONT (analysis->font))
+ {
+ const hb_feature_t *font_features;
+ guint n_font_features;
+
+ font_features = pango_hb_font_get_features (PANGO_HB_FONT (analysis->font),
+ &n_font_features);
+ *num_features = MIN (length, n_font_features);
+ memcpy (features, font_features, sizeof (hb_feature_t) * *num_features);
+ }
for (l = analysis->extra_attrs; l && *num_features < length; l = l->next)
{
diff --git a/pango/serializer.c b/pango/serializer.c
index f9941faa..de8494fd 100644
--- a/pango/serializer.c
+++ b/pango/serializer.c
@@ -27,6 +27,7 @@
#include <pango/pango-font-private.h>
#include <pango/pango-line-private.h>
#include <pango/pango-hbface.h>
+#include <pango/pango-hbfont.h>
#include <pango/pango-attributes.h>
#include <pango/pango-attr-private.h>
#include <pango/pango-item-private.h>
@@ -553,7 +554,7 @@ add_font (GtkJsonPrinter *printer,
const char *data;
guint length;
const int *coords;
- hb_feature_t features[32];
+ const hb_feature_t *features;
PangoMatrix matrix;
gtk_json_printer_start_object (printer, member);
@@ -602,7 +603,8 @@ add_font (GtkJsonPrinter *printer,
}
length = 0;
- pango_font_get_features (font, features, G_N_ELEMENTS (features), &length);
+ if (PANGO_IS_HB_FONT (font))
+ features = pango_hb_font_get_features (PANGO_HB_FONT (font), &length);
if (length > 0)
{
gtk_json_printer_start_object (printer, "features");
diff --git a/tests/test-font.c b/tests/test-font.c
index f6b5b686..637dc367 100644
--- a/tests/test-font.c
+++ b/tests/test-font.c
@@ -321,7 +321,7 @@ test_roundtrip_small_caps (void)
PangoContext *context;
PangoFontDescription *desc, *desc2;
PangoFont *font;
- hb_feature_t features[32];
+ const hb_feature_t *features;
guint num = 0;
context = pango_context_new ();
@@ -333,7 +333,7 @@ test_roundtrip_small_caps (void)
desc2 = pango_font_describe (font);
num = 0;
- pango_font_get_features (font, features, G_N_ELEMENTS (features), &num);
+ features = pango_hb_font_get_features (PANGO_HB_FONT (font), &num);
g_assert_true (num == 1);
g_assert_true (features[0].tag == HB_TAG ('s', 'm', 'c', 'p'));
g_assert_true (features[0].value == 1);
@@ -353,7 +353,7 @@ test_roundtrip_small_caps (void)
desc2 = pango_font_describe (font);
num = 0;
- pango_font_get_features (font, features, G_N_ELEMENTS (features), &num);
+ features = pango_hb_font_get_features (PANGO_HB_FONT (font), &num);
g_assert_true (num == 2);
g_assert_true (features[0].tag == HB_TAG ('s', 'm', 'c', 'p'));
g_assert_true (features[0].value == 1);
@@ -374,7 +374,7 @@ test_roundtrip_small_caps (void)
desc2 = pango_font_describe (font);
num = 0;
- pango_font_get_features (font, features, G_N_ELEMENTS (features), &num);
+ features = pango_hb_font_get_features (PANGO_HB_FONT (font), &num);
g_assert_true (num == 1);
g_assert_true (features[0].tag == HB_TAG ('u', 'n', 'i', 'c'));
g_assert_true (features[0].value == 1);
diff --git a/tests/testhbfont.c b/tests/testhbfont.c
index 9fc6e62f..35f86234 100644
--- a/tests/testhbfont.c
+++ b/tests/testhbfont.c
@@ -190,7 +190,6 @@ test_hbfont_roundtrip (void)
PangoHbFace *face;
PangoHbFont *font;
PangoFontDescription *desc;
- hb_feature_t features[10];
unsigned int n_features;
path = g_test_build_filename (G_TEST_DIST, "fonts", "Cantarell-VF.otf", NULL);
@@ -201,7 +200,7 @@ test_hbfont_roundtrip (void)
font = pango_hb_font_new (face, 11 * PANGO_SCALE, NULL, 0, NULL, 0, PANGO_GRAVITY_AUTO, 96., NULL);
g_assert_true (PANGO_IS_HB_FONT (font));
g_assert_true (pango_font_get_face (PANGO_FONT (font)) == PANGO_FONT_FACE (face));
- pango_font_get_features (PANGO_FONT (font), features, G_N_ELEMENTS (features), &n_features);
+ pango_hb_font_get_features (PANGO_HB_FONT (font), &n_features);
g_assert_cmpint (n_features, ==, 0);
desc = pango_font_describe (PANGO_FONT (font));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]