[gtk/small-text-fixes: 2/2] gsk: Avoid cut-off glyphs with large scales
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/small-text-fixes: 2/2] gsk: Avoid cut-off glyphs with large scales
- Date: Wed, 1 Sep 2021 05:06:40 +0000 (UTC)
commit 18aaf41a7df77ea5ffa6e9b5f921135f68309ed9
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Aug 31 23:04:14 2021 -0400
gsk: Avoid cut-off glyphs with large scales
With large scales, I could observe the bottoms
of glyphs getting cut off on their way into the
glyph cache. Avoid that by adjusting their position.
gsk/ngl/gsknglglyphlibrary.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/gsk/ngl/gsknglglyphlibrary.c b/gsk/ngl/gsknglglyphlibrary.c
index 0fe94e05a5..4d5cdd0edd 100644
--- a/gsk/ngl/gsknglglyphlibrary.c
+++ b/gsk/ngl/gsknglglyphlibrary.c
@@ -162,11 +162,13 @@ static void
render_glyph (cairo_surface_t *surface,
const cairo_scaled_font_t *scaled_font,
const GskNglGlyphKey *key,
- const GskNglGlyphValue *value)
+ const GskNglGlyphValue *value,
+ double device_scale)
{
cairo_t *cr;
cairo_glyph_t glyph;
cairo_font_options_t *options;
+ cairo_text_extents_t extents;
g_assert (surface != NULL);
g_assert (scaled_font != NULL);
@@ -186,6 +188,13 @@ render_glyph (cairo_surface_t *surface,
glyph.x = 0.25 * key->xshift - value->ink_rect.x;
glyph.y = 0.25 * key->yshift - value->ink_rect.y;
+ cairo_glyph_extents (cr, &glyph, 1, &extents);
+
+ if (cairo_image_surface_get_width (surface)/device_scale < glyph.x + extents.x_bearing + extents.width)
+ glyph.x = cairo_image_surface_get_width (surface)/device_scale - extents.width - extents.x_bearing;
+ if (cairo_image_surface_get_height (surface)/device_scale < glyph.y + extents.y_bearing + extents.height)
+ glyph.y = cairo_image_surface_get_height (surface)/device_scale - extents.height - extents.y_bearing;
+
cairo_show_glyphs (cr, &glyph, 1);
cairo_destroy (cr);
@@ -229,7 +238,7 @@ gsk_ngl_glyph_library_upload_glyph (GskNglGlyphLibrary *self,
key->glyph);
surface = gsk_ngl_glyph_library_create_surface (self, stride, width, height, device_scale);
- render_glyph (surface, scaled_font, key, value);
+ render_glyph (surface, scaled_font, key, value, device_scale);
texture_id = GSK_NGL_TEXTURE_ATLAS_ENTRY_TEXTURE (value);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]