[gnumeric] SheetObjectGraph: tell the sheet object about the anchor size.



commit b43b1f8a91fd735188b0c3f6fc052adf4d017bf6
Author: Morten Welinder <terra gnome org>
Date:   Thu Jan 28 16:34:43 2021 -0500

    SheetObjectGraph: tell the sheet object about the anchor size.
    
    It's used for image output, see #507.

 ChangeLog                |  5 +++++
 NEWS                     |  1 +
 src/sheet-object-graph.c | 33 ++++++++++++++++++++++++---------
 src/sheet-object.c       |  1 -
 4 files changed, 30 insertions(+), 10 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 4fbb5a4b9..2d8c4408d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2021-01-28  Morten Welinder  <terra gnome org>
 
+       * src/sheet-object-graph.c (gnm_sog_bounds_changed): Make sure to
+       tell the graph about the new size.
+       (gnm_sog_set_sheet): Tell the graph object about the initial size.
+       (sheet_object_graph_set_gog): Ditto.
+
        * src/number-match.c (format_match_decimal_number_with_locale): If
        the thousands separator is a space character, allow plain space
        also.
diff --git a/NEWS b/NEWS
index 5d329165c..2508aa8f9 100644
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,7 @@ Morten:
        * Fix ods import problem with irregular sheet sizes.
        * Fix ods import problem with crazy named expressions.  [#557]
        * Allow plain space as 1000s separator in FR locale.
+       * Fix graph size problem affecting image output.  [#507]
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.48
diff --git a/src/sheet-object-graph.c b/src/sheet-object-graph.c
index ec3da1b13..2ab4e4688 100644
--- a/src/sheet-object-graph.c
+++ b/src/sheet-object-graph.c
@@ -520,12 +520,31 @@ gnm_sog_foreach_dep (SheetObject *so,
                sog_data_foreach_dep (so, ptr->data, func, user);
 }
 
+static void
+sog_update_graph_size (SheetObjectGraph *sog)
+{
+       double coords[4];
+       SheetObject *so = GNM_SO (sog);
+
+       if (sog->graph == NULL || so->sheet == NULL)
+               return;
+
+       sheet_object_position_pts_get (so, coords);
+       gog_graph_set_size (sog->graph,
+                           fabs (coords[2] - coords[0]),
+                           fabs (coords[3] - coords[1]));
+}
+
 static gboolean
 gnm_sog_set_sheet (SheetObject *so, Sheet *sheet)
 {
        SheetObjectGraph *sog = GNM_SO_GRAPH (so);
-       if (sog->graph != NULL)
+
+       if (sog->graph != NULL) {
                sog_datas_set_sheet (sog, sheet);
+               sog_update_graph_size (sog);
+       }
+
        return FALSE;
 }
 
@@ -551,14 +570,8 @@ gnm_sog_bounds_changed (SheetObject *so)
        SheetObjectGraph *sog = GNM_SO_GRAPH (so);
 
        /* If it has not been realized there is no renderer yet */
-       if (sog->renderer != NULL) {
-               double coords [4];
-               if (so->sheet->sheet_type == GNM_SHEET_DATA) {
-                       sheet_object_position_pts_get (so, coords);
-                       gog_graph_set_size (sog->graph, fabs (coords[2] - coords[0]),
-                                           fabs (coords[3] - coords[1]));
-               }
-       }
+       if (sog->renderer != NULL)
+               sog_update_graph_size (sog);
 }
 
 static void
@@ -697,6 +710,8 @@ sheet_object_graph_set_gog (SheetObject *so, GogGraph *graph)
                g_object_set (sog->renderer, "model", graph, NULL);
        else
                sog->renderer = gog_renderer_new (sog->graph);
+
+       sog_update_graph_size (sog);
 }
 
 static void
diff --git a/src/sheet-object.c b/src/sheet-object.c
index e84bd3657..ef2073cf8 100644
--- a/src/sheet-object.c
+++ b/src/sheet-object.c
@@ -1753,7 +1753,6 @@ sheet_object_write_image (SheetObject const *so, char const *format, double reso
 
        GNM_SO_IMAGEABLE_CLASS (so)->write_image (so, format, resolution,
                                                        output, err);
-
 }
 
 /**


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