[gtk/small-text-fixes: 1/4] gsk: Add font options to text nodes
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/small-text-fixes: 1/4] gsk: Add font options to text nodes
- Date: Fri, 3 Sep 2021 16:07:09 +0000 (UTC)
commit da810e6ddb8b4185680c63bfd3336ae9b6e57e25
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Sep 3 07:15:52 2021 -0400
gsk: Add font options to text nodes
Since font options affect how the glyphs get rendered,
we need to pass the font options down from the gtk level
to where the glyph cache is populated.
Add a new gsk_text_node_new_full api that takes a
cairo_font_options_t in addition to the other parameters.
gsk/gskrendernode.h | 13 ++++++
gsk/gskrendernodeimpl.c | 122 ++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 115 insertions(+), 20 deletions(-)
---
diff --git a/gsk/gskrendernode.h b/gsk/gskrendernode.h
index c420633a91..39fc403119 100644
--- a/gsk/gskrendernode.h
+++ b/gsk/gskrendernode.h
@@ -492,6 +492,19 @@ GskRenderNode * gsk_text_node_new (PangoFont
PangoGlyphString *glyphs,
const GdkRGBA *color,
const graphene_point_t *offset);
+GDK_AVAILABLE_IN_4_6
+GskRenderNode * gsk_text_node_new_full (const cairo_font_options_t *options,
+ PangoFont *font,
+ PangoGlyphString *glyphs,
+ const GdkRGBA *color,
+ const graphene_point_t *offset);
+
+GDK_AVAILABLE_IN_4_6
+gboolean gsk_text_node_get_hint_metrics (const GskRenderNode *node) G_GNUC_PURE;
+GDK_AVAILABLE_IN_4_6
+gboolean gsk_text_node_get_antialias (const GskRenderNode *node) G_GNUC_PURE;
+GDK_AVAILABLE_IN_4_6
+cairo_hint_style_t gsk_text_node_get_hint_style (const GskRenderNode *node) G_GNUC_PURE;
GDK_AVAILABLE_IN_ALL
PangoFont * gsk_text_node_get_font (const GskRenderNode *node) G_GNUC_PURE;
GDK_AVAILABLE_IN_ALL
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index 30ef0ff38b..7cc1ebc58b 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -4336,7 +4336,10 @@ struct _GskTextNode
GskRenderNode render_node;
PangoFont *font;
- gboolean has_color_glyphs;
+ guint has_color_glyphs : 1;
+ guint hint_metrics : 1;
+ guint antialias : 1;
+ guint hint_style : 3;
GdkRGBA color;
graphene_point_t offset;
@@ -4363,6 +4366,7 @@ gsk_text_node_draw (GskRenderNode *node,
{
GskTextNode *self = (GskTextNode *) node;
PangoGlyphString glyphs;
+ cairo_font_options_t *options;
glyphs.num_glyphs = self->num_glyphs;
glyphs.glyphs = self->glyphs;
@@ -4370,6 +4374,13 @@ gsk_text_node_draw (GskRenderNode *node,
cairo_save (cr);
+ options = cairo_font_options_create ();
+ cairo_font_options_set_hint_metrics (options, self->hint_metrics ? CAIRO_HINT_METRICS_ON :
CAIRO_HINT_METRICS_OFF);
+ cairo_font_options_set_antialias (options, self->antialias ? CAIRO_ANTIALIAS_GRAY : CAIRO_ANTIALIAS_NONE);
+ cairo_font_options_set_hint_style (options, self->hint_style);
+ cairo_set_font_options (cr, options);
+ cairo_font_options_destroy (options);
+
gdk_cairo_set_source_rgba (cr, &self->color);
cairo_translate (cr, self->offset.x, self->offset.y);
pango_cairo_show_glyph_string (cr, self->font, &glyphs);
@@ -4424,25 +4435,12 @@ gsk_text_node_diff (GskRenderNode *node1,
gsk_render_node_diff_impossible (node1, node2, region);
}
-/**
- * gsk_text_node_new:
- * @font: the `PangoFont` containing the glyphs
- * @glyphs: the `PangoGlyphString` to render
- * @color: the foreground color to render with
- * @offset: offset of the baseline
- *
- * Creates a render node that renders the given glyphs.
- *
- * Note that @color may not be used if the font contains
- * color glyphs.
- *
- * Returns: (nullable) (transfer full) (type GskTextNode): a new `GskRenderNode`
- */
-GskRenderNode *
-gsk_text_node_new (PangoFont *font,
- PangoGlyphString *glyphs,
- const GdkRGBA *color,
- const graphene_point_t *offset)
+static GskRenderNode *
+gsk_text_node_new_internal (const cairo_font_options_t *options,
+ PangoFont *font,
+ PangoGlyphString *glyphs,
+ const GdkRGBA *color,
+ const graphene_point_t *offset)
{
GskTextNode *self;
GskRenderNode *node;
@@ -4464,6 +4462,16 @@ gsk_text_node_new (PangoFont *font,
self->color = *color;
self->offset = *offset;
self->has_color_glyphs = FALSE;
+ self->antialias = TRUE;
+ self->hint_style = CAIRO_HINT_STYLE_NONE;
+ self->hint_metrics = FALSE;
+
+ if (options)
+ {
+ self->antialias = cairo_font_options_get_antialias (options) != CAIRO_ANTIALIAS_NONE;
+ self->hint_metrics = cairo_font_options_get_hint_metrics (options) == CAIRO_HINT_METRICS_ON;
+ self->hint_style = cairo_font_options_get_hint_style (options);
+ }
glyph_infos = g_malloc_n (glyphs->num_glyphs, sizeof (PangoGlyphInfo));
@@ -4494,6 +4502,80 @@ gsk_text_node_new (PangoFont *font,
return node;
}
+/**
+ * gsk_text_node_new_full:
+ * @options: `cairo_font_options_t` to render with
+ * @font: the `PangoFont` containing the glyphs
+ * @glyphs: the `PangoGlyphString` to render
+ * @color: the foreground color to render with
+ * @offset: offset of the baseline
+ *
+ * Creates a render node that renders the given glyphs.
+ *
+ * Note that @color may not be used if the font contains
+ * color glyphs.
+ *
+ * Returns: (nullable) (transfer full) (type GskTextNode): a new `GskRenderNode`
+ *
+ * Since: 4.6
+ */
+GskRenderNode *
+gsk_text_node_new_full (const cairo_font_options_t *options,
+ PangoFont *font,
+ PangoGlyphString *glyphs,
+ const GdkRGBA *color,
+ const graphene_point_t *offset)
+{
+ return gsk_text_node_new_internal (options, font, glyphs, color, offset);
+}
+
+/**
+ * gsk_text_node_new:
+ * @font: the `PangoFont` containing the glyphs
+ * @glyphs: the `PangoGlyphString` to render
+ * @color: the foreground color to render with
+ * @offset: offset of the baseline
+ *
+ * Creates a render node that renders the given glyphs.
+ *
+ * Note that @color may not be used if the font contains
+ * color glyphs.
+ *
+ * Returns: (nullable) (transfer full) (type GskTextNode): a new `GskRenderNode`
+ */
+GskRenderNode *
+gsk_text_node_new (PangoFont *font,
+ PangoGlyphString *glyphs,
+ const GdkRGBA *color,
+ const graphene_point_t *offset)
+{
+ return gsk_text_node_new_internal (NULL, font, glyphs, color, offset);
+}
+
+gboolean
+gsk_text_node_get_hint_metrics (const GskRenderNode *node)
+{
+ const GskTextNode *self = (const GskTextNode *) node;
+
+ return self->hint_metrics;
+}
+
+gboolean
+gsk_text_node_get_antialias (const GskRenderNode *node)
+{
+ const GskTextNode *self = (const GskTextNode *) node;
+
+ return self->antialias;
+}
+
+cairo_hint_style_t
+gsk_text_node_get_hint_style (const GskRenderNode *node)
+{
+ const GskTextNode *self = (const GskTextNode *) node;
+
+ return self->hint_style;
+}
+
/**
* gsk_text_node_get_color:
* @node: (type GskTextNode): a text `GskRenderNode`
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]