[gtk+/wip/matthiasc/gskpango] One more attempt



commit 6faf70af2365bc4ac383c9b0d1989782692a9feb
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Aug 31 15:42:38 2017 -0400

    One more attempt

 gsk/gskrendernode.h     |    4 +++-
 gsk/gskrendernodeimpl.c |   22 +++++++++++++++++-----
 gtk/gskpango.c          |    2 +-
 3 files changed, 21 insertions(+), 7 deletions(-)
---
diff --git a/gsk/gskrendernode.h b/gsk/gskrendernode.h
index a1b9b2a..e8e3379 100644
--- a/gsk/gskrendernode.h
+++ b/gsk/gskrendernode.h
@@ -177,7 +177,9 @@ GskRenderNode *         gsk_cross_fade_node_new                 (GskRenderNode
 GDK_AVAILABLE_IN_3_92
 GskRenderNode *         gsk_text_node_new                       (PangoFont        *font,
                                                                  PangoGlyphString *glyphs,
-                                                                 const GdkRGBA    *color);
+                                                                 const GdkRGBA    *color,
+                                                                 int               x_offset,
+                                                                 int               y_offset);
 
 GDK_AVAILABLE_IN_3_90
 void                    gsk_render_node_set_scaling_filters     (GskRenderNode *node,
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index cb1f080..c9a1334 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -3812,6 +3812,8 @@ struct _GskTextNode
   PangoFont *font;
   PangoGlyphString *glyphs;
   GdkRGBA color;
+  int translate_x;
+  int translate_y;
 };
 
 static void
@@ -3849,9 +3851,13 @@ gsk_text_node_draw (GskRenderNode *node,
   PangoFontDescription *desc;
   char *s, *c;
 
+  cairo_save (cr);
+
+  cairo_translate (cr, self->translate_x, self->translate_y);
+
   gdk_cairo_set_source_rgba (cr, &self->color);
   if (!_pango_cairo_font_install (self->font, cr))
-    return;
+    goto done;
 
 #if 0
   desc = pango_font_describe (self->font);
@@ -3900,6 +3906,9 @@ gsk_text_node_draw (GskRenderNode *node,
   cairo_show_glyphs (cr, cairo_glyphs, count);
 
   g_free (cairo_glyphs);
+
+done:
+  cairo_restore (cr);
 }
 
 #define GSK_TEXT_NODE_VARIANT_TYPE "(sdddda(uiiii))"
@@ -3977,7 +3986,7 @@ gsk_text_node_deserialize (GVariant  *variant,
       i++;
     }
 
-  result = gsk_text_node_new (font, glyphs, &color); /* FIXME: Avoid copying glyphs */
+  result = gsk_text_node_new (font, glyphs, &color, 0, 0); /* FIXME: Avoid copying glyphs */
 
   pango_glyph_string_free (glyphs);
   pango_font_description_free (desc);
@@ -3998,7 +4007,9 @@ static const GskRenderNodeClass GSK_TEXT_NODE_CLASS = {
 GskRenderNode *
 gsk_text_node_new (PangoFont        *font,
                    PangoGlyphString *glyphs,
-                   const GdkRGBA    *color)
+                   const GdkRGBA    *color,
+                   int               translate_x,
+                   int               translate_y)
 {
   GskTextNode *self;
   PangoRectangle ink_rect;
@@ -4008,12 +4019,13 @@ gsk_text_node_new (PangoFont        *font,
   self->font = g_object_ref (font);
   self->glyphs = pango_glyph_string_copy (glyphs);
   self->color = *color;
+  self->translate_x = translate_x;
+  self->translate_y = translate_y;
 
   pango_glyph_string_extents (glyphs, font, &ink_rect, NULL);
   pango_extents_to_pixels (&ink_rect, NULL);
 
-g_print ("glyphs ink rect: %d %d %d %d\n",  ink_rect.x, ink_rect.y, ink_rect.width, ink_rect.height);
-  graphene_rect_init (&self->render_node.bounds, ink_rect.x, ink_rect.y, ink_rect.width, ink_rect.height);
+  graphene_rect_init (&self->render_node.bounds, translate_x + ink_rect.x, translate_y + ink_rect.y, 
ink_rect.width, ink_rect.height);
 
   return &self->render_node;
 }
diff --git a/gtk/gskpango.c b/gtk/gskpango.c
index ebef83d..eefaff3 100644
--- a/gtk/gskpango.c
+++ b/gtk/gskpango.c
@@ -164,7 +164,7 @@ gsk_pango_renderer_show_text_glyphs (PangoRenderer        *renderer,
   gtk_snapshot_offset (crenderer->snapshot, base_x, base_y);
 
   /* FIXME: need to filter out unknown glyphs */
-  node = gsk_text_node_new (font, glyphs, crenderer->fg_color);
+  node = gsk_text_node_new (font, glyphs, crenderer->fg_color, base_x, base_y);
   snprintf (name, sizeof (name), "Glyphs<%d>", glyphs->num_glyphs);
   gsk_render_node_set_name (node, name);
   gtk_snapshot_append_node (crenderer->snapshot, node);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]