From: Alan Knowles Date: Mon, 25 Apr 2016 08:04:10 +0000 (+0800) Subject: BrowserWindow.bjs X-Git-Url: http://git.roojs.org/?p=app.webkitpdf;a=commitdiff_plain;h=143d3dbbf32269ef634cd3476df98c17349a00f6 BrowserWindow.bjs BrowserWindow.vala --- diff --git a/BrowserWindow.bjs b/BrowserWindow.bjs index 3bf4939..acbefb7 100644 --- a/BrowserWindow.bjs +++ b/BrowserWindow.bjs @@ -28,7 +28,7 @@ "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\t\n\t\n\tprint(\"calling print in %d seconds\\n\", (int)webkitpdf.opt_delay);\n GLib.Timeout.add_seconds(webkitpdf.opt_delay, () => { \n\n\t\tthis.printpdf();\n\t\t return false;\n }, GLib.Priority.DEFAULT);\n \n \n \n // ----------------- JPEG \n\t// resize the window...\n\t// window.document.documentElement.scrollHeight\n\tvar scroll_height = (int) _this.view.el.get_dom_document().document_element.scroll_height;\n\tprint(\"Scroll height %d\\n\", scroll_height);\n\tif (scroll_height> 1024) {\n\t\t_this.scrolled_window.el.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(webkitpdf.opt_delay, () => { \n print(\"making screenshot\\n\");\n \n \n var pixmap = _this.view.el.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(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 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 GLib.Timeout.add_seconds(webkitpdf.opt_delay, () => { \n\n\t\tthis.printpdf();\n\t\t return false;\n }, GLib.Priority.DEFAULT);\n \n \n \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.printjpg();\n\t\t\t\treturn false;\n\t\t\t});\n\t\t}\n\t\tthis.printjpg();\t\t\n\t\treturn false;\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(webkitpdf.opt_delay, () => { \n print(\"making screenshot\\n\");\n \n \n var pixmap = _this.view.el.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(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 return false;\n }, GLib.Priority.DEFAULT);\n \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", diff --git a/BrowserWindow.vala b/BrowserWindow.vala index 90fe755..9723508 100644 --- a/BrowserWindow.vala +++ b/BrowserWindow.vala @@ -136,15 +136,25 @@ public class BrowserWindow : Object - // ----------------- 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, () => { + + + // ----------------- 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.printjpg(); + return false; + }); + } + this.printjpg(); + return false; + }); //var filename = "/tmp/test.pdf"; //print("load_changed %d ?= %d\n", le, LoadEvent.FINISHED);