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
This commit is contained in:
Vincent Sanders 2011-03-15 22:02:06 +00:00
parent b69816ff79
commit 1da7b161f8
5 changed files with 39 additions and 53 deletions

View File

@ -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 *
******************************************************************************/

View File

@ -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

View File

@ -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;
}

View File

@ -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);
}
}
/**

View File

@ -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