summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2006-06-06 20:19:57 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2006-06-06 20:19:57 +0000
commit296ed093de978b8864a4829eaa30574ad877567e (patch)
treeb9653f22df6444197844f9ff5ef5e3c125fd9eb9
parenta01672546967d77e52fa98e51f9505429915fe5c (diff)
downloadpango-296ed093de978b8864a4829eaa30574ad877567e.tar.gz
Bug 343355 – Add pango_cairo_show_error_underline &
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.
-rw-r--r--ChangeLog20
-rw-r--r--docs/pango-sections.txt2
-rw-r--r--docs/tmpl/pangocairo.sgml24
-rw-r--r--pango/pangocairo-render.c308
-rw-r--r--pango/pangocairo.def2
-rw-r--r--pango/pangocairo.h12
6 files changed, 237 insertions, 131 deletions
diff --git a/ChangeLog b/ChangeLog
index 3361729a..77aa918b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,25 @@
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.
+
+2006-06-06 Behdad Esfahbod <behdad@gnome.org>
+
Bug 343966 – pango Cygwin build fixes
Patch from Cygwin Ports maintainer.
diff --git a/docs/pango-sections.txt b/docs/pango-sections.txt
index bca9ba01..9911c811 100644
--- a/docs/pango-sections.txt
+++ b/docs/pango-sections.txt
@@ -806,9 +806,11 @@ pango_cairo_update_layout
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
<SUBSECTION Standard>
PANGO_CAIRO_FONT_MAP
PANGO_IS_CAIRO_FONT_MAP
diff --git a/docs/tmpl/pangocairo.sgml b/docs/tmpl/pangocairo.sgml
index e6e57650..fcc44ba0 100644
--- a/docs/tmpl/pangocairo.sgml
+++ b/docs/tmpl/pangocairo.sgml
@@ -282,6 +282,18 @@ int main (int argc, char **argv)
@layout:
+<!-- ##### FUNCTION pango_cairo_show_error_underline ##### -->
+<para>
+
+</para>
+
+@cr:
+@x:
+@y:
+@width:
+@height:
+
+
<!-- ##### FUNCTION pango_cairo_glyph_string_path ##### -->
<para>
@@ -310,3 +322,15 @@ int main (int argc, char **argv)
@layout:
+<!-- ##### FUNCTION pango_cairo_error_underline_path ##### -->
+<para>
+
+</para>
+
+@cr:
+@x:
+@y:
+@width:
+@height:
+
+
diff --git a/pango/pangocairo-render.c b/pango/pangocairo-render.c
index a92f207c..0eb323ba 100644
--- a/pango/pangocairo-render.c
+++ b/pango/pangocairo-render.c
@@ -399,31 +399,21 @@ pango_cairo_renderer_class_init (PangoCairoRendererClass *klass)
renderer_class->draw_error_underline = pango_cairo_renderer_draw_error_underline;
}
-/**
- * pango_cairo_show_glyph_string:
- * @cr: a Cairo context
- * @font: a #PangoFont
- * @glyphs: a #PangoGlyphString
- *
- * Draws the glyphs in @glyphs in the specified cairo context.
- * The origin of the glyphs (the left edge of the baseline) will
- * be drawn at the current point of the cairo context.
- *
- * Since: 1.10
- **/
-void
-pango_cairo_show_glyph_string (cairo_t *cr,
- PangoFont *font,
- PangoGlyphString *glyphs)
+
+/* convenience wrappers using the default renderer */
+
+
+static void
+_pango_cairo_do_glyph_string (cairo_t *cr,
+ PangoFont *font,
+ PangoGlyphString *glyphs,
+ gboolean do_path)
{
PangoFontMap *fontmap;
PangoCairoRenderer *crenderer;
PangoRenderer *renderer;
gboolean unref_renderer = FALSE;
- g_return_if_fail (cr != NULL);
- g_return_if_fail (glyphs != NULL);
-
fontmap = pango_font_get_font_map (font);
renderer = _pango_cairo_font_map_get_renderer (PANGO_CAIRO_FONT_MAP (fontmap));
if (G_UNLIKELY (!renderer))
@@ -437,7 +427,7 @@ pango_cairo_show_glyph_string (cairo_t *cr,
cairo_save (cr);
crenderer->cr = cr;
- crenderer->do_path = FALSE;
+ crenderer->do_path = do_path;
cairo_get_current_point (cr, &crenderer->x_offset, &crenderer->y_offset);
pango_renderer_draw_glyphs (renderer, font, glyphs, 0, 0);
@@ -447,6 +437,7 @@ pango_cairo_show_glyph_string (cairo_t *cr,
else
{
crenderer->cr = NULL;
+ crenderer->do_path = FALSE;
crenderer->x_offset = 0.;
crenderer->y_offset = 0.;
}
@@ -454,29 +445,16 @@ pango_cairo_show_glyph_string (cairo_t *cr,
cairo_restore (cr);
}
-/**
- * pango_cairo_show_layout_line:
- * @cr: a Cairo context
- * @line: a #PangoLayoutLine
- *
- * Draws a #PangoLayoutLine in the specified cairo context.
- * The origin of the glyphs (the left edge of the line) will
- * be drawn at the current point of the cairo context.
- *
- * Since: 1.10
- **/
-void
-pango_cairo_show_layout_line (cairo_t *cr,
- PangoLayoutLine *line)
+static void
+_pango_cairo_do_layout_line (cairo_t *cr,
+ PangoLayoutLine *line,
+ gboolean do_path)
{
PangoContext *context;
PangoFontMap *fontmap;
PangoRenderer *renderer;
PangoCairoRenderer *crenderer;
- g_return_if_fail (cr != NULL);
- g_return_if_fail (line != NULL);
-
context = pango_layout_get_context (line->layout);
fontmap = pango_context_get_font_map (context);
renderer = _pango_cairo_font_map_get_renderer (PANGO_CAIRO_FONT_MAP (fontmap));
@@ -485,41 +463,29 @@ pango_cairo_show_layout_line (cairo_t *cr,
cairo_save (cr);
crenderer->cr = cr;
- crenderer->do_path = FALSE;
+ crenderer->do_path = do_path;
cairo_get_current_point (cr, &crenderer->x_offset, &crenderer->y_offset);
pango_renderer_draw_layout_line (renderer, line, 0, 0);
crenderer->cr = NULL;
+ crenderer->do_path = FALSE;
crenderer->x_offset = 0.;
crenderer->y_offset = 0.;
cairo_restore (cr);
}
-/**
- * pango_cairo_show_layout:
- * @cr: a Cairo context
- * @layout: a Pango layout
- *
- * Draws a #PangoLayoutLine in the specified cairo context.
- * The top-left corner of the #PangoLayout will be drawn
- * at the current point of the cairo context.
- *
- * Since: 1.10
- **/
-void
-pango_cairo_show_layout (cairo_t *cr,
- PangoLayout *layout)
+static void
+_pango_cairo_do_layout (cairo_t *cr,
+ PangoLayout *layout,
+ gboolean do_path)
{
PangoContext *context;
PangoFontMap *fontmap;
PangoRenderer *renderer;
PangoCairoRenderer *crenderer;
- g_return_if_fail (cr != NULL);
- g_return_if_fail (PANGO_IS_LAYOUT (layout));
-
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));
@@ -528,18 +494,144 @@ pango_cairo_show_layout (cairo_t *cr,
cairo_save (cr);
crenderer->cr = cr;
- crenderer->do_path = FALSE;
+ crenderer->do_path = do_path;
cairo_get_current_point (cr, &crenderer->x_offset, &crenderer->y_offset);
pango_renderer_draw_layout (renderer, layout, 0, 0);
crenderer->cr = NULL;
+ crenderer->do_path = FALSE;
crenderer->x_offset = 0.;
crenderer->y_offset = 0.;
cairo_restore (cr);
}
+static void
+_pango_cairo_do_error_underline (cairo_t *cr,
+ double x,
+ double y,
+ double width,
+ double height,
+ gboolean do_path)
+{
+ PangoFontMap *fontmap;
+ PangoRenderer *renderer;
+ PangoCairoRenderer *crenderer;
+
+ fontmap = pango_cairo_font_map_get_default ();
+ 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 = do_path;
+
+ pango_renderer_draw_error_underline (renderer, x, y, width, height);
+
+ crenderer->cr = NULL;
+ crenderer->do_path = FALSE;
+
+ cairo_restore (cr);
+}
+
+
+/* public wrapper of above to show or append path */
+
+
+/**
+ * pango_cairo_show_glyph_string:
+ * @cr: a Cairo context
+ * @font: a #PangoFont
+ * @glyphs: a #PangoGlyphString
+ *
+ * Draws the glyphs in @glyphs in the specified cairo context.
+ * The origin of the glyphs (the left edge of the baseline) will
+ * be drawn at the current point of the cairo context.
+ *
+ * Since: 1.10
+ **/
+void
+pango_cairo_show_glyph_string (cairo_t *cr,
+ PangoFont *font,
+ PangoGlyphString *glyphs)
+{
+ g_return_if_fail (cr != NULL);
+ g_return_if_fail (glyphs != NULL);
+
+ _pango_cairo_do_glyph_string (cr, font, glyphs, FALSE);
+}
+
+/**
+ * pango_cairo_show_layout_line:
+ * @cr: a Cairo context
+ * @line: a #PangoLayoutLine
+ *
+ * Draws a #PangoLayoutLine in the specified cairo context.
+ * The origin of the glyphs (the left edge of the line) will
+ * be drawn at the current point of the cairo context.
+ *
+ * Since: 1.10
+ **/
+void
+pango_cairo_show_layout_line (cairo_t *cr,
+ PangoLayoutLine *line)
+{
+ g_return_if_fail (cr != NULL);
+ g_return_if_fail (line != NULL);
+
+ _pango_cairo_do_layout_line (cr, line, FALSE);
+}
+
+/**
+ * pango_cairo_show_layout:
+ * @cr: a Cairo context
+ * @layout: a Pango layout
+ *
+ * Draws a #PangoLayoutLine in the specified cairo context.
+ * The top-left corner of the #PangoLayout will be drawn
+ * at the current point of the cairo context.
+ *
+ * Since: 1.10
+ **/
+void
+pango_cairo_show_layout (cairo_t *cr,
+ PangoLayout *layout)
+{
+ g_return_if_fail (cr != NULL);
+ g_return_if_fail (PANGO_IS_LAYOUT (layout));
+
+ _pango_cairo_do_layout (cr, layout, FALSE);
+}
+
+/**
+ * pango_cairo_show_error_underline:
+ * @cr: a Cairo context
+ * @x: The X coordinate of one corner of the rectangle
+ * @y: The Y coordinate of one corner of the rectangle
+ * @width: Non-negative width of the rectangle
+ * @height: Non-negative height of the rectangle
+ *
+ * Draws a wavy underline filling the given rectangle in the specified
+ * cairo context. This is typically used to draw error underlines,
+ * indicating an error such as a possilble mispelling.
+ *
+ * Since: 1.14
+ **/
+void
+pango_cairo_show_error_underline (cairo_t *cr,
+ double x,
+ double y,
+ double width,
+ double height)
+{
+ g_return_if_fail (cr != NULL);
+ g_return_if_fail ((width >= 0) && (height >= 0));
+
+ _pango_cairo_do_error_underline (cr, x, y, width, height, FALSE);
+}
+
/**
* pango_cairo_glyph_string_path
* @cr: a Cairo context
@@ -557,41 +649,10 @@ pango_cairo_glyph_string_path (cairo_t *cr,
PangoFont *font,
PangoGlyphString *glyphs)
{
- PangoFontMap *fontmap;
- PangoCairoRenderer *crenderer;
- PangoRenderer *renderer;
- gboolean unref_renderer = FALSE;
-
g_return_if_fail (cr != NULL);
g_return_if_fail (glyphs != NULL);
- fontmap = pango_font_get_font_map (font);
- renderer = _pango_cairo_font_map_get_renderer (PANGO_CAIRO_FONT_MAP (fontmap));
- if (G_UNLIKELY (!renderer))
- {
- renderer = g_object_new (PANGO_TYPE_CAIRO_RENDERER, NULL);
- unref_renderer = TRUE;
- }
-
- 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_glyphs (renderer, font, glyphs, 0, 0);
-
- if (G_UNLIKELY (unref_renderer))
- g_object_unref (renderer);
- else
- {
- crenderer->cr = NULL;
- crenderer->do_path = FALSE;
- crenderer->x_offset = 0.;
- crenderer->y_offset = 0.;
- }
-
- cairo_set_font_face (cr, NULL);
+ _pango_cairo_do_glyph_string (cr, font, glyphs, TRUE);
}
/**
@@ -609,31 +670,10 @@ void
pango_cairo_layout_line_path (cairo_t *cr,
PangoLayoutLine *line)
{
- PangoContext *context;
- PangoFontMap *fontmap;
- PangoRenderer *renderer;
- PangoCairoRenderer *crenderer;
-
g_return_if_fail (cr != NULL);
g_return_if_fail (line != NULL);
- context = pango_layout_get_context (line->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_layout_line (renderer, line, 0, 0);
-
- crenderer->cr = NULL;
- crenderer->do_path = FALSE;
- crenderer->x_offset = 0.;
- crenderer->y_offset = 0.;
-
- cairo_set_font_face (cr, NULL);
+ _pango_cairo_do_layout_line (cr, line, TRUE);
}
/**
@@ -651,30 +691,36 @@ void
pango_cairo_layout_path (cairo_t *cr,
PangoLayout *layout)
{
- PangoContext *context;
- PangoFontMap *fontmap;
- PangoRenderer *renderer;
- PangoCairoRenderer *crenderer;
-
g_return_if_fail (cr != NULL);
g_return_if_fail (PANGO_IS_LAYOUT (layout));
- 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_cairo_do_layout (cr, layout, TRUE);
+}
- pango_renderer_draw_layout (renderer, layout, 0, 0);
-
- crenderer->cr = NULL;
- crenderer->do_path = FALSE;
- crenderer->x_offset = 0.;
- crenderer->y_offset = 0.;
+/**
+ * pango_cairo_error_underline_path:
+ * @cr: a Cairo context
+ * @x: The X coordinate of one corner of the rectangle
+ * @y: The Y coordinate of one corner of the rectangle
+ * @width: Non-negative width of the rectangle
+ * @height: Non-negative height of the rectangle
+ *
+ * Adds a wavy underline filling the given rectangle to the current
+ * patch in the specified cairo context. This is typically used to
+ * draw error underlines, indicating an error such as a possilble
+ * mispelling.
+ *
+ * Since: 1.14
+ **/
+void
+pango_cairo_error_underline_path (cairo_t *cr,
+ double x,
+ double y,
+ double width,
+ double height)
+{
+ g_return_if_fail (cr != NULL);
+ g_return_if_fail ((width >= 0) && (height >= 0));
- cairo_set_font_face (cr, NULL);
+ _pango_cairo_do_error_underline (cr, x, y, width, height, TRUE);
}
-
diff --git a/pango/pangocairo.def b/pango/pangocairo.def
index 6bf68f83..2b635888 100644
--- a/pango/pangocairo.def
+++ b/pango/pangocairo.def
@@ -4,6 +4,7 @@ EXPORTS
pango_cairo_context_set_font_options
pango_cairo_context_set_resolution
pango_cairo_create_layout
+ pango_cairo_error_underline_path
pango_cairo_font_get_type
pango_cairo_font_map_create_context
pango_cairo_font_map_get_default
@@ -14,6 +15,7 @@ EXPORTS
pango_cairo_glyph_string_path
pango_cairo_layout_line_path
pango_cairo_layout_path
+ pango_cairo_show_error_underline
pango_cairo_show_glyph_string
pango_cairo_show_layout
pango_cairo_show_layout_line
diff --git a/pango/pangocairo.h b/pango/pangocairo.h
index c14fab4f..51bb3c78 100644
--- a/pango/pangocairo.h
+++ b/pango/pangocairo.h
@@ -87,6 +87,12 @@ void pango_cairo_show_layout_line (cairo_t *cr,
void pango_cairo_show_layout (cairo_t *cr,
PangoLayout *layout);
+void pango_cairo_show_error_underline (cairo_t *cr,
+ double x,
+ double y,
+ double width,
+ double height);
+
/*
* Rendering to a path
*/
@@ -97,6 +103,12 @@ void pango_cairo_layout_line_path (cairo_t *cr,
PangoLayoutLine *line);
void pango_cairo_layout_path (cairo_t *cr,
PangoLayout *layout);
+
+void pango_cairo_error_underline_path (cairo_t *cr,
+ double x,
+ double y,
+ double width,
+ double height);
G_END_DECLS