[goffice] Enhance round corners support for rectangles.
- From: Jean Bréfort <jbrefort src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Enhance round corners support for rectangles.
- Date: Tue, 9 Mar 2010 07:42:48 +0000 (UTC)
commit b8ebc01b98574548a55ff3127f9787e606048fc0
Author: Jean Brefort <jean brefort normalesup org>
Date: Tue Mar 9 08:38:37 2010 +0100
Enhance round corners support for rectangles.
ChangeLog | 6 +++
goffice/canvas/goc-rectangle.c | 70 ++++++++++++++++++++++++---------------
tests/shapes-demo.c | 11 ++++++
3 files changed, 60 insertions(+), 27 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0199a58..68ef4a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2010-03-09 Valek Filippov <frob gnome org>
+
+ * goffice/canvas/goc-rectangle.c (goc_rectangle_prepare_draw): enhance
+ round corners support.
+ * tests/shapes-demo.c (parse_line): ditto.
+
2010-03-08 Morten Welinder <terra gnome org>
* configure.in: Post-release bump.
diff --git a/goffice/canvas/goc-rectangle.c b/goffice/canvas/goc-rectangle.c
index b5c7b41..2f2ec2f 100644
--- a/goffice/canvas/goc-rectangle.c
+++ b/goffice/canvas/goc-rectangle.c
@@ -171,33 +171,49 @@ goc_rectangle_prepare_draw (GocItem const *item, cairo_t *cr, gboolean flag)
cairo_rectangle (cr, 0., 0., (int) rect->width * sign, (int) rect->height);
} else {
- cairo_move_to (cr, priv->rx, 0.);
- cairo_save (cr);
- cairo_translate (cr, priv->rx, priv->ry);
- cairo_scale (cr, priv->rx, priv->ry);
- cairo_arc_negative (cr, 0. , 0. ,1. , -M_PI/2. , M_PI);
- cairo_restore (cr);
-
- cairo_line_to (cr, 0, rect->height - priv->ry);
- cairo_save (cr);
- cairo_translate (cr, priv->rx, rect->height - priv->ry);
- cairo_scale (cr, priv->rx, priv->ry);
- cairo_arc_negative (cr, 0., 0. ,1. , M_PI, M_PI/2.);
- cairo_restore (cr);
-
- cairo_line_to (cr, rect->width - priv->rx, rect->height);
- cairo_save (cr);
- cairo_translate (cr, rect->width - priv->rx, rect->height - priv->ry);
- cairo_scale (cr, priv->rx, priv->ry);
- cairo_arc_negative (cr, 0., 0. ,1. , M_PI/2., 0.);
- cairo_restore (cr);
-
- cairo_line_to (cr, rect->width, priv->ry);
- cairo_save (cr);
- cairo_translate (cr, rect->width - priv->rx, priv->ry);
- cairo_scale (cr, priv->rx, priv->ry);
- cairo_arc_negative (cr, 0., 0. ,1. , 0., -M_PI/2.);
- cairo_restore (cr);
+ if (priv->type&1) {
+ cairo_move_to (cr, priv->rx, 0.);
+ cairo_save (cr);
+ cairo_translate (cr, priv->rx, priv->ry);
+ cairo_scale (cr, priv->rx, priv->ry);
+ cairo_arc_negative (cr, 0. , 0. ,1. , -M_PI/2. , M_PI);
+ cairo_restore (cr);
+ } else {
+ cairo_move_to (cr, 0., 0.);
+ }
+
+ if (priv->type&8) {
+ cairo_line_to (cr, 0., rect->height - priv->ry);
+ cairo_save (cr);
+ cairo_translate (cr, priv->rx, rect->height - priv->ry);
+ cairo_scale (cr, priv->rx, priv->ry);
+ cairo_arc_negative (cr, 0., 0. ,1. , M_PI, M_PI/2.);
+ cairo_restore (cr);
+ } else {
+ cairo_line_to (cr, 0., rect->height);
+ }
+
+ if (priv->type&4) {
+ cairo_line_to (cr, rect->width - priv->rx, rect->height);
+ cairo_save (cr);
+ cairo_translate (cr, rect->width - priv->rx, rect->height - priv->ry);
+ cairo_scale (cr, priv->rx, priv->ry);
+ cairo_arc_negative (cr, 0., 0. ,1. , M_PI/2., 0.);
+ cairo_restore (cr);
+ } else {
+ cairo_line_to (cr, rect->width, rect->height);
+ }
+
+ if (priv->type&2) {
+ cairo_line_to (cr, rect->width, priv->ry);
+ cairo_save (cr);
+ cairo_translate (cr, rect->width - priv->rx, priv->ry);
+ cairo_scale (cr, priv->rx, priv->ry);
+ cairo_arc_negative (cr, 0., 0. ,1. , 0., -M_PI/2.);
+ cairo_restore (cr);
+ } else {
+ cairo_line_to (cr, rect->width, 0.);
+ }
cairo_close_path (cr);
}
cairo_restore (cr);
diff --git a/tests/shapes-demo.c b/tests/shapes-demo.c
index c7cbb3f..1f1b7d8 100644
--- a/tests/shapes-demo.c
+++ b/tests/shapes-demo.c
@@ -143,6 +143,8 @@ parse_line (GocCanvas *canvas, gchar *entry)
cmd = 6;
} else if (g_ascii_strcasecmp (v[0], "POLYG") == 0) {
cmd = 7;
+ } else if (g_ascii_strcasecmp (v[0], "RRECT") == 0) {
+ cmd = 8;
} else if (g_ascii_strcasecmp (v[0], "STROKE") == 0) {
cmd = 20;
} else if (g_ascii_strcasecmp (v[0], "FILL") == 0) {
@@ -213,6 +215,13 @@ parse_line (GocCanvas *canvas, gchar *entry)
item = goc_item_new (goc_canvas_get_root (canvas), GOC_TYPE_POLYGON, "points", points, NULL);
}
break;
+ case 8: /* RRECT */
+ if (g_strv_length (v) > 8) {
+ item = goc_item_new (goc_canvas_get_root (canvas), GOC_TYPE_RECTANGLE,
+ "x", (double) atoi (v[1]), "y", (double) atoi (v[2]), "width", (double) atoi (v[3]), "height", (double) atoi (v[4]),
+ "rx", (double) atoi (v[5]), "ry", (double) atoi (v[6]), "rotation", (double) atoi (v[7]) * M_PI / 180., "type", atoi (v[8]), NULL);
+ }
+ break;
case 20: /* STROKE */
group = (GocGroup*) goc_canvas_get_root (canvas);
item = g_list_nth_data (group->children, atoi (v[1]));
@@ -226,6 +235,7 @@ parse_line (GocCanvas *canvas, gchar *entry)
style->line.dash_type = 0;
} else if (g_strv_length(v) > 6) {
style->line.color = GO_COLOR_FROM_RGBA (atoi (v[3]), atoi (v[4]), atoi (v[5]), atoi (v[6]));
+ style->line.auto_color = FALSE;
}
goc_item_set (item, "style", style, NULL);
g_object_unref (style);
@@ -241,6 +251,7 @@ parse_line (GocCanvas *canvas, gchar *entry)
} else if (g_strv_length (v) > 5) {
style->fill.type = GO_STYLE_FILL_PATTERN;
style-> fill.pattern.back = GO_COLOR_FROM_RGBA (atoi (v[2]), atoi (v[3]), atoi (v[4]), atoi (v[5]));
+ style->fill.auto_back = FALSE;
}
goc_item_set (item, "style", style, NULL);
g_object_unref (style);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]