From 9c36d71ab89c8768dfe05cbf91f453282fc8baf9 Mon Sep 17 00:00:00 2001 From: John Tytgat Date: Sun, 28 Sep 2008 13:40:06 +0000 Subject: * desktop/save_pdf/pdf_plotters.c: - save_pdf(): constify path parameter and routine no longer frees it. Follow latter change in pdf_end(), nsgtk_PDF_set_pass() and nsgtk_PDF_no_pass() - pdf_printer: constify - last_clip_x0, last_clip_y0, last_clip_x1, last_clip_y1, in_text_mode, text_mode_request: make static - pdf_doc: free previous PDF document if previous save attempt failed. - set PDF Creator entry based on our user_agent_string(). * other minor changes. svn path=/trunk/netsurf/; revision=5452 --- desktop/save_pdf/pdf_plotters.c | 95 +++++++++++++++++++---------------------- desktop/save_pdf/pdf_plotters.h | 7 ++- 2 files changed, 46 insertions(+), 56 deletions(-) (limited to 'desktop') diff --git a/desktop/save_pdf/pdf_plotters.c b/desktop/save_pdf/pdf_plotters.c index 2dfea9779..b4a460cc1 100644 --- a/desktop/save_pdf/pdf_plotters.c +++ b/desktop/save_pdf/pdf_plotters.c @@ -32,9 +32,10 @@ #include "desktop/print.h" #include "desktop/printer.h" #include "desktop/save_pdf/pdf_plotters.h" +#include "image/bitmap.h" #include "utils/log.h" #include "utils/utils.h" -#include "image/bitmap.h" +#include "utils/useragent.h" #include "font_haru.h" @@ -91,9 +92,9 @@ static HPDF_REAL page_height, page_width; /*Remeber if pdf_plot_clip was invoked for current page*/ static bool page_clipped; -int last_clip_x0, last_clip_y0, last_clip_x1, last_clip_y1; +static int last_clip_x0, last_clip_y0, last_clip_x1, last_clip_y1; -bool in_text_mode, text_mode_request; +static bool in_text_mode, text_mode_request; static struct print_settings* settings; @@ -116,7 +117,7 @@ static const struct plotter_table pdf_plotters = { false }; -struct printer pdf_printer= { +const struct printer pdf_printer = { &pdf_plotters, pdf_begin, pdf_next_page, @@ -409,8 +410,9 @@ bool pdf_plot_bitmap_tile(int x, int y, int width, int height, apply_clip_and_mode(); image = pdf_extract_image(bitmap, content); - - if (image) { + if (!image) + return false; + else { /*The position of the next tile*/ HPDF_REAL current_x, current_y ; HPDF_REAL max_width, max_height; @@ -425,21 +427,14 @@ bool pdf_plot_bitmap_tile(int x, int y, int width, int height, current_x + x, page_height-current_y - y - height, width, height); - - return true; } - else - return false; return true; } HPDF_Image pdf_extract_image(struct bitmap *bitmap, struct content *content) { - HPDF_Image image = NULL,smask; - char *img_buffer, *rgb_buffer, *alpha_buffer; - int img_width, img_height, img_rowstride; - int i, j; + HPDF_Image image = NULL; if (content) { /*Not sure if I don't have to check if downloading has been @@ -450,7 +445,7 @@ HPDF_Image pdf_extract_image(struct bitmap *bitmap, struct content *content) /*Handle "embeddable" types of images*/ case CONTENT_JPEG: image = HPDF_LoadJpegImageFromMem(pdf_doc, - content->source_data, + (const HPDF_BYTE *)content->source_data, content->source_size); break; @@ -458,7 +453,7 @@ HPDF_Image pdf_extract_image(struct bitmap *bitmap, struct content *content) case CONTENT_PNG: image = HPDF_LoadPngImageFromMem(pdf_doc, - content->source_data, + (const HPDF_BYTE *)content->source_data, content->total_size); break;*/ default: @@ -467,28 +462,28 @@ HPDF_Image pdf_extract_image(struct bitmap *bitmap, struct content *content) } if (!image) { + HPDF_Image smask; + unsigned char *img_buffer, *rgb_buffer, *alpha_buffer; + int img_width, img_height, img_rowstride; + int i, j; + /*Handle pixmaps*/ img_buffer = bitmap_get_buffer(bitmap); img_width = bitmap_get_width(bitmap); img_height = bitmap_get_height(bitmap); img_rowstride = bitmap_get_rowstride(bitmap); - rgb_buffer = (char*)malloc(3 * img_width * img_height); - if (rgb_buffer == NULL) { + rgb_buffer = (unsigned char *)malloc(3 * img_width * img_height); + alpha_buffer = (unsigned char *)malloc(img_width * img_height); + if (rgb_buffer == NULL || alpha_buffer == NULL) { LOG(("Not enough memory to create RGB buffer")); - return NULL; - } - - alpha_buffer = (char*)malloc(img_width * img_height); - if (alpha_buffer == NULL) { - LOG(("Not enough memory to create alpha buffer")); free(rgb_buffer); + free(alpha_buffer); return NULL; } - - for (i = 0; ioutput != NULL) - path = strdup(settings->output); - else - path = NULL; - /*Encryption on*/ if (option_enable_PDF_password) - PDF_Password(&owner_pass, &user_pass, path); + PDF_Password(&owner_pass, &user_pass, + (void *)settings->output); else - save_pdf(path); + save_pdf(settings->output); #ifdef PDF_DEBUG LOG(("pdf_end finishes")); #endif } + /** saves the pdf optionally encrypting it before*/ -void save_pdf(char *path) +void save_pdf(const char *path) { bool success = false; @@ -776,14 +768,13 @@ void save_pdf(char *path) remove(path); else success = true; - - free(path); } if (!success) warn_user("Unable to save PDF file.", 0); HPDF_Free(pdf_doc); + pdf_doc = NULL; } diff --git a/desktop/save_pdf/pdf_plotters.h b/desktop/save_pdf/pdf_plotters.h index ba815c552..a64b91768 100644 --- a/desktop/save_pdf/pdf_plotters.h +++ b/desktop/save_pdf/pdf_plotters.h @@ -24,12 +24,11 @@ #define NETSURF_PDF_PLOTTERS_H #include "desktop/print.h" -struct plotter_table; -extern struct printer pdf_printer; +extern const struct printer pdf_printer; /**Start plotting a pdf file*/ -bool pdf_begin(struct print_settings* settings); +bool pdf_begin(struct print_settings *settings); /**Finish the current page and start a new one*/ bool pdf_next_page(void); @@ -39,6 +38,6 @@ void pdf_end(void); void pdf_set_scale(float s); -void save_pdf(char *path); +void save_pdf(const char *path); #endif /*NETSURF_PDF_PLOTTERS_H*/ -- cgit v1.2.3