File: gvplugin_gdiplus.cpp

package info (click to toggle)
graphviz 2.26.3-5%2Bsqueeze3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 63,044 kB
  • ctags: 25,930
  • sloc: ansic: 212,134; sh: 20,316; cpp: 7,239; makefile: 4,211; yacc: 3,335; xml: 2,450; tcl: 1,900; cs: 1,890; objc: 1,149; perl: 829; lex: 364; awk: 171; python: 41; ruby: 35; php: 26
file content (108 lines) | stat: -rwxr-xr-x 3,417 bytes parent folder | download | duplicates (3)
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
107
108
/* $Id: gvplugin_gdiplus.cpp,v 1.9 2009/07/14 21:14:51 arif Exp $ $Revision: 1.9 $ */
/* vim:set shiftwidth=4 ts=8: */

/**********************************************************
*      This software is part of the graphviz package      *
*                http://www.graphviz.org/                 *
*                                                         *
*            Copyright (c) 1994-2008 AT&T Corp.           *
*                and is licensed under the                *
*            Common Public License, Version 1.0           *
*                      by AT&T Corp.                      *
*                                                         *
*        Information and Software Systems Research        *
*              AT&T Research, Florham Park NJ             *
**********************************************************/

#include "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 = NULL;

static void UnuseGdiplus()
{
	GdiplusShutdown(_gdiplusToken);
}

void UseGdiplus()
{
	/* only startup once, and ensure we get shutdown */
	if (!_gdiplusToken)
	{
		GdiplusStartupInput input;
		GdiplusStartup(&_gdiplusToken, &input, NULL);
		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, NULL);
	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 (memcmp(&(format_id[format]), &codecs[i].FormatID, sizeof(GUID)) == 0) {
			bitmap.Save(stream, &codecs[i].Clsid, NULL);
			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 WIN32_DLL /*visual studio*/
#ifndef GVPLUGIN_GDIPLUS_EXPORTS
__declspec(dllimport) gvplugin_library_t gvplugin_gdiplus_LTX_library = { "gdiplus", apis };
#else
__declspec(dllexport) gvplugin_library_t gvplugin_gdiplus_LTX_library = { "gdiplus", apis };
#endif
#else /*end visual studio*/
#ifdef GVDLL
__declspec(dllexport) gvplugin_library_t gvplugin_gdiplus_LTX_library = { "gdiplus", apis };
#else
extern "C" gvplugin_library_t gvplugin_gdiplus_LTX_library = { "gdiplus", apis };
#endif
#endif