1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/*************************************************************************
* Copyright (c) 2011 AT&T Intellectual Property
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors: Details at https://graphviz.org
*************************************************************************/
#include <guiddef.h>
#include <gvc/gvplugin.h>
#include "gvplugin_gdiplus.h"
extern gvplugin_installed_t gvrender_gdiplus_types[];
extern gvplugin_installed_t gvtextlayout_gdiplus_types[];
extern gvplugin_installed_t gvloadimage_gdiplus_types[];
extern gvplugin_installed_t gvdevice_gdiplus_types[];
extern gvplugin_installed_t gvdevice_gdiplus_types_for_cairo[];
using namespace std;
using namespace Gdiplus;
/* class id corresponding to each format_type */
static GUID format_id [] = {
GUID_NULL,
GUID_NULL,
ImageFormatBMP,
ImageFormatEMF,
ImageFormatEMF,
ImageFormatGIF,
ImageFormatJPEG,
ImageFormatPNG,
ImageFormatTIFF
};
static ULONG_PTR _gdiplusToken = 0;
static void UnuseGdiplus()
{
GdiplusShutdown(_gdiplusToken);
}
void UseGdiplus()
{
/* only startup once, and ensure we get shutdown */
if (!_gdiplusToken)
{
GdiplusStartupInput input;
GdiplusStartup(&_gdiplusToken, &input, nullptr);
atexit(&UnuseGdiplus);
}
}
const Gdiplus::StringFormat* GetGenericTypographic()
{
const Gdiplus::StringFormat* format = StringFormat::GenericTypographic();
return format;
}
void SaveBitmapToStream(Bitmap &bitmap, IStream *stream, int format)
{
/* search the encoders for one that matches our device id, then save the bitmap there */
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr);
UINT encoderNum;
UINT encoderSize;
GetImageEncodersSize(&encoderNum, &encoderSize);
vector<char> codec_buffer(encoderSize);
ImageCodecInfo *codecs = (ImageCodecInfo *)&codec_buffer.front();
GetImageEncoders(encoderNum, encoderSize, codecs);
for (UINT i = 0; i < encoderNum; ++i)
if (IsEqualGUID(format_id[format], codecs[i].FormatID)) {
bitmap.Save(stream, &codecs[i].Clsid, nullptr);
break;
}
}
static gvplugin_api_t apis[] = {
{API_render, gvrender_gdiplus_types},
{API_textlayout, gvtextlayout_gdiplus_types},
{API_loadimage, gvloadimage_gdiplus_types},
{API_device, gvdevice_gdiplus_types},
{API_device, gvdevice_gdiplus_types_for_cairo},
{(api_t)0, 0},
};
#ifdef __cplusplus
extern "C" {
#endif
#ifdef GVDLL
#define GVPLUGIN_GDIPLUS_API __declspec(dllexport)
#else
#define GVPLUGIN_GDIPLUS_API
#endif
GVPLUGIN_GDIPLUS_API gvplugin_library_t gvplugin_gdiplus_LTX_library = {
const_cast<char*>("gdiplus"), apis
};
#ifdef __cplusplus
}
#endif
|