[gtk/matthiasc/color-profile-rebased: 7/22] cairo: Use stem darkening for glyphs




commit 8973c9fda52b5cbaf114d526a9697ec43d35803d
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun May 8 13:41:14 2022 -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 | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
---
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index 99ae7493b8..38f685cc51 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -33,6 +33,13 @@
 
 #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
+
 /* maximal number of rectangles we keep in a diff region before we throw
  * the towel and just use the bounding box of the parent node.
  * Meant to avoid performance corner cases.
@@ -4428,12 +4435,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;
@@ -4446,8 +4463,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]