Graphviz
13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
gvloadimage_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 <stdlib.h>
14
#include <stddef.h>
15
#include <string.h>
16
17
#include <
gvc/gvplugin_loadimage.h
>
18
#include "
gvplugin_gdiplus.h
"
19
#include <stringapiset.h>
20
#include <windows.h>
21
#include <gdiplus.h>
22
#include <vector>
23
24
using namespace
Gdiplus;
25
26
static
void
gdiplus_freeimage
(
usershape_t
*us) {
27
delete
reinterpret_cast<
Image*
>
(us->
data
);
28
}
29
30
// convert a UTF-8 string to UTF-16
31
static
std::vector<wchar_t>
utf8_to_utf16
(
const
char
*
s
) {
32
33
// how much space do we need for the UTF-16 string?
34
const
int
wide_count = MultiByteToWideChar(CP_UTF8, 0,
s
, -1,
nullptr
, 0);
35
36
// translate it
37
std::vector<wchar_t> utf16(wide_count);
38
if
(wide_count > 0) {
39
(void)MultiByteToWideChar(CP_UTF8, 0,
s
, -1, utf16.data(), wide_count);
40
}
else
{
41
utf16.push_back(0);
42
}
43
44
return
utf16;
45
}
46
47
static
Image *
gdiplus_loadimage
(
usershape_t
*us) {
48
assert(us);
49
assert(us->
name
);
50
51
if
(us->
data
&& us->
datafree
!=
gdiplus_freeimage
) {
52
us->
datafree
(us);
/* free incompatible cache data */
53
us->
data
=
nullptr
;
54
us->
datafree
=
nullptr
;
55
}
56
57
if
(!us->
data
) {
/* read file into cache */
58
if
(!
gvusershape_file_access
(us))
59
return
nullptr
;
60
61
/* create image from the usershape file */
62
const
std::vector<wchar_t> filename =
utf8_to_utf16
(us->
name
);
63
us->
data
= Image::FromFile(filename.data());
64
65
/* clean up */
66
if
(us->
data
)
67
us->
datafree
=
gdiplus_freeimage
;
68
69
gvusershape_file_release
(us);
70
}
71
return
reinterpret_cast<
Image*
>
(us->
data
);
72
}
73
74
static
void
gdiplus_loadimage_gdiplus
(
GVJ_t
* job,
usershape_t
*us,
boxf
b,
bool
)
75
{
76
/* get the image from usershape details, then blit it to the context */
77
if
(Image *
image
=
gdiplus_loadimage
(us)) {
78
assert(job !=
NULL
);
79
auto
g =
reinterpret_cast<
Graphics*
>
(job->
context
);
80
g->DrawImage(
image
, RectF(b.
LL
.
x
, b.
LL
.
y
, b.
UR
.
x
- b.
LL
.
x
, b.
UR
.
y
- b.
LL
.
y
));
81
}
82
}
83
84
static
gvloadimage_engine_t
engine
= {
85
gdiplus_loadimage_gdiplus
86
};
87
88
gvplugin_installed_t
gvloadimage_gdiplus_types
[] = {
89
{
FORMAT_BMP
,
"bmp:gdiplus"
, 8, &
engine
,
nullptr
},
90
{
FORMAT_GIF
,
"gif:gdiplus"
, 8, &
engine
,
nullptr
},
91
{
FORMAT_JPEG
,
"jpe:gdiplus"
, 8, &
engine
,
nullptr
},
92
{
FORMAT_JPEG
,
"jpeg:gdiplus"
, 8, &
engine
,
nullptr
},
93
{
FORMAT_JPEG
,
"jpg:gdiplus"
, 8, &
engine
,
nullptr
},
94
{
FORMAT_PNG
,
"png:gdiplus"
, 8, &
engine
,
nullptr
},
95
{0,
nullptr
, 0,
nullptr
,
nullptr
}
96
};
NULL
node NULL
Definition
grammar.y:163
gvusershape_file_release
void gvusershape_file_release(usershape_t *us)
Definition
gvusershape.c:654
gvusershape_file_access
bool gvusershape_file_access(usershape_t *us)
Definition
gvusershape.c:624
engine
static gvloadimage_engine_t engine
Definition
gvloadimage_gdiplus.cpp:84
gdiplus_loadimage
static Image * gdiplus_loadimage(usershape_t *us)
Definition
gvloadimage_gdiplus.cpp:47
gdiplus_loadimage_gdiplus
static void gdiplus_loadimage_gdiplus(GVJ_t *job, usershape_t *us, boxf b, bool)
Definition
gvloadimage_gdiplus.cpp:74
utf8_to_utf16
static std::vector< wchar_t > utf8_to_utf16(const char *s)
Definition
gvloadimage_gdiplus.cpp:31
gdiplus_freeimage
static void gdiplus_freeimage(usershape_t *us)
Definition
gvloadimage_gdiplus.cpp:26
gvloadimage_gdiplus_types
gvplugin_installed_t gvloadimage_gdiplus_types[]
Definition
gvloadimage_gdiplus.cpp:88
gvplugin_gdiplus.h
FORMAT_BMP
@ FORMAT_BMP
Definition
gvplugin_gdiplus.h:22
gvplugin_loadimage.h
FORMAT_JPEG
@ FORMAT_JPEG
Definition
gvrender_gd.c:37
FORMAT_GIF
@ FORMAT_GIF
Definition
gvrender_gd.c:36
FORMAT_PNG
@ FORMAT_PNG
Definition
gvrender_gd.c:38
image
T_cell image
Definition
htmlparse.y:340
GVJ_s
Definition
gvcjob.h:262
GVJ_s::context
void * context
Definition
gvcjob.h:295
boxf
Definition
geom.h:41
boxf::UR
pointf UR
Definition
geom.h:41
boxf::LL
pointf LL
Definition
geom.h:41
gvloadimage_engine_s
Definition
gvplugin_loadimage.h:46
gvplugin_installed_t
ingroup plugin_api
Definition
gvplugin.h:35
pointf_s::x
double x
Definition
geom.h:29
pointf_s::y
double y
Definition
geom.h:29
usershape_s
Definition
usershape.h:52
usershape_s::name
const char * name
Definition
usershape.h:54
usershape_s::datafree
void(* datafree)(usershape_t *us)
Definition
usershape.h:65
usershape_s::data
void * data
Definition
usershape.h:63
s
Definition
grammar.c:93
plugin
gdiplus
gvloadimage_gdiplus.cpp
Generated by
1.9.8