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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-05-02 12:15:16 +02:00
|
|
|
*/
|
|
|
|
|
2004-06-18 21:33:41 +02:00
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-11-05 03:05:07 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
1999-05-02 12:15:16 +02:00
|
|
|
#include "windef.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winbase.h"
|
1999-05-02 12:15:16 +02:00
|
|
|
#include "wingdi.h"
|
2004-01-15 01:35:38 +01:00
|
|
|
#include "gdi_private.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 */
|
2004-08-02 20:54:54 +02:00
|
|
|
NULL, /* pAlphaBlend */
|
1999-12-06 00:54:02 +01:00
|
|
|
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 */
|
2003-10-15 04:33:15 +02:00
|
|
|
EMFDRV_BitBlt, /* pBitBlt */
|
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-05-31 20:43:22 +02:00
|
|
|
NULL, /* pDeleteBitmap */
|
2002-03-28 23:22:05 +01:00
|
|
|
NULL, /* pDeleteDC */
|
2003-11-25 06:03:09 +01:00
|
|
|
EMFDRV_DeleteObject, /* 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 */
|
2002-08-17 03:36:55 +02:00
|
|
|
EMFDRV_ExtTextOut, /* 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 */
|
2003-05-21 20:28:49 +02:00
|
|
|
EMFDRV_GdiComment, /* pGdiComment */
|
2002-05-31 20:43:22 +02:00
|
|
|
NULL, /* pGetBitmapBits */
|
1999-05-02 12:15:16 +02:00
|
|
|
NULL, /* pGetCharWidth */
|
2000-03-19 22:19:21 +01:00
|
|
|
NULL, /* pGetDCOrgEx */
|
2002-03-28 23:22:05 +01:00
|
|
|
NULL, /* pGetDIBColorTable */
|
|
|
|
NULL, /* pGetDIBits */
|
2002-08-17 02:25:05 +02:00
|
|
|
EMFDRV_GetDeviceCaps, /* pGetDeviceCaps */
|
2001-03-20 02:55:18 +01:00
|
|
|
NULL, /* pGetDeviceGammaRamp */
|
2008-03-05 15:57:21 +01:00
|
|
|
NULL, /* pGetICMProfile */
|
2002-06-02 23:40:24 +02:00
|
|
|
NULL, /* pGetNearestColor */
|
2002-03-28 23:22:05 +01:00
|
|
|
NULL, /* pGetPixel */
|
2000-05-12 22:18:14 +02:00
|
|
|
NULL, /* pGetPixelFormat */
|
2002-06-02 23:40:24 +02:00
|
|
|
NULL, /* pGetSystemPaletteEntries */
|
2006-07-12 02:58:35 +02:00
|
|
|
NULL, /* pGetTextExtentExPoint */
|
1999-05-02 12:15:16 +02:00
|
|
|
NULL, /* pGetTextMetrics */
|
|
|
|
EMFDRV_IntersectClipRect, /* pIntersectClipRect */
|
|
|
|
EMFDRV_InvertRgn, /* pInvertRgn */
|
|
|
|
EMFDRV_LineTo, /* pLineTo */
|
2003-06-23 21:46:56 +02:00
|
|
|
EMFDRV_ModifyWorldTransform, /* pModifyWorldTransform */
|
2000-11-05 04:28:18 +01:00
|
|
|
EMFDRV_MoveTo, /* pMoveTo */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_OffsetClipRgn, /* pOffsetClipRgn */
|
2003-10-09 06:42:45 +02:00
|
|
|
EMFDRV_OffsetViewportOrg, /* pOffsetViewportOrg */
|
|
|
|
EMFDRV_OffsetWindowOrg, /* pOffsetWindowOrg */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_PaintRgn, /* pPaintRgn */
|
2002-06-14 02:00:56 +02:00
|
|
|
EMFDRV_PatBlt, /* pPatBlt */
|
1999-05-02 12:15:16 +02:00
|
|
|
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 */
|
2002-06-02 23:40:24 +02:00
|
|
|
NULL, /* pRealizeDefaultPalette */
|
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 */
|
2008-05-07 13:35:04 +02:00
|
|
|
EMFDRV_SelectPalette, /* pSelectPalette */
|
2002-03-28 23:22:05 +01:00
|
|
|
EMFDRV_SelectPen, /* pSelectPen */
|
2003-10-04 05:08:25 +02:00
|
|
|
EMFDRV_SetArcDirection, /* pSetArcDirection */
|
2002-05-31 20:43:22 +02:00
|
|
|
NULL, /* pSetBitmapBits */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_SetBkColor, /* pSetBkColor */
|
|
|
|
EMFDRV_SetBkMode, /* pSetBkMode */
|
2003-11-05 02:43:57 +01:00
|
|
|
NULL, /* pSetDCBrushColor */
|
2002-06-11 00:52:47 +02:00
|
|
|
NULL, /* pSetDCOrg */
|
2003-11-05 02:43:57 +01:00
|
|
|
NULL, /* pSetDCPenColor */
|
2002-03-28 23:22:05 +01:00
|
|
|
NULL, /* pSetDIBColorTable */
|
|
|
|
NULL, /* pSetDIBits */
|
2003-10-15 04:33:15 +02:00
|
|
|
EMFDRV_SetDIBitsToDevice, /* 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 */
|
2008-04-25 15:39:59 +02:00
|
|
|
EMFDRV_SetPixel, /* 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 */
|
2003-10-10 02:06:59 +02:00
|
|
|
EMFDRV_SetTextJustification, /* pSetTextJustification */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_SetViewportExt, /* pSetViewportExt */
|
|
|
|
EMFDRV_SetViewportOrg, /* pSetViewportOrg */
|
|
|
|
EMFDRV_SetWindowExt, /* pSetWindowExt */
|
|
|
|
EMFDRV_SetWindowOrg, /* pSetWindowOrg */
|
2003-06-23 21:46:56 +02:00
|
|
|
EMFDRV_SetWorldTransform, /* pSetWorldTransform */
|
1999-05-17 18:20:51 +02:00
|
|
|
NULL, /* pStartDoc */
|
|
|
|
NULL, /* pStartPage */
|
2003-10-15 04:33:15 +02:00
|
|
|
EMFDRV_StretchBlt, /* pStretchBlt */
|
2003-05-19 20:49:52 +02:00
|
|
|
EMFDRV_StretchDIBits, /* pStretchDIBits */
|
1999-12-06 00:54:02 +01:00
|
|
|
EMFDRV_StrokeAndFillPath, /* pStrokeAndFillPath */
|
|
|
|
EMFDRV_StrokePath, /* pStrokePath */
|
2000-05-12 22:18:14 +02:00
|
|
|
NULL, /* pSwapBuffers */
|
2006-11-17 14:38:11 +01:00
|
|
|
NULL, /* pUnrealizePalette */
|
2003-05-19 20:49:52 +02:00
|
|
|
EMFDRV_WidenPath /* pWidenPath */
|
1999-05-02 12:15:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* EMFDRV_DeleteDC
|
|
|
|
*/
|
2007-09-12 20:23:03 +02:00
|
|
|
static BOOL EMFDRV_DeleteDC( DC *dc )
|
1999-05-02 12:15:16 +02:00
|
|
|
{
|
2007-09-12 20:23:03 +02:00
|
|
|
EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE *)dc->physDev;
|
2003-11-25 06:03:09 +01:00
|
|
|
UINT index;
|
2002-03-28 23:22:05 +01:00
|
|
|
|
2000-02-16 23:47:24 +01:00
|
|
|
if (physDev->emh) HeapFree( GetProcessHeap(), 0, physDev->emh );
|
2003-11-25 06:03:09 +01:00
|
|
|
for(index = 0; index < physDev->handles_size; index++)
|
|
|
|
if(physDev->handles[index])
|
|
|
|
GDI_hdc_not_using_object(physDev->handles[index], physDev->hdc);
|
|
|
|
HeapFree( GetProcessHeap(), 0, physDev->handles );
|
2000-02-16 23:47:24 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, physDev );
|
1999-05-02 12:15:16 +02:00
|
|
|
dc->physDev = NULL;
|
2007-09-26 17:39:25 +02:00
|
|
|
free_dc_ptr( 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
|
|
|
|
2006-10-12 22:56:56 +02:00
|
|
|
TRACE("record %d, size %d %s\n",
|
2004-06-18 21:33:41 +02:00
|
|
|
emr->iType, emr->nSize, physDev->hFile ? "(to disk)" : "");
|
|
|
|
|
|
|
|
assert( !(emr->nSize & 3) );
|
|
|
|
|
1999-05-02 12:15:16 +02:00
|
|
|
physDev->emh->nBytes += emr->nSize;
|
|
|
|
physDev->emh->nRecords++;
|
|
|
|
|
|
|
|
if(physDev->hFile) {
|
2009-01-26 11:01:12 +01:00
|
|
|
if (!WriteFile(physDev->hFile, emr, emr->nSize, NULL, NULL))
|
1999-05-02 12:15:16 +02:00
|
|
|
return FALSE;
|
|
|
|
} else {
|
2003-10-09 00:33:35 +02:00
|
|
|
DWORD nEmfSize = HeapSize(GetProcessHeap(), 0, physDev->emh);
|
|
|
|
len = physDev->emh->nBytes;
|
|
|
|
if (len > nEmfSize) {
|
|
|
|
nEmfSize += (nEmfSize / 2) + emr->nSize;
|
|
|
|
emh = HeapReAlloc(GetProcessHeap(), 0, physDev->emh, nEmfSize);
|
|
|
|
if (!emh) return FALSE;
|
|
|
|
physDev->emh = emh;
|
|
|
|
}
|
|
|
|
memcpy((CHAR *)physDev->emh + physDev->emh->nBytes - emr->nSize, emr,
|
|
|
|
emr->nSize);
|
1999-05-02 12:15:16 +02:00
|
|
|
}
|
|
|
|
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;
|
2003-10-22 05:02:08 +02:00
|
|
|
RECTL vportRect = *rect;
|
|
|
|
|
|
|
|
LPtoDP(physDev->hdc, (LPPOINT)&vportRect, 2);
|
2006-01-25 13:14:27 +01:00
|
|
|
|
|
|
|
/* The coordinate systems may be mirrored
|
|
|
|
(LPtoDP handles points, not rectangles) */
|
|
|
|
if (vportRect.left > vportRect.right)
|
|
|
|
{
|
|
|
|
LONG temp = vportRect.right;
|
|
|
|
vportRect.right = vportRect.left;
|
|
|
|
vportRect.left = temp;
|
|
|
|
}
|
|
|
|
if (vportRect.top > vportRect.bottom)
|
|
|
|
{
|
|
|
|
LONG temp = vportRect.bottom;
|
|
|
|
vportRect.bottom = vportRect.top;
|
|
|
|
vportRect.top = temp;
|
|
|
|
}
|
1999-05-02 12:15:16 +02:00
|
|
|
|
2006-01-25 13:14:27 +01:00
|
|
|
if (bounds->left > bounds->right)
|
|
|
|
{
|
|
|
|
/* first bounding rectangle */
|
|
|
|
*bounds = vportRect;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bounds->left = min(bounds->left, vportRect.left);
|
|
|
|
bounds->top = min(bounds->top, vportRect.top);
|
|
|
|
bounds->right = max(bounds->right, vportRect.right);
|
|
|
|
bounds->bottom = max(bounds->bottom, vportRect.bottom);
|
1999-05-02 12:15:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-02-15 00:11:17 +01:00
|
|
|
* CreateEnhMetaFileA (GDI32.@)
|
2000-12-02 00:58:28 +01:00
|
|
|
*/
|
2002-06-01 01:06:46 +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 */
|
2002-06-01 01:06:46 +02:00
|
|
|
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 */
|
2002-06-01 01:06:46 +02:00
|
|
|
LPCWSTR description /* [in] optional description */
|
1999-05-02 12:15:16 +02:00
|
|
|
)
|
|
|
|
{
|
2003-03-08 00:08:59 +01:00
|
|
|
static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0};
|
2000-08-19 23:38:55 +02:00
|
|
|
HDC ret;
|
1999-05-02 12:15:16 +02:00
|
|
|
DC *dc;
|
2003-03-08 00:08:59 +01:00
|
|
|
HDC hRefDC = hdc ? hdc : CreateDCW(displayW,NULL,NULL,NULL);
|
|
|
|
/* If no ref, use current display */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_PDEVICE *physDev;
|
2002-07-31 19:20:00 +02:00
|
|
|
HANDLE hFile;
|
1999-05-02 12:15:16 +02:00
|
|
|
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
|
|
|
|
2009-01-28 16:20:56 +01:00
|
|
|
if (!(dc = alloc_dc_ptr( &EMFDRV_Funcs, OBJ_ENHMETADC ))) return 0;
|
1999-05-02 12:15:16 +02:00
|
|
|
|
2005-03-24 22:01:35 +01:00
|
|
|
physDev = HeapAlloc(GetProcessHeap(),0,sizeof(*physDev));
|
1999-05-02 12:15:16 +02:00
|
|
|
if (!physDev) {
|
2007-09-26 17:39:25 +02:00
|
|
|
free_dc_ptr( 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;
|
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 );
|
2007-09-26 17:39:25 +02:00
|
|
|
free_dc_ptr( dc );
|
1999-05-02 12:15:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-11-25 06:03:09 +01:00
|
|
|
physDev->handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, HANDLE_LIST_INC * sizeof(physDev->handles[0]));
|
|
|
|
physDev->handles_size = HANDLE_LIST_INC;
|
|
|
|
physDev->cur_handles = 1;
|
1999-05-02 12:15:16 +02:00
|
|
|
physDev->hFile = 0;
|
|
|
|
|
2002-08-17 02:25:05 +02:00
|
|
|
physDev->horzres = GetDeviceCaps(hRefDC, HORZRES);
|
|
|
|
physDev->vertres = GetDeviceCaps(hRefDC, VERTRES);
|
|
|
|
physDev->logpixelsx = GetDeviceCaps(hRefDC, LOGPIXELSX);
|
|
|
|
physDev->logpixelsy = GetDeviceCaps(hRefDC, LOGPIXELSY);
|
|
|
|
physDev->horzsize = GetDeviceCaps(hRefDC, HORZSIZE);
|
|
|
|
physDev->vertsize = GetDeviceCaps(hRefDC, VERTSIZE);
|
|
|
|
physDev->bitspixel = GetDeviceCaps(hRefDC, BITSPIXEL);
|
2003-05-19 23:51:44 +02:00
|
|
|
physDev->textcaps = GetDeviceCaps(hRefDC, TEXTCAPS);
|
|
|
|
physDev->rastercaps = GetDeviceCaps(hRefDC, RASTERCAPS);
|
|
|
|
physDev->technology = GetDeviceCaps(hRefDC, TECHNOLOGY);
|
|
|
|
physDev->planes = GetDeviceCaps(hRefDC, PLANES);
|
2007-03-27 09:54:49 +02:00
|
|
|
physDev->numcolors = GetDeviceCaps(hRefDC, NUMCOLORS);
|
2009-04-07 20:41:41 +02:00
|
|
|
physDev->restoring = 0;
|
2002-08-17 02:25:05 +02:00
|
|
|
|
2009-06-23 15:55:32 +02:00
|
|
|
SetVirtualResolution(dc->hSelf, 0, 0, 0, 0);
|
|
|
|
|
1999-05-02 12:15:16 +02:00
|
|
|
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 */
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-01-15 23:16:51 +01:00
|
|
|
/* Size in pixels */
|
2002-08-17 02:25:05 +02:00
|
|
|
physDev->emh->szlDevice.cx = physDev->horzres;
|
|
|
|
physDev->emh->szlDevice.cy = physDev->vertres;
|
2000-01-15 23:16:51 +01:00
|
|
|
|
|
|
|
/* Size in millimeters */
|
2002-08-17 02:25:05 +02:00
|
|
|
physDev->emh->szlMillimeters.cx = physDev->horzsize;
|
|
|
|
physDev->emh->szlMillimeters.cy = physDev->vertsize;
|
2000-01-15 23:16:51 +01:00
|
|
|
|
2003-05-19 23:51:44 +02:00
|
|
|
/* Size in micrometers */
|
|
|
|
physDev->emh->szlMicrometers.cx = physDev->horzsize * 1000;
|
|
|
|
physDev->emh->szlMicrometers.cy = physDev->vertsize * 1000;
|
|
|
|
|
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) {
|
2007-09-12 20:23:03 +02:00
|
|
|
EMFDRV_DeleteDC( dc );
|
1999-05-02 12:15:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2009-01-26 11:01:12 +01:00
|
|
|
if (!WriteFile( hFile, physDev->emh, size, NULL, NULL )) {
|
2007-09-12 20:23:03 +02:00
|
|
|
EMFDRV_DeleteDC( dc );
|
1999-05-02 12:15:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
physDev->hFile = hFile;
|
|
|
|
}
|
2000-01-15 23:16:51 +01:00
|
|
|
|
2002-11-22 23:16:53 +01:00
|
|
|
TRACE("returning %p\n", dc->hSelf);
|
2000-08-19 23:38:55 +02:00
|
|
|
ret = dc->hSelf;
|
2007-09-26 17:39:25 +02:00
|
|
|
release_dc_ptr( dc );
|
2001-09-14 02:11:16 +02:00
|
|
|
|
|
|
|
if( !hdc )
|
|
|
|
DeleteDC( hRefDC );
|
2002-06-01 01:06:46 +02:00
|
|
|
|
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;
|
|
|
|
|
2002-11-22 23:16:53 +01:00
|
|
|
TRACE("(%p)\n", hdc );
|
1999-05-02 12:15:16 +02:00
|
|
|
|
2007-09-26 17:39:25 +02:00
|
|
|
if (!(dc = get_dc_ptr( hdc ))) return NULL;
|
2009-01-28 16:20:56 +01:00
|
|
|
if (dc->header.type != OBJ_ENHMETADC)
|
2007-08-21 21:37:40 +02:00
|
|
|
{
|
2007-09-26 17:39:25 +02:00
|
|
|
release_dc_ptr( dc );
|
2007-08-21 21:37:40 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-08-31 15:58:38 +02:00
|
|
|
if (dc->refcount != 1)
|
|
|
|
{
|
|
|
|
FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount );
|
2007-09-26 17:39:25 +02:00
|
|
|
release_dc_ptr( dc );
|
2007-08-31 15:58:38 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
1999-05-02 12:15:16 +02:00
|
|
|
physDev = (EMFDRV_PDEVICE *)dc->physDev;
|
|
|
|
|
2005-10-31 11:05:52 +01:00
|
|
|
if(dc->saveLevel)
|
|
|
|
RestoreDC(hdc, 1);
|
|
|
|
|
1999-05-02 12:15:16 +02:00
|
|
|
emr.emr.iType = EMR_EOF;
|
|
|
|
emr.emr.nSize = sizeof(emr);
|
|
|
|
emr.nPalEntries = 0;
|
2008-05-07 13:34:12 +02:00
|
|
|
emr.offPalEntries = FIELD_OFFSET(EMREOF, nSizeLast);
|
1999-05-02 12:15:16 +02:00
|
|
|
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 );
|
2007-09-12 20:23:03 +02:00
|
|
|
EMFDRV_DeleteDC( dc );
|
1999-05-02 12:15:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-26 11:01:12 +01:00
|
|
|
if (!WriteFile(physDev->hFile, physDev->emh, sizeof(*physDev->emh),
|
|
|
|
NULL, NULL))
|
2001-07-25 00:15:47 +02:00
|
|
|
{
|
|
|
|
CloseHandle( physDev->hFile );
|
2007-09-12 20:23:03 +02:00
|
|
|
EMFDRV_DeleteDC( dc );
|
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);
|
2002-11-22 23:16:53 +01:00
|
|
|
TRACE("hMapping = %p\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 */
|
2007-09-12 20:23:03 +02:00
|
|
|
EMFDRV_DeleteDC( dc );
|
1999-05-02 12:15:16 +02:00
|
|
|
return hmf;
|
|
|
|
}
|