Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
gvdevice_gdiplus.cpp
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
14#include <gvc/gvplugin_device.h>
15#include <gvc/gvplugin_render.h>
16#include <gvc/gvio.h>
17#include "gvplugin_gdiplus.h"
18
19using namespace Gdiplus;
20
21static void gdiplus_format(GVJ_t *job)
22{
23 UseGdiplus();
24
25 /* allocate memory and attach stream to it */
26 HGLOBAL buffer = GlobalAlloc(GMEM_MOVEABLE, 0);
27 IStream *stream = nullptr;
28 CreateStreamOnHGlobal(buffer, FALSE, &stream); /* FALSE means don't deallocate buffer when releasing stream */
29
30 Bitmap bitmap(
31 job->width, /* width in pixels */
32 job->height, /* height in pixels */
33 job->width * BYTES_PER_PIXEL, /* bytes per row: exactly width # of pixels */
34 PixelFormat32bppPARGB, /* pixel format: corresponds to CAIRO_FORMAT_ARGB32 */
35 (BYTE*)job->imagedata); /* pixel data from job */
36 SaveBitmapToStream(bitmap, stream, job->device.id);
37
38 /* blast the streamed buffer back to the gvdevice */
39 /* NOTE: this is somewhat inefficient since we should be streaming directly to gvdevice rather than buffering first */
40 /* ... however, GDI+ requires any such direct IStream to implement Seek Read, Write, Stat methods and gvdevice really only offers a write-once model */
41 stream->Release();
42 gvwrite(job, (const char*)GlobalLock(buffer), GlobalSize(buffer));
43
44 GlobalFree(buffer);
45}
46
48 nullptr, /* gdiplus_initialize */
50 nullptr, /* gdiplus_finalize */
51};
52
55 | GVDEVICE_DOES_TRUECOLOR,/* flags */
56 {0.,0.}, /* default margin - points */
57 {0.,0.}, /* default page width, height - points */
58 {96.,96.}, /* dpi */
59};
60
#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:179
static gvdevice_features_t device_features_gdiplus
gvplugin_installed_t gvdevice_gdiplus_types_for_cairo[]
static void gdiplus_format(GVJ_t *job)
static gvdevice_engine_t gdiplus_engine
void UseGdiplus()
void SaveBitmapToStream(Bitmap &bitmap, IStream *stream, int format)
static const int BYTES_PER_PIXEL
@ FORMAT_TIFF
@ FORMAT_BMP
@ FORMAT_JPEG
Definition gvrender_gd.c:32
@ FORMAT_GIF
Definition gvrender_gd.c:31
@ FORMAT_PNG
Definition gvrender_gd.c:33
char * imagedata
Definition gvcjob.h:297
gvplugin_active_device_t device
Definition gvcjob.h:286
unsigned int width
Definition gvcjob.h:327
unsigned int height
Definition gvcjob.h:328
ingroup plugin_api
Definition gvplugin.h:35