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




commit ecf88c0d2b97bf8fa464a81398eb1d721ca12bcf
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 fa0bdb661e..3e65f05dba 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -32,6 +32,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)
@@ -4358,12 +4366,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;
@@ -4376,8 +4394,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]