[gnumeric] Add 'object' option to ssconvert pdf export. [#661405]
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Add 'object' option to ssconvert pdf export. [#661405]
- Date: Thu, 3 Nov 2011 18:27:55 +0000 (UTC)
commit 02ca4e22e0d8b7b1da20f53539b5d4a8ee8b4918
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Thu Nov 3 12:27:20 2011 -0600
Add 'object' option to ssconvert pdf export. [#661405]
2011-11-03 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/print-info.c (pdf_write_workbook): madify arguments
(cb_free_sheets): deleted
(pdf_export): new
(cb_set_pdf_option): use g_ptr_array_unref and support 'object' option
(print_init): use pdf_export instead of pdf_write_workbook
* src/print.h (gnm_print_so): modify arguments
* src/print.c (gnm_print_so): modify arguments and support output to gsf
* src/sheet-object.c (cb_so_print): adjust for modified arguments to
gnm_print_so
* src/ssconvert.c (convert): do not unref wb twice on error
2011-11-03 Andreas J. Guelzow <aguelzow pyrshep ca>
* ssconvert.1: add new 'object' option for pdf exporter
ChangeLog | 13 +++++++++++
NEWS | 1 +
doc/C/ChangeLog | 4 +++
doc/C/ssconvert.1 | 7 +++++-
src/print-info.c | 55 +++++++++++++++++++++++++++++++++++++++++-----
src/print.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++---
src/print.h | 3 +-
src/sheet-object.c | 5 +++-
src/ssconvert.c | 4 +--
9 files changed, 138 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 07a3d3f..f52e36c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2011-11-03 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * src/print-info.c (pdf_write_workbook): madify arguments
+ (cb_free_sheets): deleted
+ (pdf_export): new
+ (cb_set_pdf_option): use g_ptr_array_unref and support 'object' option
+ (print_init): use pdf_export instead of pdf_write_workbook
+ * src/print.h (gnm_print_so): modify arguments
+ * src/print.c (gnm_print_so): modify arguments and support output to gsf
+ * src/sheet-object.c (cb_so_print): adjust for modified arguments to
+ gnm_print_so
+ * src/ssconvert.c (convert): do not unref wb twice on error
+
2011-11-03 Morten Welinder <terra gnome org>
* src/print-info.c (print_info_load_defaults): Plug leak.
diff --git a/NEWS b/NEWS
index 8a89753..65ed37c 100644
--- a/NEWS
+++ b/NEWS
@@ -48,6 +48,7 @@ Andreas:
* Import hyperlinks from ODF. [#603533]
* Fix status of sub- and superscript buttons. [#662474]
* Fix name-definition in presence of placeholder. [#663117]
+ * Add 'object' option to ssconvert pdf export. [#661405]
Jean:
* Make things build against gtk+-3.0.
diff --git a/doc/C/ChangeLog b/doc/C/ChangeLog
index a2b741c..a7547d2 100644
--- a/doc/C/ChangeLog
+++ b/doc/C/ChangeLog
@@ -1,3 +1,7 @@
+2011-11-03 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * ssconvert.1: add new 'object' option for pdf exporter
+
2011-08-19 Andreas J. Guelzow <aguelzow pyrshep ca>
* func.defs: update
diff --git a/doc/C/ssconvert.1 b/doc/C/ssconvert.1
index 3fc7d93..b9fa35d 100644
--- a/doc/C/ssconvert.1
+++ b/doc/C/ssconvert.1
@@ -234,7 +234,12 @@ Mixed Integer Linear Programming (MILP) solver
.TP
.B sheet
-Name of the workbook sheet to operate on.
+Name of the workbook sheet to operate on. This is ignored if the \fBobject\fR option is given.
+
+.TP
+.B object
+Name of the sheet object to print. If this option is given any \fBsheet\fR option is ignored.
+Only the first \fBobject\fR given is exported.
.TP
.B paper
diff --git a/src/print-info.c b/src/print-info.c
index b6b631a..2ad51f6 100644
--- a/src/print-info.c
+++ b/src/print-info.c
@@ -709,9 +709,8 @@ hf_render_info_destroy (HFRenderInfo *hfi)
static void
pdf_write_workbook (GOFileSaver const *fs, GOIOContext *context,
- gconstpointer wbv_, GsfOutput *output)
+ WorkbookView const *wbv, GsfOutput *output)
{
- WorkbookView const *wbv = wbv_;
Workbook const *wb = wb_view_get_workbook (wbv);
GPtrArray *sheets = g_object_get_data (G_OBJECT (wb), "pdf-sheets");
@@ -733,9 +732,18 @@ pdf_write_workbook (GOFileSaver const *fs, GOIOContext *context,
}
static void
-cb_free_sheets (GPtrArray *a)
+pdf_export (GOFileSaver const *fs, GOIOContext *context,
+ gconstpointer wbv_, GsfOutput *output)
{
- g_ptr_array_free (a, TRUE);
+ WorkbookView const *wbv = wbv_;
+ Workbook const *wb = wb_view_get_workbook (wbv);
+ GPtrArray *sheets = g_object_get_data (G_OBJECT (wb), "pdf-sheets");
+ GPtrArray *objects = g_object_get_data (G_OBJECT (wb), "pdf-objects");
+
+ if (objects && objects->len > 0)
+ gnm_print_so (NULL, objects, output);
+ else
+ pdf_write_workbook (fs, context, wbv, output);
}
static gboolean
@@ -759,13 +767,48 @@ cb_set_pdf_option (const char *key, const char *value,
sheets = g_ptr_array_new ();
g_object_set_data_full (G_OBJECT (wb),
"pdf-sheets", sheets,
- (GDestroyNotify)cb_free_sheets);
+ (GDestroyNotify)g_ptr_array_unref);
}
g_ptr_array_add (sheets, sheet);
return FALSE;
}
+ if (strcmp (key, "object") == 0) {
+ GPtrArray *objects = g_object_get_data (G_OBJECT (wb), "pdf-objects");
+ GSList *sheets = workbook_sheets (wb);
+ gboolean object_seen = FALSE;
+
+ if (!objects) {
+ objects = g_ptr_array_new ();
+ g_object_set_data_full (G_OBJECT (wb),
+ "pdf-objects", objects,
+ (GDestroyNotify)g_ptr_array_unref);
+ }
+
+ for (; sheets != NULL; sheets = sheets->next) {
+ Sheet *sheet = sheets->data;
+ GSList *sobjects = sheet->sheet_objects;
+ for (; sobjects != NULL; sobjects = sobjects->next) {
+ SheetObject *so = sobjects->data;
+ gchar *name = NULL;
+ g_object_get (so, "name", &name, NULL);
+ if (strcmp (name, value) == 0) {
+ g_ptr_array_add (objects, so);
+ object_seen = TRUE;
+ }
+ }
+ }
+ if (!object_seen) {
+ *err = g_error_new (go_error_invalid (), 0,
+ _("There is no object with name "
+ "\'%s\'"), value);
+ return TRUE;
+ }
+
+ return FALSE;
+ }
+
if (strcmp (key, "paper") == 0) {
int i;
@@ -805,7 +848,7 @@ print_init (void)
GOFileSaver *saver = go_file_saver_new (
PDF_SAVER_ID, "pdf",
_("PDF export"),
- GO_FILE_FL_WRITE_ONLY, pdf_write_workbook);
+ GO_FILE_FL_WRITE_ONLY, pdf_export);
g_signal_connect (G_OBJECT (saver), "set-export-options",
G_CALLBACK (pdf_set_export_options),
NULL);
diff --git a/src/print.c b/src/print.c
index c1bf267..020348c 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1936,16 +1936,24 @@ gnm_draw_so_page_cb (G_GNUC_UNUSED GtkPrintOperation *operation,
}
void
-gnm_print_so (WorkbookControl *wbc, SheetObject *so)
+gnm_print_so (WorkbookControl *wbc, GPtrArray *sos,
+ GsfOutput *export_dst)
{
GtkPrintOperation *print;
GtkPageSetup *page_setup;
GtkPrintSettings* settings;
Sheet *sheet;
GtkWindow *parent = NULL;
+ GtkPrintOperationAction action;
+ gchar *tmp_file_name = NULL;
+ int tmp_file_fd = -1;
+ SheetObject *so;
- g_return_if_fail (so != NULL);
+ g_return_if_fail (sos != NULL && sos->len > 0);
+ /* FIXME: we should print all objects in teh array, not just the first! */
+
+ so = g_ptr_array_index (sos, 0),
sheet = sheet_object_get_sheet (so);
if (NULL != wbc && IS_WBC_GTK(wbc))
parent = wbcg_toplevel (WBC_GTK (wbc));
@@ -1971,9 +1979,55 @@ gnm_print_so (WorkbookControl *wbc, SheetObject *so)
gtk_print_operation_set_use_full_page (print, FALSE);
gtk_print_operation_set_unit (print, GTK_UNIT_POINTS);
- gtk_print_operation_set_show_progress (print, TRUE);
- gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, parent, NULL);
+ if (export_dst) {
+ GError *err = NULL;
+
+ tmp_file_fd = g_file_open_tmp ("gnmXXXXXX.pdf",
+ &tmp_file_name, &err);
+ if (err) {
+ gsf_output_set_error (export_dst, 0,
+ "%s", err->message);
+ g_error_free (err);
+ if (tmp_file_fd >= 0)
+ close (tmp_file_fd);
+ cb_delete_and_free (tmp_file_name);
+
+ g_object_unref (print);
+ return;
+ }
+ action = GTK_PRINT_OPERATION_ACTION_EXPORT;
+ gtk_print_operation_set_export_filename (print, tmp_file_name);
+ gtk_print_operation_set_show_progress (print, FALSE);
+ } else {
+ action = GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG;
+ gtk_print_operation_set_show_progress (print, TRUE);
+ }
+
+ gtk_print_operation_run (print, action, parent, NULL);
+
+ if (tmp_file_name) {
+ char buffer[64 * 1024];
+ gssize bytes_read;
+
+ if (lseek (tmp_file_fd, 0, SEEK_SET) < 0)
+ bytes_read = -1;
+ else {
+ while ((bytes_read = read
+ (tmp_file_fd, buffer, sizeof (buffer))) > 0) {
+ gsf_output_write (export_dst, bytes_read, buffer);
+ }
+ }
+ if (bytes_read < 0) {
+ int save_errno = errno;
+ if (!gsf_output_error (export_dst))
+ gsf_output_set_error (export_dst,
+ g_file_error_from_errno (save_errno),
+ "%s", g_strerror (save_errno));
+ }
+ close (tmp_file_fd);
+ cb_delete_and_free (tmp_file_name);
+ }
g_object_unref (print);
}
diff --git a/src/print.h b/src/print.h
index 3ab2cd2..00dc296 100644
--- a/src/print.h
+++ b/src/print.h
@@ -28,7 +28,8 @@ void gnm_print_sheet (WorkbookControl *wbc, Sheet *sheet,
gboolean preview, PrintRange default_range,
GsfOutput *export_dst);
-void gnm_print_so (WorkbookControl *wbc, SheetObject *so);
+void gnm_print_so (WorkbookControl *wbc, GPtrArray *sos,
+ GsfOutput *export_dst);
void gnm_print_sheet_objects (cairo_t *cr,
Sheet const *sheet,
diff --git a/src/sheet-object.c b/src/sheet-object.c
index 8d1103f..e779fea 100644
--- a/src/sheet-object.c
+++ b/src/sheet-object.c
@@ -133,7 +133,10 @@ cb_so_delete (SheetObject *so, SheetControl *sc)
static void
cb_so_print (SheetObject *so, SheetControl *sc)
{
- gnm_print_so (sc_wbc (sc), so);
+ GPtrArray *a = g_ptr_array_new ();
+ g_ptr_array_add (a, so);
+ gnm_print_so (sc_wbc (sc), a, NULL);
+ g_ptr_array_unref (a);
}
void
sheet_object_get_editor (SheetObject *so, SheetControl *sc)
diff --git a/src/ssconvert.c b/src/ssconvert.c
index 49f1380..5949a8f 100644
--- a/src/ssconvert.c
+++ b/src/ssconvert.c
@@ -609,10 +609,8 @@ convert (char const *inarg, char const *outarg, char const *mergeargs[],
wb = wb_view_get_workbook (wbv);
res = handle_export_options (fs, GO_DOC (wb));
- if (res) {
- g_object_unref (wb);
+ if (res)
goto out;
- }
if (mergeargs != NULL) {
if (merge (wb, mergeargs, fo, io_context, cc))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]