From b6d6fbc3578b12006c763a8388a9fd81591cdbec Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Mon, 25 Apr 2016 16:07:33 +0800 Subject: [PATCH] BrowserWindow.bjs BrowserWindow.vala --- BrowserWindow.bjs | 3 +- BrowserWindow.vala | 109 +++++++++++++++++++++++++-------------------- 2 files changed, 63 insertions(+), 49 deletions(-) diff --git a/BrowserWindow.bjs b/BrowserWindow.bjs index 0dfda2b..6b26192 100644 --- a/BrowserWindow.bjs +++ b/BrowserWindow.bjs @@ -28,10 +28,11 @@ "load_finished" : "( ) => {\n\t\t \n this.printit();\n \n}" }, "id" : "view", - "| void printit" : "() {\n print(\"load_finsihed\\n\");\n \n\t// inject any javascript if needed..\n\tif (webkitpdf.opt_inject_js != null) {\n\t\tfor(var i =0; i < webkitpdf.opt_inject_js.length;i++) {\n\t\t\tstring str;\n\t\t\ttry {\n\t\t\t\tFileUtils.get_contents( webkitpdf.opt_inject_js[i], out str);\n\t\t\t} catch(FileError e) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.el.execute_script(str);\n\t\t}\n\t}\n\t\n\tif (webkitpdf.opt_target_pdf != null ) {\n\t\n\t\tprint(\"calling print in %d seconds\\n\", (int)webkitpdf.opt_delay);\n\t\tGLib.Timeout.add_seconds(webkitpdf.opt_delay, () => { \n\n\t\t\tthis.printpdf();\n\t\t\n\t\t}, GLib.Priority.DEFAULT);\n\t\t\n\t\treturn;\n\t}\n \n // ----------------- JPEG \n\t// resize the window...\n\t// window.document.documentElement.scrollHeight\n\tvar scroll_height = (int) _this.view.get_dom_document().document_element.scroll_height;\n\tif (scroll_height> 1024) {\n\t\t_this.scrolled_window.set_size_request(1200, Int.min(scroll_height, 6000));\n\t\tprint(\"Resize to %d\\n\", scroll_height);\n\t}\n\n //var filename = \"/tmp/test.pdf\";\n //print(\"load_changed %d ?= %d\\n\", le, LoadEvent.FINISHED);\n\n //if (le != LoadEvent.FINISHED) {\n // return;\n // }\n \n // what size is the documet.\n \n GLib.Timeout.add_seconds(Browser.opt_delay, () => { \n print(\"making screenshot\\n\");\n \n \n var pixmap = _this.view.get_snapshot( null );\n\n \n \n int w,h;\n\t\tpixmap.get_size( out w , out h);\n\t\tvar pixbuf = Gdk.pixbuf_get_from_drawable(null, pixmap, null , 0, 0, 0, 0, w, h);\n\t\tprint(\"pixbuf size: %d x %d\\n \", w,h);\n\t\t \n \n \n pixbuf.save(Browser.opt_target_png, \"png\");\n //view.get_snapshot.begin(WebKit.SnapshotRegion.FULL_DOCUMENT, WebKit.SnapshotOptions.NONE, null, (obj, res) => {\n // var sf = view.get_snapshot.end(res);\n\n // sf.write_to_png(Browser.opt_target_png);\n //});\n Gtk.main_quit();\n return false;\n }, GLib.Priority.DEFAULT);\n \n \n\n \n \n}\n", + "| void printit" : "() {\n print(\"load_finsihed\\n\");\n \n\t// inject any javascript if needed..\n\tif (webkitpdf.opt_inject_js != null) {\n\t\tfor(var i =0; i < webkitpdf.opt_inject_js.length;i++) {\n\t\t\tstring str;\n\t\t\ttry {\n\t\t\t\tFileUtils.get_contents( webkitpdf.opt_inject_js[i], out str);\n\t\t\t} catch(FileError e) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.el.execute_script(str);\n\t\t}\n\t}\n\t\n\t\n\t\n\tprint(\"calling print in %d seconds\\n\", (int)webkitpdf.opt_delay);\n\tif (webkitpdf.opt_target_pdf != null) {\n\t\tGLib.Timeout.add_seconds(webkitpdf.opt_delay, () => { \n\n\t\t\tthis.printpdf();\n\t\t\t return false;\n\t\t}, GLib.Priority.DEFAULT);\n\t}\n\t\t\n\t\t\n GLib.Timeout.add_seconds(webkitpdf.opt_delay, () => { \n \n\t\t\n\t\t// ----------------- JPEG \n\t\t// resize the window...\n\t\t// window.document.documentElement.scrollHeight\n\t\tvar scroll_height = (int) _this.view.el.get_dom_document().document_element.scroll_height;\n\t\tprint(\"Scroll height %d\\n\", scroll_height);\n\t\tif (scroll_height> 1024) {\n\t\t\t_this.scrolled_window.el.set_size_request(1200, int.min(scroll_height, 6000));\n\t\t\tprint(\"Resize to %d\\n\", scroll_height);\n\t\t GLib.Timeout.add_seconds(webkitpdf.opt_delay, () => { \n\t\t\t\tthis.printpng();\n\t\t\t\treturn false;\n\t\t\t }, GLib.Priority.DEFAULT);\n\t\t}\n\t\tthis.printpng();\t\t\n\t\treturn false;\n\t }, GLib.Priority.DEFAULT);\n\n\n \n \n}\n", "* pack" : "add", "xtype" : "WebView", "| bool printpdf" : "() {\n\t \n\t\tvar pe = new Gtk.PrintOperation();\n\t\tpe.export_filename = webkitpdf.opt_target_pdf;\n\t\tprint(\"got callback for print\");\n\t\tpe.ref();\n\t\t/*pe.failed.connect(() => {\n\t\t\tprint(\"print failed\\n\");\n\t\t\t Gtk.main_quit();\n \t\t\n\t\t})\n\t\t*/;\n\t\t pe.done.connect(() => {\n\t\t\tprint(\"print completed\\n\");\n\t\t\t Gtk.main_quit();\n \t\t\n\t\t});\n\t\t\n\t\t//pe.run_dialog(_this.el);\n\t \n\t\t\n\t var list = Gtk.PaperSize.get_paper_sizes(false);\n\t var psetup = new Gtk.PageSetup();\n\t for(var i = 0; i < list.length(); i++ ) {\n\t var entry = list.nth_data(i).copy();\n\t if (entry.get_name() == \"iso_a2\") {\n\t psetup.set_paper_size(entry);\n\t }\n\t }\n\t \n\n\n\t pe.set_default_page_setup(psetup);\n\t print(\"Calling Print?\\n\");\n\t //pe.run_dialog(_this.el);\n\t try {\n\t\t this.el.get_main_frame().print_full(pe,Gtk.PrintOperationAction.EXPORT);\n\t } catch (Error e) {\n\t\t\t// print failed...\n\t\t}\n\t \n\t \n\t \n\t\treturn false;\n}\n", + "| void printpng" : "() {\n //var filename = \"/tmp/test.pdf\";\n //print(\"load_changed %d ?= %d\\n\", le, LoadEvent.FINISHED);\n\n //if (le != LoadEvent.FINISHED) {\n // return;\n // }\n \n// what size is the documet.\n\n print(\"making screenshot\\n\");\n \n \n var pixmap = _this.view.el.get_snapshot( null );\n\n \n \n int w,h;\n\tpixmap.get_size( out w , out h);\n\tvar pixbuf = Gdk.pixbuf_get_from_drawable(null, pixmap, null , 0, 0, 0, 0, w, h);\n\tprint(\"pixbuf size: %d x %d\\n \", w,h);\n\t \n \n \n pixbuf.save(webkitpdf.opt_target_png, \"png\");\n //view.get_snapshot.begin(WebKit.SnapshotRegion.FULL_DOCUMENT, WebKit.SnapshotOptions.NONE, null, (obj, res) => {\n // var sf = view.get_snapshot.end(res);\n\n // sf.write_to_png(Browser.opt_target_png);\n //});\n Gtk.main_quit();\n \n \n \n \n\n}\n", "$ xns" : "WebKit" } ] diff --git a/BrowserWindow.vala b/BrowserWindow.vala index ed64db6..7b9c249 100644 --- a/BrowserWindow.vala +++ b/BrowserWindow.vala @@ -125,62 +125,38 @@ public class BrowserWindow : Object } } - if (webkitpdf.opt_target_pdf != null ) { - print("calling print in %d seconds\n", (int)webkitpdf.opt_delay); + + print("calling print in %d seconds\n", (int)webkitpdf.opt_delay); + if (webkitpdf.opt_target_pdf != null) { GLib.Timeout.add_seconds(webkitpdf.opt_delay, () => { this.printpdf(); - + return false; }, GLib.Priority.DEFAULT); - - return; } - - // ----------------- JPEG - // resize the window... - // window.document.documentElement.scrollHeight - var scroll_height = (int) _this.view.get_dom_document().document_element.scroll_height; - if (scroll_height> 1024) { - _this.scrolled_window.set_size_request(1200, Int.min(scroll_height, 6000)); - print("Resize to %d\n", scroll_height); - } - - //var filename = "/tmp/test.pdf"; - //print("load_changed %d ?= %d\n", le, LoadEvent.FINISHED); - - //if (le != LoadEvent.FINISHED) { - // return; - // } - - // what size is the documet. + + + GLib.Timeout.add_seconds(webkitpdf.opt_delay, () => { - GLib.Timeout.add_seconds(Browser.opt_delay, () => { - print("making screenshot\n"); - - - var pixmap = _this.view.get_snapshot( null ); - - - - int w,h; - pixmap.get_size( out w , out h); - var pixbuf = Gdk.pixbuf_get_from_drawable(null, pixmap, null , 0, 0, 0, 0, w, h); - print("pixbuf size: %d x %d\n ", w,h); - - - - pixbuf.save(Browser.opt_target_png, "png"); - //view.get_snapshot.begin(WebKit.SnapshotRegion.FULL_DOCUMENT, WebKit.SnapshotOptions.NONE, null, (obj, res) => { - // var sf = view.get_snapshot.end(res); + + // ----------------- JPEG + // resize the window... + // window.document.documentElement.scrollHeight + var scroll_height = (int) _this.view.el.get_dom_document().document_element.scroll_height; + print("Scroll height %d\n", scroll_height); + if (scroll_height> 1024) { + _this.scrolled_window.el.set_size_request(1200, int.min(scroll_height, 6000)); + print("Resize to %d\n", scroll_height); + GLib.Timeout.add_seconds(webkitpdf.opt_delay, () => { + this.printpng(); + return false; + }, GLib.Priority.DEFAULT); + } + this.printpng(); + return false; + }, GLib.Priority.DEFAULT); - // sf.write_to_png(Browser.opt_target_png); - //}); - Gtk.main_quit(); - return false; - }, GLib.Priority.DEFAULT); - - @@ -229,6 +205,43 @@ public class BrowserWindow : Object return false; + } + public void printpng () { + //var filename = "/tmp/test.pdf"; + //print("load_changed %d ?= %d\n", le, LoadEvent.FINISHED); + + //if (le != LoadEvent.FINISHED) { + // return; + // } + + // what size is the documet. + + print("making screenshot\n"); + + + var pixmap = _this.view.el.get_snapshot( null ); + + + + int w,h; + pixmap.get_size( out w , out h); + var pixbuf = Gdk.pixbuf_get_from_drawable(null, pixmap, null , 0, 0, 0, 0, w, h); + print("pixbuf size: %d x %d\n ", w,h); + + + + pixbuf.save(webkitpdf.opt_target_png, "png"); + //view.get_snapshot.begin(WebKit.SnapshotRegion.FULL_DOCUMENT, WebKit.SnapshotOptions.NONE, null, (obj, res) => { + // var sf = view.get_snapshot.end(res); + + // sf.write_to_png(Browser.opt_target_png); + //}); + Gtk.main_quit(); + + + + + } } -- 2.39.2