[gnumeric] ssconvert: doc fixes and impose ordering of graph export.



commit 741d68dcbaa1d26fe279f28d41057e660a7a2c6b
Author: Morten Welinder <terra gnome org>
Date:   Sun Apr 19 20:13:14 2020 -0400

    ssconvert: doc fixes and impose ordering of graph export.

 ChangeLog       |  7 +++++++
 NEWS            |  2 ++
 doc/ssconvert.1 | 16 ++++++++++++----
 src/ssconvert.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6197cafcb..821e1c8d1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-04-19  Morten Welinder  <terra gnome org>
+
+       * src/ssconvert.c (list_image_formats): New function, handling new
+       option --list-image-formats.
+       (do_split_save): When exporting graphs, sort top-to-bottom,
+       left-to-right.
+
 2020-04-13  Morten Welinder  <terra gnome org>
 
        * src/sheet-object-graph.c (gnm_sog_write_image): Fix criticals.
diff --git a/NEWS b/NEWS
index 05b5aaf2c..91751c95b 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,8 @@ Morten:
        * Improve tests.
        * Improve speed on exit with lots of conditional formatting.
        * Improve error message [#472]
+       * Impose ordering of ssconvert --export-graphs
+       * Doc fixes.
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.46
diff --git a/doc/ssconvert.1 b/doc/ssconvert.1
index c814772e3..575b59084 100644
--- a/doc/ssconvert.1
+++ b/doc/ssconvert.1
@@ -2,7 +2,7 @@
 \\$2 \(laURL: \\$1 \(ra\\$3
 ..
 .if \n[.g] .mso www.tmac
-.TH SSCONVERT 1 "2019-01-19" "gnumeric" "GNOME"
+.TH SSCONVERT 1 "2020-04-19" "gnumeric" "GNOME"
 .SH NAME
 ssconvert \- a command line spreadsheet format converter
 
@@ -37,7 +37,7 @@ put an expression in a cell, add an extra =, for example \-\-set "A11==A10+1".
 This option may be repeated as many times as needed.  The workbook will be
 recalculated after all cells have been set, provided that the workbook is
 set for automatic recalculation.  If not, recalculation can be forced
-with --recalc.
+with \-\-recalc.
 .TP
 .B \-v, \-\-verbose
 Be slightly more verbose about what is going on.
@@ -48,7 +48,11 @@ List the available exporters (file formats that can be written).
 .B \-T, \-\-export\-type=\fIID\fR
 Specify which exporter to use; see below for a list. This is only
 necessary when the right format does not follow from the output file
-name.
+name.  The list of available export formats can be generated using the
+\-\-list\-exporters option.  However, when image export is requested
+using the \-\-export\-graphs option, the list of image formats should be
+consulted instead.  That list can be generated using the
+\-\-list\-image\-formats option.
 .TP
 .B \-O, \-\-export\-options=\fIoptionsstring\fR
 Specify parameters for the chosen exporter.
@@ -59,7 +63,8 @@ documented below. Multiple parameters can be specified
 .TP
 .B \-\-export\-graphs
 Export the graphs (or charts) inside the input spreadsheet to
-numbered image files (SVG by default).
+numbered image files (SVG by default).  The list of available image
+formats can be printed with \-\-list\-image-formats
 .TP
 .B \-\-list\-importers
 List the available importers (file formats that can be read).
@@ -68,6 +73,9 @@ Specify which importer to use; see below for a list. This is only
 necessary when the right format does not follow from the input file
 name.
 .TP
+.B \-\-list\-image\-formats
+List the available image formats for graph export
+.TP
 .B \-E, \-\-import\-encoding=\fISTRING\fR
 Specify an encoding for imported content.
 .TP
diff --git a/src/ssconvert.c b/src/ssconvert.c
index 41b3a6931..c2cf5db5a 100644
--- a/src/ssconvert.c
+++ b/src/ssconvert.c
@@ -53,6 +53,7 @@ static gboolean ssconvert_show_version = FALSE;
 static gboolean ssconvert_verbose = FALSE;
 static gboolean ssconvert_list_exporters = FALSE;
 static gboolean ssconvert_list_importers = FALSE;
+static gboolean ssconvert_list_image_formats = FALSE;
 static gboolean ssconvert_one_file_per_sheet = FALSE;
 static gboolean ssconvert_object_export = FALSE;
 static GType ssconvert_object_export_type;
@@ -153,6 +154,13 @@ static const GOptionEntry ssconvert_options [] = {
                NULL
        },
 
+       {
+               "list-image-formats", 0,
+               0, G_OPTION_ARG_NONE, &ssconvert_list_image_formats,
+               N_("List the available image formats"),
+               NULL
+       },
+
        {
                "set", 0,
                0, G_OPTION_ARG_STRING_ARRAY, &ssconvert_set_cells,
@@ -405,6 +413,32 @@ list_them (GList *them,
        g_list_free (them_copy);
 }
 
+static void
+list_image_formats (void)
+{
+       GOImageFormat imfmt;
+       unsigned len = 0;
+
+       for (imfmt = (GOImageFormat)0; imfmt < GO_IMAGE_FORMAT_UNKNOWN; imfmt++) {
+               GOImageFormatInfo const *info = go_image_get_format_info (imfmt);
+               len = MAX (len, strlen (info->name));
+       }
+
+       g_printerr ("%-*s | %s\n", len,
+                   /* Translate these? */
+                   _("ID"),
+                   _("Description"));
+
+       for (imfmt = (GOImageFormat)0; imfmt < GO_IMAGE_FORMAT_UNKNOWN; imfmt++) {
+               GOImageFormatInfo const *info = go_image_get_format_info (imfmt);
+
+               g_printerr ("%-*s | %s\n", len,
+                           info->name,
+                           info->desc);
+       }
+}
+
+
 /*
  * Read the files we're going to merge and return a list of Workbooks.
  */
@@ -790,6 +824,26 @@ run_tool_test (const char *tool, char **argv, WorkbookView *wbv)
 #undef RANGE_LISTARG
 #undef SHEET_ARG
 
+static int
+by_anchor (gconstpointer a_, gconstpointer b_)
+{
+       SheetObject const *a = a_;
+       SheetObject const *b = b_;
+       double ca[4], cb[4];
+       unsigned ui;
+
+       // Caller ensures that sheets are the same
+       sheet_object_position_pts_get (a, ca);
+       sheet_object_position_pts_get (b, cb);
+
+       for (ui = 0; ui < G_N_ELEMENTS (ca); ui++) {
+               // We want T,L,B,R order
+               double d = ca[ui ^ 1] - cb[ui ^ 1];
+               if (d != 0)
+                       return d < 0 ? -1 : +1;
+       }
+       return 0;
+}
 
 static int
 do_split_save (GOFileSaver *fs, WorkbookView *wbv,
@@ -850,6 +904,7 @@ do_split_save (GOFileSaver *fs, WorkbookView *wbv,
                if (ssconvert_object_export) {
                        GSList *l, *objs = sheet_objects_get (sheet, NULL, GNM_SO_GRAPH_TYPE);
                        double resolution = 100.0;
+                       objs = g_slist_sort (objs, by_anchor);
                        for (l = objs; l; l = l->next) {
                                SheetObject *so = l->data;
                                char *tmpfile;
@@ -1312,6 +1367,8 @@ main (int argc, char const **argv)
                list_them (go_get_file_openers (),
                           (get_desc_f) &go_file_opener_get_id,
                           (get_desc_f) &go_file_opener_get_description);
+       else if (ssconvert_list_image_formats)
+               list_image_formats ();
        else if (ssconvert_clipboard)
                if (argc == 3 && ssconvert_range)
                        res = clipboard_export (argv[1], argv[2], cc);


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