[goffice] GOArrow: one drawing routine is enough.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] GOArrow: one drawing routine is enough.
- Date: Wed, 11 Feb 2015 15:52:15 +0000 (UTC)
commit 44185e4f7f9d708f016621cebda6ec4b00faa122
Author: Morten Welinder <terra gnome org>
Date: Wed Feb 11 10:51:17 2015 -0500
GOArrow: one drawing routine is enough.
ChangeLog | 7 +++++
goffice/canvas/goc-line.c | 56 ++++++++++----------------------------------
goffice/utils/go-line.c | 10 +++++---
3 files changed, 26 insertions(+), 47 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7537306..afc136c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2015-02-11 Morten Welinder <terra gnome org>
+ * goffice/canvas/goc-line.c (goc_line_draw): Avoid overflow.
+ Round a bit more consistently.
+ (draw_arrow): Use go_arrow_draw.
+
+ * goffice/utils/go-line.c (go_arrow_draw): Only draw oval heads
+ when sizes are positive.
+
* goffice/gtk/go-font-sel.c (GOFontSelClass): Fix base class.
* goffice/utils/go-line.c (go_arrow_draw): New function extracted
diff --git a/goffice/canvas/goc-line.c b/goffice/canvas/goc-line.c
index 174c41c..30946cd 100644
--- a/goffice/canvas/goc-line.c
+++ b/goffice/canvas/goc-line.c
@@ -206,49 +206,18 @@ static void
draw_arrow (GOArrow const *arrow, cairo_t *cr, GOStyle *style,
double *endx, double *endy, double phi)
{
- double l, w;
+ double dx, dy;
if (arrow->typ == GO_ARROW_NONE)
return;
- l = hypot (*endx, *endy);
- w = style->line.width ? style->line.width / 2.0 : 0.5;
-
- switch (arrow->typ) {
- case GO_ARROW_KITE:
- cairo_save (cr);
- cairo_translate (cr, (int) *endx, (int) *endy);
- cairo_rotate (cr, phi);
- cairo_move_to (cr, -arrow->a, w);
- cairo_line_to (cr, -arrow->b, w + arrow->c);
- cairo_line_to (cr, 0., 0.);
- cairo_line_to (cr, -arrow->b, -w - arrow->c);
- cairo_line_to (cr, -arrow->a, -w);
- cairo_close_path (cr);
- cairo_set_source_rgba (cr, GO_COLOR_TO_CAIRO (style->line.color));
- cairo_fill (cr);
- cairo_restore (cr);
- if (l > 0.) {
- (*endx) -= arrow->a * *endx / l;
- (*endy) -= arrow->a * *endy / l;
- } else
- *endx = *endy = 0.;
- break;
-
- case GO_ARROW_OVAL:
- cairo_save (cr);
- cairo_translate (cr, *endx, *endy);
- cairo_rotate (cr, phi);
- cairo_scale (cr, arrow->a, arrow->b);
- cairo_arc (cr, 0., 0., 1., 0., 2 * M_PI);
- cairo_set_source_rgba (cr, GO_COLOR_TO_CAIRO (style->line.color));
- cairo_fill (cr);
- cairo_restore (cr);
- break;
-
- default:
- g_assert_not_reached ();
- }
+ cairo_save (cr);
+ cairo_translate (cr, *endx, *endy);
+ cairo_set_source_rgba (cr, GO_COLOR_TO_CAIRO (style->line.color));
+ go_arrow_draw (arrow, cr, &dx, &dy, phi - M_PI / 2);
+ *endx += dx;
+ *endy += dy;
+ cairo_restore (cr);
}
static void
@@ -276,8 +245,11 @@ goc_line_draw (GocItem const *item, cairo_t *cr)
cairo_save (cr);
_goc_item_transform (item, cr, TRUE);
goc_group_cairo_transform (item->parent, cr,
- hoffs + (int) line->startx,
- voffs + (int) line->starty);
+ hoffs + floor (line->startx),
+ voffs + floor (line->starty));
+
+ endx = (endx > 0.)? ceil (endx): floor (endx);
+ endy = (endy > 0.)? ceil (endy): floor (endy);
phi = atan2 (endy, endx);
draw_arrow (&line->start_arrow, cr, style,
@@ -289,8 +261,6 @@ goc_line_draw (GocItem const *item, cairo_t *cr)
go_styled_object_set_cairo_line (GO_STYLED_OBJECT (item), cr)) {
/* try to avoid horizontal and vertical lines between two pixels */
cairo_move_to (cr, 0., 0.);
- endx = (endx > 0.)? ceil (endx): floor (endx);
- endy = (endy > 0.)? ceil (endy): floor (endy);
cairo_line_to (cr, endx, endy);
cairo_stroke (cr);
}
diff --git a/goffice/utils/go-line.c b/goffice/utils/go-line.c
index 8b20c47..c4fc2ac 100644
--- a/goffice/utils/go-line.c
+++ b/goffice/utils/go-line.c
@@ -550,10 +550,12 @@ go_arrow_draw (const GOArrow *arrow, cairo_t *cr,
break;
case GO_ARROW_OVAL:
- cairo_rotate (cr, phi);
- cairo_scale (cr, arrow->a, arrow->b);
- cairo_arc (cr, 0., 0., 1., 0., 2 * M_PI);
- cairo_fill (cr);
+ if (arrow->a > 0 && arrow->b > 0) {
+ cairo_rotate (cr, phi);
+ cairo_scale (cr, arrow->a, arrow->b);
+ cairo_arc (cr, 0., 0., 1., 0., 2 * M_PI);
+ cairo_fill (cr);
+ }
break;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]