Esempio n. 1
0
static void
gwy_graph_label_draw_label(GtkWidget *widget)
{
    gint winheight, winwidth, windepth, winx, winy;
    GwyGraphLabel *label;
    PangoLayout *layout;
    GdkGC *mygc;

    mygc = gdk_gc_new(widget->window);

    label = GWY_GRAPH_LABEL(widget);
    layout = gtk_widget_create_pango_layout(widget, NULL);

    gdk_window_get_geometry(widget->window,
                            &winx, &winy, &winwidth, &winheight, &windepth);
    gwy_graph_label_draw_on_drawable(label, GDK_DRAWABLE(widget->window),
                                     mygc, layout,
                                     0, 0, winwidth, winheight);
    g_object_unref(mygc);
    g_object_unref(layout);

}
Esempio n. 2
0
GdkPixbuf*
gwy_graph_export_pixmap(GwyGraph *graph,
                        G_GNUC_UNUSED gboolean export_title,
                        G_GNUC_UNUSED gboolean export_axis,
                        G_GNUC_UNUSED gboolean export_labels)
{
    GdkColor color = { 0, 65535, 65535, 65535 };
    GdkPixbuf *pixbuf;
    GdkColormap *cmap;
    GdkGC *gc;
    GdkVisual *visual;
    GdkPixmap *pixmap;
    PangoLayout *layout;
    PangoContext *context;
    gint width, height, topheight, bottomheight, rightwidth, leftwidth;
    gint labelx, labely, labelw, labelh;

    width = (GTK_WIDGET(graph))->allocation.width;
    height = (GTK_WIDGET(graph))->allocation.height;

    topheight = (GTK_WIDGET(graph->axis[GTK_POS_TOP]))->allocation.height;
    bottomheight = (GTK_WIDGET(graph->axis[GTK_POS_BOTTOM]))->allocation.height;
    leftwidth = (GTK_WIDGET(graph->axis[GTK_POS_LEFT]))->allocation.width;
    rightwidth = (GTK_WIDGET(graph->axis[GTK_POS_RIGHT]))->allocation.width;

    labelx = (GTK_WIDGET(graph->area->lab))->allocation.x + leftwidth;
    labely = (GTK_WIDGET(graph->area->lab))->allocation.y + topheight;
    labelw = (GWY_GRAPH_LABEL(graph->area->lab))->reqwidth;
    labelh = (GWY_GRAPH_LABEL(graph->area->lab))->reqheight;

    visual = gdk_visual_get_best();
    cmap = gdk_colormap_new(visual, FALSE);

    pixmap = gdk_pixmap_new(NULL, width, height, visual->depth);
    gdk_drawable_set_colormap(pixmap, cmap);

    gc = gdk_gc_new(pixmap);
    gdk_gc_set_colormap(gc, cmap);

    gdk_gc_set_rgb_fg_color(gc, &color);
    gdk_draw_rectangle(pixmap, gc, TRUE, 0, 0, width, height);

    gwy_graph_area_draw_on_drawable(graph->area, pixmap, gc,
                                    leftwidth, topheight,
                                    width - leftwidth - rightwidth,
                                    height - topheight - bottomheight);

    /* Draw axes */
    gwy_axis_draw_on_drawable(graph->axis[GTK_POS_TOP], pixmap, gc,
                              leftwidth, 0,
                              width - leftwidth - rightwidth, topheight);
    gwy_axis_draw_on_drawable(graph->axis[GTK_POS_BOTTOM], pixmap, gc,
                              leftwidth, height - bottomheight,
                              width - leftwidth - rightwidth, bottomheight);
    gwy_axis_draw_on_drawable(graph->axis[GTK_POS_LEFT], pixmap, gc,
                              0, topheight,
                              leftwidth, height - topheight - bottomheight);
    gwy_axis_draw_on_drawable(graph->axis[GTK_POS_RIGHT], pixmap, gc,
                              width - rightwidth, topheight,
                              rightwidth, height - topheight - bottomheight);

    context = gdk_pango_context_get_for_screen(gdk_screen_get_default());
    pango_context_set_font_description(context, graph->area->lab->font_desc);
    layout = pango_layout_new(context);
    gwy_graph_label_draw_on_drawable(graph->area->lab, pixmap, gc, layout,
                                     labelx, labely, labelw, labelh);

    pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, cmap,
                                          0, 0, 0, 0,
                                          -1, -1);

    g_object_unref(pixmap);
    g_object_unref(layout);
    g_object_unref(context);
    g_object_unref(gc);
    g_object_unref(cmap);

    return pixbuf;
}