source: subversion/applications/editors/josm/plugins/wmsplugin/webkit-image-gtk.c @ 12640

Last change on this file since 12640 was 12328, checked in by Dirk Stoecker, 11 years ago

renamed

File size: 1.5 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3
4#include <webkit.h>
5
6#define WIDTH 2000
7
8/* compile with:
9gcc -W webkit-image-gtk.cpp `pkg-config --libs --cflags WebKitGtk gtk+-2.0`
10*/
11
12static void
13on_finished (WebKitWebView *view, WebKitWebFrame *frame)
14{
15        GdkPixmap *pixmap;
16        GdkColormap *cmap;
17        GdkPixbuf *pixbuf;
18        gchar *buffer;
19        gsize size;
20
21        pixmap = gtk_widget_get_snapshot (GTK_WIDGET (view), NULL);
22        cmap = gdk_colormap_get_system ();
23        pixbuf = gdk_pixbuf_get_from_drawable (NULL, GDK_DRAWABLE (pixmap), cmap,
24                                               0, 0, 0, 0, WIDTH, WIDTH);
25
26        gdk_pixbuf_save_to_buffer (pixbuf, &buffer, &size, "png", NULL, NULL);
27
28        fwrite (buffer, 1, size, stdout);
29
30        exit (1);
31}
32
33int main (int argc, char **argv)
34{
35        GtkWidget *window;
36        GtkWidget *view;
37
38        if (argc != 2)
39                exit (20);
40
41        gtk_init (&argc, &argv);
42
43        /* Horribly hacky */
44        window = gtk_window_new (GTK_WINDOW_POPUP);
45        gtk_window_set_opacity (GTK_WINDOW (window), 0.0);
46
47        view = webkit_web_view_new ();
48        webkit_web_view_open (WEBKIT_WEB_VIEW (view), argv[1]);
49        gtk_widget_set_size_request (view, WIDTH, WIDTH);
50        gtk_container_add (GTK_CONTAINER (window), view);
51
52        gtk_widget_show_all (window);
53
54        g_signal_connect (G_OBJECT (view), "load-finished",
55                          G_CALLBACK (on_finished), NULL);
56
57        gtk_main ();
58        return 0;
59}
Note: See TracBrowser for help on using the repository browser.