From d204d6d555ac8e79da330a93e96fb070c8ee8f8c Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 26 Oct 2014 23:49:18 +0000 Subject: [PATCH] Clean up saving as PDF This removes the global PDF_Password interface that had completely bitrotted and moves it into the standard misc operation table with a sensible defualt implementation. This also cleans up and fixes the gtk frontend implementation of the pdf password callback so it compiles. Finally this moves the implementation to a sensible place alongside the other exporters reducing target makefile complexity futher. --- Makefile | 3 - amiga/Makefile.target | 2 +- amiga/save_pdf.c | 5 - cocoa/utils.m | 9 -- desktop/Makefile | 4 +- desktop/{save_pdf => }/font_haru.c | 97 +++++++------- desktop/{save_pdf => }/font_haru.h | 10 +- desktop/gui_factory.c | 22 +++- desktop/gui_misc.h | 10 ++ .../{save_pdf/pdf_plotters.c => save_pdf.c} | 69 ++++++---- .../{save_pdf/pdf_plotters.h => save_pdf.h} | 2 +- desktop/save_pdf/Makefile | 6 - desktop/save_pdf/TODO | 19 --- gtk/Makefile.target | 2 +- gtk/gui.c | 119 ++++++++++-------- riscos/Makefile.target | 2 +- riscos/gui.c | 7 -- utils/utils.h | 1 - 18 files changed, 201 insertions(+), 188 deletions(-) rename desktop/{save_pdf => }/font_haru.c (93%) rename desktop/{save_pdf => }/font_haru.h (93%) rename desktop/{save_pdf/pdf_plotters.c => save_pdf.c} (94%) rename desktop/{save_pdf/pdf_plotters.h => save_pdf.h} (99%) delete mode 100644 desktop/save_pdf/Makefile delete mode 100644 desktop/save_pdf/TODO diff --git a/Makefile b/Makefile index 4fe22e2a3..08766089f 100644 --- a/Makefile +++ b/Makefile @@ -571,9 +571,6 @@ include javascript/Makefile # Image content handler sources include image/Makefile -# PDF saving sources -include desktop/save_pdf/Makefile - # S_COMMON are sources common to all builds S_COMMON := $(S_CONTENT) $(S_FETCHERS) $(S_CSS) $(S_RENDER) $(S_UTILS) \ $(S_HTTP) $(S_DESKTOP) $(S_JAVASCRIPT) diff --git a/amiga/Makefile.target b/amiga/Makefile.target index ea765af36..8939dbc83 100644 --- a/amiga/Makefile.target +++ b/amiga/Makefile.target @@ -78,7 +78,7 @@ S_AMIGA := $(addprefix amiga/,$(S_AMIGA)) # This is the final source build list # Note this is deliberately *not* expanded here as common and image # are not yet available -SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_AMIGA) $(S_PDF) +SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_AMIGA) # ---------------------------------------------------------------------------- # Install target diff --git a/amiga/save_pdf.c b/amiga/save_pdf.c index 16592215b..b70fc5716 100644 --- a/amiga/save_pdf.c +++ b/amiga/save_pdf.c @@ -56,9 +56,4 @@ bool save_as_pdf(struct hlcache_handle *c, const char *path) return true; } -void PDF_Password(char **owner_pass, char **user_pass, char *path) -{ - /*TODO:this waits to be written, until then no PDF encryption*/ - *owner_pass = NULL; -} #endif diff --git a/cocoa/utils.m b/cocoa/utils.m index b49e503d0..2c73e9b49 100644 --- a/cocoa/utils.m +++ b/cocoa/utils.m @@ -20,9 +20,6 @@ #import "utils/utils.h" -#define UNIMPL() NSLog( @"Function '%s' unimplemented", __func__ ) - - void warn_user(const char *warning, const char *detail) { NSRunAlertPanel( NSLocalizedString( @"Warning", @"Warning title" ), @@ -31,9 +28,3 @@ void warn_user(const char *warning, const char *detail) warning, detail != NULL ? ": " : "", detail != NULL ? detail : "" ); } - -void PDF_Password(char **owner_pass, char **user_pass, char *path) -{ - UNIMPL(); -} - diff --git a/desktop/Makefile b/desktop/Makefile index 218f60e67..894b51861 100644 --- a/desktop/Makefile +++ b/desktop/Makefile @@ -13,7 +13,7 @@ desktop/version.c: testament $(OBJROOT)/testament.h # S_BROWSER are sources related to full browsers but are common # between RISC OS, GTK, BeOS and AmigaOS builds S_BROWSER := browser.c browser_history.c download.c frames.c netsurf.c \ - save_complete.c save_text.c selection.c textinput.c gui_factory.c + save_complete.c save_text.c selection.c textinput.c gui_factory.c \ + save_pdf.c font_haru.c S_BROWSER := $(addprefix desktop/,$(S_BROWSER)) - diff --git a/desktop/save_pdf/font_haru.c b/desktop/font_haru.c similarity index 93% rename from desktop/save_pdf/font_haru.c rename to desktop/font_haru.c index e8643f701..aaee84c35 100644 --- a/desktop/save_pdf/font_haru.c +++ b/desktop/font_haru.c @@ -16,7 +16,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + /** \file * Font handling in Haru pdf documents (implementation). * @@ -28,11 +28,11 @@ #ifdef WITH_PDF_EXPORT /*#define FONT_HARU_DEBUG */ - -#include -#include + +#include +#include #include -#include +#include #include @@ -59,7 +59,7 @@ static bool haru_nsfont_position_in_string(const plot_font_style_t *fstyle, static bool haru_nsfont_split(const plot_font_style_t *fstyle, const char *string, size_t length, int x, size_t *char_offset, int *actual_x); - + static float pdf_text_scale = DEFAULT_EXPORT_SCALE; const struct font_functions haru_nsfont = { @@ -77,37 +77,37 @@ const struct font_functions haru_nsfont = { static void error_handler(HPDF_STATUS error_no, HPDF_STATUS detail_no, void *user_data) { - LOG(("ERROR: in font_haru \n\terror_no=%x\n\tdetail_no=%d\n", + LOG(("ERROR: in font_haru \n\terror_no=%x\n\tdetail_no=%d\n", (HPDF_UINT)error_no, (HPDF_UINT)detail_no)); -#ifdef FONT_HARU_DEBUG +#ifdef FONT_HARU_DEBUG exit(1); -#endif +#endif } static bool haru_nsfont_init(HPDF_Doc *pdf, HPDF_Page *page, const char *string, char **string_nt, int length) { - + *pdf = HPDF_New(error_handler, NULL); - + if (*pdf == NULL) return false; *page = HPDF_AddPage(*pdf); - + if (*page == NULL) { HPDF_Free(*pdf); - return false; + return false; } - + *string_nt = malloc((length + 1) * sizeof(char)); if (*string_nt == NULL) { HPDF_Free(*pdf); return false; } - + memcpy(*string_nt, string, length); - (*string_nt)[length] = '\0'; + (*string_nt)[length] = '\0'; return true; } @@ -146,7 +146,7 @@ bool haru_nsfont_width(const plot_font_style_t *fstyle, width_real = HPDF_Page_TextWidth(page, string_nt); *width = width_real; -#ifdef FONT_HARU_DEBUG +#ifdef FONT_HARU_DEBUG LOG(("Measuring string: %s ; Calculated width: %f %i",string_nt, width_real, *width)); #endif free(string_nt); @@ -177,10 +177,10 @@ bool haru_nsfont_position_in_string(const plot_font_style_t *fstyle, char *string_nt; HPDF_UINT offset; HPDF_REAL real_width; - + if (!haru_nsfont_init(&pdf, &page, string, &string_nt, length)) return false; - + if (HPDF_Page_SetWidth(page, x) != HPDF_OK || !haru_nsfont_apply_style(fstyle, pdf, page, NULL, NULL)) { free(string_nt); @@ -188,10 +188,10 @@ bool haru_nsfont_position_in_string(const plot_font_style_t *fstyle, return false; } - + offset = HPDF_Page_MeasureText(page, string_nt, x, HPDF_FALSE, &real_width); - + if (real_width < x) *char_offset = offset; @@ -200,17 +200,17 @@ bool haru_nsfont_position_in_string(const plot_font_style_t *fstyle, assert(offset > 0); *char_offset = offset - 1; } - + /*TODO: this is only the right edge of the character*/ *actual_x = real_width; - -#ifdef FONT_HARU_DEBUG + +#ifdef FONT_HARU_DEBUG LOG(("Position in string: %s at x: %i; Calculated position: %i", - string_nt, x, *char_offset)); -#endif + string_nt, x, *char_offset)); +#endif free(string_nt); HPDF_Free(pdf); - + return true; } @@ -235,34 +235,34 @@ bool haru_nsfont_split(const plot_font_style_t *fstyle, char *string_nt; HPDF_REAL real_width; HPDF_UINT offset; - - + + if (!haru_nsfont_init(&pdf, &page, string, &string_nt, length)) return false; - + if (HPDF_Page_SetWidth(page, x) != HPDF_OK || !haru_nsfont_apply_style(fstyle, pdf, page, NULL, NULL)) { free(string_nt); HPDF_Free(pdf); return false; } - + offset = HPDF_Page_MeasureText(page, string_nt, x, HPDF_TRUE, &real_width); - -#ifdef FONT_HARU_DEBUG - LOG(("Splitting string: %s for width: %i ; Calculated position: %i Calculated real_width: %f", - string_nt, x, *char_offset, real_width)); -#endif + +#ifdef FONT_HARU_DEBUG + LOG(("Splitting string: %s for width: %i ; Calculated position: %i Calculated real_width: %f", + string_nt, x, *char_offset, real_width)); +#endif *char_offset = offset - 1; - + /*TODO: this is only the right edge of the character*/ *actual_x = real_width; - + free(string_nt); HPDF_Free(pdf); - - return true; + + return true; } /** @@ -305,14 +305,14 @@ bool haru_nsfont_apply_style(const plot_font_style_t *fstyle, case PLOT_FONT_FAMILY_SANS_SERIF: strcpy(font_name, "Helvetica"); break; - case PLOT_FONT_FAMILY_CURSIVE: - case PLOT_FONT_FAMILY_FANTASY: + case PLOT_FONT_FAMILY_CURSIVE: + case PLOT_FONT_FAMILY_FANTASY: default: strcpy(font_name, "Times"); roman=true; break; } - + if (fstyle->weight == 700) { strcat(font_name, "-Bold"); bold = true; @@ -325,16 +325,16 @@ bool haru_nsfont_apply_style(const plot_font_style_t *fstyle, strcat(font_name,"Italic"); else strcat(font_name,"Oblique"); - + styled = true; } - + if (roman && !styled && !bold) strcat(font_name, "-Roman"); -#ifdef FONT_HARU_DEBUG +#ifdef FONT_HARU_DEBUG LOG(("Setting font: %s", font_name)); -#endif +#endif size = fstyle->size; @@ -360,7 +360,7 @@ bool haru_nsfont_apply_style(const plot_font_style_t *fstyle, if (font == NULL || font_size == NULL) HPDF_Page_SetFontAndSize(page, pdf_font, size); - + return true; } @@ -373,4 +373,3 @@ void haru_nsfont_set_scale(float s) } #endif /* WITH_PDF_EXPORT */ - diff --git a/desktop/save_pdf/font_haru.h b/desktop/font_haru.h similarity index 93% rename from desktop/save_pdf/font_haru.h rename to desktop/font_haru.h index c6578b09f..479f7deb0 100644 --- a/desktop/save_pdf/font_haru.h +++ b/desktop/font_haru.h @@ -16,19 +16,19 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + /** \file * Font handling in Haru pdf documents (interface). */ - -#ifndef _NETSURF_RENDER_FONT_HARU_H_ -#define _NETSURF_RENDER_FONT_HARU_H_ + +#ifndef _NETSURF_DESKTOP_FONT_HARU_H_ +#define _NETSURF_DESKTOP_FONT_HARU_H_ #include #include "desktop/plot_style.h" #include "desktop/font.h" - + bool haru_nsfont_apply_style(const plot_font_style_t *fstyle, HPDF_Doc doc, HPDF_Page page, HPDF_Font *font, HPDF_REAL *font_size); diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index e7770e770..b69700fca 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -20,6 +20,7 @@ #include "content/backing_store.h" #include "utils/file.h" +#include "desktop/save_pdf.h" #include "desktop/download.h" #include "desktop/searchweb.h" #include "desktop/gui_download.h" @@ -259,6 +260,12 @@ static void gui_default_download_done(struct gui_download_window *dw) { } +static struct gui_download_table default_download_table = { + .create = gui_default_download_create, + .data = gui_default_download_data, + .error = gui_default_download_error, + .done = gui_default_download_done, +}; /** verify download window table is valid */ static nserror verify_download_register(struct gui_download_table *gdt) @@ -566,12 +573,12 @@ static void gui_default_401login_open(nsurl *url, const char *realm, cb(false, cbpw); } -static struct gui_download_table default_download_table = { - .create = gui_default_download_create, - .data = gui_default_download_data, - .error = gui_default_download_error, - .done = gui_default_download_done, -}; +static void +gui_default_pdf_password(char **owner_pass, char **user_pass, char *path) +{ + *owner_pass = NULL; + save_pdf(path); +} /** verify browser table is valid */ static nserror verify_browser_register(struct gui_browser_table *gbt) @@ -599,6 +606,9 @@ static nserror verify_browser_register(struct gui_browser_table *gbt) if (gbt->login == NULL) { gbt->login = gui_default_401login_open; } + if (gbt->pdf_password == NULL) { + gbt->pdf_password = gui_default_pdf_password; + } return NSERROR_OK; } diff --git a/desktop/gui_misc.h b/desktop/gui_misc.h index daad6ba2e..8005006c7 100644 --- a/desktop/gui_misc.h +++ b/desktop/gui_misc.h @@ -80,6 +80,16 @@ struct gui_browser_table { void (*login)(struct nsurl *url, const char *realm, nserror (*cb)(bool proceed, void *pw), void *cbpw); + /** + * Warn the user of an event. + */ + void (*warning)(const char *warning, const char *detail); + + /** + * Prompt the user for a password for a PDF. + */ + void (*pdf_password)(char **owner_pass, char **user_pass, char *path); + }; #endif diff --git a/desktop/save_pdf/pdf_plotters.c b/desktop/save_pdf.c similarity index 94% rename from desktop/save_pdf/pdf_plotters.c rename to desktop/save_pdf.c index 123408dd3..e3f9cbc34 100644 --- a/desktop/save_pdf/pdf_plotters.c +++ b/desktop/save_pdf.c @@ -21,7 +21,32 @@ * Target independent PDF plotting using Haru Free PDF Library. */ +/* TODO + * - finish all graphic primitives + * - allow adding raw bitmaps + * - make image-aware (embed the image in its native/original type if possible) + * + * - adjust content width to page width + * - divide output into multiple pages (not just the first one) + * - rearrange file structure + * + * - separate print-plotting as much as possible from window redrawing + * - add text-scaling (if not yet using the original font - make the default one + * have the same width) + * - add a save file.. dialogue + * - add utf support to Haru ( doable? ) + * - wait for browser to end fetching? + * - analyze and deal with performance issues(huge file hangs some pdf viewers, + * for example kpdf when viewing plotted http://www.onet.pl) + * - deal with to wide pages - when window layouting adds a horizontal + * scrollbar, we should treat it otherwise - either print + * horizontal or scale or, better, find a new layout. + */ + #include "utils/config.h" + +#include "desktop/save_pdf.h" + #ifdef WITH_PDF_EXPORT #include @@ -35,7 +60,6 @@ #include "desktop/plotters.h" #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" @@ -50,7 +74,7 @@ static bool pdf_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_ static bool pdf_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *pstyle); static bool pdf_plot_polygon(const int *p, unsigned int n, const plot_style_t *style); static bool pdf_plot_clip(const struct rect *clip); -static bool pdf_plot_text(int x, int y, const char *text, size_t length, +static bool pdf_plot_text(int x, int y, const char *text, size_t length, const plot_font_style_t *fstyle); static bool pdf_plot_disc(int x, int y, int radius, const plot_style_t *style); static bool pdf_plot_arc(int x, int y, int radius, int angle1, int angle2, @@ -86,7 +110,7 @@ static void pdfw_gs_linewidth(HPDF_Page page, float lineWidth); static void pdfw_gs_font(HPDF_Page page, HPDF_Font font, HPDF_REAL font_size); static void pdfw_gs_dash(HPDF_Page page, DashPattern_e dash); -/** +/** * Our PDF gstate mirror which we use to minimize gstate updates * in the PDF file. */ @@ -186,9 +210,9 @@ bool pdf_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *psty } - apply_clip_and_mode(false, - NS_TRANSPARENT, - pstyle->stroke_colour, + apply_clip_and_mode(false, + NS_TRANSPARENT, + pstyle->stroke_colour, pstyle->stroke_width, dash); @@ -218,9 +242,9 @@ bool pdf_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *pstyle) } - apply_clip_and_mode(false, - NS_TRANSPARENT, - pstyle->stroke_colour, + apply_clip_and_mode(false, + NS_TRANSPARENT, + pstyle->stroke_colour, pstyle->stroke_width, dash); @@ -285,7 +309,7 @@ bool pdf_plot_clip(const struct rect *clip) return true; } -bool pdf_plot_text(int x, int y, const char *text, size_t length, +bool pdf_plot_text(int x, int y, const char *text, size_t length, const plot_font_style_t *fstyle) { #ifdef PDF_DEBUG @@ -298,7 +322,7 @@ bool pdf_plot_text(int x, int y, const char *text, size_t length, if (length == 0) return true; - apply_clip_and_mode(true, fstyle->foreground, NS_TRANSPARENT, 0., + apply_clip_and_mode(true, fstyle->foreground, NS_TRANSPARENT, 0., DashPattern_eNone); haru_nsfont_apply_style(fstyle, pdf_doc, pdf_page, &pdf_font, &size); @@ -326,7 +350,7 @@ bool pdf_plot_disc(int x, int y, int radius, const plot_style_t *style) #endif if (style->fill_type != PLOT_OP_TYPE_NONE) { apply_clip_and_mode(false, - style->fill_colour, + style->fill_colour, NS_TRANSPARENT, 1., DashPattern_eNone); @@ -338,7 +362,7 @@ bool pdf_plot_disc(int x, int y, int radius, const plot_style_t *style) if (style->stroke_type != PLOT_OP_TYPE_NONE) { /* FIXME: line width 1 is ok ? */ apply_clip_and_mode(false, - NS_TRANSPARENT, + NS_TRANSPARENT, style->stroke_colour, 1., DashPattern_eNone); @@ -410,9 +434,9 @@ bool pdf_plot_bitmap_tile(int x, int y, int width, int height, HPDF_Image pdf_extract_image(struct bitmap *bitmap) { HPDF_Image image = NULL; - hlcache_handle *content = NULL; + hlcache_handle *content = NULL; - /* TODO - get content from bitmap pointer */ + /* TODO - get content from bitmap pointer */ if (content) { const char *source_data; @@ -667,11 +691,11 @@ bool pdf_begin(struct print_settings *print_settings) settings = print_settings; - page_width = settings->page_width - + page_width = settings->page_width - FIXTOFLT(FSUB(settings->margins[MARGINLEFT], settings->margins[MARGINRIGHT])); - page_height = settings->page_height - + page_height = settings->page_height - FIXTOFLT(settings->margins[MARGINTOP]); @@ -715,7 +739,7 @@ bool pdf_next_page(void) HPDF_Page_SetWidth (pdf_page, settings->page_width); HPDF_Page_SetHeight(pdf_page, settings->page_height); - HPDF_Page_Concat(pdf_page, 1, 0, 0, 1, + HPDF_Page_Concat(pdf_page, 1, 0, 0, 1, FIXTOFLT(settings->margins[MARGINLEFT]), 0); pdfw_gs_save(pdf_page); @@ -751,7 +775,7 @@ void pdf_end(void) /*Encryption on*/ if (option_enable_PDF_password) - PDF_Password(&owner_pass, &user_pass, + guit->browser->pdf_password(&owner_pass, &user_pass, (void *)settings->output); else save_pdf(settings->output); @@ -760,7 +784,7 @@ void pdf_end(void) #endif } -/** saves the pdf optionally encrypting it before*/ +/** saves the pdf with optional encryption */ void save_pdf(const char *path) { bool success = false; @@ -959,5 +983,8 @@ void pdfw_gs_dash(HPDF_Page page, DashPattern_e dash) } } +#else +void save_pdf(const char *path) +{ +} #endif /* WITH_PDF_EXPORT */ - diff --git a/desktop/save_pdf/pdf_plotters.h b/desktop/save_pdf.h similarity index 99% rename from desktop/save_pdf/pdf_plotters.h rename to desktop/save_pdf.h index 7ecb54964..d02c356e8 100644 --- a/desktop/save_pdf/pdf_plotters.h +++ b/desktop/save_pdf.h @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -/** \file +/** \file PDF Plotting */ diff --git a/desktop/save_pdf/Makefile b/desktop/save_pdf/Makefile deleted file mode 100644 index cf1f978e6..000000000 --- a/desktop/save_pdf/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# PDF saving sources - -# S_PDF are sources of the pdf plotter + the ones for paged-printing -S_PDF := pdf_plotters.c font_haru.c - -S_PDF := $(addprefix desktop/save_pdf/,$(S_PDF)) diff --git a/desktop/save_pdf/TODO b/desktop/save_pdf/TODO deleted file mode 100644 index 1b3a896b9..000000000 --- a/desktop/save_pdf/TODO +++ /dev/null @@ -1,19 +0,0 @@ -- finish all graphic primitives -- allow adding raw bitmaps -- make image-aware (embed the image in its native/original type if possible) - -- adjust content width to page width -- divide output into multiple pages (not just the first one) -- rearrange file structure - -- separate print-plotting as much as possible from window redrawing -- add text-scaling (if not yet using the original font - make the default one - have the same width) -- add a save file.. dialogue -- add utf support to Haru ( doable? ) -- wait for browser to end fetching? -- analyze and deal with performance issues(huge file hangs some pdf viewers, - for example kpdf when viewing plotted http://www.onet.pl) -- deal with to wide pages - when window layouting adds a horizontal scrollbar, - we should treat it otherwise - either print horizontal or scale or, - better, find a new layout. \ No newline at end of file diff --git a/gtk/Makefile.target b/gtk/Makefile.target index be0dad2ae..b1a6f61f8 100644 --- a/gtk/Makefile.target +++ b/gtk/Makefile.target @@ -117,7 +117,7 @@ S_GTK := $(addprefix gtk/,$(S_GTK)) $(addprefix utils/,container.c) # This is the final source build list # Note this is deliberately *not* expanded here as common and image # are not yet available -SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_PDF) $(S_PIXBUF) $(S_GTK) +SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_PIXBUF) $(S_GTK) EXETARGET := nsgtk # ---------------------------------------------------------------------------- diff --git a/gtk/gui.c b/gtk/gui.c index eeba46619..c4dc0e171 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -54,7 +54,7 @@ #include "content/backing_store.h" #include "desktop/browser.h" #include "desktop/save_complete.h" -#include "desktop/save_pdf/pdf_plotters.h" +#include "desktop/save_pdf.h" #include "desktop/searchweb.h" #include "desktop/sslcert_viewer.h" #include "desktop/textinput.h" @@ -696,71 +696,45 @@ gboolean nsgtk_ssl_delete_event(GtkWidget *w, GdkEvent *event, gpointer data) return FALSE; } -#ifdef WITH_PDF_EXPORT - -void PDF_Password(char **owner_pass, char **user_pass, char *path) -{ - GladeXML *x = glade_xml_new(glade_password_file_location, NULL, NULL); - GtkWindow *wnd = GTK_WINDOW(glade_xml_get_widget(x, "wndPDFPassword")); - GtkButton *ok, *no; - void **data = malloc(5 * sizeof(void *)); - - *owner_pass = NULL; - *user_pass = NULL; - - data[0] = owner_pass; - data[1] = user_pass; - data[2] = wnd; - data[3] = x; - data[4] = path; - - ok = GTK_BUTTON(glade_xml_get_widget(x, "buttonPDFSetPassword")); - no = GTK_BUTTON(glade_xml_get_widget(x, "buttonPDFNoPassword")); - - g_signal_connect(G_OBJECT(ok), "clicked", - G_CALLBACK(nsgtk_PDF_set_pass), (gpointer)data); - g_signal_connect(G_OBJECT(no), "clicked", - G_CALLBACK(nsgtk_PDF_no_pass), (gpointer)data); - - gtk_widget_show(GTK_WIDGET(wnd)); -} static void nsgtk_PDF_set_pass(GtkButton *w, gpointer data) { char **owner_pass = ((void **)data)[0]; char **user_pass = ((void **)data)[1]; GtkWindow *wnd = ((void **)data)[2]; - GladeXML *x = ((void **)data)[3]; + GtkBuilder *gladeFile = ((void **)data)[3]; char *path = ((void **)data)[4]; char *op, *op1; char *up, *up1; - op = strdup(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(x, - "entryPDFOwnerPassword")))); - op1 = strdup(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(x, - "entryPDFOwnerPassword1")))); - up = strdup(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(x, - "entryPDFUserPassword")))); - up1 = strdup(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(x, - "entryPDFUserPassword1")))); + op = strdup(gtk_entry_get_text( + GTK_ENTRY(gtk_builder_get_object(gladeFile, + "entryPDFOwnerPassword")))); + op1 = strdup(gtk_entry_get_text( + GTK_ENTRY(gtk_builder_get_object(gladeFile, + "entryPDFOwnerPassword1")))); + up = strdup(gtk_entry_get_text( + GTK_ENTRY(gtk_builder_get_object(gladeFile, + "entryPDFUserPassword")))); + up1 = strdup(gtk_entry_get_text( + GTK_ENTRY(gtk_builder_get_object(gladeFile, + "entryPDFUserPassword1")))); if (op[0] == '\0') { - gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(x, + gtk_label_set_text(GTK_LABEL(gtk_builder_get_object(gladeFile, "labelInfo")), "Owner password must be at least 1 character long:"); free(op); free(up); - } - else if (!strcmp(op, up)) { - gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(x, + } else if (!strcmp(op, up)) { + gtk_label_set_text(GTK_LABEL(gtk_builder_get_object(gladeFile, "labelInfo")), "User and owner passwords must be different:"); free(op); free(up); - } - else if (!strcmp(op, op1) && !strcmp(up, up1)) { + } else if (!strcmp(op, op1) && !strcmp(up, up1)) { *owner_pass = op; if (up[0] == '\0') @@ -770,13 +744,13 @@ static void nsgtk_PDF_set_pass(GtkButton *w, gpointer data) free(data); gtk_widget_destroy(GTK_WIDGET(wnd)); - g_object_unref(G_OBJECT(x)); + g_object_unref(G_OBJECT(gladeFile)); save_pdf(path); + free(path); - } - else { - gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(x, + } else { + gtk_label_set_text(GTK_LABEL(gtk_builder_get_object(gladeFile, "labelInfo")), "Passwords not confirmed:"); free(op); free(up); @@ -789,18 +763,60 @@ static void nsgtk_PDF_set_pass(GtkButton *w, gpointer data) static void nsgtk_PDF_no_pass(GtkButton *w, gpointer data) { GtkWindow *wnd = ((void **)data)[2]; - GladeXML *x = ((void **)data)[3]; + GtkBuilder *gladeFile = ((void **)data)[3]; char *path = ((void **)data)[4]; free(data); gtk_widget_destroy(GTK_WIDGET(wnd)); - g_object_unref(G_OBJECT(x)); + g_object_unref(G_OBJECT(gladeFile)); save_pdf(path); + free(path); } -#endif + +static void nsgtk_pdf_password(char **owner_pass, char **user_pass, char *path) +{ + GtkButton *ok, *no; + GtkWindow *wnd; + void **data; + GtkBuilder *gladeFile; + GError* error = NULL; + + gladeFile = gtk_builder_new(); + if (!gtk_builder_add_from_file(gladeFile, + glade_file_location->password, + &error)) { + g_warning ("Couldn't load builder file: %s", error->message); + g_error_free (error); + return; + } + + wnd = GTK_WINDOW(gtk_builder_get_object(gladeFile, "wndPDFPassword")); + + data = malloc(5 * sizeof(void *)); + + *owner_pass = NULL; + *user_pass = NULL; + + data[0] = owner_pass; + data[1] = user_pass; + data[2] = wnd; + data[3] = gladeFile; + data[4] = path; + + ok = GTK_BUTTON(gtk_builder_get_object(gladeFile, "buttonPDFSetPassword")); + no = GTK_BUTTON(gtk_builder_get_object(gladeFile, "buttonPDFNoPassword")); + + g_signal_connect(G_OBJECT(ok), "clicked", + G_CALLBACK(nsgtk_PDF_set_pass), (gpointer)data); + g_signal_connect(G_OBJECT(no), "clicked", + G_CALLBACK(nsgtk_PDF_no_pass), (gpointer)data); + + gtk_widget_show(GTK_WIDGET(wnd)); +} + uint32_t gtk_gui_gdkkey_to_nskey(GdkEventKey *key) { @@ -1194,6 +1210,7 @@ static struct gui_browser_table nsgtk_browser_table = { .launch_url = gui_launch_url, .cert_verify = gui_cert_verify, .login = gui_401login_open, + .pdf_password = nsgtk_pdf_password, }; /** diff --git a/riscos/Makefile.target b/riscos/Makefile.target index 46ca34116..a52c03f5a 100644 --- a/riscos/Makefile.target +++ b/riscos/Makefile.target @@ -92,7 +92,7 @@ TPL_RISCOS := $(addprefix riscos/templates/,$(TPL_RISCOS)) # This is the final source build list # Note this is deliberately *not* expanded here as common and image # are not yet available -SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_PDF) $(S_RISCOS) +SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_RISCOS) EXETARGET := !NetSurf/!RunImage$(EXEEXT) !NetSurf/!Run$(RUNEXT): riscos/scripts/Run $(EXETARGET) diff --git a/riscos/gui.c b/riscos/gui.c index ade22cb48..198fd2391 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -2152,13 +2152,6 @@ bool ro_gui_prequit(void) } -void PDF_Password(char **owner_pass, char **user_pass, char *path) -{ - /** @todo this waits to be written, until then no PDF encryption */ - *owner_pass = NULL; -} - - /** * Generate a riscos path from one or more component elemnts. * diff --git a/utils/utils.h b/utils/utils.h index b90843271..00d150126 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -258,6 +258,5 @@ int dir_sort_alpha(const struct dirent **d1, const struct dirent **d2); /* Platform specific functions */ void warn_user(const char *warning, const char *detail); -void PDF_Password(char **owner_pass, char **user_pass, char *path); #endif