[RFC Patch] renderer: Add draw_layout vfunc

2010-10-25 Thread Robert Bragg
Hi,

I'm hoping to get some feedback about an experimental addition I made to
the PangoRendererClass vtable which gives renderers more contextual
information when drawing layouts. This adds a draw_layout vfunc which
allows a backend to potentially cache state with a user's layout so when
the same layout is drawn multiple times it may be optimized for
subsequent drawing.

For example; Cogl - the 3D graphics API used by Clutter - implements a
custom renderer which can cache the geometry of a layout in a vertex
buffer which can be mapped into the GPU the first time it is used.  Then
for subsequent draws we only need to bind the glyph cache texture and
re-draw from that existing vertex buffer, avoiding repeatedly processing
and uploading/mapping that vertex data.

Without something like this Cogl needs a cogl_pango_render_layout
function to wrap calls to pango_renderer_draw_layout so it can check and
initialize private state associated with the layout but with this change
that wrapper is no longer necessary and users can instead use the
pristine pango API to draw layouts using Cogl.

An example use of this new vfunc can be found in the
wip/cogl-pango-draw-layout branch in the clutter repo:
git://git.clutter-project.org/clutter.git

kind regards,
- Robert

---
 pango/pango-renderer.c |   61 +--
 pango/pango-renderer.h |6 -
 2 files changed, 43 insertions(+), 24 deletions(-)

diff --git a/pango/pango-renderer.c b/pango/pango-renderer.c
index db75446..6d5c0f8 100644
--- a/pango/pango-renderer.c
+++ b/pango/pango-renderer.c
@@ -59,6 +59,11 @@ struct _PangoRendererPrivate
 };
 
 static void pango_renderer_finalize (GObject  
*gobject);
+static void pango_renderer_default_draw_layout (PangoRenderer *renderer,
+PangoLayout   *layout,
+intx,
+inty);
+
 static void pango_renderer_default_draw_glyphs  (PangoRenderer
*renderer,
 PangoFont*font,
 PangoGlyphString 
*glyphs,
@@ -115,6 +120,7 @@ pango_renderer_class_init (PangoRendererClass *klass)
 
   parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
 
+  klass-draw_layout = pango_renderer_default_draw_layout;
   klass-draw_glyphs = pango_renderer_default_draw_glyphs;
   klass-draw_glyph_item = pango_renderer_default_draw_glyph_item;
   klass-draw_rectangle = pango_renderer_default_draw_rectangle;
@@ -146,6 +152,37 @@ pango_renderer_finalize (GObject *gobject)
   parent_class-finalize (gobject);
 }
 
+static void
+pango_renderer_default_draw_layout (PangoRenderer *renderer,
+   PangoLayout   *layout,
+   intx,
+   inty)
+{
+  PangoLayoutIter *iter;
+
+  iter = pango_layout_get_iter (layout);
+
+  do
+{
+  PangoRectangle   logical_rect;
+  PangoLayoutLine *line;
+  int  baseline;
+
+  line = pango_layout_iter_get_line_readonly (iter);
+
+  pango_layout_iter_get_line_extents (iter, NULL, logical_rect);
+  baseline = pango_layout_iter_get_baseline (iter);
+
+  pango_renderer_draw_layout_line (renderer,
+  line,
+  x + logical_rect.x,
+  y + baseline);
+}
+  while (pango_layout_iter_next_line (iter));
+
+  pango_layout_iter_free (iter);
+}
+
 /**
  * pango_renderer_draw_layout:
  * @renderer: a #PangoRenderer
@@ -165,8 +202,6 @@ pango_renderer_draw_layout (PangoRenderer*renderer,
int   x,
int   y)
 {
-  PangoLayoutIter *iter;
-
   g_return_if_fail (PANGO_IS_RENDERER (renderer));
   g_return_if_fail (PANGO_IS_LAYOUT (layout));
 
@@ -182,27 +217,7 @@ pango_renderer_draw_layout (PangoRenderer*renderer,
 
   pango_renderer_activate (renderer);
 
-  iter = pango_layout_get_iter (layout);
-
-  do
-{
-  PangoRectangle   logical_rect;
-  PangoLayoutLine *line;
-  int  baseline;
-
-  line = pango_layout_iter_get_line_readonly (iter);
-
-  pango_layout_iter_get_line_extents (iter, NULL, logical_rect);
-  baseline = pango_layout_iter_get_baseline (iter);
-
-  pango_renderer_draw_layout_line (renderer,
-  line,
-  x + logical_rect.x,
-  y + baseline);
-}
-  while (pango_layout_iter_next_line (iter));
-
-  pango_layout_iter_free (iter);
+  PANGO_RENDERER_GET_CLASS (renderer)-draw_layout (renderer, layout, x, y);
 
   pango_renderer_deactivate (renderer);
 }
diff --git 

re: Private license (non-LGPL) for Pango ??

2010-10-25 Thread tommyl

Hi,

I understand that Pango supports an LGPL model and would like to know 
if Pango is also available as a private license that can be used outside LGPL?


Thanks,
T.Le

___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list


Re: go from PangoGlyphItemIter to an index into a PangoLogAttr ?

2010-10-25 Thread august
 My main problem, which I have partially solved, is how to iterate
 through a layout (line by line, run by run, and then glyphitem by gitem)
 and keep the log_attributes I get from the layout in sync with my
 iteration.
 
 I noticed that when I change the set_width() of my layout, the number of
 characters in the layout/log_attr array changes.  Why is that? 
 I was surprised when I found this out...but still don't know how it
 changes the character count.  Is there now an extra char in my log_attr
 for every line or run or some mixture?  I ran some tests where I
 increment my index into the log_attr array for each line or run, but did
 not see any regularity.   My solution for now is to not set_width on the
 layout.
 
 I've also tried to get an index into the log_attr array using
 log_attr[glyphitemiter.glyph_item.glyphs.log_clusters[i]] 
 
 where i is incremented for every call to next_cluster()
 
 however, this does not work ( at least not when you set_width on the
 layout).

I think I can narrow my question down a bit.  I the pango docs for
pango_layout_get_log_attr() it says:

n_attrs: location to store the number of the attributes in the array.
(The stored value will be one more than the total number of characters
 in the layout, since there need to be attributes corresponding to both
 the position before the first character and the position after the last
 character.) 

So, when I do this, I know the number of characters in the layout.  I
can also count the number of characters in the source text fed into the
layout.  However, what I don't know is the correlation between the  #
characters in the layout and the # characters in the source text.  They
are not the same.

-august.


___
gtk-i18n-list mailing list
gtk-i18n-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-i18n-list