+++ /dev/null
-
-//valac --vapidir=./vapi --pkg glib-2.0 --pkg webkit-1.0 --pkg gtk+-2.0 wksnapshot.vala -o /tmp/wksnapshot
-
-// not used?
-
-// gdk vapi class Pixmap:: public void get_size (out int width, out int height);
-// gtk vapi widget get_snapshot (Rectangle? ....)
-
-
-using GLib;
-using Gtk;
-using WebKit;
-
-public class Browser : Window {
-
- public Browser() {
- this.add(this.create_web_window());
- this.resize(1320,1024);
- this.destroy.connect(() => { Gtk.main_quit(); });
- }
-
- private ScrolledWindow create_web_window() {
- var view = new WebView();
- view.load_uri(Browser.opt_url);
-
- var scrolled_window = new ScrolledWindow(null, null);
- scrolled_window.set_policy(PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
- scrolled_window.add(view);
-
-
- view.load_finished.connect((le) => {
-
- // resize the window...
- // window.document.documentElement.scrollHeight
- var scroll_height = (int) view.get_dom_document().document_element.scroll_height;
- if (scroll_height> 1024) {
- 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(Browser.opt_delay, () => {
- print("making screenshot\n");
-
-
- var pixmap = 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);
-
- // sf.write_to_png(Browser.opt_target_png);
- //});
- Gtk.main_quit();
- return false;
- }, GLib.Priority.DEFAULT);
-
-
-
- });
-
-
- return scrolled_window;
- }
-
- public static string? opt_url = null;
- public static uint opt_delay = 0;
- public static string opt_target_png = null;
- const OptionEntry[] options = {
-
-
- { "url", 0, 0, OptionArg.STRING, ref opt_url, "Url to grab", null },
- { "delay", 0, 0, OptionArg.INT, ref opt_delay, "Delay before snapshot in seconds", null },
- { "png", 0, 0, OptionArg.STRING, ref opt_target_png, "File to write (PNG)", null },
- { null }
- };
- public static int main(string[] args) {
- Gtk.init(ref args);
-
-
- var opt_context = new OptionContext ("wksnapshot");
-
-
- try {
- opt_context.set_help_enabled (true);
- opt_context.add_main_entries (options, null);
- opt_context.parse (ref args);
-
- if (Browser.opt_url == null) {
- throw new OptionError.BAD_VALUE("missing url");
- }
- if (Browser.opt_target_png == null) {
- throw new OptionError.BAD_VALUE("missing png");
- }
-
- } catch (OptionError e) {
- stdout.printf ("error: %s\n", e.message);
- stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s",
- args[0], opt_context.get_help(true,null));
- return 0;
- }
-
-
- var browser = new Browser();
- browser.show_all();
-
- Gtk.main();
-
- return 0;
- }
-}
-
-
-
\ No newline at end of file