1999-05-02 10:15:16 +00:00
|
|
|
/*
|
|
|
|
* Enhanced MetaFile driver initialisation functions
|
|
|
|
*
|
|
|
|
* Copyright 1999 Huw D M Davies
|
2002-03-09 23:29:33 +00: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 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-05-02 10:15:16 +00:00
|
|
|
*/
|
|
|
|
|
2004-06-18 19:33:41 +00:00
|
|
|
#include <assert.h>
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <stdarg.h>
|
2000-11-05 02:05:07 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
1999-05-02 10:15:16 +00:00
|
|
|
#include "windef.h"
|
2003-09-05 23:08:26 +00:00
|
|
|
#include "winbase.h"
|
1999-05-02 10:15:16 +00:00
|
|
|
#include "wingdi.h"
|
2009-12-05 10:45:31 +00:00
|
|
|
#include "winnls.h"
|
2004-01-15 00:35:38 +00:00
|
|
|
#include "gdi_private.h"
|
2002-03-27 21:13:40 +00:00
|
|
|
#include "enhmfdrv/enhmetafiledrv.h"
|
2002-03-09 23:29:33 +00:00
|
|
|
#include "wine/debug.h"
|
1999-05-02 10:15:16 +00:00
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile);
|
1999-05-02 10:15:16 +00:00
|
|
|
|
2011-07-13 12:56:12 +00:00
|
|
|
static BOOL EMFDRV_DeleteDC( PHYSDEV dev );
|
2011-03-16 20:45:39 +00:00
|
|
|
|
2016-06-21 05:52:43 +00:00
|
|
|
static const struct gdi_dc_funcs emfdrv_driver =
|
1999-05-02 10:15:16 +00:00
|
|
|
{
|
1999-05-17 16:20:51 +00:00
|
|
|
NULL, /* pAbortDoc */
|
1999-12-05 23:54:02 +00:00
|
|
|
EMFDRV_AbortPath, /* pAbortPath */
|
2004-08-02 18:54:54 +00:00
|
|
|
NULL, /* pAlphaBlend */
|
2016-06-17 07:24:54 +00:00
|
|
|
EMFDRV_AngleArc, /* pAngleArc */
|
1999-05-02 10:15:16 +00:00
|
|
|
EMFDRV_Arc, /* pArc */
|
2016-06-17 04:51:05 +00:00
|
|
|
EMFDRV_ArcTo, /* pArcTo */
|
1999-12-05 23:54:02 +00:00
|
|
|
EMFDRV_BeginPath, /* pBeginPath */
|
2011-09-14 09:57:45 +00:00
|
|
|
NULL, /* pBlendImage */
|
1999-05-02 10:15:16 +00:00
|
|
|
EMFDRV_Chord, /* pChord */
|
1999-12-05 23:54:02 +00:00
|
|
|
EMFDRV_CloseFigure, /* pCloseFigure */
|
2011-09-07 13:36:58 +00:00
|
|
|
NULL, /* pCreateCompatibleDC */
|
2002-03-28 22:22:05 +00:00
|
|
|
NULL, /* pCreateDC */
|
2011-03-16 20:45:39 +00:00
|
|
|
EMFDRV_DeleteDC, /* pDeleteDC */
|
2003-11-25 05:03:09 +00:00
|
|
|
EMFDRV_DeleteObject, /* pDeleteObject */
|
1999-05-17 16:20:51 +00:00
|
|
|
NULL, /* pDeviceCapabilities */
|
1999-05-02 10:15:16 +00:00
|
|
|
EMFDRV_Ellipse, /* pEllipse */
|
1999-05-17 16:20:51 +00:00
|
|
|
NULL, /* pEndDoc */
|
|
|
|
NULL, /* pEndPage */
|
1999-12-05 23:54:02 +00:00
|
|
|
EMFDRV_EndPath, /* pEndPath */
|
2011-10-19 13:37:10 +00:00
|
|
|
NULL, /* pEnumFonts */
|
2010-10-26 10:40:41 +00:00
|
|
|
NULL, /* pEnumICMProfiles */
|
1999-05-02 10:15:16 +00:00
|
|
|
EMFDRV_ExcludeClipRect, /* pExcludeClipRect */
|
1999-05-17 16:20:51 +00:00
|
|
|
NULL, /* pExtDeviceMode */
|
2001-07-29 20:25:14 +00:00
|
|
|
NULL, /* pExtEscape */
|
1999-05-02 10:15:16 +00:00
|
|
|
EMFDRV_ExtFloodFill, /* pExtFloodFill */
|
2002-05-09 04:03:46 +00:00
|
|
|
EMFDRV_ExtSelectClipRgn, /* pExtSelectClipRgn */
|
2002-08-17 01:36:55 +00:00
|
|
|
EMFDRV_ExtTextOut, /* pExtTextOut */
|
1999-12-05 23:54:02 +00:00
|
|
|
EMFDRV_FillPath, /* pFillPath */
|
1999-05-02 10:15:16 +00:00
|
|
|
EMFDRV_FillRgn, /* pFillRgn */
|
1999-12-05 23:54:02 +00:00
|
|
|
EMFDRV_FlattenPath, /* pFlattenPath */
|
2011-10-19 19:51:39 +00:00
|
|
|
NULL, /* pFontIsLinked */
|
1999-05-02 10:15:16 +00:00
|
|
|
EMFDRV_FrameRgn, /* pFrameRgn */
|
2003-05-21 18:28:49 +00:00
|
|
|
EMFDRV_GdiComment, /* pGdiComment */
|
2012-04-10 14:17:14 +00:00
|
|
|
NULL, /* pGetBoundsRect */
|
2011-10-19 19:51:39 +00:00
|
|
|
NULL, /* pGetCharABCWidths */
|
|
|
|
NULL, /* pGetCharABCWidthsI */
|
1999-05-02 10:15:16 +00:00
|
|
|
NULL, /* pGetCharWidth */
|
2002-08-17 00:25:05 +00:00
|
|
|
EMFDRV_GetDeviceCaps, /* pGetDeviceCaps */
|
2001-03-20 01:55:18 +00:00
|
|
|
NULL, /* pGetDeviceGammaRamp */
|
2011-10-19 19:51:39 +00:00
|
|
|
NULL, /* pGetFontData */
|
2015-08-29 16:54:17 +00:00
|
|
|
NULL, /* pGetFontRealizationInfo */
|
2011-10-19 19:51:39 +00:00
|
|
|
NULL, /* pGetFontUnicodeRanges */
|
|
|
|
NULL, /* pGetGlyphIndices */
|
|
|
|
NULL, /* pGetGlyphOutline */
|
2008-03-05 14:57:21 +00:00
|
|
|
NULL, /* pGetICMProfile */
|
2011-07-14 09:30:58 +00:00
|
|
|
NULL, /* pGetImage */
|
2011-10-19 19:51:39 +00:00
|
|
|
NULL, /* pGetKerningPairs */
|
2002-06-02 21:40:24 +00:00
|
|
|
NULL, /* pGetNearestColor */
|
2011-10-19 19:51:39 +00:00
|
|
|
NULL, /* pGetOutlineTextMetrics */
|
2002-03-28 22:22:05 +00:00
|
|
|
NULL, /* pGetPixel */
|
2002-06-02 21:40:24 +00:00
|
|
|
NULL, /* pGetSystemPaletteEntries */
|
2011-10-19 19:51:39 +00:00
|
|
|
NULL, /* pGetTextCharsetInfo */
|
2006-07-12 00:58:35 +00:00
|
|
|
NULL, /* pGetTextExtentExPoint */
|
2011-10-19 19:51:39 +00:00
|
|
|
NULL, /* pGetTextExtentExPointI */
|
|
|
|
NULL, /* pGetTextFace */
|
1999-05-02 10:15:16 +00:00
|
|
|
NULL, /* pGetTextMetrics */
|
2016-04-08 10:40:56 +00:00
|
|
|
EMFDRV_GradientFill, /* pGradientFill */
|
1999-05-02 10:15:16 +00:00
|
|
|
EMFDRV_IntersectClipRect, /* pIntersectClipRect */
|
|
|
|
EMFDRV_InvertRgn, /* pInvertRgn */
|
|
|
|
EMFDRV_LineTo, /* pLineTo */
|
2003-06-23 19:46:56 +00:00
|
|
|
EMFDRV_ModifyWorldTransform, /* pModifyWorldTransform */
|
2000-11-05 03:28:18 +00:00
|
|
|
EMFDRV_MoveTo, /* pMoveTo */
|
1999-05-02 10:15:16 +00:00
|
|
|
EMFDRV_OffsetClipRgn, /* pOffsetClipRgn */
|
2011-03-09 15:21:45 +00:00
|
|
|
EMFDRV_OffsetViewportOrgEx, /* pOffsetViewportOrgEx */
|
|
|
|
EMFDRV_OffsetWindowOrgEx, /* pOffsetWindowOrgEx */
|
1999-05-02 10:15:16 +00:00
|
|
|
EMFDRV_PaintRgn, /* pPaintRgn */
|
2002-06-14 00:00:56 +00:00
|
|
|
EMFDRV_PatBlt, /* pPatBlt */
|
1999-05-02 10:15:16 +00:00
|
|
|
EMFDRV_Pie, /* pPie */
|
2012-01-17 03:38:15 +00:00
|
|
|
EMFDRV_PolyBezier, /* pPolyBezier */
|
|
|
|
EMFDRV_PolyBezierTo, /* pPolyBezierTo */
|
2016-06-17 06:08:57 +00:00
|
|
|
EMFDRV_PolyDraw, /* pPolyDraw */
|
1999-05-02 10:15:16 +00:00
|
|
|
EMFDRV_PolyPolygon, /* pPolyPolygon */
|
|
|
|
EMFDRV_PolyPolyline, /* pPolyPolyline */
|
|
|
|
EMFDRV_Polygon, /* pPolygon */
|
|
|
|
EMFDRV_Polyline, /* pPolyline */
|
2016-06-17 05:00:17 +00:00
|
|
|
EMFDRV_PolylineTo, /* pPolylineTo */
|
2011-07-14 09:30:58 +00:00
|
|
|
NULL, /* pPutImage */
|
2002-06-02 21:40:24 +00:00
|
|
|
NULL, /* pRealizeDefaultPalette */
|
1999-05-02 10:15:16 +00:00
|
|
|
NULL, /* pRealizePalette */
|
|
|
|
EMFDRV_Rectangle, /* pRectangle */
|
2002-04-06 00:00:56 +00:00
|
|
|
NULL, /* pResetDC */
|
1999-05-02 10:15:16 +00:00
|
|
|
EMFDRV_RestoreDC, /* pRestoreDC */
|
|
|
|
EMFDRV_RoundRect, /* pRoundRect */
|
|
|
|
EMFDRV_SaveDC, /* pSaveDC */
|
2011-03-09 15:21:45 +00:00
|
|
|
EMFDRV_ScaleViewportExtEx, /* pScaleViewportExtEx */
|
|
|
|
EMFDRV_ScaleWindowExtEx, /* pScaleWindowExtEx */
|
2002-03-28 22:22:05 +00:00
|
|
|
EMFDRV_SelectBitmap, /* pSelectBitmap */
|
|
|
|
EMFDRV_SelectBrush, /* pSelectBrush */
|
1999-12-05 23:54:02 +00:00
|
|
|
EMFDRV_SelectClipPath, /* pSelectClipPath */
|
2002-03-28 22:22:05 +00:00
|
|
|
EMFDRV_SelectFont, /* pSelectFont */
|
2008-05-07 11:35:04 +00:00
|
|
|
EMFDRV_SelectPalette, /* pSelectPalette */
|
2002-03-28 22:22:05 +00:00
|
|
|
EMFDRV_SelectPen, /* pSelectPen */
|
2003-10-04 03:08:25 +00:00
|
|
|
EMFDRV_SetArcDirection, /* pSetArcDirection */
|
1999-05-02 10:15:16 +00:00
|
|
|
EMFDRV_SetBkColor, /* pSetBkColor */
|
|
|
|
EMFDRV_SetBkMode, /* pSetBkMode */
|
2012-04-25 10:26:44 +00:00
|
|
|
NULL, /* pSetBoundsRect */
|
2011-03-10 19:22:22 +00:00
|
|
|
EMFDRV_SetDCBrushColor, /* pSetDCBrushColor*/
|
|
|
|
EMFDRV_SetDCPenColor, /* pSetDCPenColor*/
|
2003-10-15 02:33:15 +00:00
|
|
|
EMFDRV_SetDIBitsToDevice, /* pSetDIBitsToDevice */
|
1999-05-02 10:15:16 +00:00
|
|
|
NULL, /* pSetDeviceClipping */
|
2001-03-20 01:55:18 +00:00
|
|
|
NULL, /* pSetDeviceGammaRamp */
|
2011-03-10 21:10:16 +00:00
|
|
|
EMFDRV_SetLayout, /* pSetLayout */
|
1999-05-02 10:15:16 +00:00
|
|
|
EMFDRV_SetMapMode, /* pSetMapMode */
|
|
|
|
EMFDRV_SetMapperFlags, /* pSetMapperFlags */
|
2008-04-25 13:39:59 +00:00
|
|
|
EMFDRV_SetPixel, /* pSetPixel */
|
1999-05-02 10:15:16 +00:00
|
|
|
EMFDRV_SetPolyFillMode, /* pSetPolyFillMode */
|
|
|
|
EMFDRV_SetROP2, /* pSetROP2 */
|
|
|
|
NULL, /* pSetRelAbs */
|
|
|
|
EMFDRV_SetStretchBltMode, /* pSetStretchBltMode */
|
|
|
|
EMFDRV_SetTextAlign, /* pSetTextAlign */
|
|
|
|
NULL, /* pSetTextCharacterExtra */
|
|
|
|
EMFDRV_SetTextColor, /* pSetTextColor */
|
2003-10-10 00:06:59 +00:00
|
|
|
EMFDRV_SetTextJustification, /* pSetTextJustification */
|
2011-03-09 15:21:45 +00:00
|
|
|
EMFDRV_SetViewportExtEx, /* pSetViewportExtEx */
|
|
|
|
EMFDRV_SetViewportOrgEx, /* pSetViewportOrgEx */
|
|
|
|
EMFDRV_SetWindowExtEx, /* pSetWindowExtEx */
|
|
|
|
EMFDRV_SetWindowOrgEx, /* pSetWindowOrgEx */
|
2003-06-23 19:46:56 +00:00
|
|
|
EMFDRV_SetWorldTransform, /* pSetWorldTransform */
|
1999-05-17 16:20:51 +00:00
|
|
|
NULL, /* pStartDoc */
|
|
|
|
NULL, /* pStartPage */
|
2003-10-15 02:33:15 +00:00
|
|
|
EMFDRV_StretchBlt, /* pStretchBlt */
|
2003-05-19 18:49:52 +00:00
|
|
|
EMFDRV_StretchDIBits, /* pStretchDIBits */
|
1999-12-05 23:54:02 +00:00
|
|
|
EMFDRV_StrokeAndFillPath, /* pStrokeAndFillPath */
|
|
|
|
EMFDRV_StrokePath, /* pStrokePath */
|
2006-11-17 13:38:11 +00:00
|
|
|
NULL, /* pUnrealizePalette */
|
2012-05-08 10:16:05 +00:00
|
|
|
EMFDRV_WidenPath, /* pWidenPath */
|
2012-06-28 12:13:24 +00:00
|
|
|
NULL, /* wine_get_wgl_driver */
|
2012-05-08 10:16:05 +00:00
|
|
|
GDI_PRIORITY_GRAPHICS_DRV /* priority */
|
1999-05-02 10:15:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* EMFDRV_DeleteDC
|
|
|
|
*/
|
2011-07-13 12:56:12 +00:00
|
|
|
static BOOL EMFDRV_DeleteDC( PHYSDEV dev )
|
1999-05-02 10:15:16 +00:00
|
|
|
{
|
2016-06-21 05:52:43 +00:00
|
|
|
EMFDRV_PDEVICE *physDev = get_emf_physdev( dev );
|
2003-11-25 05:03:09 +00:00
|
|
|
UINT index;
|
2002-03-28 22:22:05 +00:00
|
|
|
|
2016-07-08 07:59:35 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, physDev->emh );
|
2003-11-25 05:03:09 +00:00
|
|
|
for(index = 0; index < physDev->handles_size; index++)
|
|
|
|
if(physDev->handles[index])
|
2011-04-04 10:27:09 +00:00
|
|
|
GDI_hdc_not_using_object(physDev->handles[index], dev->hdc);
|
2003-11-25 05:03:09 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, physDev->handles );
|
2000-02-16 22:47:24 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, physDev );
|
1999-05-02 10:15:16 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* EMFDRV_WriteRecord
|
|
|
|
*
|
|
|
|
* Warning: this function can change the pointer to the metafile header.
|
|
|
|
*/
|
2002-03-28 22:22:05 +00:00
|
|
|
BOOL EMFDRV_WriteRecord( PHYSDEV dev, EMR *emr )
|
1999-05-02 10:15:16 +00:00
|
|
|
{
|
|
|
|
DWORD len;
|
2014-07-12 08:35:15 +00:00
|
|
|
DWORD bytes_written;
|
1999-05-02 10:15:16 +00:00
|
|
|
ENHMETAHEADER *emh;
|
2016-06-21 05:52:43 +00:00
|
|
|
EMFDRV_PDEVICE *physDev = get_emf_physdev( dev );
|
1999-05-02 10:15:16 +00:00
|
|
|
|
2006-10-12 20:56:56 +00:00
|
|
|
TRACE("record %d, size %d %s\n",
|
2004-06-18 19:33:41 +00:00
|
|
|
emr->iType, emr->nSize, physDev->hFile ? "(to disk)" : "");
|
|
|
|
|
|
|
|
assert( !(emr->nSize & 3) );
|
|
|
|
|
1999-05-02 10:15:16 +00:00
|
|
|
physDev->emh->nBytes += emr->nSize;
|
|
|
|
physDev->emh->nRecords++;
|
|
|
|
|
|
|
|
if(physDev->hFile) {
|
2014-07-12 08:35:15 +00:00
|
|
|
if (!WriteFile(physDev->hFile, emr, emr->nSize, &bytes_written, NULL))
|
1999-05-02 10:15:16 +00:00
|
|
|
return FALSE;
|
|
|
|
} else {
|
2003-10-08 22:33:35 +00: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 10:15:16 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* EMFDRV_UpdateBBox
|
|
|
|
*/
|
2002-03-28 22:22:05 +00:00
|
|
|
void EMFDRV_UpdateBBox( PHYSDEV dev, RECTL *rect )
|
1999-05-02 10:15:16 +00:00
|
|
|
{
|
2016-06-21 05:52:43 +00:00
|
|
|
EMFDRV_PDEVICE *physDev = get_emf_physdev( dev );
|
1999-05-02 10:15:16 +00:00
|
|
|
RECTL *bounds = &physDev->emh->rclBounds;
|
2003-10-22 03:02:08 +00:00
|
|
|
RECTL vportRect = *rect;
|
|
|
|
|
2011-04-04 10:27:09 +00:00
|
|
|
LPtoDP( dev->hdc, (LPPOINT)&vportRect, 2 );
|
|
|
|
|
2006-01-25 12:14:27 +00: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 10:15:16 +00:00
|
|
|
|
2006-01-25 12:14:27 +00: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 10:15:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-02-14 23:11:17 +00:00
|
|
|
* CreateEnhMetaFileA (GDI32.@)
|
2000-12-01 23:58:28 +00:00
|
|
|
*/
|
2002-05-31 23:06:46 +00:00
|
|
|
HDC WINAPI CreateEnhMetaFileA(
|
2000-12-01 23:58:28 +00:00
|
|
|
HDC hdc, /* [in] optional reference DC */
|
|
|
|
LPCSTR filename, /* [in] optional filename for disk metafiles */
|
|
|
|
const RECT *rect, /* [in] optional bounding rectangle */
|
2002-05-31 23:06:46 +00:00
|
|
|
LPCSTR description /* [in] optional description */
|
1999-05-02 10:15:16 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
LPWSTR filenameW = NULL;
|
|
|
|
LPWSTR descriptionW = NULL;
|
|
|
|
HDC hReturnDC;
|
2000-11-28 22:40:56 +00:00
|
|
|
DWORD len1, len2, total;
|
1999-05-02 10:15:16 +00:00
|
|
|
|
2002-01-01 00:24:30 +00: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 10:15:16 +00:00
|
|
|
if(description) {
|
|
|
|
len1 = strlen(description);
|
|
|
|
len2 = strlen(description + len1 + 1);
|
2000-11-28 22:40:56 +00: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 10:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hReturnDC = CreateEnhMetaFileW(hdc, filenameW, rect, descriptionW);
|
|
|
|
|
2010-08-20 12:33:37 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, filenameW );
|
|
|
|
HeapFree( GetProcessHeap(), 0, descriptionW );
|
1999-05-02 10:15:16 +00:00
|
|
|
|
|
|
|
return hReturnDC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2001-02-14 23:11:17 +00:00
|
|
|
* CreateEnhMetaFileW (GDI32.@)
|
1999-05-02 10:15:16 +00:00
|
|
|
*/
|
|
|
|
HDC WINAPI CreateEnhMetaFileW(
|
2000-12-01 23:58:28 +00:00
|
|
|
HDC hdc, /* [in] optional reference DC */
|
|
|
|
LPCWSTR filename, /* [in] optional filename for disk metafiles */
|
|
|
|
const RECT* rect, /* [in] optional bounding rectangle */
|
2002-05-31 23:06:46 +00:00
|
|
|
LPCWSTR description /* [in] optional description */
|
1999-05-02 10:15:16 +00:00
|
|
|
)
|
|
|
|
{
|
2003-03-07 23:08:59 +00:00
|
|
|
static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0};
|
2000-08-19 21:38:55 +00:00
|
|
|
HDC ret;
|
1999-05-02 10:15:16 +00:00
|
|
|
DC *dc;
|
|
|
|
EMFDRV_PDEVICE *physDev;
|
2002-07-31 17:20:00 +00:00
|
|
|
HANDLE hFile;
|
1999-05-02 10:15:16 +00:00
|
|
|
DWORD size = 0, length = 0;
|
2014-07-12 08:35:15 +00:00
|
|
|
DWORD bytes_written;
|
1999-05-02 10:15:16 +00:00
|
|
|
|
2001-05-11 20:03:40 +00:00
|
|
|
TRACE("%s\n", debugstr_w(filename) );
|
1999-05-02 10:15:16 +00:00
|
|
|
|
2011-03-16 20:45:39 +00:00
|
|
|
if (!(dc = alloc_dc_ptr( OBJ_ENHMETADC ))) return 0;
|
1999-05-02 10:15:16 +00:00
|
|
|
|
2005-03-24 21:01:35 +00:00
|
|
|
physDev = HeapAlloc(GetProcessHeap(),0,sizeof(*physDev));
|
1999-05-02 10:15:16 +00:00
|
|
|
if (!physDev) {
|
2007-09-26 15:39:25 +00:00
|
|
|
free_dc_ptr( dc );
|
1999-05-02 10:15:16 +00: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 22:47:24 +00:00
|
|
|
if (!(physDev->emh = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size))) {
|
|
|
|
HeapFree( GetProcessHeap(), 0, physDev );
|
2007-09-26 15:39:25 +00:00
|
|
|
free_dc_ptr( dc );
|
1999-05-02 10:15:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-21 05:52:43 +00:00
|
|
|
push_dc_driver( &dc->physDev, &physDev->dev, &emfdrv_driver );
|
2011-03-16 20:45:39 +00:00
|
|
|
|
2003-11-25 05:03:09 +00: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 10:15:16 +00:00
|
|
|
physDev->hFile = 0;
|
2011-03-10 19:22:22 +00:00
|
|
|
physDev->dc_brush = 0;
|
|
|
|
physDev->dc_pen = 0;
|
2012-04-10 12:42:50 +00:00
|
|
|
physDev->screen_dc = 0;
|
2009-04-07 18:41:41 +00:00
|
|
|
physDev->restoring = 0;
|
2016-04-28 16:47:14 +00:00
|
|
|
physDev->path = FALSE;
|
2012-04-10 12:42:50 +00: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 00:25:05 +00:00
|
|
|
|
2011-04-04 10:27:09 +00:00
|
|
|
SetVirtualResolution(physDev->dev.hdc, 0, 0, 0, 0);
|
2009-06-23 13:55:32 +00:00
|
|
|
|
1999-05-02 10:15:16 +00:00
|
|
|
physDev->emh->iType = EMR_HEADER;
|
|
|
|
physDev->emh->nSize = size;
|
2000-01-15 22:16:51 +00:00
|
|
|
|
|
|
|
physDev->emh->rclBounds.left = physDev->emh->rclBounds.top = 0;
|
|
|
|
physDev->emh->rclBounds.right = physDev->emh->rclBounds.bottom = -1;
|
|
|
|
|
2000-04-14 14:07:51 +00: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 10:15:16 +00: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 22:16:51 +00:00
|
|
|
|
|
|
|
physDev->emh->sReserved = 0; /* According to docs, this is reserved and must be 0 */
|
1999-05-02 10:15:16 +00:00
|
|
|
physDev->emh->nDescription = length / 2;
|
2000-01-15 22:16:51 +00:00
|
|
|
|
1999-05-02 10:15:16 +00:00
|
|
|
physDev->emh->offDescription = length ? sizeof(ENHMETAHEADER) : 0;
|
2000-01-15 22:16:51 +00:00
|
|
|
|
|
|
|
physDev->emh->nPalEntries = 0; /* I guess this should start at 0 */
|
2002-05-31 23:06:46 +00:00
|
|
|
|
2000-01-15 22:16:51 +00:00
|
|
|
/* Size in pixels */
|
2012-04-10 12:42:50 +00:00
|
|
|
physDev->emh->szlDevice.cx = GetDeviceCaps( physDev->ref_dc, HORZRES );
|
|
|
|
physDev->emh->szlDevice.cy = GetDeviceCaps( physDev->ref_dc, VERTRES );
|
2000-01-15 22:16:51 +00:00
|
|
|
|
|
|
|
/* Size in millimeters */
|
2012-04-10 12:42:50 +00:00
|
|
|
physDev->emh->szlMillimeters.cx = GetDeviceCaps( physDev->ref_dc, HORZSIZE );
|
|
|
|
physDev->emh->szlMillimeters.cy = GetDeviceCaps( physDev->ref_dc, VERTSIZE );
|
2000-01-15 22:16:51 +00:00
|
|
|
|
2003-05-19 21:51:44 +00:00
|
|
|
/* Size in micrometers */
|
2012-04-10 12:42:50 +00:00
|
|
|
physDev->emh->szlMicrometers.cx = physDev->emh->szlMillimeters.cx * 1000;
|
|
|
|
physDev->emh->szlMicrometers.cy = physDev->emh->szlMillimeters.cy * 1000;
|
2003-05-19 21:51:44 +00:00
|
|
|
|
1999-05-02 10:15:16 +00: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 01:29:18 +00:00
|
|
|
NULL, CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) {
|
2011-03-16 20:45:39 +00:00
|
|
|
free_dc_ptr( dc );
|
1999-05-02 10:15:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-07-12 08:35:15 +00:00
|
|
|
if (!WriteFile( hFile, physDev->emh, size, &bytes_written, NULL )) {
|
2011-03-16 20:45:39 +00:00
|
|
|
free_dc_ptr( dc );
|
2013-06-22 15:21:39 +00:00
|
|
|
CloseHandle( hFile );
|
1999-05-02 10:15:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
physDev->hFile = hFile;
|
|
|
|
}
|
2000-01-15 22:16:51 +00:00
|
|
|
|
2011-04-04 10:27:09 +00:00
|
|
|
TRACE("returning %p\n", physDev->dev.hdc);
|
|
|
|
ret = physDev->dev.hdc;
|
2007-09-26 15:39:25 +00:00
|
|
|
release_dc_ptr( dc );
|
2001-09-14 00:11:16 +00:00
|
|
|
|
2000-08-19 21:38:55 +00:00
|
|
|
return ret;
|
1999-05-02 10:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2001-02-14 23:11:17 +00:00
|
|
|
* CloseEnhMetaFile (GDI32.@)
|
1999-05-02 10:15:16 +00:00
|
|
|
*/
|
2000-12-01 23:58:28 +00:00
|
|
|
HENHMETAFILE WINAPI CloseEnhMetaFile(HDC hdc) /* [in] metafile DC */
|
1999-05-02 10:15:16 +00:00
|
|
|
{
|
|
|
|
HENHMETAFILE hmf;
|
|
|
|
EMFDRV_PDEVICE *physDev;
|
|
|
|
DC *dc;
|
|
|
|
EMREOF emr;
|
|
|
|
HANDLE hMapping = 0;
|
|
|
|
|
2002-11-22 22:16:53 +00:00
|
|
|
TRACE("(%p)\n", hdc );
|
1999-05-02 10:15:16 +00:00
|
|
|
|
2007-09-26 15:39:25 +00:00
|
|
|
if (!(dc = get_dc_ptr( hdc ))) return NULL;
|
2012-10-17 10:25:28 +00:00
|
|
|
if (GetObjectType( hdc ) != OBJ_ENHMETADC)
|
2007-08-21 19:37:40 +00:00
|
|
|
{
|
2007-09-26 15:39:25 +00:00
|
|
|
release_dc_ptr( dc );
|
2007-08-21 19:37:40 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-08-31 13:58:38 +00:00
|
|
|
if (dc->refcount != 1)
|
|
|
|
{
|
2011-04-04 10:27:09 +00:00
|
|
|
FIXME( "not deleting busy DC %p refcount %u\n", hdc, dc->refcount );
|
2007-09-26 15:39:25 +00:00
|
|
|
release_dc_ptr( dc );
|
2007-08-31 13:58:38 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2016-06-21 05:52:43 +00:00
|
|
|
physDev = get_emf_physdev( find_dc_driver( dc, &emfdrv_driver ));
|
1999-05-02 10:15:16 +00:00
|
|
|
|
2005-10-31 10:05:52 +00:00
|
|
|
if(dc->saveLevel)
|
|
|
|
RestoreDC(hdc, 1);
|
|
|
|
|
2011-03-10 19:22:22 +00:00
|
|
|
if (physDev->dc_brush) DeleteObject( physDev->dc_brush );
|
|
|
|
if (physDev->dc_pen) DeleteObject( physDev->dc_pen );
|
2012-04-10 12:42:50 +00:00
|
|
|
if (physDev->screen_dc) DeleteDC( physDev->screen_dc );
|
2011-03-10 19:22:22 +00:00
|
|
|
|
1999-05-02 10:15:16 +00:00
|
|
|
emr.emr.iType = EMR_EOF;
|
|
|
|
emr.emr.nSize = sizeof(emr);
|
|
|
|
emr.nPalEntries = 0;
|
2008-05-07 11:34:12 +00:00
|
|
|
emr.offPalEntries = FIELD_OFFSET(EMREOF, nSizeLast);
|
1999-05-02 10:15:16 +00:00
|
|
|
emr.nSizeLast = emr.emr.nSize;
|
2016-06-21 05:52:43 +00:00
|
|
|
EMFDRV_WriteRecord( &physDev->dev, &emr.emr );
|
1999-05-02 10:15:16 +00:00
|
|
|
|
2000-04-14 14:07:51 +00: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 10:15:16 +00:00
|
|
|
if (physDev->hFile) /* disk based metafile */
|
|
|
|
{
|
2001-07-24 22:15:47 +00:00
|
|
|
if (SetFilePointer(physDev->hFile, 0, NULL, FILE_BEGIN) != 0)
|
|
|
|
{
|
|
|
|
CloseHandle( physDev->hFile );
|
2011-03-16 20:45:39 +00:00
|
|
|
free_dc_ptr( dc );
|
1999-05-02 10:15:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-26 10:01:12 +00:00
|
|
|
if (!WriteFile(physDev->hFile, physDev->emh, sizeof(*physDev->emh),
|
|
|
|
NULL, NULL))
|
2001-07-24 22:15:47 +00:00
|
|
|
{
|
|
|
|
CloseHandle( physDev->hFile );
|
2011-03-16 20:45:39 +00:00
|
|
|
free_dc_ptr( dc );
|
1999-05-02 10:15:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2000-02-16 22:47:24 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, physDev->emh );
|
1999-05-02 10:15:16 +00:00
|
|
|
hMapping = CreateFileMappingA(physDev->hFile, NULL, PAGE_READONLY, 0,
|
|
|
|
0, NULL);
|
2002-11-22 22:16:53 +00:00
|
|
|
TRACE("hMapping = %p\n", hMapping );
|
1999-05-02 10:15:16 +00:00
|
|
|
physDev->emh = MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0);
|
1999-06-26 19:09:08 +00:00
|
|
|
TRACE("view = %p\n", physDev->emh );
|
2001-07-24 22:15:47 +00:00
|
|
|
CloseHandle( hMapping );
|
|
|
|
CloseHandle( physDev->hFile );
|
1999-05-02 10:15:16 +00:00
|
|
|
}
|
|
|
|
|
2001-07-24 22:15:47 +00:00
|
|
|
hmf = EMF_Create_HENHMETAFILE( physDev->emh, (physDev->hFile != 0) );
|
1999-05-02 10:15:16 +00:00
|
|
|
physDev->emh = NULL; /* So it won't be deleted */
|
2011-03-16 20:45:39 +00:00
|
|
|
free_dc_ptr( dc );
|
1999-05-02 10:15:16 +00:00
|
|
|
return hmf;
|
|
|
|
}
|