1999-05-02 12:15:16 +02:00
|
|
|
/*
|
|
|
|
* Enhanced MetaFile driver initialisation functions
|
|
|
|
*
|
|
|
|
* Copyright 1999 Huw D M Davies
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1999-05-02 12:15:16 +02:00
|
|
|
*/
|
|
|
|
|
2000-11-05 03:05:07 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
1999-05-02 12:15:16 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "wingdi.h"
|
2000-11-05 03:05:07 +01:00
|
|
|
#include "gdi.h"
|
2002-03-27 22:13:40 +01:00
|
|
|
#include "enhmfdrv/enhmetafiledrv.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1999-05-02 12:15:16 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile);
|
1999-05-02 12:15:16 +02:00
|
|
|
|
|
|
|
static const DC_FUNCTIONS EMFDRV_Funcs =
|
|
|
|
{
|
1999-05-17 18:20:51 +02:00
|
|
|
NULL, /* pAbortDoc */
|
1999-12-06 00:54:02 +01:00
|
|
|
EMFDRV_AbortPath, /* pAbortPath */
|
|
|
|
NULL, /* pAngleArc */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_Arc, /* pArc */
|
1999-12-06 00:54:02 +01:00
|
|
|
NULL, /* pArcTo */
|
|
|
|
EMFDRV_BeginPath, /* pBeginPath */
|
1999-05-02 12:15:16 +02:00
|
|
|
NULL, /* pBitBlt */
|
2002-03-28 23:22:05 +01:00
|
|
|
NULL, /* pBitmapBits */
|
2000-05-12 22:18:14 +02:00
|
|
|
NULL, /* pChoosePixelFormat */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_Chord, /* pChord */
|
1999-12-06 00:54:02 +01:00
|
|
|
EMFDRV_CloseFigure, /* pCloseFigure */
|
1999-05-02 12:15:16 +02:00
|
|
|
NULL, /* pCreateBitmap */
|
2002-03-28 23:22:05 +01:00
|
|
|
NULL, /* pCreateDC */
|
1999-05-02 12:15:16 +02:00
|
|
|
NULL, /* pCreateDIBSection */
|
2002-03-28 23:22:05 +01:00
|
|
|
NULL, /* pDeleteDC */
|
1999-05-02 12:15:16 +02:00
|
|
|
NULL, /* pDeleteObject */
|
2000-05-12 22:18:14 +02:00
|
|
|
NULL, /* pDescribePixelFormat */
|
1999-05-17 18:20:51 +02:00
|
|
|
NULL, /* pDeviceCapabilities */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_Ellipse, /* pEllipse */
|
1999-05-17 18:20:51 +02:00
|
|
|
NULL, /* pEndDoc */
|
|
|
|
NULL, /* pEndPage */
|
1999-12-06 00:54:02 +01:00
|
|
|
EMFDRV_EndPath, /* pEndPath */
|
1999-05-02 12:15:16 +02:00
|
|
|
NULL, /* pEnumDeviceFonts */
|
|
|
|
EMFDRV_ExcludeClipRect, /* pExcludeClipRect */
|
1999-05-17 18:20:51 +02:00
|
|
|
NULL, /* pExtDeviceMode */
|
2001-07-29 22:25:14 +02:00
|
|
|
NULL, /* pExtEscape */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_ExtFloodFill, /* pExtFloodFill */
|
2002-05-09 06:03:46 +02:00
|
|
|
EMFDRV_ExtSelectClipRgn, /* pExtSelectClipRgn */
|
1999-05-02 12:15:16 +02:00
|
|
|
NULL, /* pExtTextOut */
|
1999-12-06 00:54:02 +01:00
|
|
|
EMFDRV_FillPath, /* pFillPath */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_FillRgn, /* pFillRgn */
|
1999-12-06 00:54:02 +01:00
|
|
|
EMFDRV_FlattenPath, /* pFlattenPath */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_FrameRgn, /* pFrameRgn */
|
|
|
|
NULL, /* pGetCharWidth */
|
2000-03-19 22:19:21 +01:00
|
|
|
NULL, /* pGetDCOrgEx */
|
2002-03-28 23:22:05 +01:00
|
|
|
NULL, /* pGetDIBColorTable */
|
|
|
|
NULL, /* pGetDIBits */
|
2001-07-28 02:18:02 +02:00
|
|
|
NULL, /* pGetDeviceCaps */
|
2001-03-20 02:55:18 +01:00
|
|
|
NULL, /* pGetDeviceGammaRamp */
|
2002-03-28 23:22:05 +01:00
|
|
|
NULL, /* pGetPixel */
|
2000-05-12 22:18:14 +02:00
|
|
|
NULL, /* pGetPixelFormat */
|
1999-05-02 12:15:16 +02:00
|
|
|
NULL, /* pGetTextExtentPoint */
|
|
|
|
NULL, /* pGetTextMetrics */
|
|
|
|
EMFDRV_IntersectClipRect, /* pIntersectClipRect */
|
|
|
|
EMFDRV_InvertRgn, /* pInvertRgn */
|
|
|
|
EMFDRV_LineTo, /* pLineTo */
|
2000-11-05 04:28:18 +01:00
|
|
|
EMFDRV_MoveTo, /* pMoveTo */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_OffsetClipRgn, /* pOffsetClipRgn */
|
|
|
|
NULL, /* pOffsetViewportOrg */
|
|
|
|
NULL, /* pOffsetWindowOrg */
|
|
|
|
EMFDRV_PaintRgn, /* pPaintRgn */
|
|
|
|
NULL, /* pPatBlt */
|
|
|
|
EMFDRV_Pie, /* pPie */
|
1999-12-06 00:54:02 +01:00
|
|
|
NULL, /* pPolyBezier */
|
|
|
|
NULL, /* pPolyBezierTo */
|
|
|
|
NULL, /* pPolyDraw */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_PolyPolygon, /* pPolyPolygon */
|
|
|
|
EMFDRV_PolyPolyline, /* pPolyPolyline */
|
|
|
|
EMFDRV_Polygon, /* pPolygon */
|
|
|
|
EMFDRV_Polyline, /* pPolyline */
|
1999-12-06 00:54:02 +01:00
|
|
|
NULL, /* pPolylineTo */
|
1999-05-02 12:15:16 +02:00
|
|
|
NULL, /* pRealizePalette */
|
|
|
|
EMFDRV_Rectangle, /* pRectangle */
|
2002-04-06 02:00:56 +02:00
|
|
|
NULL, /* pResetDC */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_RestoreDC, /* pRestoreDC */
|
|
|
|
EMFDRV_RoundRect, /* pRoundRect */
|
|
|
|
EMFDRV_SaveDC, /* pSaveDC */
|
|
|
|
EMFDRV_ScaleViewportExt, /* pScaleViewportExt */
|
|
|
|
EMFDRV_ScaleWindowExt, /* pScaleWindowExt */
|
2002-03-28 23:22:05 +01:00
|
|
|
EMFDRV_SelectBitmap, /* pSelectBitmap */
|
|
|
|
EMFDRV_SelectBrush, /* pSelectBrush */
|
1999-12-06 00:54:02 +01:00
|
|
|
EMFDRV_SelectClipPath, /* pSelectClipPath */
|
2002-03-28 23:22:05 +01:00
|
|
|
EMFDRV_SelectFont, /* pSelectFont */
|
1999-05-02 12:15:16 +02:00
|
|
|
NULL, /* pSelectPalette */
|
2002-03-28 23:22:05 +01:00
|
|
|
EMFDRV_SelectPen, /* pSelectPen */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_SetBkColor, /* pSetBkColor */
|
|
|
|
EMFDRV_SetBkMode, /* pSetBkMode */
|
2002-03-28 23:22:05 +01:00
|
|
|
NULL, /* pSetDIBColorTable */
|
|
|
|
NULL, /* pSetDIBits */
|
|
|
|
NULL, /* pSetDIBitsToDevice */
|
1999-05-02 12:15:16 +02:00
|
|
|
NULL, /* pSetDeviceClipping */
|
2001-03-20 02:55:18 +01:00
|
|
|
NULL, /* pSetDeviceGammaRamp */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_SetMapMode, /* pSetMapMode */
|
|
|
|
EMFDRV_SetMapperFlags, /* pSetMapperFlags */
|
|
|
|
NULL, /* pSetPixel */
|
2000-05-12 22:18:14 +02:00
|
|
|
NULL, /* pSetPixelFormat */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_SetPolyFillMode, /* pSetPolyFillMode */
|
|
|
|
EMFDRV_SetROP2, /* pSetROP2 */
|
|
|
|
NULL, /* pSetRelAbs */
|
|
|
|
EMFDRV_SetStretchBltMode, /* pSetStretchBltMode */
|
|
|
|
EMFDRV_SetTextAlign, /* pSetTextAlign */
|
|
|
|
NULL, /* pSetTextCharacterExtra */
|
|
|
|
EMFDRV_SetTextColor, /* pSetTextColor */
|
|
|
|
NULL, /* pSetTextJustification */
|
|
|
|
EMFDRV_SetViewportExt, /* pSetViewportExt */
|
|
|
|
EMFDRV_SetViewportOrg, /* pSetViewportOrg */
|
|
|
|
EMFDRV_SetWindowExt, /* pSetWindowExt */
|
|
|
|
EMFDRV_SetWindowOrg, /* pSetWindowOrg */
|
1999-05-17 18:20:51 +02:00
|
|
|
NULL, /* pStartDoc */
|
|
|
|
NULL, /* pStartPage */
|
1999-05-02 12:15:16 +02:00
|
|
|
NULL, /* pStretchBlt */
|
1999-12-06 00:54:02 +01:00
|
|
|
NULL, /* pStretchDIBits */
|
|
|
|
EMFDRV_StrokeAndFillPath, /* pStrokeAndFillPath */
|
|
|
|
EMFDRV_StrokePath, /* pStrokePath */
|
2000-05-12 22:18:14 +02:00
|
|
|
NULL, /* pSwapBuffers */
|
1999-12-06 00:54:02 +01:00
|
|
|
EMFDRV_WidenPath /* pWiddenPath */
|
1999-05-02 12:15:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* EMFDRV_DeleteDC
|
|
|
|
*/
|
2002-03-28 23:22:05 +01:00
|
|
|
static BOOL EMFDRV_DeleteDC( PHYSDEV dev )
|
1999-05-02 12:15:16 +02:00
|
|
|
{
|
2002-03-28 23:22:05 +01:00
|
|
|
EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE *)dev;
|
|
|
|
DC *dc = physDev->dc;
|
|
|
|
|
2000-02-16 23:47:24 +01:00
|
|
|
if (physDev->emh) HeapFree( GetProcessHeap(), 0, physDev->emh );
|
|
|
|
HeapFree( GetProcessHeap(), 0, physDev );
|
1999-05-02 12:15:16 +02:00
|
|
|
dc->physDev = NULL;
|
2000-08-19 23:38:55 +02:00
|
|
|
GDI_FreeObject( dc->hSelf, dc );
|
1999-05-02 12:15:16 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* EMFDRV_WriteRecord
|
|
|
|
*
|
|
|
|
* Warning: this function can change the pointer to the metafile header.
|
|
|
|
*/
|
2002-03-28 23:22:05 +01:00
|
|
|
BOOL EMFDRV_WriteRecord( PHYSDEV dev, EMR *emr )
|
1999-05-02 12:15:16 +02:00
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
ENHMETAHEADER *emh;
|
2002-03-28 23:22:05 +01:00
|
|
|
EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE *)dev;
|
1999-05-02 12:15:16 +02:00
|
|
|
|
|
|
|
physDev->emh->nBytes += emr->nSize;
|
|
|
|
physDev->emh->nRecords++;
|
|
|
|
|
|
|
|
if(physDev->hFile) {
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE("Writing record to disk\n");
|
1999-05-02 12:15:16 +02:00
|
|
|
if (!WriteFile(physDev->hFile, (char *)emr, emr->nSize, NULL, NULL))
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
len = physDev->emh->nBytes;
|
2000-02-16 23:47:24 +01:00
|
|
|
emh = HeapReAlloc( GetProcessHeap(), 0, physDev->emh, len );
|
1999-05-02 12:15:16 +02:00
|
|
|
if (!emh) return FALSE;
|
|
|
|
physDev->emh = emh;
|
|
|
|
memcpy((CHAR *)physDev->emh + physDev->emh->nBytes - emr->nSize, emr,
|
|
|
|
emr->nSize);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* EMFDRV_UpdateBBox
|
|
|
|
*/
|
2002-03-28 23:22:05 +01:00
|
|
|
void EMFDRV_UpdateBBox( PHYSDEV dev, RECTL *rect )
|
1999-05-02 12:15:16 +02:00
|
|
|
{
|
2002-03-28 23:22:05 +01:00
|
|
|
EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE *)dev;
|
1999-05-02 12:15:16 +02:00
|
|
|
RECTL *bounds = &physDev->emh->rclBounds;
|
|
|
|
|
|
|
|
if(bounds->left > bounds->right) {/* first rect */
|
|
|
|
*bounds = *rect;
|
|
|
|
return;
|
|
|
|
}
|
2000-03-25 22:44:35 +01:00
|
|
|
bounds->left = min(bounds->left, rect->left);
|
|
|
|
bounds->top = min(bounds->top, rect->top);
|
|
|
|
bounds->right = max(bounds->right, rect->right);
|
|
|
|
bounds->bottom = max(bounds->bottom, rect->bottom);
|
1999-05-02 12:15:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* EMFDRV_AddHandleDC
|
|
|
|
*
|
|
|
|
* Note: this function assumes that we never delete objects.
|
|
|
|
* If we do someday, we'll need to maintain a table to re-use deleted
|
|
|
|
* handles.
|
|
|
|
*/
|
2002-03-28 23:22:05 +01:00
|
|
|
int EMFDRV_AddHandleDC( PHYSDEV dev )
|
1999-05-02 12:15:16 +02:00
|
|
|
{
|
2002-03-28 23:22:05 +01:00
|
|
|
EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE *)dev;
|
1999-05-02 12:15:16 +02:00
|
|
|
physDev->emh->nHandles++;
|
|
|
|
return physDev->nextHandle++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-02-15 00:11:17 +01:00
|
|
|
* CreateEnhMetaFileA (GDI32.@)
|
2000-12-02 00:58:28 +01:00
|
|
|
*/
|
1999-05-02 12:15:16 +02:00
|
|
|
HDC WINAPI CreateEnhMetaFileA(
|
2000-12-02 00:58:28 +01:00
|
|
|
HDC hdc, /* [in] optional reference DC */
|
|
|
|
LPCSTR filename, /* [in] optional filename for disk metafiles */
|
|
|
|
const RECT *rect, /* [in] optional bounding rectangle */
|
|
|
|
LPCSTR description /* [in] optional description */
|
1999-05-02 12:15:16 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
LPWSTR filenameW = NULL;
|
|
|
|
LPWSTR descriptionW = NULL;
|
|
|
|
HDC hReturnDC;
|
2000-11-28 23:40:56 +01:00
|
|
|
DWORD len1, len2, total;
|
1999-05-02 12:15:16 +02:00
|
|
|
|
2002-01-01 01:24:30 +01:00
|
|
|
if(filename)
|
|
|
|
{
|
|
|
|
total = MultiByteToWideChar( CP_ACP, 0, filename, -1, NULL, 0 );
|
|
|
|
filenameW = HeapAlloc( GetProcessHeap(), 0, total * sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, filename, -1, filenameW, total );
|
|
|
|
}
|
1999-05-02 12:15:16 +02:00
|
|
|
if(description) {
|
|
|
|
len1 = strlen(description);
|
|
|
|
len2 = strlen(description + len1 + 1);
|
2000-11-28 23:40:56 +01:00
|
|
|
total = MultiByteToWideChar( CP_ACP, 0, description, len1 + len2 + 3, NULL, 0 );
|
|
|
|
descriptionW = HeapAlloc( GetProcessHeap(), 0, total * sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, description, len1 + len2 + 3, descriptionW, total );
|
1999-05-02 12:15:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hReturnDC = CreateEnhMetaFileW(hdc, filenameW, rect, descriptionW);
|
|
|
|
|
|
|
|
if(filenameW)
|
|
|
|
HeapFree( GetProcessHeap(), 0, filenameW );
|
|
|
|
if(descriptionW)
|
|
|
|
HeapFree( GetProcessHeap(), 0, descriptionW );
|
|
|
|
|
|
|
|
return hReturnDC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-02-15 00:11:17 +01:00
|
|
|
* CreateEnhMetaFileW (GDI32.@)
|
1999-05-02 12:15:16 +02:00
|
|
|
*/
|
|
|
|
HDC WINAPI CreateEnhMetaFileW(
|
2000-12-02 00:58:28 +01:00
|
|
|
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 */
|
1999-05-02 12:15:16 +02:00
|
|
|
)
|
|
|
|
{
|
2000-08-19 23:38:55 +02:00
|
|
|
HDC ret;
|
1999-05-02 12:15:16 +02:00
|
|
|
DC *dc;
|
2000-06-03 22:45:57 +02:00
|
|
|
HDC hRefDC = hdc ? hdc : CreateDCA("DISPLAY",NULL,NULL,NULL); /* If no ref, use current display */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_PDEVICE *physDev;
|
|
|
|
HFILE hFile;
|
|
|
|
DWORD size = 0, length = 0;
|
|
|
|
|
2001-05-11 22:03:40 +02:00
|
|
|
TRACE("%s\n", debugstr_w(filename) );
|
1999-05-02 12:15:16 +02:00
|
|
|
|
|
|
|
if (!(dc = DC_AllocDC( &EMFDRV_Funcs ))) return 0;
|
|
|
|
dc->header.wMagic = ENHMETAFILE_DC_MAGIC;
|
|
|
|
|
2000-02-16 23:47:24 +01:00
|
|
|
physDev = (EMFDRV_PDEVICE *)HeapAlloc(GetProcessHeap(),0,sizeof(*physDev));
|
1999-05-02 12:15:16 +02:00
|
|
|
if (!physDev) {
|
2000-08-19 23:38:55 +02:00
|
|
|
GDI_FreeObject( dc->hSelf, dc );
|
1999-05-02 12:15:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2002-03-28 23:22:05 +01:00
|
|
|
dc->physDev = (PHYSDEV)physDev;
|
|
|
|
physDev->hdc = dc->hSelf;
|
|
|
|
physDev->dc = dc;
|
1999-05-02 12:15:16 +02:00
|
|
|
|
|
|
|
if(description) { /* App name\0Title\0\0 */
|
|
|
|
length = lstrlenW(description);
|
|
|
|
length += lstrlenW(description + length + 1);
|
|
|
|
length += 3;
|
|
|
|
length *= 2;
|
|
|
|
}
|
|
|
|
size = sizeof(ENHMETAHEADER) + (length + 3) / 4 * 4;
|
|
|
|
|
2000-02-16 23:47:24 +01:00
|
|
|
if (!(physDev->emh = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size))) {
|
|
|
|
HeapFree( GetProcessHeap(), 0, physDev );
|
2000-08-19 23:38:55 +02:00
|
|
|
GDI_FreeObject( dc->hSelf, dc );
|
1999-05-02 12:15:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
physDev->nextHandle = 1;
|
|
|
|
physDev->hFile = 0;
|
|
|
|
|
|
|
|
physDev->emh->iType = EMR_HEADER;
|
|
|
|
physDev->emh->nSize = size;
|
2000-01-15 23:16:51 +01:00
|
|
|
|
|
|
|
physDev->emh->rclBounds.left = physDev->emh->rclBounds.top = 0;
|
|
|
|
physDev->emh->rclBounds.right = physDev->emh->rclBounds.bottom = -1;
|
|
|
|
|
2000-04-14 16:07:51 +02:00
|
|
|
if(rect) {
|
|
|
|
physDev->emh->rclFrame.left = rect->left;
|
|
|
|
physDev->emh->rclFrame.top = rect->top;
|
|
|
|
physDev->emh->rclFrame.right = rect->right;
|
|
|
|
physDev->emh->rclFrame.bottom = rect->bottom;
|
|
|
|
} else { /* Set this to {0,0 - -1,-1} and update it at the end */
|
|
|
|
physDev->emh->rclFrame.left = physDev->emh->rclFrame.top = 0;
|
|
|
|
physDev->emh->rclFrame.right = physDev->emh->rclFrame.bottom = -1;
|
|
|
|
}
|
|
|
|
|
1999-05-02 12:15:16 +02:00
|
|
|
physDev->emh->dSignature = ENHMETA_SIGNATURE;
|
|
|
|
physDev->emh->nVersion = 0x10000;
|
|
|
|
physDev->emh->nBytes = physDev->emh->nSize;
|
|
|
|
physDev->emh->nRecords = 1;
|
|
|
|
physDev->emh->nHandles = 1;
|
2000-01-15 23:16:51 +01:00
|
|
|
|
|
|
|
physDev->emh->sReserved = 0; /* According to docs, this is reserved and must be 0 */
|
1999-05-02 12:15:16 +02:00
|
|
|
physDev->emh->nDescription = length / 2;
|
2000-01-15 23:16:51 +01:00
|
|
|
|
1999-05-02 12:15:16 +02:00
|
|
|
physDev->emh->offDescription = length ? sizeof(ENHMETAHEADER) : 0;
|
2000-01-15 23:16:51 +01:00
|
|
|
|
|
|
|
physDev->emh->nPalEntries = 0; /* I guess this should start at 0 */
|
|
|
|
|
|
|
|
/* Size in pixels */
|
|
|
|
physDev->emh->szlDevice.cx = GetDeviceCaps( hRefDC, HORZRES );
|
|
|
|
physDev->emh->szlDevice.cy = GetDeviceCaps( hRefDC, VERTRES );
|
|
|
|
|
|
|
|
/* Size in millimeters */
|
|
|
|
physDev->emh->szlMillimeters.cx = GetDeviceCaps( hRefDC, HORZSIZE );
|
|
|
|
physDev->emh->szlMillimeters.cy = GetDeviceCaps( hRefDC, VERTSIZE );
|
|
|
|
|
1999-05-02 12:15:16 +02:00
|
|
|
memcpy((char *)physDev->emh + sizeof(ENHMETAHEADER), description, length);
|
|
|
|
|
|
|
|
if (filename) /* disk based metafile */
|
|
|
|
{
|
|
|
|
if ((hFile = CreateFileW(filename, GENERIC_WRITE | GENERIC_READ, 0,
|
2001-01-06 02:29:18 +01:00
|
|
|
NULL, CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) {
|
2002-03-28 23:22:05 +01:00
|
|
|
EMFDRV_DeleteDC( dc->physDev );
|
1999-05-02 12:15:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!WriteFile( hFile, (LPSTR)physDev->emh, size, NULL, NULL )) {
|
2002-03-28 23:22:05 +01:00
|
|
|
EMFDRV_DeleteDC( dc->physDev );
|
1999-05-02 12:15:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
physDev->hFile = hFile;
|
|
|
|
}
|
2000-01-15 23:16:51 +01:00
|
|
|
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE("returning %04x\n", dc->hSelf);
|
2000-08-19 23:38:55 +02:00
|
|
|
ret = dc->hSelf;
|
|
|
|
GDI_ReleaseObj( dc->hSelf );
|
2001-09-14 02:11:16 +02:00
|
|
|
|
|
|
|
if( !hdc )
|
|
|
|
DeleteDC( hRefDC );
|
|
|
|
|
2000-08-19 23:38:55 +02:00
|
|
|
return ret;
|
1999-05-02 12:15:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2001-02-15 00:11:17 +01:00
|
|
|
* CloseEnhMetaFile (GDI32.@)
|
1999-05-02 12:15:16 +02:00
|
|
|
*/
|
2000-12-02 00:58:28 +01:00
|
|
|
HENHMETAFILE WINAPI CloseEnhMetaFile(HDC hdc) /* [in] metafile DC */
|
1999-05-02 12:15:16 +02:00
|
|
|
{
|
|
|
|
HENHMETAFILE hmf;
|
|
|
|
EMFDRV_PDEVICE *physDev;
|
|
|
|
DC *dc;
|
|
|
|
EMREOF emr;
|
|
|
|
HANDLE hMapping = 0;
|
|
|
|
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE("(%04x)\n", hdc );
|
1999-05-02 12:15:16 +02:00
|
|
|
|
|
|
|
if (!(dc = (DC *) GDI_GetObjPtr( hdc, ENHMETAFILE_DC_MAGIC ))) return 0;
|
|
|
|
physDev = (EMFDRV_PDEVICE *)dc->physDev;
|
|
|
|
|
|
|
|
emr.emr.iType = EMR_EOF;
|
|
|
|
emr.emr.nSize = sizeof(emr);
|
|
|
|
emr.nPalEntries = 0;
|
|
|
|
emr.offPalEntries = 0;
|
|
|
|
emr.nSizeLast = emr.emr.nSize;
|
2002-03-28 23:22:05 +01:00
|
|
|
EMFDRV_WriteRecord( dc->physDev, &emr.emr );
|
1999-05-02 12:15:16 +02:00
|
|
|
|
2000-04-14 16:07:51 +02:00
|
|
|
/* Update rclFrame if not initialized in CreateEnhMetaFile */
|
|
|
|
if(physDev->emh->rclFrame.left > physDev->emh->rclFrame.right) {
|
|
|
|
physDev->emh->rclFrame.left = physDev->emh->rclBounds.left *
|
|
|
|
physDev->emh->szlMillimeters.cx * 100 / physDev->emh->szlDevice.cx;
|
|
|
|
physDev->emh->rclFrame.top = physDev->emh->rclBounds.top *
|
|
|
|
physDev->emh->szlMillimeters.cy * 100 / physDev->emh->szlDevice.cy;
|
|
|
|
physDev->emh->rclFrame.right = physDev->emh->rclBounds.right *
|
|
|
|
physDev->emh->szlMillimeters.cx * 100 / physDev->emh->szlDevice.cx;
|
|
|
|
physDev->emh->rclFrame.bottom = physDev->emh->rclBounds.bottom *
|
|
|
|
physDev->emh->szlMillimeters.cy * 100 / physDev->emh->szlDevice.cy;
|
|
|
|
}
|
|
|
|
|
1999-05-02 12:15:16 +02:00
|
|
|
if (physDev->hFile) /* disk based metafile */
|
|
|
|
{
|
2001-07-25 00:15:47 +02:00
|
|
|
if (SetFilePointer(physDev->hFile, 0, NULL, FILE_BEGIN) != 0)
|
|
|
|
{
|
|
|
|
CloseHandle( physDev->hFile );
|
2002-03-28 23:22:05 +01:00
|
|
|
EMFDRV_DeleteDC( dc->physDev );
|
1999-05-02 12:15:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!WriteFile(physDev->hFile, (LPSTR)physDev->emh,
|
2001-07-25 00:15:47 +02:00
|
|
|
sizeof(*physDev->emh), NULL, NULL))
|
|
|
|
{
|
|
|
|
CloseHandle( physDev->hFile );
|
2002-03-28 23:22:05 +01:00
|
|
|
EMFDRV_DeleteDC( dc->physDev );
|
1999-05-02 12:15:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2000-02-16 23:47:24 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, physDev->emh );
|
1999-05-02 12:15:16 +02:00
|
|
|
hMapping = CreateFileMappingA(physDev->hFile, NULL, PAGE_READONLY, 0,
|
|
|
|
0, NULL);
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE("hMapping = %08x\n", hMapping );
|
1999-05-02 12:15:16 +02:00
|
|
|
physDev->emh = MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0);
|
1999-06-26 21:09:08 +02:00
|
|
|
TRACE("view = %p\n", physDev->emh );
|
2001-07-25 00:15:47 +02:00
|
|
|
CloseHandle( hMapping );
|
|
|
|
CloseHandle( physDev->hFile );
|
1999-05-02 12:15:16 +02:00
|
|
|
}
|
|
|
|
|
2001-07-25 00:15:47 +02:00
|
|
|
hmf = EMF_Create_HENHMETAFILE( physDev->emh, (physDev->hFile != 0) );
|
1999-05-02 12:15:16 +02:00
|
|
|
physDev->emh = NULL; /* So it won't be deleted */
|
2002-03-28 23:22:05 +01:00
|
|
|
EMFDRV_DeleteDC( dc->physDev );
|
1999-05-02 12:15:16 +02:00
|
|
|
return hmf;
|
|
|
|
}
|