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