diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-03-30 11:15:13 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-03-30 11:15:13 +0000 |
commit | b77e05ce375f60a7f470a9a11f2c22a27927a44e (patch) | |
tree | 959ec6c05832c9d9dc93d642a7729fa2969398a6 | |
parent | ef544a8c3b604b5ab695a36e3978118bb3f46eee (diff) | |
parent | ba4e66d189a014e097be555196de178194168113 (diff) | |
download | gtk+-b77e05ce375f60a7f470a9a11f2c22a27927a44e.tar.gz |
Merge branch 'ngl-text-tweaks' into 'master'
Ngl text tweaks
See merge request GNOME/gtk!3367
-rw-r--r-- | NEWS | 9 | ||||
-rw-r--r-- | gsk/gskrendernodeimpl.c | 10 | ||||
-rw-r--r-- | gsk/ngl/gsknglglyphlibraryprivate.h | 27 | ||||
-rw-r--r-- | gsk/ngl/gsknglrenderjob.c | 60 |
4 files changed, 66 insertions, 40 deletions
@@ -1,9 +1,11 @@ Overview of Changes in 4.2.0 ============================ -* Filechooser: Make the location entry work again +* GtkFileChooser: Make the location entry work again -* Label: Fix tooltips on links +* GtlLabel: Fix tooltips on links + +* GtkTextView: Make scrolling work better with renderers * X11: - Fix damage handling @@ -37,9 +39,12 @@ Overview of Changes in 4.2.0 - Include generated docs * Translation updates: + Hebrew Hungarian Italian Polish + Portuguese + Swedish Ukrainian diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c index d611977acc..640c792268 100644 --- a/gsk/gskrendernodeimpl.c +++ b/gsk/gskrendernodeimpl.c @@ -4435,9 +4435,15 @@ gsk_text_node_new (PangoFont *font, self->has_color_glyphs = font_has_color_glyphs (font); self->color = *color; self->offset = *offset; - self->num_glyphs = glyphs->num_glyphs; self->glyphs = g_malloc_n (glyphs->num_glyphs, sizeof (PangoGlyphInfo)); - memcpy (self->glyphs, glyphs->glyphs, glyphs->num_glyphs * sizeof (PangoGlyphInfo)); + + /* skip empty glyphs */ + self->num_glyphs = 0; + for (int i = 0; i < glyphs->num_glyphs; i++) + { + if (glyphs->glyphs[i].glyph != PANGO_GLYPH_EMPTY) + self->glyphs[self->num_glyphs++] = glyphs->glyphs[i]; + } graphene_rect_init (&node->bounds, offset->x + ink_rect.x - 1, diff --git a/gsk/ngl/gsknglglyphlibraryprivate.h b/gsk/ngl/gsknglglyphlibraryprivate.h index 5bf240e5e1..a9f099c0b5 100644 --- a/gsk/ngl/gsknglglyphlibraryprivate.h +++ b/gsk/ngl/gsknglglyphlibraryprivate.h @@ -33,9 +33,9 @@ typedef struct _GskNglGlyphKey { PangoFont *font; PangoGlyph glyph; - guint xshift : 3; - guint yshift : 3; - guint scale : 26; /* times 1024 */ + guint xshift : 2; + guint yshift : 2; + guint scale : 28; /* times 1024 */ } GskNglGlyphKey; typedef struct _GskNglGlyphValue @@ -68,24 +68,7 @@ gboolean gsk_ngl_glyph_library_add (GskNglGlyphLibrary *self, GskNglGlyphKey *key, const GskNglGlyphValue **out_value); -static inline int -gsk_ngl_glyph_key_phase (float value) -{ - return floorf (4 * (value + 0.125)) - 4 * floorf (value + 0.125); -} - -static inline void -gsk_ngl_glyph_key_set_glyph_and_shift (GskNglGlyphKey *key, - PangoGlyph glyph, - float x, - float y) -{ - key->glyph = glyph; - key->xshift = gsk_ngl_glyph_key_phase (x); - key->yshift = gsk_ngl_glyph_key_phase (y); -} - -static inline gboolean +static inline guint gsk_ngl_glyph_library_lookup_or_add (GskNglGlyphLibrary *self, const GskNglGlyphKey *key, const GskNglGlyphValue **out_value) @@ -112,7 +95,7 @@ gsk_ngl_glyph_library_lookup_or_add (GskNglGlyphLibrary *self, self->front[front_index].value = *out_value; } - return GSK_NGL_TEXTURE_ATLAS_ENTRY_TEXTURE (*out_value) != 0; + return GSK_NGL_TEXTURE_ATLAS_ENTRY_TEXTURE (*out_value); } G_END_DECLS diff --git a/gsk/ngl/gsknglrenderjob.c b/gsk/ngl/gsknglrenderjob.c index 324b3d29f4..5dfd78b5c8 100644 --- a/gsk/ngl/gsknglrenderjob.c +++ b/gsk/ngl/gsknglrenderjob.c @@ -2639,6 +2639,30 @@ gsk_ngl_render_job_visit_opacity_node (GskNglRenderJob *job, } } +static inline int +compute_phase_and_pos (float value, float *pos) +{ + float v; + + *pos = floorf (value); + + v = value - *pos; + + if (v < 0.125) + return 0; + else if (v < 0.375) + return 1; + else if (v < 0.625) + return 2; + else if (v < 0.875) + return 3; + else + { + *pos += 1; + return 0; + } +} + static inline void gsk_ngl_render_job_visit_text_node (GskNglRenderJob *job, const GskRenderNode *node, @@ -2662,6 +2686,8 @@ gsk_ngl_render_job_visit_text_node (GskNglRenderJob *job, GdkRGBA c; const PangoGlyphInfo *gi; guint i; + int yshift; + float ypos; if (num_glyphs == 0) return; @@ -2677,6 +2703,8 @@ gsk_ngl_render_job_visit_text_node (GskNglRenderJob *job, lookup.font = (PangoFont *)font; lookup.scale = (guint) (text_scale * 1024); + yshift = compute_phase_and_pos (y, &ypos); + gsk_ngl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, coloring)); batch = gsk_ngl_command_queue_get_batch (job->command_queue); @@ -2692,23 +2720,30 @@ gsk_ngl_render_job_visit_text_node (GskNglRenderJob *job, float cy; guint texture_id; - if G_UNLIKELY (gi->glyph == PANGO_GLYPH_EMPTY) - continue; + lookup.glyph = gi->glyph; cx = (float)(x_position + gi->geometry.x_offset) / PANGO_SCALE; - cy = (float)(gi->geometry.y_offset) / PANGO_SCALE; + lookup.xshift = compute_phase_and_pos (x + cx, &cx); - gsk_ngl_glyph_key_set_glyph_and_shift (&lookup, gi->glyph, x + cx, y + cy); + if G_UNLIKELY (gi->geometry.y_offset != 0) + { + cy = (float)(gi->geometry.y_offset) / PANGO_SCALE; + lookup.yshift = compute_phase_and_pos (y + cy, &cy); + } + else + { + lookup.yshift = yshift; + cy = ypos; + } - if G_UNLIKELY (!gsk_ngl_glyph_library_lookup_or_add (library, &lookup, &glyph)) - goto next; + x_position += gi->geometry.width; - texture_id = GSK_NGL_TEXTURE_ATLAS_ENTRY_TEXTURE (glyph); + texture_id = gsk_ngl_glyph_library_lookup_or_add (library, &lookup, &glyph); + if G_UNLIKELY (texture_id == 0) + continue; if G_UNLIKELY (last_texture != texture_id) { - g_assert (texture_id > 0); - if G_LIKELY (last_texture != 0) { guint vbo_offset = batch->draw.vbo_offset + batch->draw.vbo_count; @@ -2736,8 +2771,8 @@ gsk_ngl_render_job_visit_text_node (GskNglRenderJob *job, tx2 = glyph->entry.area.x2; ty2 = glyph->entry.area.y2; - glyph_x = floorf (x + cx + 0.125) + glyph->ink_rect.x; - glyph_y = floorf (y + cy + 0.125) + glyph->ink_rect.y; + glyph_x = cx + glyph->ink_rect.x; + glyph_y = cy + glyph->ink_rect.y; glyph_x2 = glyph_x + glyph->ink_rect.width; glyph_y2 = glyph_y + glyph->ink_rect.height; @@ -2751,9 +2786,6 @@ gsk_ngl_render_job_visit_text_node (GskNglRenderJob *job, batch->draw.vbo_count += GSK_NGL_N_VERTICES; used++; - -next: - x_position += gi->geometry.width; } if (used != num_glyphs) |