[goffice] Fixed GORotationSel.
- From: Jean BrÃfort <jbrefort src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Fixed GORotationSel.
- Date: Mon, 15 Aug 2011 15:01:11 +0000 (UTC)
commit df24a6499b1718f8c45768dccbc181a3da89fcce
Author: Jean Brefort <jean brefort normalesup org>
Date: Mon Aug 15 17:05:37 2011 +0200
Fixed GORotationSel.
ChangeLog | 13 +++++++++++++
goffice/canvas/goc-canvas.c | 8 ++++----
goffice/canvas/goc-text.c | 27 ++++++++++++++-------------
goffice/graph/gog-series-labels.c | 23 ++++++++++++++++++++---
goffice/gtk/go-rotation-sel.c | 35 ++++++++++++++---------------------
5 files changed, 65 insertions(+), 41 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 48f05a7..e13d5e4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2011-08-15 Jean Brefort <jean brefort normalesup org>
+
+ * goffice/canvas/goc-canvas.c (goc_canvas_invalidate): add a one pixel wide
+ margin to the invalidated region to avoid pixels dust.
+ * goffice/canvas/goc-text.c (goc_text_prepare_draw),
+ (goc_text_draw): ensure that the rotation is around the anchor point.
+ * goffice/graph/gog-series-labels.c (used_selection_changed_cb),
+ (raise_cb), (lower_cb), (position_changed_cb),
+ (gog_series_labels_changed), (gog_series_labels_update): ensure that all
+ changes instant apply in the preview.
+ * goffice/gtk/go-rotation-sel.c (cb_rotate_changed),
+ (cb_rotate_canvas_realize): replaced the GtkLabel by a GocText item.
+
2011-08-14 Andreas J. Guelzow <aguelzow pyrshep ca>
* goffice/app/go-plugin-loader-module.c
diff --git a/goffice/canvas/goc-canvas.c b/goffice/canvas/goc-canvas.c
index f8b1a6c..5bcf781 100644
--- a/goffice/canvas/goc-canvas.c
+++ b/goffice/canvas/goc-canvas.c
@@ -460,11 +460,11 @@ goc_canvas_invalidate (GocCanvas *canvas, double x0, double y0, double x1, doubl
x0 = canvas->width - x1;
x1 = canvas->width - tmp;
}
- if (x1 > x0 && y1 > y0)
+ if (x1 > x0 && y1 > y0) /* invalidate with an extra one pixel wide margin */
gtk_widget_queue_draw_area (GTK_WIDGET (canvas),
- (int) floor (x0), (int) floor (y0),
- (int) ceil (x1) - (int) floor (x0),
- (int) ceil (y1) - (int) floor (y0));
+ (int) floor (x0) - 1, (int) floor (y0) - 1,
+ (int) ceil (x1) - (int) floor (x0) + 2,
+ (int) ceil (y1) - (int) floor (y0) + 2);
}
/**
diff --git a/goffice/canvas/goc-text.c b/goffice/canvas/goc-text.c
index cf439cc..7dc59c4 100644
--- a/goffice/canvas/goc-text.c
+++ b/goffice/canvas/goc-text.c
@@ -256,7 +256,7 @@ goc_text_prepare_draw (GocItem *item, cairo_t *cr)
{
GocText *text = GOC_TEXT (item);
PangoRectangle rect;
- double sign = (goc_canvas_get_direction (item->canvas) == GOC_DIRECTION_RTL)? -1.: 1.;
+ double sign = (goc_canvas_get_direction (item->canvas) == GOC_DIRECTION_RTL)? -1.: 1., dx, dy;
pango_layout_get_extents (text->layout, NULL, &rect);
text->w = (double) rect.width / PANGO_SCALE;
@@ -268,7 +268,7 @@ goc_text_prepare_draw (GocItem *item, cairo_t *cr)
case GO_ANCHOR_CENTER:
case GO_ANCHOR_NORTH:
case GO_ANCHOR_SOUTH:
- item->x0 -= text->w / 2.;
+ dx = -text->w / 2.;
break;
case GO_ANCHOR_NORTH_WEST:
case GO_ANCHOR_SOUTH_WEST:
@@ -277,7 +277,7 @@ goc_text_prepare_draw (GocItem *item, cairo_t *cr)
case GO_ANCHOR_NORTH_EAST:
case GO_ANCHOR_SOUTH_EAST:
case GO_ANCHOR_EAST:
- item->x0 -= text->w;
+ dx = -text->w;
break;
default: /* should not occur */
break;
@@ -291,12 +291,12 @@ goc_text_prepare_draw (GocItem *item, cairo_t *cr)
case GO_ANCHOR_CENTER:
case GO_ANCHOR_WEST:
case GO_ANCHOR_EAST:
- item->y0 -= text->h / 2.;
+ dy = -text->h / 2.;
break;
case GO_ANCHOR_SOUTH:
case GO_ANCHOR_SOUTH_WEST:
case GO_ANCHOR_SOUTH_EAST:
- item->y0 -= text->h;
+ dy = -text->h;
break;
default: /* should not occur */
break;
@@ -305,9 +305,9 @@ goc_text_prepare_draw (GocItem *item, cairo_t *cr)
cairo_translate (cr, item->x0, item->y0);
cairo_rotate (cr, text->rotation * sign);
if (text->clip_height > 0. && text->clip_width > 0.) {
- cairo_rectangle (cr, 0., 0., text->clip_width, text->clip_height);
+ cairo_rectangle (cr, dx, dy, text->clip_width, text->clip_height);
} else {
- cairo_rectangle (cr, 0., 0., text->w, text->h);
+ cairo_rectangle (cr, dx, dy, text->w, text->h);
}
cairo_restore (cr);
}
@@ -358,7 +358,8 @@ static void
goc_text_draw (GocItem const *item, cairo_t *cr)
{
GocText *text = GOC_TEXT (item);
- double x = (goc_canvas_get_direction (item->canvas) == GOC_DIRECTION_RTL)? text->x + text->w: text->x, y = text->y;
+ double x = (goc_canvas_get_direction (item->canvas) == GOC_DIRECTION_RTL)? text->x + text->w: text->x,
+ y = text->y, dx = 0., dy = 0.;
double sign = (goc_canvas_get_direction (item->canvas) == GOC_DIRECTION_RTL)? -1.: 1.;
PangoLayout *pl;
@@ -379,7 +380,7 @@ goc_text_draw (GocItem const *item, cairo_t *cr)
case GO_ANCHOR_CENTER:
case GO_ANCHOR_NORTH:
case GO_ANCHOR_SOUTH:
- x -= text->w / 2.;
+ dx = -text->w / 2.;
break;
case GO_ANCHOR_NORTH_WEST:
case GO_ANCHOR_SOUTH_WEST:
@@ -388,7 +389,7 @@ goc_text_draw (GocItem const *item, cairo_t *cr)
case GO_ANCHOR_NORTH_EAST:
case GO_ANCHOR_SOUTH_EAST:
case GO_ANCHOR_EAST:
- x -= text->w;
+ dx = -text->w;
break;
default: /* should not occur */
break;
@@ -402,12 +403,12 @@ goc_text_draw (GocItem const *item, cairo_t *cr)
case GO_ANCHOR_CENTER:
case GO_ANCHOR_WEST:
case GO_ANCHOR_EAST:
- y -= text->h / 2.;
+ dy = -text->h / 2.;
break;
case GO_ANCHOR_SOUTH:
case GO_ANCHOR_SOUTH_WEST:
case GO_ANCHOR_SOUTH_EAST:
- y -= text->h;
+ dy = -text->h;
break;
default: /* should not occur */
break;
@@ -416,7 +417,7 @@ goc_text_draw (GocItem const *item, cairo_t *cr)
cairo_set_source_rgb (cr, 0., 0., 0.);
goc_group_cairo_transform (item->parent, cr, x, y);
cairo_rotate (cr, text->rotation * sign);
- cairo_move_to (cr, 0., 0.);
+ cairo_move_to (cr, dx, dy);
if (text->clip_height > 0. && text->clip_width > 0.) {
cairo_rectangle (cr, 0., 0., text->clip_width, text->clip_height);
cairo_clip (cr);
diff --git a/goffice/graph/gog-series-labels.c b/goffice/graph/gog-series-labels.c
index 33d396e..7c32c5f 100644
--- a/goffice/graph/gog-series-labels.c
+++ b/goffice/graph/gog-series-labels.c
@@ -120,6 +120,7 @@ used_selection_changed_cb (struct SeriesLabelsState *state)
}
gtk_widget_set_sensitive (state->remove,
count > 0 && gtk_tree_selection_count_selected_rows (state->used_sel));
+ gog_object_emit_changed (GOG_OBJECT (state->labels), TRUE);
}
static void
@@ -185,7 +186,7 @@ raise_cb (G_GNUC_UNUSED GtkButton *btn, struct SeriesLabelsState *state)
gtk_list_store_move_before (state->used_list, &iter, &prev);
gtk_tree_model_get_iter_first (model, &iter);
used_selection_changed_cb (state);
- gog_object_emit_changed (GOG_OBJECT (state->labels), TRUE);
+ gog_object_emit_changed (GOG_OBJECT (state->labels), FALSE);
}
static void
@@ -219,7 +220,7 @@ lower_cb (G_GNUC_UNUSED GtkButton *btn, struct SeriesLabelsState *state)
gtk_list_store_move_before (state->used_list, &last, &prev);
}
used_selection_changed_cb (state);
- gog_object_emit_changed (GOG_OBJECT (state->labels), TRUE);
+ gog_object_emit_changed (GOG_OBJECT (state->labels), FALSE);
}
static void
@@ -241,6 +242,7 @@ position_changed_cb (GtkComboBox *box, struct SeriesLabelsState *state)
gtk_widget_set_sensitive (state->offset_lbl, TRUE);
}
}
+ gog_object_emit_changed (GOG_OBJECT (state->labels), TRUE);
}
static void
@@ -573,6 +575,7 @@ static void
gog_series_labels_changed (GogObject *obj, gboolean size)
{
gog_object_emit_changed (gog_object_get_parent (obj), size);
+ gog_object_request_update (gog_object_get_parent (obj));
}
struct attr_closure {
@@ -596,6 +599,8 @@ gog_series_labels_update (GogObject *obj)
{
GogSeriesLabels *labels = GOG_SERIES_LABELS (obj);
GogObject *parent = gog_object_get_parent (GOG_OBJECT (obj));
+ GOStyle *style = go_styled_object_get_style (GO_STYLED_OBJECT (obj));
+ int height = pango_font_description_get_size (style->font.font->desc);
unsigned i, n;
if (labels->elements) {
n = labels->n_elts;
@@ -635,8 +640,20 @@ gog_series_labels_update (GogObject *obj)
}
}
break;
- case 'l':
+ case 'l': {
+ /* add room for the legend entry */
+ PangoRectangle rect;
+ PangoAttribute *attr;
+ rect.x = rect.y = 0;
+ rect.height = 1; /* only the width is important */
+ rect.width = 2 * height; /* FIXME, should not always be 2 */
+ attr = pango_attr_shape_new (&rect, &rect);
+ attr->start_index = str->len;
+ g_string_append_c (str, 'o');
+ attr->end_index = str->len;
+ pango_attr_list_insert (markup, attr);
break;
+ }
case '0':
case '1':
case '2':
diff --git a/goffice/gtk/go-rotation-sel.c b/goffice/gtk/go-rotation-sel.c
index 52e287c..c8d1dcf 100644
--- a/goffice/gtk/go-rotation-sel.c
+++ b/goffice/gtk/go-rotation-sel.c
@@ -84,17 +84,11 @@ cb_rotate_changed (GORotationSel *grs)
if (grs->text) {
double x = 15.0;
double y = 100.0;
- double rad = grs->angle * M_PI / 180.;
- double w = grs->rot_width * cos (fabs (rad)) + grs->rot_height * sin (fabs (rad));
- double h = grs->rot_width * sin (fabs (rad)) + grs->rot_height * cos (fabs (rad));
- x -= grs->rot_height * sin (fabs (rad)) / 2;
- y -= grs->rot_height * cos (rad) / 2;
- if (rad >= 0)
- y -= grs->rot_width * sin (rad);
+ double rad = -grs->angle * M_PI / 180.;
+ if (rad < 0)
+ rad += 2 * M_PI;
goc_item_set (grs->text, "x", x, "y", y,
- "width", w, "height", h, NULL);
- gtk_label_set_angle (GTK_LABEL (grs->text_widget),
- (grs->angle + 360) % 360);
+ "rotation", rad, NULL);
}
}
@@ -131,10 +125,11 @@ cb_rotate_canvas_realize (GocCanvas *canvas, GORotationSel *grs)
go_style->line.color = GO_COLOR_BLACK;
{
- int w, h;
- GtkWidget *tw = grs->text_widget = gtk_label_new (_("Text"));
+ double x, y, w, h;
+ PangoContext *ctxt = gtk_widget_get_pango_context (GTK_WIDGET (canvas));
+ PangoFontDescription const *desc = pango_context_get_font_description (ctxt);
PangoAttrList *attrs = pango_attr_list_new ();
- PangoAttribute *attr = pango_attr_scale_new (1.3);
+ PangoAttribute *attr = pango_attr_size_new (1.3 * pango_font_description_get_size (desc));
attr->start_index = 0;
attr->end_index = -1;
pango_attr_list_insert (attrs, attr);
@@ -144,16 +139,14 @@ cb_rotate_canvas_realize (GocCanvas *canvas, GORotationSel *grs)
attr->end_index = -1;
pango_attr_list_insert (attrs, attr);
#endif
- gtk_label_set_attributes (GTK_LABEL (tw), attrs);
+ grs->text = goc_item_new (group, GOC_TYPE_TEXT,
+ "text", _("Text"), "attributes", attrs,
+ "anchor", GO_ANCHOR_W, "x", 15., "y", 100., NULL);
+ goc_item_get_bounds (grs->text, &x, &y, &w, &h);
pango_attr_list_unref (attrs);
- pango_layout_get_pixel_size (gtk_label_get_layout (GTK_LABEL (tw)), &w, &h);
- grs->rot_width = w;
- grs->rot_height = h;
-
- grs->text = goc_item_new (group, GOC_TYPE_WIDGET,
- "widget", tw, NULL);
- gtk_widget_show (tw);
+ grs->rot_width = w - x;
+ grs->rot_height = h - y;
}
cb_rotate_changed (grs);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]