[gtk/small-text-fixes] 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] gsk: Avoid cut-off glyphs with large scales
- Date: Wed, 1 Sep 2021 18:17:22 +0000 (UTC)
commit 46a8f4d67e1a2893936a48f95062989faccda3ed
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 | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/gsk/ngl/gsknglglyphlibrary.c b/gsk/ngl/gsknglglyphlibrary.c
index 0fe94e05a5..4a29ecbae4 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,14 @@ 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);
+
+ /* FIXME: this should not happen. But it does, with large text sizes. */
+ 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 +239,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]