After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 343355 - Add pango_cairo_show_error_underline & pango_cairo_error_underline_path
Add pango_cairo_show_error_underline & pango_cairo_error_underline_path
Status: RESOLVED FIXED
Product: pango
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Behdad Esfahbod
pango-maint
Depends on:
Blocks: 340141
 
 
Reported: 2006-05-30 04:00 UTC by Behdad Esfahbod
Modified: 2006-06-06 21:42 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
my patch (3.68 KB, patch)
2006-06-01 09:25 UTC, LingNing Zhang
none Details | Review
modified patch (2.99 KB, patch)
2006-06-05 03:03 UTC, LingNing Zhang
none Details | Review

Description Behdad Esfahbod 2006-05-30 04:00:17 UTC
The PangoCairoRenderer is made private, but that's not a limitation, as most of its functionality is available through the pango_cairo_show_* and pango_cairo_*_path functions, using a singleton internally.  This way, custom PangoRenderer implementations that use the cairo backend can "chain up" for those operations.  The only missing part is the error_underline stuff, so gdkpango for example has to duplicate it.

The simplest way to solve this is to provide the functions named in the summary.  Another of course is to make PangoCairoRenderer public.
Comment 1 LingNing Zhang 2006-06-01 09:25:32 UTC
Created attachment 66588 [details] [review]
my patch

I wrote a patch for fixing this bug. I added two functions: pango_cairo_show_error_underline( ) and pango_cairo_error_underline_path( ).
Is it OK?
Comment 2 Behdad Esfahbod 2006-06-03 02:35:09 UTC
Comment on attachment 66588 [details] [review]
my patch

>diff -uNr pango_origin/pango/pangocairo.h pango_modify/pango/pangocairo.h
>--- pango_origin/pango/pangocairo.h	2005-07-21 21:55:19.000000000 +0800
>+++ pango_modify/pango/pangocairo.h	2006-06-01 17:21:35.000000000 +0800
>@@ -87,6 +87,12 @@
> void pango_cairo_show_layout       (cairo_t          *cr,
> 				    PangoLayout      *layout);
> 
>+void pango_cairo_show_error_underline (cairo_t       *cr,                                       
>+					                   int            x,
>+					                   int            y,
>+					                   int            width,
>+					                   int            height);
>+

Seems like your editor has tab-width other than 8.  That should be fixed.


> /*
>  * Rendering to a path
>  */
>@@ -97,6 +103,12 @@
> 				    PangoLayoutLine  *line);
> void pango_cairo_layout_path       (cairo_t          *cr,
> 				    PangoLayout      *layout);
>+					
>+void pango_cairo_error_underline_path (cairo_t       *cr,                                       
>+					                   int            x,
>+					                   int            y,
>+					                   int            width,
>+					                   int            height);

Same here.


> G_END_DECLS
> 
>diff -uNr pango_origin/pango/pangocairo-render.c pango_modify/pango/pangocairo-render.c
>--- pango_origin/pango/pangocairo-render.c	2006-05-30 13:18:59.000000000 +0800
>+++ pango_modify/pango/pangocairo-render.c	2006-06-01 17:21:39.000000000 +0800
>@@ -540,6 +540,43 @@
>   cairo_restore (cr);
> }
> 
>+void 
>+pango_cairo_show_error_underline (cairo_t       *cr,                                  
>+					              int            x,
>+					              int            y,
>+					              int            width,
>+					              int            height)
>+{
>+  PangoLayout *layout;
>+  PangoContext *context;
>+  PangoFontMap *fontmap;
>+  PangoRenderer *renderer;
>+  PangoCairoRenderer *crenderer;
>+
>+  g_return_if_fail (cr != NULL);
>+  g_return_if_fail ((width > 0) && (height > 0));
>+  
>+  layout = pango_cairo_create_layout (cr);
>+  context = pango_layout_get_context (layout);
>+  fontmap = pango_context_get_font_map (context);

This is a very convoluted way of getting a fontmap.  Just use pango_cairo_font_map_get_default().  And you are not unrefing these stuff.


>+  renderer = _pango_cairo_font_map_get_renderer (PANGO_CAIRO_FONT_MAP (fontmap));
>+  crenderer = PANGO_CAIRO_RENDERER (renderer);
>+  
>+  cairo_save (cr);
>+
>+  crenderer->cr = cr;
>+  crenderer->do_path = FALSE;

>+  cairo_get_current_point (cr, &crenderer->x_offset, &crenderer->y_offset);

Don't need this, as draw_error_underline doesn't use the current point.


>+  pango_renderer_draw_error_underline (renderer, x, y, width, height);
>+  
>+  crenderer->cr = NULL;


>+  crenderer->x_offset = 0.;
>+  crenderer->y_offset = 0.;

So these are not needed either.


>+  cairo_restore (cr);
>+} 
>+
> /**
>  * pango_cairo_glyph_string_path
>  * @cr: a Cairo context
>@@ -678,3 +715,39 @@
>   cairo_set_font_face (cr, NULL);
> }
> 
>+void 
>+pango_cairo_error_underline_path (cairo_t       *cr,                                  
>+					              int            x,
>+					              int            y,
>+					              int            width,
>+					              int            height)
>+{
>+  PangoLayout *layout;
>+  PangoContext *context;
>+  PangoFontMap *fontmap;
>+  PangoRenderer *renderer;
>+  PangoCairoRenderer *crenderer;
>+
>+  g_return_if_fail (cr != NULL);
>+  g_return_if_fail ((width > 0) && (height > 0));
>+  
>+  layout = pango_cairo_create_layout (cr);
>+  context = pango_layout_get_context (layout);
>+  fontmap = pango_context_get_font_map (context);
>+  renderer = _pango_cairo_font_map_get_renderer (PANGO_CAIRO_FONT_MAP (fontmap));
>+  crenderer = PANGO_CAIRO_RENDERER (renderer);
>+
>+  crenderer->cr = cr;
>+  crenderer->do_path = TRUE;
>+  cairo_get_current_point (cr, &crenderer->x_offset, &crenderer->y_offset);
>+
>+  pango_renderer_draw_error_underline (renderer, x, y, width, height);
>+  
>+  crenderer->cr = NULL;
>+  crenderer->do_path = FALSE;
>+  crenderer->x_offset = 0.;
>+  crenderer->y_offset = 0.;
>+  
>+  cairo_set_font_face (cr, NULL);
>+}

Same comments here.
Comment 3 LingNing Zhang 2006-06-05 03:03:56 UTC
Created attachment 66755 [details] [review]
modified patch

I modified the patch.
The viewing of vi and the viewing of source-navigator and the viewing of the patch that is created by diff are all different. My vi and my source-navigator are set tab-width to 4.
It is strange.
Comment 4 Behdad Esfahbod 2006-06-06 21:42:25 UTC
I actually ended up committing a very different patch.

2006-06-06  Behdad Esfahbod  <behdad@gnome.org>

        Followup on previous change.

        * pango/pango-renderer.c: Note that pango_renderer_draw_rectangle
        and pango_renderer_draw_error_underline should be called with
        active renderer.

        * pango/pangocairo-render.c (pango_cairo_renderer_draw_glyphs),
        (_pango_cairo_do_glyph_string), (_pango_cairo_do_layout_line),
        (_pango_cairo_do_layout): Remove excess cairo_save/restore() calls.

        * pango/pangocairo-render.c (_pango_cairo_do_error_underline): Don't
        go through renderer.

2006-06-06  Behdad Esfahbod  <behdad@gnome.org>

        Bug 343355 – Add pango_cairo_show_error_underline &
        pango_cairo_error_underline_path
        Based on patch by LingNing Zhang.

        * docs/pango-sections.txt, docs/tmpl/pangocairo.sgml,
        pango/pangocairo.def, pango/pangocairo.h, pango/pangocairo-render.c:
        New functions pango_cairo_show_error_underline and
        pango_cairo_error_underline_path.

        * pango/pangocairo-render.c (_pango_cairo_do_glyph_string),
        (_pango_cairo_do_layout_line), (_pango_cairo_do_layout),
        (_pango_cairo_do_error_underline), (pango_cairo_show_glyph_string),
        (pango_cairo_show_layout_line), (pango_cairo_show_layout),
        (pango_cairo_show_error_underline),
        (pango_cairo_glyph_string_path), (pango_cairo_layout_line_path),
        (pango_cairo_layout_path), (pango_cairo_error_underline_path): Merge
        similar code for pango_cairo_show_* and pango_cairo_*_path functions.