[gtk/matthiasc/color-profile-rebased: 32/47] gsk: Use stem darkening for glyphs




commit 51db90368a92f8e6bcd69fd082c45b96e9a7f407
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun May 8 13:38:36 2022 -0400

    gsk: 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/gl/gskglglyphlibrary.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
---
diff --git a/gsk/gl/gskglglyphlibrary.c b/gsk/gl/gskglglyphlibrary.c
index e86effe643..84cf07e25e 100644
--- a/gsk/gl/gskglglyphlibrary.c
+++ b/gsk/gl/gskglglyphlibrary.c
@@ -29,6 +29,14 @@
 #include "gskgldriverprivate.h"
 #include "gskglglyphlibraryprivate.h"
 
+#ifdef HAVE_PANGOFT
+#include <pango/pangofc-font.h>
+#include <cairo-ft.h>
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_PARAMETER_TAGS_H
+#endif
+
 #define MAX_GLYPH_SIZE 128
 
 G_DEFINE_TYPE (GskGLGlyphLibrary, gsk_gl_glyph_library, GSK_TYPE_GL_TEXTURE_LIBRARY)
@@ -210,6 +218,8 @@ gsk_gl_glyph_library_create_surface (GskGLGlyphLibrary *self,
   return surface;
 }
 
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+
 static void
 render_glyph (cairo_surface_t           *surface,
               const GskGLGlyphKey       *key,
@@ -218,6 +228,14 @@ render_glyph (cairo_surface_t           *surface,
   cairo_t *cr;
   PangoGlyphString glyph_string;
   PangoGlyphInfo glyph_info;
+#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 (key->font));
+  FT_Face_Properties (face, 1, &property);
+#endif
 
   g_assert (surface != NULL);
 
@@ -236,8 +254,14 @@ render_glyph (cairo_surface_t           *surface,
   cairo_destroy (cr);
 
   cairo_surface_flush (surface);
+
+#ifdef HAVE_PANGOFT
+  pango_fc_font_unlock_face (PANGO_FC_FONT (key->font));
+#endif
 }
 
+G_GNUC_END_IGNORE_DEPRECATIONS
+
 static void
 gsk_gl_glyph_library_upload_glyph (GskGLGlyphLibrary     *self,
                                    const GskGLGlyphKey   *key,


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