コード例 #1
0
ファイル: gvloadimage_pango.c プロジェクト: ekoontz/graphviz
static void pango_loadimage_ps(GVJ_t * job, usershape_t *us, boxf b, boolean filled)
{
    cairo_surface_t *surface; 	/* source surface */
    cairo_format_t format;
    FILE *out = job->output_file;
    int X, Y, x, y, stride;
    unsigned char *data, *ix, alpha, red, green, blue;

    surface = cairo_loadimage(job, us);
    if (surface) {
       	format = cairo_image_surface_get_format(surface);
        if ((format != CAIRO_FORMAT_ARGB32) && (format != CAIRO_FORMAT_RGB24))
	    return;

	X = cairo_image_surface_get_width(surface);
	Y = cairo_image_surface_get_height(surface);
	stride = cairo_image_surface_get_stride(surface);
	data = cairo_image_surface_get_data(surface);

        fprintf(out, "save\n");

	/* define image data as string array (one per raster line) */
	/* see parallel code in gd_loadimage_ps().  FIXME: refactor... */
        fprintf(out, "/myctr 0 def\n");
        fprintf(out, "/myarray [\n");
        for (y = 0; y < Y; y++) {
	    fprintf(out, "<");
	    ix = data + y * stride;
            for (x = 0; x < X; x++) {
		/* FIXME - this code may have endian problems */
		blue = *ix++;
		green = *ix++;
		red = *ix++;
		alpha = *ix++;
                fprintf(out, "%02x%02x%02x", red, green, blue);
            }
	    fprintf(out, ">\n");
        }
	fprintf(out, "] def\n");
        fprintf(out,"/myproc { myarray myctr get /myctr myctr 1 add def } def\n");

        /* this sets the position of the image */
        fprintf(out, "%g %g translate %% lower-left coordinate\n", b.LL.x, b.LL.y);

        /* this sets the rendered size to fit the box */
        fprintf(out,"%g %g scale\n", b.UR.x - b.LL.x, b.UR.y - b.LL.y);

        /* xsize ysize bits-per-sample [matrix] */
        fprintf(out, "%d %d 8 [%d 0 0 %d 0 %d]\n", X, Y, X, -Y, Y);

        fprintf(out, "{myproc} false 3 colorimage\n");

        fprintf(out, "restore\n");
    }
}
コード例 #2
0
ファイル: gvloadimage_pango.c プロジェクト: ekoontz/graphviz
static void pango_loadimage_cairo(GVJ_t * job, usershape_t *us, boxf b, boolean filled)
{
    cairo_t *cr = (cairo_t *) job->context; /* target context */
    cairo_surface_t *surface;	 /* source surface */

    surface = cairo_loadimage(job, us);
    if (surface) {
        cairo_save(cr);
        cairo_translate(cr, ROUND(b.LL.x), ROUND(-b.UR.y));
        cairo_scale(cr, (b.UR.x - b.LL.x) / us->w,
                        (b.UR.y - b.LL.y) / us->h);
        cairo_set_source_surface (cr, surface, 0, 0);
        cairo_paint (cr);
        cairo_restore(cr);
    }
}
コード例 #3
0
static void pango_loadimage_cairo(GVJ_t * job, usershape_t *us, boxf b, boolean filled)
{
    cairo_t *cr = (cairo_t *) job->context; /* target context */
    cairo_surface_t *surface;	 /* source surface */

    surface = cairo_loadimage(job, us);
    if (surface) {
        cairo_save(cr);
        cairo_translate(cr,
		(b.LL.x + (b.UR.x - b.LL.x) * (1. - (job->dpi.x) / 96.) / 2.),
		(-b.UR.y + (b.UR.y - b.LL.y) * (1. - (job->dpi.y) / 96.) / 2.));
        cairo_scale(cr,
		((b.UR.x - b.LL.x) * (job->dpi.x) / (96. * us->w)),
                ((b.UR.y - b.LL.y) * (job->dpi.y) / (96. * us->h)));
        cairo_set_source_surface (cr, surface, 0, 0);
        cairo_paint (cr);
        cairo_restore(cr);
    }
}