metafile.c
来自「一个类似windows」· C语言 代码 · 共 613 行 · 第 1/2 页
C
613 行
ok (mfsize == bsize, "%s: mfsize=%d, bsize=%d.\n",
desc, mfsize, bsize);
else
ok (bsize >= MF_BUFSIZE, "%s: mfsize > bufsize (%d bytes), bsize=%d.\n",
desc, mfsize, bsize);
if (mfsize != bsize)
return -1;
diff = 0;
for (i=0; i<bsize; i++)
{
if (buf[i] != bits[i])
diff++;
}
ok (diff == 0, "%s: mfsize=%d, bsize=%d, diff=%d\n",
desc, mfsize, bsize, diff);
return diff;
}
/* Test a blank metafile. May be used as a template for new tests. */
static void test_mf_Blank(void)
{
HDC hdcMetafile;
HMETAFILE hMetafile;
INT caps;
BOOL ret;
hdcMetafile = CreateMetaFileA(NULL);
ok(hdcMetafile != 0, "CreateMetaFileA(NULL) error %ld\n", GetLastError());
trace("hdcMetafile %p\n", hdcMetafile);
/* Tests on metafile initialization */
caps = GetDeviceCaps (hdcMetafile, TECHNOLOGY);
ok (caps == DT_METAFILE,
"GetDeviceCaps: TECHNOLOGY=%d != DT_METAFILE.\n", caps);
hMetafile = CloseMetaFile(hdcMetafile);
ok(hMetafile != 0, "CloseMetaFile error %ld\n", GetLastError());
ok(!GetObjectType(hdcMetafile), "CloseMetaFile has to destroy metafile hdc\n");
if (compare_mf_bits (hMetafile, MF_BLANK_BITS, sizeof(MF_BLANK_BITS),
"mf_blank") != 0)
dump_mf_bits (hMetafile, "mf_Blank");
ret = DeleteMetaFile(hMetafile);
ok( ret, "DeleteMetaFile(%p) error %ld\n", hMetafile, GetLastError());
}
/* Simple APIs from mfdrv/graphics.c
*/
static void test_mf_Graphics(void)
{
HDC hdcMetafile;
HMETAFILE hMetafile;
POINT oldpoint;
BOOL ret;
hdcMetafile = CreateMetaFileA(NULL);
ok(hdcMetafile != 0, "CreateMetaFileA(NULL) error %ld\n", GetLastError());
trace("hdcMetafile %p\n", hdcMetafile);
ret = MoveToEx(hdcMetafile, 1, 1, NULL);
ok( ret, "MoveToEx error %ld.\n", GetLastError());
ret = LineTo(hdcMetafile, 2, 2);
ok( ret, "LineTo error %ld.\n", GetLastError());
ret = MoveToEx(hdcMetafile, 1, 1, &oldpoint);
ok( ret, "MoveToEx error %ld.\n", GetLastError());
/* oldpoint gets garbage under Win XP, so the following test would
* work under Wine but fails under Windows:
*
* ok((oldpoint.x == 2) && (oldpoint.y == 2),
* "MoveToEx: (x, y) = (%ld, %ld), should be (2, 2).\n",
* oldpoint.x, oldpoint.y);
*/
ret = Ellipse(hdcMetafile, 0, 0, 2, 2);
ok( ret, "Ellipse error %ld.\n", GetLastError());
hMetafile = CloseMetaFile(hdcMetafile);
ok(hMetafile != 0, "CloseMetaFile error %ld\n", GetLastError());
ok(!GetObjectType(hdcMetafile), "CloseMetaFile has to destroy metafile hdc\n");
if (compare_mf_bits (hMetafile, MF_GRAPHICS_BITS, sizeof(MF_GRAPHICS_BITS),
"mf_Graphics") != 0)
dump_mf_bits (hMetafile, "mf_Graphics");
ret = DeleteMetaFile(hMetafile);
ok( ret, "DeleteMetaFile(%p) error %ld\n",
hMetafile, GetLastError());
}
static void test_mf_PatternBrush(void)
{
HDC hdcMetafile;
HMETAFILE hMetafile;
LOGBRUSH *orig_lb;
HBRUSH hBrush;
BOOL ret;
orig_lb = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LOGBRUSH));
orig_lb->lbStyle = BS_PATTERN;
orig_lb->lbColor = RGB(0, 0, 0);
orig_lb->lbHatch = (INT) CreateBitmap (8, 8, 1, 1, SAMPLE_PATTERN_BRUSH);
ok((HBITMAP *)orig_lb->lbHatch != NULL, "CreateBitmap error %ld.\n", GetLastError());
hBrush = CreateBrushIndirect (orig_lb);
ok(hBrush != 0, "CreateBrushIndirect error %ld\n", GetLastError());
hdcMetafile = CreateMetaFileA(NULL);
ok(hdcMetafile != 0, "CreateMetaFileA error %ld\n", GetLastError());
trace("hdcMetafile %p\n", hdcMetafile);
hBrush = SelectObject(hdcMetafile, hBrush);
ok(hBrush != 0, "SelectObject error %ld.\n", GetLastError());
hMetafile = CloseMetaFile(hdcMetafile);
ok(hMetafile != 0, "CloseMetaFile error %ld\n", GetLastError());
ok(!GetObjectType(hdcMetafile), "CloseMetaFile has to destroy metafile hdc\n");
if (compare_mf_bits (hMetafile, MF_PATTERN_BRUSH_BITS, sizeof(MF_PATTERN_BRUSH_BITS),
"mf_Pattern_Brush") != 0)
dump_mf_bits (hMetafile, "mf_Pattern_Brush");
ret = DeleteMetaFile(hMetafile);
ok( ret, "DeleteMetaFile error %ld\n", GetLastError());
ret = DeleteObject(hBrush);
ok( ret, "DeleteObject(HBRUSH) error %ld\n", GetLastError());
ret = DeleteObject((HBITMAP *)orig_lb->lbHatch);
ok( ret, "DeleteObject(HBITMAP) error %ld\n",
GetLastError());
HeapFree (GetProcessHeap(), 0, orig_lb);
}
static INT CALLBACK EmfEnumProc(HDC hdc, HANDLETABLE *lpHTable, const ENHMETARECORD *lpEMFR, INT nObj, LPARAM lpData)
{
LPMETAFILEPICT lpMFP = (LPMETAFILEPICT)lpData;
POINT mapping[2] = { { 0, 0 }, { 10, 10 } };
/* When using MM_TEXT Win9x does not update the mapping mode
* until a record is played which actually outputs something */
PlayEnhMetaFileRecord(hdc, lpHTable, lpEMFR, nObj);
LPtoDP(hdc, mapping, 2);
trace("Meta record: iType = %ld, (%ld,%ld)-(%ld,%ld)\n", lpEMFR->iType, mapping[0].x, mapping[0].y, mapping[1].x, mapping[1].y);
if (lpEMFR->iType == EMR_LINETO)
{
INT x0, y0, x1, y1;
if (!lpMFP || lpMFP->mm == MM_TEXT)
{
x0 = 0;
y0 = 0;
x1 = (INT)floor(10 * 100.0 / LINE_X + 0.5);
y1 = (INT)floor(10 * 100.0 / LINE_Y + 0.5);
}
else
{
ok(lpMFP->mm == MM_ANISOTROPIC, "mm=%ld\n", lpMFP->mm);
x0 = MulDiv(0, GetDeviceCaps(hdc, HORZSIZE) * 100, GetDeviceCaps(hdc, HORZRES));
y0 = MulDiv(0, GetDeviceCaps(hdc, VERTSIZE) * 100, GetDeviceCaps(hdc, VERTRES));
x1 = MulDiv(10, GetDeviceCaps(hdc, HORZSIZE) * 100, GetDeviceCaps(hdc, HORZRES));
y1 = MulDiv(10, GetDeviceCaps(hdc, VERTSIZE) * 100, GetDeviceCaps(hdc, VERTRES));
}
ok(mapping[0].x == x0 && mapping[0].y == y0 && mapping[1].x == x1 && mapping[1].y == y1,
"(%ld,%ld)->(%ld,%ld), expected (%d,%d)->(%d,%d)\n",
mapping[0].x, mapping[0].y, mapping[1].x, mapping[1].y,
x0, y0, x1, y1);
}
return TRUE;
}
static HENHMETAFILE create_converted_emf(const METAFILEPICT *mfp)
{
HDC hdcMf;
HMETAFILE hmf;
BOOL ret;
UINT size;
LPBYTE pBits;
hdcMf = CreateMetaFile(NULL);
ok(hdcMf != NULL, "CreateMetaFile failed with error %ld\n", GetLastError());
ret = LineTo(hdcMf, (INT)LINE_X, (INT)LINE_Y);
ok(ret, "LineTo failed with error %ld\n", GetLastError());
hmf = CloseMetaFile(hdcMf);
ok(hmf != NULL, "CloseMetaFile failed with error %ld\n", GetLastError());
size = GetMetaFileBitsEx(hmf, 0, NULL);
ok(size, "GetMetaFileBitsEx failed with error %ld\n", GetLastError());
pBits = HeapAlloc(GetProcessHeap(), 0, size);
GetMetaFileBitsEx(hmf, size, pBits);
DeleteMetaFile(hmf);
return SetWinMetaFileBits(size, pBits, NULL, mfp);
}
static void test_mf_conversions(void)
{
trace("Testing MF->EMF conversion (MM_ANISOTROPIC)\n");
{
HDC hdcOffscreen = CreateCompatibleDC(NULL);
HENHMETAFILE hemf;
METAFILEPICT mfp;
RECT rect = { 0, 0, 100, 100 };
mfp.mm = MM_ANISOTROPIC;
mfp.xExt = 100;
mfp.yExt = 100;
mfp.hMF = NULL;
hemf = create_converted_emf(&mfp);
EnumEnhMetaFile(hdcOffscreen, hemf, EmfEnumProc, &mfp, &rect);
DeleteEnhMetaFile(hemf);
DeleteDC(hdcOffscreen);
}
trace("Testing MF->EMF conversion (MM_TEXT)\n");
{
HDC hdcOffscreen = CreateCompatibleDC(NULL);
HENHMETAFILE hemf;
METAFILEPICT mfp;
RECT rect = { 0, 0, 100, 100 };
mfp.mm = MM_TEXT;
mfp.xExt = 0;
mfp.yExt = 0;
mfp.hMF = NULL;
hemf = create_converted_emf(&mfp);
EnumEnhMetaFile(hdcOffscreen, hemf, EmfEnumProc, &mfp, &rect);
DeleteEnhMetaFile(hemf);
DeleteDC(hdcOffscreen);
}
trace("Testing MF->EMF conversion (NULL mfp)\n");
{
HDC hdcOffscreen = CreateCompatibleDC(NULL);
HENHMETAFILE hemf;
RECT rect = { 0, 0, 100, 100 };
hemf = create_converted_emf(NULL);
EnumEnhMetaFile(hdcOffscreen, hemf, EmfEnumProc, NULL, &rect);
DeleteEnhMetaFile(hemf);
DeleteDC(hdcOffscreen);
}
}
static BOOL (WINAPI *pGdiIsMetaPrintDC)(HDC);
static BOOL (WINAPI *pGdiIsMetaFileDC)(HDC);
static BOOL (WINAPI *pGdiIsPlayMetafileDC)(HDC);
static void test_gdiis(void)
{
RECT rect = {0,0,100,100};
HDC hdc, hemfDC, hmfDC;
HENHMETAFILE hemf;
HMODULE hgdi32;
/* resolve all the functions */
hgdi32 = GetModuleHandle("gdi32");
pGdiIsMetaPrintDC = (void*) GetProcAddress(hgdi32, "GdiIsMetaPrintDC");
pGdiIsMetaFileDC = (void*) GetProcAddress(hgdi32, "GdiIsMetaFileDC");
pGdiIsPlayMetafileDC = (void*) GetProcAddress(hgdi32, "GdiIsPlayMetafileDC");
/* they should all exist or none should exist */
if(!pGdiIsMetaPrintDC)
return;
/* try with nothing */
ok(!pGdiIsMetaPrintDC(NULL), "ismetaprint with NULL parameter\n");
ok(!pGdiIsMetaFileDC(NULL), "ismetafile with NULL parameter\n");
ok(!pGdiIsPlayMetafileDC(NULL), "isplaymetafile with NULL parameter\n");
/* try with a metafile */
hmfDC = CreateMetaFile(NULL);
ok(!pGdiIsMetaPrintDC(hmfDC), "ismetaprint on metafile\n");
ok(pGdiIsMetaFileDC(hmfDC), "ismetafile on metafile\n");
ok(!pGdiIsPlayMetafileDC(hmfDC), "isplaymetafile on metafile\n");
DeleteObject(CloseMetaFile(hmfDC));
/* try with an enhanced metafile */
hdc = GetDC(NULL);
hemfDC = CreateEnhMetaFileW(hdc, NULL, &rect, NULL);
ok(hemfDC != NULL, "failed to create emf\n");
ok(!pGdiIsMetaPrintDC(hemfDC), "ismetaprint on emf\n");
ok(pGdiIsMetaFileDC(hemfDC), "ismetafile on emf\n");
ok(!pGdiIsPlayMetafileDC(hemfDC), "isplaymetafile on emf\n");
hemf = CloseEnhMetaFile(hemfDC);
ok(hemf != NULL, "failed to close EMF\n");
DeleteObject(hemf);
ReleaseDC(NULL,hdc);
}
START_TEST(metafile)
{
/* For enhanced metafiles (enhmfdrv) */
test_ExtTextOut();
/* For win-format metafiles (mfdrv) */
test_mf_Blank();
test_mf_Graphics();
test_mf_PatternBrush();
/* For metafile conversions */
test_mf_conversions();
test_gdiis();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?