[gtk/matthiasc/color-profiles: 10/32] cairo: Use stem darkening for glyphs




commit eb8de621e4506aafa4f1f59cb48700f7828640c9
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Sep 30 10:04:31 2021 -0400

    cairo: Use stem darkening for glyphs
    
    This involves tweaking a freetype driver property
    directly, since cairo font options don't cover this.
    
    So the code is a bit ugly, but it does make text
    appear darker.

 gsk/gskrendernodeimpl.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
---
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index e2bafe8826..36d6105cc6 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -33,6 +33,14 @@
 
 #include <hb-ot.h>
 
+#ifdef HAVE_PANGOFT
+#include <pango/pangofc-font.h>
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_PARAMETER_TAGS_H
+#endif
+
+
 static inline void
 gsk_cairo_rectangle (cairo_t               *cr,
                      const graphene_rect_t *rect)
@@ -4377,12 +4385,22 @@ gsk_text_node_finalize (GskRenderNode *node)
   parent_class->finalize (node);
 }
 
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+
 static void
 gsk_text_node_draw (GskRenderNode *node,
                     cairo_t       *cr)
 {
   GskTextNode *self = (GskTextNode *) node;
   PangoGlyphString glyphs;
+#ifdef HAVE_PANGOFT
+  FT_Face face;
+  FT_Bool darken = 1;
+  FT_Parameter property = { FT_PARAM_TAG_STEM_DARKENING, &darken };
+
+  face = pango_fc_font_lock_face (PANGO_FC_FONT (self->font));
+  FT_Face_Properties (face, 1, &property);
+#endif
 
   glyphs.num_glyphs = self->num_glyphs;
   glyphs.glyphs = self->glyphs;
@@ -4395,8 +4413,14 @@ gsk_text_node_draw (GskRenderNode *node,
   pango_cairo_show_glyph_string (cr, self->font, &glyphs);
 
   cairo_restore (cr);
+
+#ifdef HAVE_PANGOFT
+  pango_fc_font_unlock_face (PANGO_FC_FONT (self->font));
+#endif
 }
 
+G_GNUC_END_IGNORE_DEPRECATIONS
+
 static void
 gsk_text_node_diff (GskRenderNode  *node1,
                     GskRenderNode  *node2,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]