forked from AuroraMiddleware/gtk
gskpango: Don't create text nodes for clipped text
Measure the text here directly and check if the created node bounds will be clipped away before even creating the text node.
This commit is contained in:
parent
2d50d9ebe6
commit
8a062f4f9a
@ -115,11 +115,43 @@ gsk_pango_renderer_show_text_glyphs (PangoRenderer *renderer,
|
||||
int x_offset, y_offset;
|
||||
GskRenderNode *node;
|
||||
GdkRGBA color;
|
||||
graphene_rect_t node_bounds;
|
||||
PangoRectangle ink_rect;
|
||||
|
||||
pango_glyph_string_extents (glyphs, font, &ink_rect, NULL);
|
||||
pango_extents_to_pixels (&ink_rect, NULL);
|
||||
|
||||
/* Don't create empty nodes */
|
||||
if (ink_rect.width == 0 || ink_rect.height == 0)
|
||||
return;
|
||||
|
||||
gtk_snapshot_get_offset (crenderer->snapshot, &x_offset, &y_offset);
|
||||
|
||||
graphene_rect_init (&node_bounds,
|
||||
x_offset + (float)x/PANGO_SCALE,
|
||||
y_offset + (float)y/PANGO_SCALE + ink_rect.y,
|
||||
ink_rect.x + ink_rect.width,
|
||||
ink_rect.height);
|
||||
|
||||
/* Remove the snapshot offset from the position here again since
|
||||
* gtk_snapshot_clips_rect will apply it to the given rect. */
|
||||
if (gtk_snapshot_clips_rect (crenderer->snapshot,
|
||||
&(cairo_rectangle_int_t){
|
||||
node_bounds.origin.x - x_offset,
|
||||
node_bounds.origin.y - y_offset,
|
||||
ceil (node_bounds.size.width),
|
||||
ceil (node_bounds.size.height)
|
||||
}))
|
||||
return;
|
||||
|
||||
get_color (crenderer, PANGO_RENDER_PART_FOREGROUND, &color);
|
||||
|
||||
node = gsk_text_node_new (font, glyphs, &color, x_offset + (double)x/PANGO_SCALE, y_offset + (double)y/PANGO_SCALE);
|
||||
node = gsk_text_node_new_with_bounds (font,
|
||||
glyphs,
|
||||
&color,
|
||||
x_offset + (double)x/PANGO_SCALE,
|
||||
y_offset + (double)y/PANGO_SCALE,
|
||||
&node_bounds);
|
||||
if (node == NULL)
|
||||
return;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user