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