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
|
/** \file
* \brief Windows GDI+ EMF Driver
*
* See Copyright Notice in cd.h
*/
#include "cdwinp.h"
#include "cdemf.h"
#include <stdlib.h>
#include <stdio.h>
static void cdkillcanvas (cdCtxCanvas* ctxcanvas)
{
cdwpKillCanvas(ctxcanvas);
delete ctxcanvas->metafile;
delete ctxcanvas;
}
/*
%F cdCreateCanvas para EMF.
O DC é um EMF em memoria.
*/
static void cdcreatecanvas(cdCanvas* canvas, void* data)
{
char* strdata = (char*)data;
char filename[10240] = "";
Metafile* metafile;
/* Inicializa parametros */
if (strdata == NULL)
return;
strdata += cdGetFileName(strdata, filename);
if (filename[0] == 0)
return;
int w = 0, h = 0;
sscanf(strdata,"%dx%d", &w, &h);
if (w == 0 || h == 0)
return;
{
/* Verifica se o arquivo pode ser aberto para escrita */
FILE* file = fopen(filename, "wb");
if (file == NULL)
return;
fclose(file);
}
{
HDC ScreenDC = GetDC(NULL);
/* LOGPIXELS can not be used for EMF */
canvas->xres = (double)GetDeviceCaps(ScreenDC, HORZRES) / (double)GetDeviceCaps(ScreenDC, HORZSIZE);
canvas->yres = (double)GetDeviceCaps(ScreenDC, VERTRES) / (double)GetDeviceCaps(ScreenDC, VERTSIZE);
Rect frameRect(0, 0, (int)(100 * w / canvas->xres), (int)(100 * h / canvas->yres));
metafile = new Metafile(cdwpString2Unicode(filename, strlen(filename)),
ScreenDC, frameRect, MetafileFrameUnitGdi, EmfTypeEmfPlusDual, NULL);
ReleaseDC(NULL, ScreenDC);
}
canvas->w = w;
canvas->h = h;
canvas->bpp = 24;
Graphics* graphics = new Graphics(metafile);
/* Inicializa driver WIN32 */
cdCtxCanvas* ctxcanvas = cdwpCreateCanvas(canvas, graphics, CDW_EMF);
/* Inicializacao de variaveis particulares para o EMF */
ctxcanvas->metafile = metafile;
}
static void cdinittable(cdCanvas* canvas)
{
cdwpInitTable(canvas);
canvas->cxKillCanvas = cdkillcanvas;
}
static cdContext cdEMFContext =
{
CD_CAP_ALL & ~(CD_CAP_CLEAR | CD_CAP_PLAY | CD_CAP_FLUSH | CD_CAP_YAXIS |
CD_CAP_FPRIMTIVES |
CD_CAP_GETIMAGERGB | CD_CAP_IMAGESRV),
1,
cdcreatecanvas,
cdinittable,
NULL,
NULL
};
extern "C" {
cdContext* cdContextEMFPlus(void)
{
return &cdEMFContext;
}
}
|