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 better, in particular at small sizes. See https://freetype.org/freetype2/docs/hinting/text-rendering-general.html
This commit is contained in:
@@ -48,6 +48,13 @@
|
||||
#endif
|
||||
#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
|
||||
|
||||
/* for oversized image fallback - we use a smaller size than Cairo actually
|
||||
* allows to avoid rounding errors in Cairo */
|
||||
#define MAX_CAIRO_IMAGE_WIDTH 16384
|
||||
@@ -5769,6 +5776,16 @@ gsk_text_node_draw (GskRenderNode *node,
|
||||
{
|
||||
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 };
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
face = pango_fc_font_lock_face (PANGO_FC_FONT (self->font));
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
FT_Face_Properties (face, 1, &property);
|
||||
#endif
|
||||
|
||||
glyphs.num_glyphs = self->num_glyphs;
|
||||
glyphs.glyphs = self->glyphs;
|
||||
@@ -5781,6 +5798,12 @@ gsk_text_node_draw (GskRenderNode *node,
|
||||
pango_cairo_show_glyph_string (cr, self->font, &glyphs);
|
||||
|
||||
cairo_restore (cr);
|
||||
|
||||
#ifdef HAVE_PANGOFT
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
pango_fc_font_unlock_face (PANGO_FC_FONT (self->font));
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user