Changeset 21401 in osm for applications/editors/josm


Ignore:
Timestamp:
2010-05-22T12:32:00+02:00 (15 years ago)
Author:
tomhughes
Message:

Updated version of webkit-image-gtk.c from original author. Closes #1429.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wmsplugin/webkit-image-gtk.c

    r16592 r21401  
    11/* There is no licence for this, I don't care what you do with it */
    2 #include <stdio.h>
    32#include <stdlib.h>
     3#include <unistd.h>
    44
     5#include <gio/gunixoutputstream.h>
    56#include <webkit/webkit.h>
    67
     
    89
    910/* compile with:
    10 gcc -o webkit-image-gtk webkit-image-gtk.c `pkg-config --cflags --libs webkit-1.0`
    11 */
     11 * gcc -o webkit-image-gtk webkit-image-gtk.c `pkg-config --cflags --libs webkit-1.0 gio-unix-2.0`
     12 * Requires GTK+ 2.20 and WebKitGtk+ 1.1.1
     13 */
    1214
    1315static void
    14 on_finished (WebKitWebView *view, WebKitWebFrame *frame)
     16on_finished (WebKitWebView      *view,
     17             WebKitWebFrame     *frame,
     18             GtkOffscreenWindow *window)
    1519{
    16         GdkPixmap *pixmap;
    17         GdkColormap *cmap;
    1820        GdkPixbuf *pixbuf;
    19         gchar *buffer;
    20         gsize size;
     21        GOutputStream *stream;
    2122
    22         pixmap = gtk_widget_get_snapshot (GTK_WIDGET (view), NULL);
    23         cmap = gdk_colormap_get_system ();
    24         pixbuf = gdk_pixbuf_get_from_drawable (NULL, GDK_DRAWABLE (pixmap), cmap,
    25                                                0, 0, 0, 0, WIDTH, WIDTH);
     23        pixbuf = gtk_offscreen_window_get_pixbuf (window);
    2624
    27         gdk_pixbuf_save_to_buffer (pixbuf, &buffer, &size, "png", NULL, NULL);
    28 
    29         fwrite (buffer, 1, size, stdout);
     25        stream = g_unix_output_stream_new (STDOUT_FILENO, TRUE);
     26        gdk_pixbuf_save_to_stream (pixbuf, stream, "png", NULL, NULL, NULL);
    3027
    3128        exit (1);
    3229}
    3330
    34 int main (int argc, char **argv)
     31int
     32main (int    argc,
     33      char **argv)
    3534{
    3635        GtkWidget *window;
     
    4241        gtk_init (&argc, &argv);
    4342
    44         window = gtk_window_new (GTK_WINDOW_POPUP);
    45 
    46         /* Check if compositing window manager is running, needs one for now */
    47         if (gtk_widget_is_composited (window))
    48                 gtk_window_set_opacity (GTK_WINDOW (window), 0.0);
    49         else
    50                 g_error ("This requires a compositing window manager for now");
     43        window = gtk_offscreen_window_new ();
    5144
    5245        view = webkit_web_view_new ();
    53         webkit_web_view_open (WEBKIT_WEB_VIEW (view), argv[1]);
     46        webkit_web_view_load_uri (WEBKIT_WEB_VIEW (view), argv[1]);
    5447        gtk_widget_set_size_request (view, WIDTH, WIDTH);
    5548        gtk_container_add (GTK_CONTAINER (window), view);
     
    5750        gtk_widget_show_all (window);
    5851
    59         g_signal_connect (G_OBJECT (view), "load-finished",
    60                           G_CALLBACK (on_finished), NULL);
     52        g_signal_connect (view, "load-finished",
     53                          G_CALLBACK (on_finished), window);
    6154
    6255        gtk_main ();
Note: See TracChangeset for help on using the changeset viewer.