[goffice] Enhanced text rotation in graphs.



commit 746a8705d6e621d1aaa1cd951c850cf9e6affdc0
Author: Jean Brefort <jean brefort normalesup org>
Date:   Sat Oct 20 10:23:42 2012 +0200

    Enhanced text rotation in graphs.

 ChangeLog                      |   13 ++++++++++++
 goffice/graph/gog-label.c      |   21 ++++++++++++++----
 goffice/gtk/go-rotation-sel.c  |   43 +++++++++++++++++++++++++++-------------
 goffice/gtk/go-rotation-sel.h  |    1 +
 goffice/gtk/go-rotation-sel.ui |   21 +++++++++++++++---
 goffice/utils/go-style.c       |    2 +-
 6 files changed, 77 insertions(+), 24 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7b59dd7..5da2100 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2012-10-20  Jean Brefort  <jean brefort normalesup org>
+
+	* goffice/graph/gog-label.c (gog_text_view_size_request),
+	(gog_text_view_render): fix rotated frames position.
+	* goffice/gtk/go-rotation-sel.c (cb_rotate_changed),
+	(cb_rotate_canvas_realize), (set_rot_from_point),
+	(go_rotation_sel_new), (go_rotation_sel_new_full): optionally support
+	-180Â to 180Â as allowed by GOStyle.
+	* goffice/gtk/go-rotation-sel.h: ditto.
+	* goffice/gtk/go-rotation-sel.ui: minor layout fix.
+	* goffice/utils/go-style.c (text_layout_init): use a full circle rotation
+	selector.
+
 2012-10-19  Jean Brefort  <jean brefort normalesup org>
 
 	* goffice/graph/gog-label.c (gog_text_view_render):
diff --git a/goffice/graph/gog-label.c b/goffice/graph/gog-label.c
index c57b682..4463fa9 100644
--- a/goffice/graph/gog-label.c
+++ b/goffice/graph/gog-label.c
@@ -661,7 +661,9 @@ gog_text_view_size_request (GogView *v,
 			: NULL;
 		GOStyle *style = go_style_dup (text->base.base.style);
 		double rot = fabs (style->text_layout.angle / 180 * M_PI);
-		if (text->rotate_frame)
+		if (rot > M_PI / 2.)
+			rot = M_PI - rot;
+	    if (text->rotate_frame)
 			style->text_layout.angle = 0.;
 		gog_renderer_push_style (v->renderer, style);
 		if (gostr) {
@@ -722,10 +724,19 @@ gog_text_view_render (GogView *view, GogViewAllocation const *bbox)
 			rect.w = aabr.w + 2. * outline + pad_x;
 			rect.h = aabr.h + 2. * outline + pad_y;
 			if (text->rotate_frame) {
-				if (rot > 0.)
-					rect.y += rect.w * sin (rot);
-				else
-					rect.x -= rect.h * sin (rot);
+				if (rot > 0.) {
+					if (rot > M_PI / 2.) {
+						rect.y += rect.w * sin (rot) - rect.h * cos (rot);
+						rect.x -= rect.w * cos (rot);
+					} else
+						rect.y += rect.w * sin (rot);
+				} else {
+					if (rot < -M_PI / 2.) {
+						rect.y -= rect.h * cos (rot);
+						rect.x -= rect.w * cos (rot) + rect.h * sin (rot);
+					} else
+						rect.x -= rect.h * sin (rot);
+				}
 				gog_renderer_pop_style (view->renderer);
 				g_object_unref (rect_style);
 				gog_renderer_draw_rotated_rectangle (view->renderer, &rect, text->rotate_bg);
diff --git a/goffice/gtk/go-rotation-sel.c b/goffice/gtk/go-rotation-sel.c
index 4125bed..42b613c 100644
--- a/goffice/gtk/go-rotation-sel.c
+++ b/goffice/gtk/go-rotation-sel.c
@@ -30,12 +30,13 @@ struct _GORotationSel {
 
 	GtkSpinButton	*rotate_spinner;
 	GocCanvas       *rotate_canvas;
-	GocItem		*rotate_marks[13];
+	GocItem		*rotate_marks[25];
 	GocItem		*line;
 	GtkWidget       *text_widget;
 	GocItem		*text;
 	int		 rot_width, rot_height;
 	gulong		 motion_handle;
+	gboolean full;
 };
 
 typedef struct {
@@ -55,15 +56,18 @@ static void
 cb_rotate_changed (GORotationSel *grs)
 {
 	GOColor colour;
-	int i;
+	int i, maxi = grs->full? 23: 12;
+	double x0 = grs->full? 100.: 15.;
+	int angle;
 
 	go_rotation_sel_set_rotation (grs,
 		gtk_spin_button_get_value_as_int (grs->rotate_spinner) % 360);
+	angle = (grs->angle < -90)? grs->angle + 360: grs->angle;
 
-	for (i = 0 ; i <= 12 ; i++)
+	for (i = 0 ; i <= maxi ; i++)
 		if (grs->rotate_marks[i] != NULL) {
 			GOStyle *style = go_styled_object_get_style (GO_STYLED_OBJECT (grs->rotate_marks[i]));
-			colour = (grs->angle == (i-6)*15) ? GO_COLOR_GREEN : GO_COLOR_BLACK;
+			colour = (angle == (i-6)*15) ? GO_COLOR_GREEN : GO_COLOR_BLACK;
 			if (style->fill.pattern.back != colour){
 				style->fill.pattern.back = colour;
 				goc_item_invalidate (grs->rotate_marks[i]);
@@ -73,20 +77,18 @@ cb_rotate_changed (GORotationSel *grs)
 	if (grs->line != NULL) {
 		double rad = grs->angle * M_PI / 180.;
 		goc_item_set (grs->line,
-		              "x0", 15 + cos (rad) * grs->rot_width,
+		              "x0", x0 + cos (rad) * grs->rot_width,
 		              "y0", 100 - sin (rad) * grs->rot_width,
-		              "x1", 15 + cos (rad) * 72.,
+		              "x1", x0 + cos (rad) * 72.,
 		              "y1", 100 - sin (rad) * 72.,
 		              NULL);
 	}
 
 	if (grs->text) {
-		double x = 15.0;
-		double y = 100.0;
 		double rad = -grs->angle * M_PI / 180.;
 		if (rad < 0)
 			rad += 2 * M_PI;
-		goc_item_set (grs->text, "x", x, "y", y,
+		goc_item_set (grs->text, "x", x0, "y", 100.,
 		              "rotation", rad, NULL);
 	}
 }
@@ -95,16 +97,17 @@ static void
 cb_rotate_canvas_realize (GocCanvas *canvas, GORotationSel *grs)
 {
 	GocGroup  *group = goc_canvas_get_root (canvas);
-	int i;
+	int i, maxint = grs->full? 23: 12;
 	GOStyle *go_style;
 	GdkRGBA color = {1., 1., 1., 1.};
+	double x0 = grs->full? 100.: 15.;
 
 	gtk_widget_override_background_color (GTK_WIDGET (canvas),
 	                                      GTK_STATE_NORMAL, &color);
 
-	for (i = 0 ; i <= 12 ; i++) {
+	for (i = 0 ; i <= maxint ; i++) {
 		double rad = (i-6) * M_PI / 12.;
-		double x = 15 + cos (rad) * 80.;
+		double x = x0 + cos (rad) * 80.;
 		double y = 100 - sin (rad) * 80.;
 		double size = (i % 3) ? 3.0 : 4.0;
 		GocItem *item = goc_item_new (group,
@@ -140,7 +143,7 @@ cb_rotate_canvas_realize (GocCanvas *canvas, GORotationSel *grs)
 #endif
 		grs->text = goc_item_new (group, GOC_TYPE_TEXT,
 			"text", _("Text"), "attributes", attrs,
-		         "anchor", GO_ANCHOR_W, "x", 15., "y", 100., NULL);
+		         "anchor", GO_ANCHOR_W, "x", x0, "y", 100., NULL);
 		goc_item_get_bounds (grs->text, &x, &y, &w, &h);
 		pango_attr_list_unref (attrs);
 
@@ -155,7 +158,7 @@ static void
 set_rot_from_point (GORotationSel *grs, double x, double y)
 {
 	double degrees;
-	x -= 15.;	if (x < 0.) x = 0.;
+	x -= grs->full? 100.: 15.;	if (!grs->full && x < 0.) x = 0.;
 	y -= 100.;
 
 	degrees = atan2 (-y, x) * 180 / M_PI;
@@ -274,6 +277,18 @@ go_rotation_sel_new (void)
 	return g_object_new (GO_TYPE_ROTATION_SEL, NULL);
 }
 
+GtkWidget *
+go_rotation_sel_new_full (void)
+{
+	GORotationSel *grs = g_object_new (GO_TYPE_ROTATION_SEL, NULL);
+	GtkAdjustment *adj = gtk_spin_button_get_adjustment (grs->rotate_spinner);
+	gtk_adjustment_set_lower (adj, -180.);
+	gtk_adjustment_set_upper (adj, 180.);
+	grs->full = TRUE;
+	g_object_set (gtk_builder_get_object (grs->gui, "rotate_canvas_container"), "width-request", 200, NULL);
+	return (GtkWidget *) grs;
+}
+
 int
 go_rotation_sel_get_rotation (GORotationSel const *grs)
 {
diff --git a/goffice/gtk/go-rotation-sel.h b/goffice/gtk/go-rotation-sel.h
index b06d092..e6abea3 100644
--- a/goffice/gtk/go-rotation-sel.h
+++ b/goffice/gtk/go-rotation-sel.h
@@ -31,6 +31,7 @@ typedef struct _GORotationSel GORotationSel;
 
 GType      go_rotation_sel_get_type (void);
 GtkWidget *go_rotation_sel_new      (void);
+GtkWidget *go_rotation_sel_new_full (void);
 void	   go_rotation_sel_set_rotation (GORotationSel *rs, int degrees);
 int	   go_rotation_sel_get_rotation (GORotationSel const *rs);
 
diff --git a/goffice/gtk/go-rotation-sel.ui b/goffice/gtk/go-rotation-sel.ui
index 1176e5b..74fa85f 100644
--- a/goffice/gtk/go-rotation-sel.ui
+++ b/goffice/gtk/go-rotation-sel.ui
@@ -1,7 +1,6 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
-  <!-- interface-naming-policy toplevel-contextual -->
   <object class="GtkAdjustment" id="adjustment1">
     <property name="lower">-90</property>
     <property name="upper">90</property>
@@ -10,11 +9,13 @@
   </object>
   <object class="GtkBox" id="toplevel">
     <property name="visible">True</property>
+    <property name="can_focus">False</property>
     <property name="orientation">vertical</property>
     <property name="spacing">12</property>
     <child>
       <object class="GtkLabel" id="label72">
         <property name="visible">True</property>
+        <property name="can_focus">False</property>
         <property name="xalign">0</property>
         <property name="label" translatable="yes">&lt;b&gt;Orientation&lt;/b&gt;</property>
         <property name="use_markup">True</property>
@@ -28,9 +29,11 @@
     <child>
       <object class="GtkBox" id="hbox44">
         <property name="visible">True</property>
+        <property name="can_focus">False</property>
         <child>
           <object class="GtkLabel" id="label73">
             <property name="visible">True</property>
+            <property name="can_focus">False</property>
             <property name="label">    </property>
           </object>
           <packing>
@@ -42,15 +45,17 @@
         <child>
           <object class="GtkBox" id="vbox53">
             <property name="visible">True</property>
+            <property name="can_focus">False</property>
             <property name="orientation">vertical</property>
             <property name="spacing">6</property>
             <child>
               <object class="GtkBox" id="hbox58">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
                 <child>
                   <object class="GtkScrolledWindow" id="rotate_canvas_container">
                     <property name="width_request">140</property>
-                    <property name="height_request">210</property>
+                    <property name="height_request">200</property>
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="hscrollbar_policy">never</property>
@@ -76,10 +81,12 @@
             <child>
               <object class="GtkBox" id="hbox39">
                 <property name="visible">True</property>
+                <property name="can_focus">False</property>
                 <property name="spacing">6</property>
                 <child>
                   <object class="GtkLabel" id="label87">
                     <property name="visible">True</property>
+                    <property name="can_focus">False</property>
                     <property name="label" translatable="yes">A_ngle:</property>
                     <property name="use_underline">True</property>
                     <property name="mnemonic_widget">rotate_spinner</property>
@@ -94,19 +101,21 @@
                   <object class="GtkSpinButton" id="rotate_spinner">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
-                    <property name="invisible_char">&#x2022;</property>
+                    <property name="invisible_char">â</property>
                     <property name="adjustment">adjustment1</property>
                     <property name="climb_rate">1</property>
                     <property name="numeric">True</property>
                   </object>
                   <packing>
                     <property name="expand">False</property>
+                    <property name="fill">True</property>
                     <property name="position">1</property>
                   </packing>
                 </child>
                 <child>
                   <object class="GtkLabel" id="label62">
                     <property name="visible">True</property>
+                    <property name="can_focus">False</property>
                     <property name="label" translatable="yes">degrees</property>
                     <property name="use_underline">True</property>
                     <property name="mnemonic_widget">rotate_spinner</property>
@@ -120,17 +129,21 @@
               </object>
               <packing>
                 <property name="expand">False</property>
+                <property name="fill">True</property>
                 <property name="position">1</property>
               </packing>
             </child>
           </object>
           <packing>
             <property name="expand">False</property>
+            <property name="fill">True</property>
             <property name="position">1</property>
           </packing>
         </child>
       </object>
       <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
         <property name="position">1</property>
       </packing>
     </child>
diff --git a/goffice/utils/go-style.c b/goffice/utils/go-style.c
index 7902494..46573a6 100644
--- a/goffice/utils/go-style.c
+++ b/goffice/utils/go-style.c
@@ -960,7 +960,7 @@ text_layout_init (StylePrefState *state, guint32 enable, GOEditor *editor, GOCmd
 	if (!enable)
 		return;
 
-	w = go_rotation_sel_new ();
+	w = go_rotation_sel_new_full ();
 	go_rotation_sel_set_rotation (GO_ROTATION_SEL (w),
 		style->text_layout.angle);
 	g_signal_connect (G_OBJECT (w), "rotation-changed",



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]