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"
|
2009-12-05 11:45:31 +01:00
|
|
|
#include "winnls.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
|
|
|
|
2011-07-13 14:56:12 +02:00
|
|
|
static BOOL EMFDRV_DeleteDC( PHYSDEV dev );
|
2011-03-16 21:45:39 +01:00
|
|
|
|
2011-10-17 20:39:54 +02:00
|
|
|
static const struct gdi_dc_funcs EMFDRV_Funcs =
|
1999-05-02 12:15:16 +02:00
|
|
|
{
|
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 */
|
2011-09-14 11:57:45 +02:00
|
|
|
NULL, /* pBlendImage */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_Chord, /* pChord */
|
1999-12-06 00:54:02 +01:00
|
|
|
EMFDRV_CloseFigure, /* pCloseFigure */
|
2011-09-07 15:36:58 +02:00
|
|
|
NULL, /* pCreateCompatibleDC */
|
2002-03-28 23:22:05 +01:00
|
|
|
NULL, /* pCreateDC */
|
2011-03-16 21:45:39 +01:00
|
|
|
EMFDRV_DeleteDC, /* pDeleteDC */
|
2003-11-25 06:03:09 +01:00
|
|
|
EMFDRV_DeleteObject, /* pDeleteObject */
|
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 */
|
2011-10-19 15:37:10 +02:00
|
|
|
NULL, /* pEnumFonts */
|
2010-10-26 12:40:41 +02:00
|
|
|
NULL, /* pEnumICMProfiles */
|
1999-05-02 12:15:16 +02:00
|
|
|
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 */
|
2011-10-19 21:51:39 +02:00
|
|
|
NULL, /* pFontIsLinked */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_FrameRgn, /* pFrameRgn */
|
2003-05-21 20:28:49 +02:00
|
|
|
EMFDRV_GdiComment, /* pGdiComment */
|
2012-04-10 16:17:14 +02:00
|
|
|
NULL, /* pGetBoundsRect */
|
2011-10-19 21:51:39 +02:00
|
|
|
NULL, /* pGetCharABCWidths */
|
|
|
|
NULL, /* pGetCharABCWidthsI */
|
1999-05-02 12:15:16 +02:00
|
|
|
NULL, /* pGetCharWidth */
|
2002-08-17 02:25:05 +02:00
|
|
|
EMFDRV_GetDeviceCaps, /* pGetDeviceCaps */
|
2001-03-20 02:55:18 +01:00
|
|
|
NULL, /* pGetDeviceGammaRamp */
|
2011-10-19 21:51:39 +02:00
|
|
|
NULL, /* pGetFontData */
|
2015-08-29 18:54:17 +02:00
|
|
|
NULL, /* pGetFontRealizationInfo */
|
2011-10-19 21:51:39 +02:00
|
|
|
NULL, /* pGetFontUnicodeRanges */
|
|
|
|
NULL, /* pGetGlyphIndices */
|
|
|
|
NULL, /* pGetGlyphOutline */
|
2008-03-05 15:57:21 +01:00
|
|
|
NULL, /* pGetICMProfile */
|
2011-07-14 11:30:58 +02:00
|
|
|
NULL, /* pGetImage */
|
2011-10-19 21:51:39 +02:00
|
|
|
NULL, /* pGetKerningPairs */
|
2002-06-02 23:40:24 +02:00
|
|
|
NULL, /* pGetNearestColor */
|
2011-10-19 21:51:39 +02:00
|
|
|
NULL, /* pGetOutlineTextMetrics */
|
2002-03-28 23:22:05 +01:00
|
|
|
NULL, /* pGetPixel */
|
2002-06-02 23:40:24 +02:00
|
|
|
NULL, /* pGetSystemPaletteEntries */
|
2011-10-19 21:51:39 +02:00
|
|
|
NULL, /* pGetTextCharsetInfo */
|
2006-07-12 02:58:35 +02:00
|
|
|
NULL, /* pGetTextExtentExPoint */
|
2011-10-19 21:51:39 +02:00
|
|
|
NULL, /* pGetTextExtentExPointI */
|
|
|
|
NULL, /* pGetTextFace */
|
1999-05-02 12:15:16 +02:00
|
|
|
NULL, /* pGetTextMetrics */
|
2011-10-31 23:51:38 +01:00
|
|
|
NULL, /* pGradientFill */
|
1999-05-02 12:15:16 +02:00
|
|
|
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 */
|
2011-03-09 16:21:45 +01:00
|
|
|
EMFDRV_OffsetViewportOrgEx, /* pOffsetViewportOrgEx */
|
|
|
|
EMFDRV_OffsetWindowOrgEx, /* pOffsetWindowOrgEx */
|
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 */
|
2012-01-17 04:38:15 +01:00
|
|
|
EMFDRV_PolyBezier, /* pPolyBezier */
|
|
|
|
EMFDRV_PolyBezierTo, /* pPolyBezierTo */
|
1999-12-06 00:54:02 +01:00
|
|
|
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 */
|
2011-07-14 11:30:58 +02:00
|
|
|
NULL, /* pPutImage */
|
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 */
|
2011-03-09 16:21:45 +01:00
|
|
|
EMFDRV_ScaleViewportExtEx, /* pScaleViewportExtEx */
|
|
|
|
EMFDRV_ScaleWindowExtEx, /* pScaleWindowExtEx */
|
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 */
|
1999-05-02 12:15:16 +02:00
|
|
|
EMFDRV_SetBkColor, /* pSetBkColor */
|
|
|
|
EMFDRV_SetBkMode, /* pSetBkMode */
|
2012-04-25 12:26:44 +02:00
|
|
|
NULL, /* pSetBoundsRect */
|
2011-03-10 20:22:22 +01:00
|
|
|
EMFDRV_SetDCBrushColor, /* pSetDCBrushColor*/
|
|
|
|
EMFDRV_SetDCPenColor, /* pSetDCPenColor*/
|
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 */
|
2011-03-10 22:10:16 +01:00
|
|
|
EMFDRV_SetLayout, /* pSetLayout */
|
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 */
|
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 */
|
2011-03-09 16:21:45 +01:00
|
|
|
EMFDRV_SetViewportExtEx, /* pSetViewportExtEx */
|
|
|
|
EMFDRV_SetViewportOrgEx, /* pSetViewportOrgEx */
|
|
|
|
EMFDRV_SetWindowExtEx, /* pSetWindowExtEx */
|
|
|
|
EMFDRV_SetWindowOrgEx, /* pSetWindowOrgEx */
|
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 */
|
2006-11-17 14:38:11 +01:00
|
|
|
NULL, /* pUnrealizePalette */
|
2012-05-08 12:16:05 +02:00
|
|
|
EMFDRV_WidenPath, /* pWidenPath */
|
2012-06-28 14:13:24 +02:00
|
|
|
NULL, /* wine_get_wgl_driver */
|
2012-05-08 12:16:05 +02:00
|
|
|
GDI_PRIORITY_GRAPHICS_DRV /* priority */
|
1999-05-02 12:15:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* EMFDRV_DeleteDC
|
|
|
|
*/
|
2011-07-13 14:56:12 +02:00
|
|
|
static BOOL EMFDRV_DeleteDC( PHYSDEV dev )
|
1999-05-02 12:15:16 +02:00
|
|
|
{
|
2011-03-16 21:45:39 +01:00
|
|
|
EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE *)dev;
|
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])
|
2011-04-04 12:27:09 +02:00
|
|
|
GDI_hdc_not_using_object(physDev->handles[index], dev->hdc);
|
2003-11-25 06:03:09 +01:00
|
|
|
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
|
|
|
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;
|
2014-07-12 10:35:15 +02:00
|
|
|
DWORD bytes_written;
|
1999-05-02 12:15:16 +02:00
|
|
|
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) {
|
2014-07-12 10:35:15 +02:00
|
|
|
if (!WriteFile(physDev->hFile, emr, emr->nSize, &bytes_written, 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;
|
|
|
|
|
2011-04-04 12:27:09 +02:00
|
|
|
LPtoDP( dev->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);
|
|
|
|
|
2010-08-20 14:33:37 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, filenameW );
|
|
|
|
HeapFree( GetProcessHeap(), 0, descriptionW );
|
1999-05-02 12:15:16 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
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;
|
2014-07-12 10:35:15 +02:00
|
|
|
DWORD bytes_written;
|
1999-05-02 12:15:16 +02:00
|
|
|
|
2001-05-11 22:03:40 +02:00
|
|
|
TRACE("%s\n", debugstr_w(filename) );
|
1999-05-02 12:15:16 +02:00
|
|
|
|
2011-03-16 21:45:39 +01:00
|
|
|
if (!(dc = alloc_dc_ptr( 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;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-09-07 14:39:46 +02:00
|
|
|
push_dc_driver( &dc->physDev, &physDev->dev, &EMFDRV_Funcs );
|
2011-03-16 21:45:39 +01:00
|
|
|
|
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;
|
2011-03-10 20:22:22 +01:00
|
|
|
physDev->dc_brush = 0;
|
|
|
|
physDev->dc_pen = 0;
|
2012-04-10 14:42:50 +02:00
|
|
|
physDev->screen_dc = 0;
|
2009-04-07 20:41:41 +02:00
|
|
|
physDev->restoring = 0;
|
2012-04-10 14:42:50 +02:00
|
|
|
if (hdc) /* if no ref, use current display */
|
|
|
|
physDev->ref_dc = hdc;
|
|
|
|
else
|
|
|
|
physDev->ref_dc = physDev->screen_dc = CreateDCW( displayW, NULL, NULL, NULL );
|
2002-08-17 02:25:05 +02:00
|
|
|
|
2011-04-04 12:27:09 +02:00
|
|
|
SetVirtualResolution(physDev->dev.hdc, 0, 0, 0, 0);
|
2009-06-23 15:55:32 +02:00
|
|
|
|
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 */
|
2012-04-10 14:42:50 +02:00
|
|
|
physDev->emh->szlDevice.cx = GetDeviceCaps( physDev->ref_dc, HORZRES );
|
|
|
|
physDev->emh->szlDevice.cy = GetDeviceCaps( physDev->ref_dc, VERTRES );
|
2000-01-15 23:16:51 +01:00
|
|
|
|
|
|
|
/* Size in millimeters */
|
2012-04-10 14:42:50 +02:00
|
|
|
physDev->emh->szlMillimeters.cx = GetDeviceCaps( physDev->ref_dc, HORZSIZE );
|
|
|
|
physDev->emh->szlMillimeters.cy = GetDeviceCaps( physDev->ref_dc, VERTSIZE );
|
2000-01-15 23:16:51 +01:00
|
|
|
|
2003-05-19 23:51:44 +02:00
|
|
|
/* Size in micrometers */
|
2012-04-10 14:42:50 +02:00
|
|
|
physDev->emh->szlMicrometers.cx = physDev->emh->szlMillimeters.cx * 1000;
|
|
|
|
physDev->emh->szlMicrometers.cy = physDev->emh->szlMillimeters.cy * 1000;
|
2003-05-19 23:51:44 +02:00
|
|
|
|
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) {
|
2011-03-16 21:45:39 +01:00
|
|
|
free_dc_ptr( dc );
|
1999-05-02 12:15:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2014-07-12 10:35:15 +02:00
|
|
|
if (!WriteFile( hFile, physDev->emh, size, &bytes_written, NULL )) {
|
2011-03-16 21:45:39 +01:00
|
|
|
free_dc_ptr( dc );
|
2013-06-22 17:21:39 +02:00
|
|
|
CloseHandle( hFile );
|
1999-05-02 12:15:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
physDev->hFile = hFile;
|
|
|
|
}
|
2000-01-15 23:16:51 +01:00
|
|
|
|
2011-04-04 12:27:09 +02:00
|
|
|
TRACE("returning %p\n", physDev->dev.hdc);
|
|
|
|
ret = physDev->dev.hdc;
|
2007-09-26 17:39:25 +02:00
|
|
|
release_dc_ptr( dc );
|
2001-09-14 02:11:16 +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;
|
2012-10-17 12:25:28 +02:00
|
|
|
if (GetObjectType( hdc ) != 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)
|
|
|
|
{
|
2011-04-04 12:27:09 +02:00
|
|
|
FIXME( "not deleting busy DC %p refcount %u\n", hdc, 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);
|
|
|
|
|
2011-03-10 20:22:22 +01:00
|
|
|
if (physDev->dc_brush) DeleteObject( physDev->dc_brush );
|
|
|
|
if (physDev->dc_pen) DeleteObject( physDev->dc_pen );
|
2012-04-10 14:42:50 +02:00
|
|
|
if (physDev->screen_dc) DeleteDC( physDev->screen_dc );
|
2011-03-10 20:22:22 +01:00
|
|
|
|
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 );
|
2011-03-16 21:45:39 +01:00
|
|
|
free_dc_ptr( 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 );
|
2011-03-16 21:45:39 +01:00
|
|
|
free_dc_ptr( 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 */
|
2011-03-16 21:45:39 +01:00
|
|
|
free_dc_ptr( dc );
|
1999-05-02 12:15:16 +02:00
|
|
|
return hmf;
|
|
|
|
}
|