Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
gvplugin_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 <gvc/gvplugin.h>
12
13#include "gvplugin_gdiplus.h"
14
20
21using namespace std;
22using namespace Gdiplus;
23
24/* class id corresponding to each format_type */
25static GUID format_id [] = {
26 GUID_NULL,
27 GUID_NULL,
28 ImageFormatBMP,
29 ImageFormatEMF,
30 ImageFormatEMF,
31 ImageFormatGIF,
32 ImageFormatJPEG,
33 ImageFormatPNG,
34 ImageFormatTIFF
35};
36
37static ULONG_PTR _gdiplusToken = 0;
38
39static void UnuseGdiplus()
40{
41 GdiplusShutdown(_gdiplusToken);
42}
43
45{
46 /* only startup once, and ensure we get shutdown */
47 if (!_gdiplusToken)
48 {
49 GdiplusStartupInput input;
50 GdiplusStartup(&_gdiplusToken, &input, nullptr);
51 atexit(&UnuseGdiplus);
52 }
53}
54
55const Gdiplus::StringFormat* GetGenericTypographic()
56{
57 const Gdiplus::StringFormat* format = StringFormat::GenericTypographic();
58 return format;
59}
60
61void SaveBitmapToStream(Bitmap &bitmap, IStream *stream, int format)
62{
63 /* search the encoders for one that matches our device id, then save the bitmap there */
64 GdiplusStartupInput gdiplusStartupInput;
65 ULONG_PTR gdiplusToken;
66 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr);
67 UINT encoderNum;
68 UINT encoderSize;
69 GetImageEncodersSize(&encoderNum, &encoderSize);
70 vector<char> codec_buffer(encoderSize);
71 ImageCodecInfo *codecs = (ImageCodecInfo *)&codec_buffer.front();
72 GetImageEncoders(encoderNum, encoderSize, codecs);
73 for (UINT i = 0; i < encoderNum; ++i)
74 if (memcmp(&(format_id[format]), &codecs[i].FormatID, sizeof(GUID)) == 0) {
75 bitmap.Save(stream, &codecs[i].Clsid, nullptr);
76 break;
77 }
78}
79
80static gvplugin_api_t apis[] = {
81 {API_render, gvrender_gdiplus_types},
82 {API_textlayout, gvtextlayout_gdiplus_types},
83 {API_loadimage, gvloadimage_gdiplus_types},
84 {API_device, gvdevice_gdiplus_types},
86 {(api_t)0, 0},
87};
88
89#ifdef __cplusplus
90extern "C" {
91#endif
92
93#ifdef GVDLL
94#define GVPLUGIN_GDIPLUS_API __declspec(dllexport)
95#else
96#define GVPLUGIN_GDIPLUS_API
97#endif
98
102
103#ifdef __cplusplus
104}
105#endif
api_t
Definition gvcext.h:32
GVIO_API const char * format
Definition gvio.h:51
#define GVPLUGIN_GDIPLUS_API
static GUID format_id[]
gvplugin_installed_t gvdevice_gdiplus_types[]
gvplugin_installed_t gvdevice_gdiplus_types_for_cairo[]
void UseGdiplus()
static ULONG_PTR _gdiplusToken
void SaveBitmapToStream(Bitmap &bitmap, IStream *stream, int format)
const Gdiplus::StringFormat * GetGenericTypographic()
static gvplugin_api_t apis[]
gvplugin_installed_t gvtextlayout_gdiplus_types[]
gvplugin_installed_t gvloadimage_gdiplus_types[]
static void UnuseGdiplus()
GVPLUGIN_GDIPLUS_API gvplugin_library_t gvplugin_gdiplus_LTX_library
gvplugin_installed_t gvrender_gdiplus_types[]
ingroup plugin_api
Definition gvplugin.h:35