From 8076cb9096322a80df13a28812686785e23662ca Mon Sep 17 00:00:00 2001 From: James Tabor Date: Sat, 25 Nov 2006 20:21:22 +0000 Subject: [PATCH] Example coding for Enhance Meta File and Meta DC implementation. - Add printing.c - Add a new CreateEnhMetaFileW svn path=/trunk/; revision=24825 --- reactos/dll/win32/gdi32/objects/metafile.c | 131 +++++++++++++++ reactos/dll/win32/gdi32/objects/painting.c | 185 +++++++++++++++++++++ 2 files changed, 316 insertions(+) create mode 100644 reactos/dll/win32/gdi32/objects/painting.c diff --git a/reactos/dll/win32/gdi32/objects/metafile.c b/reactos/dll/win32/gdi32/objects/metafile.c index 15a93909ced..ad824ddfb4e 100644 --- a/reactos/dll/win32/gdi32/objects/metafile.c +++ b/reactos/dll/win32/gdi32/objects/metafile.c @@ -131,6 +131,137 @@ GetMetaFileA( return rc; } +#if 0 + +HDC WINAPI CreateEnhMetaFileW( + HDC hDC, /* [in] optional reference DC */ + LPCWSTR filename, /* [in] optional filename for disk metafiles */ + const RECT* rect, /* [in] optional bounding rectangle */ + LPCWSTR description /* [in] optional description */ + ) +{ + HDC mDC; + PDC_ATTR Dc_Attr; + PLDC pLDC; + HANDLE hFile; + PENHMETAFILE EmfDC; + DWORD size = 0, length = 0; + + mDC = NtGdiCreateMetafileDC( hDC ); // Basically changes the handle from 1xxxx to 46xxxx. + // If hDC == NULL, works just like createdc in win32k. + + if ( !GdiGetHandleUserData((HGDIOBJ) mDC, (PVOID) &Dc_Attr)) + { + SetLastError (ERROR_INVALID_PARAMETER); + return NULL; // need to delete the handle? + } + + pLDC = LocalAlloc(LMEM_ZEROINIT, sizeof(LDC)); + + Dc_Attr->pvLDC = pLDC; + pLDC->hDC = mDC; + pLDC->iType = LDC_EMFDC + + + if (description) + { /* App name\0Title\0\0 */ + length = lstrlenW(description); + length += lstrlenW(description + length + 1); + length += 3; + length *= 2; + } + + size = sizeof(ENHMETAFILE) + (length + 3) / 4 * 4; + + //Allocate ENHMETAFILE structure + EmfDC = LocalAlloc(LMEM_ZEROINIT, sizeof(ENHMETAFILE)); + pLDC->pvEmfDC = EmfDC; + + EmfDC->handles_size = HANDLE_LIST_INC; + EmfDC->cur_handles = 1; + + EmfDC->horzres = GetDeviceCaps(mDC, HORZRES); + EmfDC->vertres = GetDeviceCaps(mDC, VERTRES); + EmfDC->logpixelsx = GetDeviceCaps(mDC, LOGPIXELSX); + EmfDC->logpixelsy = GetDeviceCaps(mDC, LOGPIXELSY); + EmfDC->horzsize = GetDeviceCaps(mDC, HORZSIZE); + EmfDC->vertsize = GetDeviceCaps(mDC, VERTSIZE); + EmfDC->bitspixel = GetDeviceCaps(mDC, BITSPIXEL); + EmfDC->textcaps = GetDeviceCaps(mDC, TEXTCAPS); + EmfDC->rastercaps = GetDeviceCaps(mDC, RASTERCAPS); + EmfDC->technology = GetDeviceCaps(mDC, TECHNOLOGY); + EmfDC->planes = GetDeviceCaps(mDC, PLANES); + + EmfDC->emf = LocalAlloc(LMEM_ZEROINIT, size); + + EmfDC->emf->iType = EMR_HEADER; + EmfDC->emf->nSize = size; + + EmfDC->emf->rclBounds.left = EmfDC->emf->rclBounds.top = 0; + EmfDC->emf->rclBounds.right = EmfDC->emf->rclBounds.bottom = -1; + + if(rect) + { + EmfDC->emf->rclFrame.left = rect->left; + EmfDC->emf->rclFrame.top = rect->top; + EmfDC->emf->rclFrame.right = rect->right; + EmfDC->emf->rclFrame.bottom = rect->bottom; + } + else + { /* Set this to {0,0 - -1,-1} and update it at the end */ + EmfDC->emf->rclFrame.left = EmfDC->emf->rclFrame.top = 0; + EmfDC->emf->rclFrame.right = EmfDC->emf->rclFrame.bottom = -1; + } + + EmfDC->emf->dSignature = ENHMETA_SIGNATURE; + EmfDC->emf->nVersion = 0x10000; + EmfDC->emf->nBytes = pLDC->pvEmfDC->nSize; + EmfDC->emf->nRecords = 1; + EmfDC->emf->nHandles = 1; + + EmfDC->emf->sReserved = 0; /* According to docs, this is reserved and must be 0 */ + EmfDC->emf->nDescription = length / 2; + + EmfDC->emf->offDescription = length ? sizeof(ENHMETAHEADER) : 0; + + EmfDC->emf->nPalEntries = 0; /* I guess this should start at 0 */ + + /* Size in pixels */ + EmfDC->emf->szlDevice.cx = EmfDC->horzres; + EmfDC->emf->szlDevice.cy = EmfDC->vertres; + + /* Size in millimeters */ + EmfDC->emf->szlMillimeters.cx = EmfDC->horzsize; + EmfDC->emf->szlMillimeters.cy = EmfDC->vertsize; + + /* Size in micrometers */ + EmfDC->emf->szlMicrometers.cx = EmfDC->horzsize * 1000; + EmfDC->emf->szlMicrometers.cy = EmfDC->vertsize * 1000; + + RtlCopyMemory((char *)EmfDC->emf + sizeof(ENHMETAHEADER), description, length); + + if (filename) /* disk based metafile */ + { + if ((hFile = CreateFileW(filename, GENERIC_WRITE | GENERIC_READ, 0, + NULL, CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) + { + EMFDRV_DeleteDC( EmfDC ); + return NULL; + } + if (!WriteFile( hFile, (LPSTR)EmfDC->emf, size, NULL, NULL )) + { + EMFDRV_DeleteDC( EmfDC ); + return NULL; + } + EmfDC.hFile = hFile; + EmfDC->emf.iType = 2; + } + else + EmfDC->emf.iType = 1; + + return mDC; +} +#endif /* * @implemented diff --git a/reactos/dll/win32/gdi32/objects/painting.c b/reactos/dll/win32/gdi32/objects/painting.c new file mode 100644 index 00000000000..69bf61aabb2 --- /dev/null +++ b/reactos/dll/win32/gdi32/objects/painting.c @@ -0,0 +1,185 @@ +#include "precomp.h" + + +/* + * @unimplemented + */ +BOOL +STDCALL +NewArc( + HDC hDC, + int a1, + int a2, + int a3, + int a4, + int a5, + int a6, + int a7, + int a8 + ) +{ +// Handle something other than a normal dc object. + if (GDI_HANDLE_GET_TYPE(hDC) != GDI_OBJECT_TYPE_DC) + { + if (GDI_HANDLE_GET_TYPE(hDC) == GDI_OBJECT_TYPE_METADC) +// Call Wine (rewrite of) MFDRV_MetaParam8 + return MFDRV_MetaParam8( hDC, META_ARC, a1, a2, a3, a4, a5, a6, a7, a8) + else + { + PDC_ATTR Dc_Attr; + PLDC pLDC; + GdiGetHandleUserData((HGDIOBJ) hDC, (PVOID) &Dc_Attr); + pLDC = Dc_Attr->pvLDC; + if ( !pLDC ) + { + SetLastError(ERROR_INVALID_HANDLE) + return FALSE; + } + if (pLDC->iType == LDC_EMFLDC) + { +// Call Wine (rewrite of) EMFDRV_ArcChordPie + BOOL Ret = EMFDRV_ArcChordPie( hDC, a1, a2, a3, a4, a5, a6, a7, a8, EMR_ARC); + return Ret; + } + return FALSE; + } + } + return NtGdiArcInternal(GdiTypeArc, hDC, a1, a2, a3, a4, a5, a6, a7, a8); +} + + +/* + * @unimplemented + */ +BOOL +STDCALL +NewArcTo( + HDC hDC, + int a1, + int a2, + int a3, + int a4, + int a5, + int a6, + int a7, + int a8 + ) +{ +// Handle something other than a normal dc object. + if (GDI_HANDLE_GET_TYPE(hDC) != GDI_OBJECT_TYPE_DC) + { + if (GDI_HANDLE_GET_TYPE(hDC) == GDI_OBJECT_TYPE_METADC) + return FALSE; //No meta support for ArcTo + else + { + PDC_ATTR Dc_Attr; + PLDC pLDC; + GdiGetHandleUserData((HGDIOBJ) hDC, (PVOID) &Dc_Attr); + pLDC = Dc_Attr->pvLDC; + if ( !pLDC ) + { + SetLastError(ERROR_INVALID_HANDLE) + return FALSE; + } + if (pLDC->iType == LDC_EMFLDC) + { + BOOL Ret = EMFDRV_ArcChordPie( hDC, a1, a2, a3, a4, a5, a6, a7, a8, EMR_ARCTO); + return Ret; + } + return FALSE; + } + } + return NtGdiArcInternal(GdiTypeArcTo, hDC, a1, a2, a3, a4, a5, a6, a7, a8); +} + + +/* + * @unimplemented + */ +BOOL +STDCALL +Chord( + HDC hDC, + int a1, + int a2, + int a3, + int a4, + int a5, + int a6, + int a7, + int a8 + ) +{ +// Handle something other than a normal dc object. + if (GDI_HANDLE_GET_TYPE(hDC) != GDI_OBJECT_TYPE_DC) + { + if (GDI_HANDLE_GET_TYPE(hDC) == GDI_OBJECT_TYPE_METADC) + return MFDRV_MetaParam8( hDC, META_CHORD, a1, a2, a3, a4, a5, a6, a7, a8) + else + { + PDC_ATTR Dc_Attr; + PLDC pLDC; + GdiGetHandleUserData((HGDIOBJ) hDC, (PVOID) &Dc_Attr); + pLDC = Dc_Attr->pvLDC; + if ( !pLDC ) + { + SetLastError(ERROR_INVALID_HANDLE) + return FALSE; + } + if (pLDC->iType == LDC_EMFLDC) + { + BOOL Ret = EMFDRV_ArcChordPie( hDC, a1, a2, a3, a4, a5, a6, a7, a8, EMR_CHORD); + return Ret; + } + return FALSE; + } + } + return NtGdiArcInternal(GdiTypeChord, hDC, a1, a2, a3, a4, a5, a6, a7, a8); +} + + +/* + * @unimplemented + */ +BOOL +STDCALL +NewPie( + HDC hDC, + int a1, + int a2, + int a3, + int a4, + int a5, + int a6, + int a7, + int a8 + ) +{ +// Handle something other than a normal dc object. + if (GDI_HANDLE_GET_TYPE(hDC) != GDI_OBJECT_TYPE_DC) + { + if (GDI_HANDLE_GET_TYPE(hDC) == GDI_OBJECT_TYPE_METADC) + return MFDRV_MetaParam8( hDC, META_PIE, a1, a2, a3, a4, a5, a6, a7, a8) + else + { + PDC_ATTR Dc_Attr; + PLDC pLDC; + GdiGetHandleUserData((HGDIOBJ) hDC, (PVOID) &Dc_Attr); + pLDC = Dc_Attr->pvLDC; + if ( !pLDC ) + { + SetLastError(ERROR_INVALID_HANDLE) + return FALSE; + } + if (pLDC->iType == LDC_EMFLDC) + { + BOOL Ret = EMFDRV_ArcChordPie( hDC, a1, a2, a3, a4, a5, a6, a7, a8, EMR_PIE); + return Ret; + } + return FALSE; + } + } + return NtGdiArcInternal(GdiTypePie, hDC, a1, a2, a3, a4, a5, a6, a7, a8); +} + +