Graphviz 14.1.2~dev.20260118.1035
Loading...
Searching...
No Matches
gvdevice_gdk.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include "config.h"
12
13#include <assert.h>
14#include <gvc/gvplugin_device.h>
15#include <gvc/gvio.h>
16#include <limits.h>
17#include <util/gv_math.h>
18#include <gdk-pixbuf/gdk-pixbuf.h>
19#include <util/agxbuf.h>
20
21enum {
27};
28
29static gboolean writer(const char *buf, gsize count, GError **error,
30 void *data) {
31 (void)error;
32 return count == gvwrite(data, buf, count);
33}
34
35static void gdk_format(GVJ_t * job)
36{
37 char *const format_strs[] = {
38 [FORMAT_BMP] = "bmp",
39 [FORMAT_ICO] = "ico",
40 [FORMAT_JPEG] = "jpeg",
41 [FORMAT_PNG] = "png",
42 [FORMAT_TIFF] = "tiff"
43 };
44 assert(job->device.id >= 0);
45 assert(job->device.id < (int)(sizeof(format_strs) / sizeof(format_strs[0])));
46 char *const format_str = format_strs[job->device.id];
47 GdkPixbuf *pixbuf;
48
49 argb2rgba(job->width, job->height, job->imagedata);
50
51 assert(job->width <= INT_MAX / BYTES_PER_PIXEL && "width out of range");
52 assert(job->height <= INT_MAX && "height out of range");
53
54 pixbuf = gdk_pixbuf_new_from_data(
55 job->imagedata, // data
56 GDK_COLORSPACE_RGB, // colorspace
57 TRUE, // has_alpha
58 8, // bits_per_sample
59 (int)job->width, // width
60 (int)job->height, // height
61 BYTES_PER_PIXEL * (int)job->width, // rowstride
62 NULL, // destroy_fn
63 NULL // destroy_fn_data
64 );
65
66 agxbuf x_dpi = {0};
67 agxbprint(&x_dpi, "%.0f", job->dpi.x);
68 agxbuf y_dpi = {0};
69 agxbprint(&y_dpi, "%.0f", job->dpi.y);
70
71 gdk_pixbuf_save_to_callback(pixbuf, writer, job, format_str, NULL, "x-dpi",
72 agxbuse(&x_dpi), "y-dpi", agxbuse(&y_dpi),
73 NULL);
74
75 agxbfree(&y_dpi);
76 agxbfree(&x_dpi);
77 g_object_unref(pixbuf);
78}
79
81 NULL, /* gdk_initialize */
83 NULL, /* gdk_finalize */
84};
85
88 | GVDEVICE_DOES_TRUECOLOR,/* flags */
89 {0.,0.}, /* default margin - points */
90 {0.,0.}, /* default page width, height - points */
91 {96.,96.}, /* dpi */
92};
93
95 {FORMAT_BMP, "bmp:cairo", 6, &gdk_engine, &device_features_gdk},
96 {FORMAT_ICO, "ico:cairo", 6, &gdk_engine, &device_features_gdk},
97 {FORMAT_JPEG, "jpe:cairo", 6, &gdk_engine, &device_features_gdk},
98 {FORMAT_JPEG, "jpeg:cairo", 6, &gdk_engine, &device_features_gdk},
99 {FORMAT_JPEG, "jpg:cairo", 6, &gdk_engine, &device_features_gdk},
100 {FORMAT_PNG, "png:cairo", 6, &gdk_engine, &device_features_gdk},
101 {FORMAT_TIFF, "tif:cairo", 6, &gdk_engine, &device_features_gdk},
102 {FORMAT_TIFF, "tiff:cairo", 6, &gdk_engine, &device_features_gdk},
103 {0, NULL, 0, NULL, NULL}
104};
Dynamically expanding string buffers.
static void agxbfree(agxbuf *xb)
free any malloced resources
Definition agxbuf.h:97
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
Definition agxbuf.h:252
static WUR char * agxbuse(agxbuf *xb)
Definition agxbuf.h:325
node NULL
Definition grammar.y:181
Arithmetic helper functions.
@ BYTES_PER_PIXEL
Definition gv_math.h:91
static void argb2rgba(size_t width, size_t height, unsigned char *data)
Definition gv_math.h:109
#define GVDEVICE_DOES_TRUECOLOR
Definition gvcjob.h:90
#define GVDEVICE_BINARY_FORMAT
Definition gvcjob.h:91
size_t gvwrite(GVJ_t *job, const char *s, size_t len)
Definition gvdevice.c:182
static gvdevice_engine_t gdk_engine
@ FORMAT_ICO
@ FORMAT_JPEG
@ FORMAT_TIFF
@ FORMAT_BMP
@ FORMAT_PNG
static gvdevice_features_t device_features_gdk
gvplugin_installed_t gvdevice_gdk_types[]
static gboolean writer(const char *buf, gsize count, GError **error, void *data)
static void gdk_format(GVJ_t *job)
table Syntax error
Definition htmlparse.y:288
pointf dpi
Definition gvcjob.h:325
gvplugin_active_device_t device
Definition gvcjob.h:286
unsigned char * imagedata
location of imagedata
Definition gvcjob.h:297
unsigned int width
Definition gvcjob.h:327
unsigned int height
Definition gvcjob.h:328
ingroup plugin_api
Definition gvplugin.h:35
double x
Definition geom.h:29
double y
Definition geom.h:29