GNOME Bugzilla – Bug 343355
Add pango_cairo_show_error_underline & pango_cairo_error_underline_path
Last modified: 2006-06-06 21:42:25 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.
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 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.
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.
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.