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