summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2011-03-15 22:02:06 +0000
committerVincent Sanders <vince@netsurf-browser.org>2011-03-15 22:02:06 +0000
commit1da7b161f8eb8e2afbb46e9e2904dc3973fc2458 (patch)
treeb8e3f8f4fdd19d316c12dc39d515f053a6723a9a
parentb69816ff79aec1a472cdb184c45452d6926cf6f7 (diff)
downloadnetsurf-1da7b161f8eb8e2afbb46e9e2904dc3973fc2458.tar.gz
netsurf-1da7b161f8eb8e2afbb46e9e2904dc3973fc2458.tar.bz2
Stop gtk printing from exploding if its unable to initialise the job
add interface to clone a high level cache handle make generic printing core call new hlcache interface svn path=/trunk/netsurf/; revision=12068
-rw-r--r--content/hlcache.c6
-rw-r--r--content/hlcache.h10
-rw-r--r--desktop/print.c43
-rw-r--r--gtk/print.c29
-rw-r--r--utils/errors.h4
5 files changed, 39 insertions, 53 deletions
diff --git a/content/hlcache.c b/content/hlcache.c
index d1da79509..a53db5d9f 100644
--- a/content/hlcache.c
+++ b/content/hlcache.c
@@ -370,6 +370,12 @@ nserror hlcache_handle_replace_callback(hlcache_handle *handle,
return NSERROR_OK;
}
+nserror hlcache_handle_clone(hlcache_handle *handle, hlcache_handle **result)
+{
+ *result = NULL;
+ return NSERROR_CLONE_FAILED;
+}
+
/******************************************************************************
* High-level cache internals *
******************************************************************************/
diff --git a/content/hlcache.h b/content/hlcache.h
index 3006b9e4d..c4e10915a 100644
--- a/content/hlcache.h
+++ b/content/hlcache.h
@@ -165,4 +165,14 @@ nserror hlcache_handle_replace_callback(hlcache_handle *handle,
*/
struct content *hlcache_handle_get_content(const hlcache_handle *handle);
+/**
+ * Clone a high level cache handle.
+ *
+ * \param handle The handle to clone.
+ * \param result The cloned handle.
+ * \return NSERROR_OK on success, appropriate error otherwise
+ *
+ */
+nserror hlcache_handle_clone(hlcache_handle *handle, hlcache_handle **result);
+
#endif
diff --git a/desktop/print.c b/desktop/print.c
index fbc0c4790..ab36f24f1 100644
--- a/desktop/print.c
+++ b/desktop/print.c
@@ -159,43 +159,11 @@ bool print_draw_next_page(const struct printer *printer,
hlcache_handle *print_init(hlcache_handle *content,
struct print_settings *settings)
{
-#ifdef FIX_CORE_PRINTING
hlcache_handle* printed_content;
- hlcache_handle_user *user_sentinel;
-
- content_add_user(content, NULL, (intptr_t) print_init, 0);
-
- printed_content = talloc_memdup(content, content, sizeof *content);
-
- if (!printed_content)
- return NULL;
-
- printed_content->data.html.bw = 0;
-
- user_sentinel = talloc(printed_content, hlcache_handle_user);
- user_sentinel->callback = 0;
- user_sentinel->p1 = user_sentinel->p2 = 0;
- user_sentinel->next = 0;
- printed_content->user_list = user_sentinel;
- content_add_user(printed_content, NULL, (intptr_t)print_init, 0);
-
- printed_content->data.html.layout =
- box_duplicate_tree(content->data.html.layout,
- printed_content);
-
- if (!printed_content->data.html.layout) {
- talloc_free(printed_content);
- return NULL;
- }
-
- assert(settings->font_func != NULL);
-
- printed_content->data.html.font_func = settings->font_func;
+ hlcache_handle_clone(content, &printed_content);
+
return printed_content;
-#else
- return NULL;
-#endif
}
/**
@@ -240,21 +208,16 @@ bool print_apply_settings(hlcache_handle *content,
bool print_cleanup(hlcache_handle *content, const struct printer *printer,
struct print_settings *settings)
{
-#ifdef FIX_CORE_PRINTING
printer->print_end();
html_redraw_printing = false;
if (printed_content) {
- content_remove_user(printed_content, NULL, print_init);
- talloc_free(printed_content);
+ hlcache_handle_release(printed_content);
}
- content_remove_user(content, NULL, print_init);
-
free((void *)settings->output);
free(settings);
-#endif
return true;
}
diff --git a/gtk/print.c b/gtk/print.c
index 667c554ee..ecd9a93f3 100644
--- a/gtk/print.c
+++ b/gtk/print.c
@@ -497,24 +497,29 @@ void gtk_print_signal_begin_print (GtkPrintOperation *operation,
settings->scale = 0.7;/*at 0.7 the pages look the best*/
settings->font_func = &nsfont;
- print_set_up(content_to_print, &gtk_printer,
- settings, &height_to_print);
+ if (print_set_up(content_to_print, &gtk_printer,
+ settings, &height_to_print) == false) {
+ gtk_print_operation_cancel(operation);
+
+ } else {
- LOG(("page_width: %f ;page_height: %f; content height: %lf",
- settings->page_width, settings->page_height, height_to_print));
+ LOG(("page_width: %f ;page_height: %f; content height: %lf",
+ settings->page_width, settings->page_height,
+ height_to_print));
- height_on_page = settings->page_height;
- height_on_page = height_on_page -
+ height_on_page = settings->page_height;
+ height_on_page = height_on_page -
FIXTOFLT(FSUB(settings->margins[MARGINTOP],
- settings->margins[MARGINBOTTOM]));
- height_to_print *= settings->scale;
+ settings->margins[MARGINBOTTOM]));
+ height_to_print *= settings->scale;
- page_number = height_to_print / height_on_page;
+ page_number = height_to_print / height_on_page;
- if (height_to_print - page_number * height_on_page > 0)
- page_number += 1;
+ if (height_to_print - page_number * height_on_page > 0)
+ page_number += 1;
- gtk_print_operation_set_n_pages(operation, page_number);
+ gtk_print_operation_set_n_pages(operation, page_number);
+ }
}
/**
diff --git a/utils/errors.h b/utils/errors.h
index 818ccc5fd..1a634f615 100644
--- a/utils/errors.h
+++ b/utils/errors.h
@@ -35,7 +35,9 @@ typedef enum {
NSERROR_NOT_FOUND, /**< Requested item not found */
- NSERROR_SAVE_FAILED /**< Failed to save data */
+ NSERROR_SAVE_FAILED, /**< Failed to save data */
+
+ NSERROR_CLONE_FAILED /**< Failed to clone handle */
} nserror;
#endif