forked from AuroraMiddleware/gtk
snapshot: Refactor text rendering
The code didn't change, it was just shuffled around to make the with_bounds() versions of the text rendering unnecessary and instead pass through the generic append_node() path.
This commit is contained in:
parent
e1570e9ebc
commit
0d119f81c8
@ -287,8 +287,8 @@ GDK_AVAILABLE_IN_ALL
|
|||||||
GskRenderNode * gsk_text_node_new (PangoFont *font,
|
GskRenderNode * gsk_text_node_new (PangoFont *font,
|
||||||
PangoGlyphString *glyphs,
|
PangoGlyphString *glyphs,
|
||||||
const GdkRGBA *color,
|
const GdkRGBA *color,
|
||||||
double x,
|
float x,
|
||||||
double y);
|
float y);
|
||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
const PangoFont * gsk_text_node_peek_font (GskRenderNode *node);
|
const PangoFont * gsk_text_node_peek_font (GskRenderNode *node);
|
||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
|
@ -4647,8 +4647,8 @@ GskRenderNode *
|
|||||||
gsk_text_node_new (PangoFont *font,
|
gsk_text_node_new (PangoFont *font,
|
||||||
PangoGlyphString *glyphs,
|
PangoGlyphString *glyphs,
|
||||||
const GdkRGBA *color,
|
const GdkRGBA *color,
|
||||||
double x,
|
float x,
|
||||||
double y)
|
float y)
|
||||||
{
|
{
|
||||||
GskTextNode *self;
|
GskTextNode *self;
|
||||||
PangoRectangle ink_rect;
|
PangoRectangle ink_rect;
|
||||||
@ -4660,42 +4660,6 @@ gsk_text_node_new (PangoFont *font,
|
|||||||
if (ink_rect.width == 0 || ink_rect.height == 0)
|
if (ink_rect.width == 0 || ink_rect.height == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
self = (GskTextNode *)gsk_text_node_new_with_bounds (font, glyphs, color, x, y,
|
|
||||||
&GRAPHENE_RECT_INIT (x,
|
|
||||||
y + ink_rect.y,
|
|
||||||
ink_rect.x + ink_rect.width,
|
|
||||||
ink_rect.height));
|
|
||||||
|
|
||||||
return &self->render_node;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gsk_text_node_new_with_bounds:
|
|
||||||
* @font: the #PangoFont containing the glyphs
|
|
||||||
* @glyphs: the #PangoGlyphString to render
|
|
||||||
* @color: the foreground color to render with
|
|
||||||
* @x: the x coordinate at which to put the baseline
|
|
||||||
* @y: the y coordinate at wihch to put the baseline
|
|
||||||
* @bounds: the node bounds
|
|
||||||
*
|
|
||||||
* Creates a render node that renders the given glyphs,
|
|
||||||
* Note that @color may not be used if the font contains
|
|
||||||
* color glyphs.
|
|
||||||
*
|
|
||||||
* This function will not do any text measuring, contrary to gsk_text_node_new().
|
|
||||||
*
|
|
||||||
* Returns: (nullable): a new text node, or %NULL
|
|
||||||
*/
|
|
||||||
GskRenderNode *
|
|
||||||
gsk_text_node_new_with_bounds (PangoFont *font,
|
|
||||||
PangoGlyphString *glyphs,
|
|
||||||
const GdkRGBA *color,
|
|
||||||
double x,
|
|
||||||
double y,
|
|
||||||
const graphene_rect_t *bounds)
|
|
||||||
{
|
|
||||||
GskTextNode *self;
|
|
||||||
|
|
||||||
self = (GskTextNode *) gsk_render_node_new (&GSK_TEXT_NODE_CLASS, sizeof (PangoGlyphInfo) * glyphs->num_glyphs);
|
self = (GskTextNode *) gsk_render_node_new (&GSK_TEXT_NODE_CLASS, sizeof (PangoGlyphInfo) * glyphs->num_glyphs);
|
||||||
|
|
||||||
self->font = g_object_ref (font);
|
self->font = g_object_ref (font);
|
||||||
@ -4705,7 +4669,11 @@ gsk_text_node_new_with_bounds (PangoFont *font,
|
|||||||
self->num_glyphs = glyphs->num_glyphs;
|
self->num_glyphs = glyphs->num_glyphs;
|
||||||
memcpy (self->glyphs, glyphs->glyphs, sizeof (PangoGlyphInfo) * glyphs->num_glyphs);
|
memcpy (self->glyphs, glyphs->glyphs, sizeof (PangoGlyphInfo) * glyphs->num_glyphs);
|
||||||
|
|
||||||
graphene_rect_init_from_rect (&self->render_node.bounds, bounds);
|
graphene_rect_init (&self->render_node.bounds,
|
||||||
|
x + ink_rect.x - 1,
|
||||||
|
y + ink_rect.y - 1,
|
||||||
|
ink_rect.width + 2,
|
||||||
|
ink_rect.height + 2);
|
||||||
|
|
||||||
return &self->render_node;
|
return &self->render_node;
|
||||||
}
|
}
|
||||||
|
@ -101,13 +101,6 @@ GskRenderNode * gsk_transform_node_new_with_category (GskRenderNode
|
|||||||
GskMatrixCategory category);
|
GskMatrixCategory category);
|
||||||
GskMatrixCategory gsk_transform_node_get_category (GskRenderNode *node);
|
GskMatrixCategory gsk_transform_node_get_category (GskRenderNode *node);
|
||||||
|
|
||||||
GskRenderNode * gsk_text_node_new_with_bounds (PangoFont *font,
|
|
||||||
PangoGlyphString *glyphs,
|
|
||||||
const GdkRGBA *color,
|
|
||||||
double x,
|
|
||||||
double y,
|
|
||||||
const graphene_rect_t *bounds);
|
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
@ -113,41 +113,16 @@ gsk_pango_renderer_show_text_glyphs (PangoRenderer *renderer,
|
|||||||
int y)
|
int y)
|
||||||
{
|
{
|
||||||
GskPangoRenderer *crenderer = (GskPangoRenderer *) (renderer);
|
GskPangoRenderer *crenderer = (GskPangoRenderer *) (renderer);
|
||||||
int x_offset, y_offset;
|
|
||||||
GskRenderNode *node;
|
|
||||||
GdkRGBA color;
|
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;
|
|
||||||
|
|
||||||
graphene_rect_init (&node_bounds,
|
|
||||||
(float)x/PANGO_SCALE - 1.0,
|
|
||||||
(float)y/PANGO_SCALE + ink_rect.y - 1.0,
|
|
||||||
ink_rect.x + ink_rect.width + 2.0,
|
|
||||||
ink_rect.height + 2.0);
|
|
||||||
|
|
||||||
gtk_snapshot_get_offset (crenderer->snapshot, &x_offset, &y_offset);
|
|
||||||
graphene_rect_offset (&node_bounds, x_offset, y_offset);
|
|
||||||
|
|
||||||
get_color (crenderer, PANGO_RENDER_PART_FOREGROUND, &color);
|
get_color (crenderer, PANGO_RENDER_PART_FOREGROUND, &color);
|
||||||
|
|
||||||
node = gsk_text_node_new_with_bounds (font,
|
gtk_snapshot_append_text (crenderer->snapshot,
|
||||||
glyphs,
|
font,
|
||||||
&color,
|
glyphs,
|
||||||
x_offset + (double)x/PANGO_SCALE,
|
&color,
|
||||||
y_offset + (double)y/PANGO_SCALE,
|
(float) x / PANGO_SCALE,
|
||||||
&node_bounds);
|
(float) y / PANGO_SCALE);
|
||||||
if (node == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
gtk_snapshot_append_node_internal (crenderer->snapshot, node);
|
|
||||||
gsk_render_node_unref (node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -606,6 +606,23 @@ gtk_snapshot_ensure_affine (GtkSnapshot *snapshot,
|
|||||||
*dx = *dy = 0;
|
*dx = *dy = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_snapshot_ensure_translate (GtkSnapshot *snapshot,
|
||||||
|
float *dx,
|
||||||
|
float *dy)
|
||||||
|
{
|
||||||
|
const GtkSnapshotState *current_state = gtk_snapshot_get_current_state (snapshot);
|
||||||
|
float scale_x, scale_y;
|
||||||
|
|
||||||
|
if (gtk_transform_to_affine (current_state->transform, &scale_x, &scale_y, dx, dy) &&
|
||||||
|
scale_x == 1.0f && scale_y == 1.0f)
|
||||||
|
return;
|
||||||
|
|
||||||
|
gtk_snapshot_autopush_transform (snapshot);
|
||||||
|
|
||||||
|
*dx = *dy = 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_snapshot_ensure_identity (GtkSnapshot *snapshot)
|
gtk_snapshot_ensure_identity (GtkSnapshot *snapshot)
|
||||||
{
|
{
|
||||||
@ -1463,6 +1480,31 @@ gtk_snapshot_render_layout (GtkSnapshot *snapshot,
|
|||||||
gtk_snapshot_offset (snapshot, -x, -y);
|
gtk_snapshot_offset (snapshot, -x, -y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gtk_snapshot_append_text (GtkSnapshot *snapshot,
|
||||||
|
PangoFont *font,
|
||||||
|
PangoGlyphString *glyphs,
|
||||||
|
const GdkRGBA *color,
|
||||||
|
float x,
|
||||||
|
float y)
|
||||||
|
{
|
||||||
|
GskRenderNode *node;
|
||||||
|
float dx, dy;
|
||||||
|
|
||||||
|
gtk_snapshot_ensure_translate (snapshot, &dx, &dy);
|
||||||
|
|
||||||
|
node = gsk_text_node_new (font,
|
||||||
|
glyphs,
|
||||||
|
color,
|
||||||
|
x + dx,
|
||||||
|
y + dy);
|
||||||
|
if (node == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
gtk_snapshot_append_node_internal (snapshot, node);
|
||||||
|
gsk_render_node_unref (node);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gtk_snapshot_append_linear_gradient:
|
* gtk_snapshot_append_linear_gradient:
|
||||||
* @snapshot: a #GtkSnapshot
|
* @snapshot: a #GtkSnapshot
|
||||||
|
@ -108,6 +108,12 @@ GtkSnapshot * gtk_snapshot_new_with_parent (GtkSnapshot
|
|||||||
void gtk_snapshot_push_transform_with_category (GtkSnapshot *snapshot,
|
void gtk_snapshot_push_transform_with_category (GtkSnapshot *snapshot,
|
||||||
const graphene_matrix_t*transform,
|
const graphene_matrix_t*transform,
|
||||||
GskMatrixCategory category);
|
GskMatrixCategory category);
|
||||||
|
void gtk_snapshot_append_text (GtkSnapshot *snapshot,
|
||||||
|
PangoFont *font,
|
||||||
|
PangoGlyphString *glyphs,
|
||||||
|
const GdkRGBA *color,
|
||||||
|
float x,
|
||||||
|
float y);
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GTK_SNAPSHOT_PRIVATE_H__ */
|
#endif /* __GTK_SNAPSHOT_PRIVATE_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user