summaryrefslogtreecommitdiff
path: root/pango/pangoft2.c
diff options
context:
space:
mode:
authorAlexander Larsson <alla@lysator.liu.se>2002-01-20 23:37:26 +0000
committerAlexander Larsson <alexl@src.gnome.org>2002-01-20 23:37:26 +0000
commit25c41188236ec73f0ec61b5a4d11eef0fb54560b (patch)
tree1178cd65399d1bda03b6d3c2e20f1722bb44f88c /pango/pangoft2.c
parent51e1022cc9ce854b69e7d336c09f7b8e5395d2c8 (diff)
downloadpango-25c41188236ec73f0ec61b5a4d11eef0fb54560b.tar.gz
Clean up underline drawing. Fixes segfaults.
2002-01-20 Alexander Larsson <alla@lysator.liu.se> * pango/pangoft2.c (pango_ft2_draw_hline): Clean up underline drawing. Fixes segfaults.
Diffstat (limited to 'pango/pangoft2.c')
-rw-r--r--pango/pangoft2.c57
1 files changed, 37 insertions, 20 deletions
diff --git a/pango/pangoft2.c b/pango/pangoft2.c
index ab942dc5..01b1f354 100644
--- a/pango/pangoft2.c
+++ b/pango/pangoft2.c
@@ -718,6 +718,34 @@ pango_ft2_get_unknown_glyph (PangoFont *font)
return 0;
}
+
+static void
+pango_ft2_draw_hline (FT_Bitmap *bitmap,
+ int y,
+ int start,
+ int end)
+{
+ unsigned char *p;
+ int ix;
+
+ if (y < 0 || y >= bitmap->rows)
+ return;
+
+ if (end <= 0 || start >= bitmap->width)
+ return;
+
+ if (start < 0)
+ start = 0;
+
+ if (end >= bitmap->width)
+ end = bitmap->width;
+
+ p = bitmap->buffer + y * bitmap->pitch + start;
+
+ for (ix = 0; ix < end - start; ix++)
+ *p++ = 0xff;
+}
+
/**
* pango_ft2_render_layout_line:
* @bitmap: a FT_Bitmap to render the line onto
@@ -737,10 +765,7 @@ pango_ft2_render_layout_line (FT_Bitmap *bitmap,
PangoRectangle overall_rect;
PangoRectangle logical_rect;
PangoRectangle ink_rect;
- unsigned char *p;
- int ix;
int x_off = 0;
- int x_limit;
pango_layout_line_get_extents (line,NULL, &overall_rect);
@@ -765,32 +790,24 @@ pango_ft2_render_layout_line (FT_Bitmap *bitmap,
pango_ft2_render (bitmap, run->item->analysis.font, run->glyphs,
x + PANGO_PIXELS (x_off), y);
- x_limit = PANGO_PIXELS (ink_rect.width);
switch (uline)
{
case PANGO_UNDERLINE_NONE:
break;
case PANGO_UNDERLINE_DOUBLE:
- p = bitmap->buffer +
- (y + 4) * bitmap->pitch +
- x + PANGO_PIXELS (x_off + ink_rect.x) - 1;
-
- for (ix = 0; ix < x_limit; ix++)
- *p++ = 0xff;
+ pango_ft2_draw_hline (bitmap, y + 4,
+ x + PANGO_PIXELS (x_off + ink_rect.x),
+ x + PANGO_PIXELS (x_off + ink_rect.x + ink_rect.width));
/* Fall through */
case PANGO_UNDERLINE_SINGLE:
- p = bitmap->buffer +
- (y + 2) * bitmap->pitch +
- x + PANGO_PIXELS (x_off + ink_rect.x) - 1;
- for (ix = 0; ix < x_limit; ix++)
- *p++ = 0xff;
+ pango_ft2_draw_hline (bitmap, y + 2,
+ x + PANGO_PIXELS (x_off + ink_rect.x),
+ x + PANGO_PIXELS (x_off + ink_rect.x + ink_rect.width));
break;
case PANGO_UNDERLINE_LOW:
- p = bitmap->buffer +
- (y + PANGO_PIXELS (ink_rect.y + ink_rect.height)) * bitmap->pitch +
- x + PANGO_PIXELS (x_off + ink_rect.x) - 1;
- for (ix = 0; ix < PANGO_PIXELS (ink_rect.width); ix++)
- *p++ = 0xff;
+ pango_ft2_draw_hline (bitmap, y + PANGO_PIXELS (ink_rect.y + ink_rect.height),
+ x + PANGO_PIXELS (x_off + ink_rect.x),
+ x + PANGO_PIXELS (x_off + ink_rect.x + ink_rect.width));
break;
}