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




commit 925b1937b192654a13512fcd87b017b6b662f6a2
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Sep 30 09:48:54 2021 -0400

    ngl: 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/ngl/gsknglglyphlibrary.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
---
diff --git a/gsk/ngl/gsknglglyphlibrary.c b/gsk/ngl/gsknglglyphlibrary.c
index 1e67bd098d..f5267a75be 100644
--- a/gsk/ngl/gsknglglyphlibrary.c
+++ b/gsk/ngl/gsknglglyphlibrary.c
@@ -29,6 +29,13 @@
 #include "gskngldriverprivate.h"
 #include "gsknglglyphlibraryprivate.h"
 
+#ifdef HAVE_PANGOFT
+#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 (GskNglGlyphLibrary, gsk_ngl_glyph_library, GSK_TYPE_GL_TEXTURE_LIBRARY)
@@ -162,16 +169,26 @@ gsk_ngl_glyph_library_create_surface (GskNglGlyphLibrary *self,
 
 static void
 render_glyph (cairo_surface_t           *surface,
-              const cairo_scaled_font_t *scaled_font,
+              cairo_scaled_font_t       *scaled_font,
               const GskNglGlyphKey      *key,
               const GskNglGlyphValue    *value)
 {
   cairo_t *cr;
   cairo_glyph_t glyph;
+#ifdef HAVE_PANGOFT
+  FT_Face face;
+  FT_Bool darken = 1;
+  FT_Parameter property = { FT_PARAM_TAG_STEM_DARKENING, &darken };
+#endif
 
   g_assert (surface != NULL);
   g_assert (scaled_font != NULL);
 
+#ifdef HAVE_PANGOFT
+  face = cairo_ft_scaled_font_lock_face (scaled_font);
+  FT_Face_Properties (face, 1, &property);
+#endif
+
   cr = cairo_create (surface);
   cairo_set_scaled_font (cr, scaled_font);
   cairo_set_source_rgba (cr, 1, 1, 1, 1);
@@ -184,6 +201,10 @@ render_glyph (cairo_surface_t           *surface,
   cairo_destroy (cr);
 
   cairo_surface_flush (surface);
+
+#ifdef HAVE_PANGOFT
+  cairo_ft_scaled_font_unlock_face (scaled_font);
+#endif
 }
 
 static void


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