Exemple #1
0
HENHMETAFILE CxImageWMF::ConvertEmfFiletoEmf(CxFile *pFile, ENHMETAHEADER *pemfh)
{
	HENHMETAFILE	hMeta;
	long iLen = pFile->Size();

	BYTE* pBuff = (BYTE *)malloc(iLen);
	if (!pBuff)	return (FALSE);

	// Read the Enhanced Metafile
	long iLenRead = pFile->Read(pBuff, 1, iLen);
	if (iLenRead != iLen) {
		free(pBuff);
		return (FALSE);
	}

	// Make it a Memory Metafile
	hMeta = SetEnhMetaFileBits(iLen, pBuff);

	free(pBuff);	// finished with this one

	if (!hMeta)	return (FALSE);	// oops.

	// Get the Enhanced Metafile Header
	UINT uRet = GetEnhMetaFileHeader(hMeta,					// handle of enhanced metafile 
								sizeof(ENHMETAHEADER),	// size of buffer, in bytes 
								pemfh); 					// address of buffer to receive data  
  
	if (!uRet) {
		DeleteEnhMetaFile(hMeta);
		return (FALSE);
	}

	return (hMeta);
}
Exemple #2
0
BOOL CFemmplotDoc::GrabMetafile()
{
	if (IsClipboardFormatAvailable(CF_ENHMETAFILE)==FALSE){
		hMetaPlot=NULL;
		return FALSE;
	
	}
	if (OpenClipboard(NULL)==FALSE)
		MsgBox("Cannot access the Clipboard");
	else{
		HENHMETAFILE hMetaClip = (HENHMETAFILE) GetClipboardData(CF_ENHMETAFILE);
		HGLOBAL hBound = (HGLOBAL) GetClipboardData(CF_TEXT);
		if(hMetaClip==NULL)
		{
			MsgBox("Couldn't GetClipboardData");
		}
		else{
			DWORD len =(DWORD) GetEnhMetaFileBits(hMetaClip,NULL,NULL);
			unsigned char *buff=(unsigned char *) malloc(len);
			if(GetEnhMetaFileBits(hMetaClip,len,buff)==0)
				MsgBox("MetaFile not copied");
			hMetaPlot=SetEnhMetaFileBits(len,buff);
			if(hBound!=NULL){
				sscanf((char *) hBound,"%lf %lf %lf %lf",
					&bb_left,&bb_bottom,&bb_right,&bb_top);
				HasBoundingBox=TRUE;
			}
			EmptyClipboard();
		}

		CloseClipboard();
	}
	
	return TRUE;
}
int DoMyControlProcessing(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam,INT_PTR *bReturn)
{
	switch(message) {
		case WM_INITDIALOG:
			EnumChildWindows(hdlg,MyControlsEnumChildren,0);
			if(hEmfHeaderLogo==NULL) {
				HRSRC hRsrc=FindResourceA(hInst,MAKEINTRESOURCEA(IDE_HDRLOGO),"EMF");
				HGLOBAL hGlob=LoadResource(hInst,hRsrc);
				hEmfHeaderLogo=SetEnhMetaFileBits(SizeofResource(hInst,hRsrc),(PBYTE)LockResource(hGlob));
			}
			SendDlgItemMessage(hdlg,IDC_HDRLOGO,STM_SETIMAGE,IMAGE_ENHMETAFILE,(LPARAM)hEmfHeaderLogo);
			break;
		case WM_CTLCOLORSTATIC:
			if((GetWindowLong((HWND)lParam,GWL_STYLE)&0xFFFF)==0) {
				char szText[256];
				GetWindowTextA((HWND)lParam,szText,sizeof(szText));
				if(!strcmp(szText,"whiterect")) {
					SetTextColor((HDC)wParam,RGB(255,255,255));
					SetBkColor((HDC)wParam,RGB(255,255,255));
					SetBkMode((HDC)wParam,OPAQUE);
					*bReturn=(INT_PTR)GetStockObject(WHITE_BRUSH);
					return TRUE;
				}
				else {
					SetBkMode((HDC)wParam,TRANSPARENT);
					*bReturn=(INT_PTR)GetStockObject(NULL_BRUSH);
					return TRUE;
				}
			}
			break;
	}
	return FALSE;
}
Exemple #4
0
// load an EMF attached as a resource, use RCDATA as type
HENHMETAFILE LoadEMF(HMODULE hModule, LPCTSTR pName)
{
	HRSRC hRsc       = FindResource(hModule, pName, RT_RCDATA);
		
	if ( hRsc==NULL )
		return NULL;

	HGLOBAL hResData = LoadResource(hModule, hRsc);
	LPVOID  pEmf     = LockResource(hResData);

	return SetEnhMetaFileBits(SizeofResource(hModule, hRsc), (const BYTE *) pEmf);
}
int CMetafileDisplay::LoadBits(UINT uiBuf, LPVOID pBuf)
{
#pragma pack(2)
typedef struct 
{
	DWORD   key;
	WORD	hmf;
	short	left;
	short	top;
	short	right;
	short	bottom;
	WORD    inch;
	DWORD	reserved;
	WORD    checksum;
} AMETAHEADER;
#pragma pack()

	if (enhMF != NULL)
	{
		DeleteEnhMetaFile(enhMF);
		enhMF = NULL;
	}

	// See if this is an enhanced metafile
	ENHMETAHEADER *emhdr = (ENHMETAHEADER *)pBuf;
	if (uiBuf >= sizeof(ENHMETAHEADER)
	 && emhdr->iType == EMR_HEADER
	 && emhdr->dSignature == ENHMETA_SIGNATURE)
	{
		enhMF = SetEnhMetaFileBits(uiBuf, (CONST BYTE *)pBuf);
	}
	else if (uiBuf >= sizeof(METAHEADER))
	{
		METAFILEPICT mp = {MM_ANISOTROPIC, 1000, 1000, NULL};
		AMETAHEADER *ahdr = (AMETAHEADER *)pBuf;
		METAHEADER *mhdr = (METAHEADER *)pBuf;
		// See if this is a placeable metafile
		if (ahdr->key == 0x9AC6CDD7)
		{
			mp.xExt = ((LONG)(ahdr->right - ahdr->left) * 25401) / (LONG)ahdr->inch;
			mp.yExt = ((LONG)(ahdr->bottom - ahdr->top) * 25401) / (LONG)ahdr->inch;
			mhdr = (METAHEADER *) (ahdr + 1);
		}
		UINT uiSizeMF = (UINT) mhdr->mtSize * 2;
		HDC dcRef = ::GetDC(NULL);
		enhMF = SetWinMetaFileBits(uiSizeMF, (LPBYTE)mhdr, dcRef, &mp);
		::ReleaseDC(NULL, dcRef);
	}

	return (enhMF == NULL) ? -1 : 0;
}
Exemple #6
0
INT_PTR CALLBACK WelcomeDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    static HENHMETAFILE hEmfWatermark;
    static HFONT hTitleFont;

    INT_PTR bReturn;
    if (DoMyControlProcessing(hdlg, message, wParam, lParam, &bReturn))
        return bReturn;

    switch (message) {
    case WM_INITDIALOG:
    {
        HRSRC hRsrcWatermark = FindResourceA(hInst, MAKEINTRESOURCEA(IDE_WATERMARK), "EMF");
        HGLOBAL hGlobWatermark = LoadResource(hInst, hRsrcWatermark);
        hEmfWatermark = SetEnhMetaFileBits(SizeofResource(hInst, hRsrcWatermark), (PBYTE)LockResource(hGlobWatermark));
    }
    SendDlgItemMessage(hdlg, IDC_WATERMARK, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)hEmfWatermark);
    {
        NONCLIENTMETRICS ncm = { 0 };
        ncm.cbSize = sizeof(ncm);
        SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
        LOGFONT TitleLogFont = ncm.lfMessageFont;
        TitleLogFont.lfWeight = FW_BOLD;
        mir_tstrcpy(TitleLogFont.lfFaceName, TEXT("Verdana Bold"));

        HDC hdc = GetDC(NULL);
        INT FontSize = 12;
        TitleLogFont.lfHeight = 0 - GetDeviceCaps(hdc, LOGPIXELSY) * FontSize / 72;
        hTitleFont = CreateFontIndirect(&TitleLogFont);
        ReleaseDC(NULL, hdc);
    }
    SendDlgItemMessage(hdlg, IDC_TITLE, WM_SETFONT, (WPARAM)hTitleFont, 0);
    EnableWindow(GetDlgItem(GetParent(hdlg), IDC_BACK), FALSE);
    return FALSE;

    case WM_COMMAND:
        switch (LOWORD(wParam)) {
        case IDOK:
            PostMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_SELECTDB, (LPARAM)SelectDbDlgProc);
            break;
        }
        break;

    case WM_DESTROY:
        DeleteEnhMetaFile(hEmfWatermark);
        DeleteObject(hTitleFont);
        break;
    }
    return FALSE;
}
Exemple #7
0
unsigned char * __RPC_USER HENHMETAFILE_UserUnmarshal(unsigned long *pFlags, unsigned char *pBuffer, HENHMETAFILE *phEmf)
{
    ULONG fContext;

    TRACE("("); dump_user_flags(pFlags); TRACE(", %p, %p\n", pBuffer, phEmf);

    fContext = *(ULONG *)pBuffer;
    pBuffer += sizeof(ULONG);

    if (((fContext == WDT_INPROC_CALL) && (sizeof(*phEmf) < 8)) ||
        ((fContext == WDT_INPROC64_CALL) && (sizeof(*phEmf) == 8)))
    {
        *phEmf = *(HENHMETAFILE *)pBuffer;
        pBuffer += sizeof(*phEmf);
    }
    else if (fContext == WDT_REMOTE_CALL)
    {
        ULONG handle;

        handle = *(ULONG *)pBuffer;
        pBuffer += sizeof(ULONG);

        if (handle)
        {
            ULONG size;
            size = *(ULONG *)pBuffer;
            pBuffer += sizeof(ULONG);
            if (size != *(ULONG *)pBuffer)
            {
                RaiseException(RPC_X_BAD_STUB_DATA, 0, 0, NULL);
                return pBuffer;
            }
            pBuffer += sizeof(ULONG);
            *phEmf = SetEnhMetaFileBits(size, pBuffer);
            pBuffer += size;
        }
        else 
            *phEmf = NULL;
    }
    else
        RaiseException(RPC_S_INVALID_TAG, 0, 0, NULL);

    return pBuffer;
}
Exemple #8
0
HENHMETAFILE CxImageWMF::ConvertEmfFiletoEmf(CxFile *pFile, ENHMETAHEADER *pemfh)
{
	HENHMETAFILE	hMeta;
	long iLen = pFile->Size();

	// Check the header first: <km>
	long pos = pFile->Tell();
	long iLenRead = pFile->Read(pemfh, 1, sizeof(ENHMETAHEADER));
	if (iLenRead < sizeof(ENHMETAHEADER))         return NULL;
	if (pemfh->iType != EMR_HEADER)               return NULL;
	if (pemfh->dSignature != ENHMETA_SIGNATURE)   return NULL;
	//if (pemfh->nBytes != (DWORD)iLen)             return NULL;
	pFile->Seek(pos,SEEK_SET);

	BYTE* pBuff = (BYTE *)malloc(iLen);
	if (!pBuff)	return (FALSE);

	// Read the Enhanced Metafile
	iLenRead = pFile->Read(pBuff, 1, iLen);
	if (iLenRead != iLen) {
		free(pBuff);
		return NULL;
	}

	// Make it a Memory Metafile
	hMeta = SetEnhMetaFileBits(iLen, pBuff);

	free(pBuff);	// finished with this one

	if (!hMeta)	return NULL;	// oops.

	// Get the Enhanced Metafile Header
	UINT uRet = GetEnhMetaFileHeader(hMeta,				// handle of enhanced metafile 
								sizeof(ENHMETAHEADER),	// size of buffer, in bytes 
								pemfh); 				// address of buffer to receive data  
  
	if (!uRet) {
		DeleteEnhMetaFile(hMeta);
		return NULL;
	}

	return (hMeta);
}
Exemple #9
0
static BOOL ClipboardReadEnhMetafile(HANDLE hFile, DWORD dwOffset, DWORD dwLength)
{
    HENHMETAFILE hEmf;
    HGLOBAL hData;
    LPVOID lpData;

    hData = ClipboardReadMemoryBlock(hFile, dwOffset, dwLength);
    if (!hData)
    {
        return FALSE;
    }

    lpData = GlobalLock(hData);
    if (!lpData)
    {
        GlobalFree(hData);
        return FALSE;
    }

    hEmf = SetEnhMetaFileBits(dwLength, lpData);

    GlobalUnlock(hData);
    GlobalFree(hData);

    if (!hEmf)
    {
        SetLastError(ERROR_OUTOFMEMORY);
        return FALSE;
    }

    if (!SetClipboardData(CF_ENHMETAFILE, hEmf))
    {
        DeleteEnhMetaFile(hEmf);
        return FALSE;
    }

    return TRUE;
}
Exemple #10
0
BOOL CFemmplotDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{
	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;
	
	// clear out any old metafile;
	DeleteEnhMetaFile(hMetaPlot);
	HasBoundingBox=FALSE;
	HENHMETAFILE hMetaPlotFile = GetEnhMetaFile(lpszPathName);
	if (hMetaPlotFile!=NULL){
		DWORD len =(DWORD) GetEnhMetaFileBits(hMetaPlotFile,NULL,NULL);
		unsigned char *buff=(unsigned char *) malloc(len);
		if(GetEnhMetaFileBits(hMetaPlotFile,len,buff)==0)
			MsgBox("MetaFile not copied");
		hMetaPlot=SetEnhMetaFileBits(len,buff);
	}
	else MsgBox("Problem opening specified file");

	DeleteEnhMetaFile(hMetaPlotFile);

	// TODO: Add your specialized creation code here
	
	return TRUE;
}
void PLWEMFDecoder::Open (PLDataSource * pDataSrc)
{
	PLASSERT_VALID(this);
  PLASSERT(m_bm == 0);
  PLASSERT(m_memdc == 0);
  PLASSERT(m_hemf == 0);

	SAPMFILEHEADER* pplaceablehdr = NULL;
	bool isadobe = false;
      bool isemf;

	// Get the type of the file (WMF or EMF) from the file name
      if (pDataSrc->NameIsWide()){
        wchar_t* strname = _wcsdup(pDataSrc->GetNameW());
        PLASSERT(strname);
        if (strname == NULL) {
                // This should never happen under 32-Bit, but who knows?
                PLASSERT(false);
                raiseError (PL_ERRNO_MEMORY,"Out of memory during strdup.");
        }
        _wcsupr(strname);
        isemf = wcsstr(strname,L".EMF") != NULL;
        free(strname);
      }
      else{
	char* strname = _strdup(pDataSrc->GetName());
	PLASSERT(strname);
	if (strname == NULL) {
		// This should never happen under 32-Bit, but who knows?
		PLASSERT(false);
		raiseError (PL_ERRNO_MEMORY,"Out of memory during strdup.");
	}
	_strupr(strname);
	bool isemf = strstr(strname,".EMF") != NULL;
	free(strname);
      }

	// Get a DC for the display
	m_dc = ::GetDC(NULL);
	PLASSERT(m_dc);
	if (m_dc == NULL) {
		PLASSERT(false);
		raiseError (PL_ERRNO_MEMORY,"Cannot allocate device context.");
	}

	if (isemf) {
		// We have an enhanced meta file which makes it alot easier
		m_hemf = SetEnhMetaFileBits(pDataSrc->GetFileSize(),pDataSrc->ReadEverything());
	}
	else {
		// Buh, old 16-Bit WMF, Convert it to an enhanced metafile before proceeding.
		// Also, check if this is a placeable metafile with an Adobe Placeable header
		pplaceablehdr = (SAPMFILEHEADER*)pDataSrc->ReadEverything();
		PLBYTE* p = NULL;
		UINT size;
		// If we have an adobe header, skip it to use only the real windows-conform data
		if (pplaceablehdr->key == ALDUSKEY) {
			isadobe = true;
			p = pDataSrc->ReadEverything()+sizeof(SAPMFILEHEADER);
			size = pDataSrc->GetFileSize() - sizeof(SAPMFILEHEADER);
		}
		else {
			// Else use the whole file contents as the metafile and assume
			// a native 16-Bit Windows-conform WMF
			p = pDataSrc->ReadEverything();
			size = pDataSrc->GetFileSize();
		}
		#ifdef _MFC_VER
		PLASSERT(AfxIsValidAddress(p,size,false));
		#endif
		m_hemf = SetWinMetaFileBits(size,p,m_dc,NULL);
	}

	// If m_hemf is NULL, windows refused to load the metafile. If this is
	// the case, we're done. Notify the caller
	if (m_hemf == NULL) {
		raiseError (PL_ERRFORMAT_NOT_SUPPORTED,"Windows Metafile functions failed to load this image.");
	}

	// Get the header from the enhanced metafile, It contains some
	// useful information which will aid us during constuction of
	// the bitmap.
	// The header is of variable length. First get the amount of
	//  memory required for the header
	UINT sizeneeded = GetEnhMetaFileHeader(m_hemf,0,NULL);
	if (sizeneeded == 0) {
		raiseError (PL_ERRFORMAT_UNKNOWN,"No header information in metafile");
	}

	// Allocate storage for the header and read it in
	m_phdr = (LPENHMETAHEADER) new PLBYTE[sizeneeded];
	if (m_phdr == NULL) {
		PLASSERT(false);
		raiseError (PL_ERRNO_MEMORY,"Out of memory during allocation of header.");
	}
	m_phdr->iType = EMR_HEADER;
	m_phdr->nSize = sizeneeded;
	#ifdef _MFC_VER
	PLASSERT(AfxIsValidAddress(m_phdr,sizeneeded,true));
	#endif
	GetEnhMetaFileHeader(m_hemf,sizeneeded,m_phdr);

	int bpp = GetDeviceCaps(m_dc,BITSPIXEL);

	// Calculate the dimensions of the final bitmap. If we have
	// a placeable header in the WMF, we use the dimensions of
	// that image, else we use the calculated dimensions in the
	// EMF
	int width,height;
	if (isadobe) {
		PLASSERT(pplaceablehdr);
		int lpx = GetDeviceCaps(m_dc,LOGPIXELSX);
		int lpy = GetDeviceCaps(m_dc,LOGPIXELSY);
		// Calculate the absolute with and height and transform from twips to pixel
		width  = (int) (pplaceablehdr->Right-pplaceablehdr->Left) * lpx / pplaceablehdr->inch;
		height = (int) (pplaceablehdr->Bottom-pplaceablehdr->Top) * lpy / pplaceablehdr->inch;
	}
	else {
		// Use the rclFrame of the header because it is the true device independent
		// information and also some applications (e.g. Corel) don't fill the
		// rclBounds correctly
		// Using:
		//     MetaPixelsX = MetaWidthMM * MetaPixels / (MetaMM * 100);
		// where:
		//     MetaWidthMM = metafile width in 0.01mm units
		//     MetaPixels  = width in pixels of the reference device
		//     MetaMM      = width in millimeters of the reference device
		// Same applies to the Y axis
		width  = ((m_phdr->rclFrame.right  - m_phdr->rclFrame.left) * m_phdr->szlDevice.cx) / (m_phdr->szlMillimeters.cx*100);
		height = ((m_phdr->rclFrame.bottom  - m_phdr->rclFrame.top) * m_phdr->szlDevice.cy) / (m_phdr->szlMillimeters.cy*100);
	}

	// If this is a very old WMF without a PLACEABLE info,
	// we use somewhat meaningful defaults. Also, if the header was
	// not written correctly, we use this as a fallback
	if (width <= 0) {
		width = 320;
	}
	if (height <= 0) {
		height = 200;
	}

	// Create a device content for the screen, and a memory device
	// content to play the metafile to

	m_memdc = CreateCompatibleDC(m_dc);
	PLASSERT(m_memdc);
	if (m_memdc == NULL) {
		PLASSERT(false);
		raiseError (PL_ERRNO_MEMORY,"Cannot allocate device context.");
	}

	m_bm = CreateCompatibleBitmap(m_dc,width,height);
	if (m_bm == NULL) {
		PLASSERT(false);
		raiseError (PL_ERRNO_MEMORY,"Cannot allocate memory bitmap.");
	}

	m_holdbm = SelectObject(m_memdc,m_bm);

	// If the metafile has a palette, read it in
	UINT pe = GetEnhMetaFilePaletteEntries(m_hemf, 0, NULL);

	// pe is the real number of palette entries. To make the resulting
	// bitmap more useful, we always setup a 256 color palette if the
	// metafile has a palette
  if (pe>0 && pe<256)
  {
    SetBmpInfo (PLPoint (width, height), PLPoint(0,0), 
             PLPixelFormat::L8);
	}
	else 
  {
    SetBmpInfo (PLPoint (width, height), PLPoint(0,0), 
            PLPixelFormat::B8G8R8A8);
  }
}
Exemple #12
0
PyObject *
PyImaging_DrawWmf(PyObject* self, PyObject* args)
{
    HBITMAP bitmap;
    HENHMETAFILE meta;
    BITMAPCOREHEADER core;
    HDC dc;
    RECT rect;
    PyObject* buffer = NULL;
    char* ptr;

    char* data;
    int datasize;
    int width, height;
    int x0, y0, x1, y1;
    if (!PyArg_ParseTuple(args, PY_ARG_BYTES_LENGTH"(ii)(iiii):_load", &data, &datasize,
                          &width, &height, &x0, &x1, &y0, &y1))
        return NULL;

    /* step 1: copy metafile contents into METAFILE object */

    if (datasize > 22 && GET32(data, 0) == 0x9ac6cdd7) {

        /* placeable windows metafile (22-byte aldus header) */
        meta = SetWinMetaFileBits(datasize-22, data+22, NULL, NULL);

    } else if (datasize > 80 && GET32(data, 0) == 1 &&
               GET32(data, 40) == 0x464d4520) {

        /* enhanced metafile */
        meta = SetEnhMetaFileBits(datasize, data);

    } else {

        /* unknown meta format */
        meta = NULL;

    }

    if (!meta) {
        PyErr_SetString(PyExc_IOError, "cannot load metafile");
        return NULL;
    }

    /* step 2: create bitmap */

    core.bcSize = sizeof(core);
    core.bcWidth = width;
    core.bcHeight = height;
    core.bcPlanes = 1;
    core.bcBitCount = 24;

    dc = CreateCompatibleDC(NULL);

    bitmap = CreateDIBSection(
        dc, (BITMAPINFO*) &core, DIB_RGB_COLORS, &ptr, NULL, 0
        );

    if (!bitmap) {
        PyErr_SetString(PyExc_IOError, "cannot create bitmap");
        goto error;
    }

    if (!SelectObject(dc, bitmap)) {
        PyErr_SetString(PyExc_IOError, "cannot select bitmap");
        goto error;
    }

    /* step 3: render metafile into bitmap */

    rect.left = rect.top = 0;
    rect.right = width;
    rect.bottom = height;

    /* FIXME: make background transparent? configurable? */
    FillRect(dc, &rect, GetStockObject(WHITE_BRUSH));

    if (!PlayEnhMetaFile(dc, meta, &rect)) {
        PyErr_SetString(PyExc_IOError, "cannot render metafile");
        goto error;
    }

    /* step 4: extract bits from bitmap */

    GdiFlush();

    buffer = PyBytes_FromStringAndSize(ptr, height * ((width*3 + 3) & -4));

error:
    DeleteEnhMetaFile(meta);

    if (bitmap)
        DeleteObject(bitmap);

    DeleteDC(dc);

    return buffer;
}
Exemple #13
0
// =========   private helper functions
// ------------------------------------------
HENHMETAFILE COXMetaFile::LoadFile(LPVOID lpvData)
{	
	unsigned long lSize;
	ALDUSHEADER* pAldusMF;
    LPENHMETAHEADER pemh =(LPENHMETAHEADER) lpvData;
	ENHMETAHEADER EnhMetaHeader;

	if(m_hEMF)
	{
		DeleteEnhMetaFile(m_hEMF);
		m_hEMF=NULL;
	}

	// get size, if it makes sense
	// Obtain a handle to a reference device context  
	HDC hdcRef=::GetDC(NULL);  
	// Determine the picture frame dimensions. 
	// iWidthMM is the display width in millimeters. 
	// iHeightMM is the display height in millimeters. 
	// iWidthPels is the display width in pixels. 
	// iHeightPels is the display height in pixels  
	int iWidthMM=GetDeviceCaps(hdcRef,HORZSIZE); 
	int iHeightMM=GetDeviceCaps(hdcRef,VERTSIZE); 
	int iWidthPels=GetDeviceCaps(hdcRef,HORZRES); 
	int iHeightPels=GetDeviceCaps(hdcRef,VERTRES);  
	::ReleaseDC(NULL,hdcRef);


    // ============== 1) is it an enhanced MetaFile ==================================
	if(pemh->dSignature == META32_SIGNATURE) 
	{
		TRACE(_T("it's an Enhanced MetaFile\n"));
		lSize = pemh->nBytes;
		m_hEMF = SetEnhMetaFileBits(lSize,(CONST BYTE*) lpvData) ;
		m_strDescription.Empty();
		// MetaFileHeader lesen
		if(m_hEMF)
		{	
			GetEnhMetaFileHeader(m_hEMF,sizeof(EnhMetaHeader),&EnhMetaHeader);
			m_rectNormalized.SetRect(EnhMetaHeader.rclFrame.left, 
				EnhMetaHeader.rclFrame.top,EnhMetaHeader.rclFrame.right, 
				EnhMetaHeader.rclFrame.bottom);
			m_rectBounds.SetRect((m_rectNormalized.left*iWidthPels)/(iWidthMM*100),
				(m_rectNormalized.top*iHeightPels)/(iHeightMM*100),
				(m_rectNormalized.right*iWidthPels)/(iWidthMM*100),
				(m_rectNormalized.bottom*iHeightPels)/(iHeightMM*100));
			if(EnhMetaHeader.nDescription>0)
			{
				GetEnhMetaFileDescription(m_hEMF, EnhMetaHeader.nDescription, 
				m_strDescription.GetBufferSetLength(EnhMetaHeader.nDescription));
				m_strDescription.ReleaseBuffer();
			}
			else
				m_strDescription.Empty();

		}
		m_metafileType=OXMETAFILE_ENHANCED;
		return m_hEMF;
	}

	// ===============2) is is an Aldus MetaFile ==================================
	// If it has an ALDUS header skip it
    // Notice: APMSIZE is used instead of sizeof(ALDUSHEAD) because the 
	//	HANDLE and RECT of the structure
    //         depends on the environment and the align value
    if(*((LPDWORD)lpvData) == ALDUS_ID) 
	{	
		TRACE(_T("It's an Aldus MetaFile\n"));
		pAldusMF =(ALDUSHEADER*) lpvData;
        lSize = *((LPDWORD)((PBYTE)lpvData + APMSIZE + 6));
        // Notice: mtSize is size of the file in word.
        // if LPMETAFILEPICT is NULL
        //    MM_ANISOTROPIC mode and default device size will be used.
        m_hEMF=::SetWinMetaFileBits(lSize*2L,(PBYTE)lpvData+APMSIZE,NULL,NULL);
		VERIFY(m_strDescription.LoadString(IDS_OX_METAFILEALDUS)); //"WMF - Aldus Format"
		if(!m_hEMF) 
		{ 
			TRACE(_T("Error in SetWinMetaFileBits in Aldus MetaFile\n"));
			return 0L;
		}
		m_rectNormalized.SetRect(0,0,
			((pAldusMF->right-pAldusMF->left)*2540)/((int)pAldusMF->inch),
			((pAldusMF->bottom-pAldusMF->top)*2540)/((int)pAldusMF->inch));
		m_rectBounds.SetRect((m_rectNormalized.left*iWidthPels)/(iWidthMM*100),
			(m_rectNormalized.top*iHeightPels)/(iHeightMM*100),
			(m_rectNormalized.right*iWidthPels)/(iWidthMM*100),
			(m_rectNormalized.bottom*iHeightPels)/(iHeightMM*100));

		m_metafileType=OXMETAFILE_ALDUS;
		return m_hEMF;
    }
	// ================== 3) old Windows MetaFile ========================
    TRACE(_T("I try old Windows 3x MetaFile\n"));
	lSize = *((LPDWORD)((PBYTE)lpvData + 6));
    m_hEMF=::SetWinMetaFileBits(lSize*2L,(PBYTE)lpvData , NULL, NULL);
	VERIFY(m_strDescription.LoadString(IDS_OX_METAFILEWINDOWS)) ; //"Windows 3.x MetaFile"
	m_rectBounds.SetRect(0,0,::GetSystemMetrics(SM_CXSCREEN), 
		::GetSystemMetrics(SM_CYSCREEN));
	m_rectNormalized.SetRect(0,0,
		(m_rectBounds.Width()*iWidthMM*100)/iWidthPels,
		(m_rectBounds.Height()*iHeightMM*100)/iHeightPels);
	if(!m_hEMF) 
	{
	   TRACE(_T("Error on SetWinMetaFileBits in old windows MetaFile\n"));
	}
	else
		m_metafileType=OXMETAFILE_WIN16;
	return m_hEMF;
}
Exemple #14
0
BOOL __stdcall pvdFileOpen2(void *pContext, const wchar_t *pFileName, INT64 lFileSize, const BYTE *pBuf, UINT32 lBuf, pvdInfoImage2 *pImageInfo)
{
	_ASSERTE(pImageInfo->cbSize >= sizeof(pvdInfoImage2));

	WmfContext *pw = (WmfContext*)CALLOC(sizeof(WmfContext));
	if (!pw) {
		pImageInfo->nErrNumber = PWE_NOT_ENOUGH_MEMORY;
		return FALSE;
	}
	//pw->h = GetEnhMetaFile ( pFileName+4 );

	const wchar_t *p = GetExtension(pFileName);
	if (!p) {
		pImageInfo->nErrNumber = PWE_NO_EXTENSION;
		return FALSE;
	}

	pImageInfo->nErrNumber = PWE_WIN32_ERROR; // заранее

	//if (pImageInfo->PreferredSize.cx && pImageInfo->PreferredSize.cy) {
	//	pw->PreferredSize = pImageInfo->PreferredSize;
	//} else {
	pw->PreferredSize.cx = 1000; pw->PreferredSize.cy = 1000;
	//}

	// First try to read it as an enhanced metafile
	// If it works, simply return the handle
	pw->h = SetEnhMetaFileBits(lBuf, pBuf);
	gnLastWin32Error = GetLastError();

	if (!pw->h) {
		pw->h = GetEnhMetaFile( pFileName );
		gnLastWin32Error = GetLastError();
	}

	if (!pw->h) {
		HMETAFILE		hOld;
		DWORD			dwSize;
		LPBYTE			pBits;
		METAFILEPICT	mp;
		HDC				hDC;

		if( (hOld = GetMetaFile( pFileName )) != NULL )
		{
			// Ok, it is a 16bit windows metafile
			// How big are the bits?
			if( (dwSize = GetMetaFileBitsEx( hOld, 0, NULL )) == 0 )
			{
				gnLastWin32Error = GetLastError();
				DeleteMetaFile( hOld );
				//MessageBox( hWndParent, "Failed to Get MetaFile Bits Size", "Error Reading MetaFile", MB_OK );
			} else {
				// Allocate that much memory
				if( (pBits = (LPBYTE)CALLOC( dwSize )) == NULL )
				{
					pImageInfo->nErrNumber = PWE_NOT_ENOUGH_MEMORY;
					gnLastWin32Error = GetLastError();
					DeleteMetaFile( hOld );
					//MessageBox( hWndParent, "Failed to Allocate Memory for Metafile Bits", "Error Reading MetaFile", MB_OK );
					//return NULL;
				} else {
					// Get the metafile bits
					if( GetMetaFileBitsEx( hOld, dwSize, pBits ) == 0 )
					{
						gnLastWin32Error = GetLastError();
						FREE( pBits );
						DeleteMetaFile( hOld );
						//MessageBox( hWndParent, "Failed to Get MetaFile Bits", "Error Reading MetaFile", MB_OK );
						//return NULL;
					} else {
						// Fill out a METAFILEPICT structure
						mp.mm = MM_ANISOTROPIC;
						mp.xExt = 1000;
						mp.yExt = 1000;
						mp.hMF = NULL;
						// Get a reference DC
						hDC = GetDC( NULL );
						// Make an enhanced metafile from the windows metafile
						pw->h = SetWinMetaFileBits( dwSize, pBits, hDC, &mp );
						gnLastWin32Error = GetLastError();
						// Clean up
						ReleaseDC( NULL, hDC );
						DeleteMetaFile( hOld );
						FREE( pBits );
					}
				}
			}
		}
	}

	if (!pw->h) {
		DWORD			dwSize = lBuf;
		LPBYTE			pBits = (LPBYTE)pBuf;
		METAFILEPICT	mp;
		HDC				hDC;

		// Is it a placeable metafile? (check the key)
		if( ((PAPMHEADER)pBits)->dwKey != 0x9ac6cdd7l )
		{
			// Not a metafile that we know how to recognise - bail out
			//MessageBox( hWndParent, "Not a Valid Metafile", szFileName, MB_OK );
			//return NULL;
			pImageInfo->nErrNumber = PWE_NOT_VALID_METAFILE;
		} else {
			// Ok, its a placeable metafile
			// Fill out a METAFILEPICT structure
			mp.mm = MM_ANISOTROPIC;
			mp.xExt = ((PAPMHEADER)pBits)->bbox.Right - ((PAPMHEADER)pBits)->bbox.Left;
			mp.xExt = ( mp.xExt * 2540l ) / (DWORD)(((PAPMHEADER)pBits)->wInch);
			mp.yExt = ((PAPMHEADER)pBits)->bbox.Bottom - ((PAPMHEADER)pBits)->bbox.Top;
			mp.yExt = ( mp.yExt * 2540l ) / (DWORD)(((PAPMHEADER)pBits)->wInch);
			mp.hMF = NULL;
			// Get a reference DC
			hDC = GetDC( NULL );
			// Create an enhanced metafile from the bits
			pw->h = SetWinMetaFileBits( dwSize, &(pBits[sizeof(APMHEADER)]), hDC, &mp );
			gnLastWin32Error = GetLastError();
			// Clean up
			ReleaseDC( NULL, hDC );
			//free( pBits );
			//if( hTemp == NULL )
			//	MessageBox( hWndParent, "Failed to Create MetaFile from Bits", "Error Reading MetaFile", MB_OK );
			//return hTemp;
		}
	}

	//if (pw->h) {
	//	//pw->hCompDC = CreateCompatibleDC(NULL);
	//	pw->mfp.mm = MM_ISOTROPIC;
	//	pw->mfp.xExt = pw->PreferredSize.cx;
	//	pw->mfp.yExt = pw->PreferredSize.cy;
	//	pw->h = (HENHMETAFILE)SetMetaFileBitsEx (lBuf, pBuf);
	//	gnLastWin32Error = GetLastError();
	//	pw->h = SetWinMetaFileBits(lBuf, pBuf, NULL, NULL); //pw->hCompDC, &pw->mfp);
	//	gnLastWin32Error = GetLastError();
	//}

	if (!pw->h) {
		//gnLastWin32Error = GetLastError(); -- уже
		FREE(pw);
		return FALSE;
	}

	pw->AddRef();
	_ASSERTE(pw->nRefCount == 1);

	ENHMETAHEADER	emh = {0};
	DWORD			PixelsX, PixelsY, MMX, MMY;
	emh.nSize = sizeof(ENHMETAHEADER);
	if( GetEnhMetaFileHeader( pw->h, sizeof( ENHMETAHEADER ), &emh ) )
	{
		// Get the characteristics of the output device
		HDC hDC = GetDC(NULL);
		PixelsX = GetDeviceCaps( hDC, HORZRES );
		PixelsY = GetDeviceCaps( hDC, VERTRES );
		MMX = GetDeviceCaps( hDC, HORZSIZE ) * 100;
		MMY = GetDeviceCaps( hDC, VERTSIZE ) * 100;
		ReleaseDC(NULL, hDC);

		// Calculate the rect in which to draw the metafile based on the
		// intended size and the current output device resolution
		// Remember that the intended size is given in 0.01mm units, so
		// convert those to device units on the target device
		//pw->PreferredSize.cx = (int)((float)(emh.rclFrame.right - emh.rclFrame.left) * PixelsX / (MMX));
		//pw->PreferredSize.cy = (int)((float)(emh.rclFrame.bottom - emh.rclFrame.top) * PixelsY / (MMY));
		pw->PreferredSize.cx = ip.MulDivI32((emh.rclFrame.right - emh.rclFrame.left), PixelsX, MMX);
		pw->PreferredSize.cy = ip.MulDivI32((emh.rclFrame.bottom - emh.rclFrame.top), PixelsY, MMY);
		_ASSERTE(pw->PreferredSize.cx>0 && pw->PreferredSize.cy>0);
		if (pw->PreferredSize.cx < 0) pw->PreferredSize.cx = -pw->PreferredSize.cx;
		if (pw->PreferredSize.cy < 0) pw->PreferredSize.cy = -pw->PreferredSize.cy;
	}

	pImageInfo->pImageContext = pw;
	pImageInfo->nPages = 1;
	pImageInfo->Flags = 0;
	pImageInfo->pFormatName = L"WMF";
	pImageInfo->pCompression = NULL;
	pImageInfo->pComments = NULL;

	return TRUE;
}
GpStatus METAFILE_GraphicsDeleted(GpMetafile* metafile)
{
    GpStatus stat;

    stat = METAFILE_WriteEndOfFile(metafile);
    metafile->record_graphics = NULL;

    metafile->hemf = CloseEnhMetaFile(metafile->record_dc);
    metafile->record_dc = NULL;

    heap_free(metafile->comment_data);
    metafile->comment_data = NULL;
    metafile->comment_data_size = 0;

    if (stat == Ok)
    {
        MetafileHeader header;

        stat = GdipGetMetafileHeaderFromEmf(metafile->hemf, &header);
        if (stat == Ok && metafile->auto_frame &&
            metafile->auto_frame_max.X >= metafile->auto_frame_min.X)
        {
            RECTL bounds_rc, gdi_bounds_rc;
            REAL x_scale = 2540.0 / header.DpiX;
            REAL y_scale = 2540.0 / header.DpiY;
            BYTE* buffer;
            UINT buffer_size;

            bounds_rc.left = floorf(metafile->auto_frame_min.X * x_scale);
            bounds_rc.top = floorf(metafile->auto_frame_min.Y * y_scale);
            bounds_rc.right = ceilf(metafile->auto_frame_max.X * x_scale);
            bounds_rc.bottom = ceilf(metafile->auto_frame_max.Y * y_scale);

            gdi_bounds_rc = header.EmfHeader.rclBounds;
            if (gdi_bounds_rc.right > gdi_bounds_rc.left && gdi_bounds_rc.bottom > gdi_bounds_rc.top)
            {
                bounds_rc.left = min(bounds_rc.left, gdi_bounds_rc.left);
                bounds_rc.top = min(bounds_rc.top, gdi_bounds_rc.top);
                bounds_rc.right = max(bounds_rc.right, gdi_bounds_rc.right);
                bounds_rc.bottom = max(bounds_rc.bottom, gdi_bounds_rc.bottom);
            }

            buffer_size = GetEnhMetaFileBits(metafile->hemf, 0, NULL);
            buffer = heap_alloc(buffer_size);
            if (buffer)
            {
                HENHMETAFILE new_hemf;

                GetEnhMetaFileBits(metafile->hemf, buffer_size, buffer);

                ((ENHMETAHEADER*)buffer)->rclFrame = bounds_rc;

                new_hemf = SetEnhMetaFileBits(buffer_size, buffer);

                if (new_hemf)
                {
                    DeleteEnhMetaFile(metafile->hemf);
                    metafile->hemf = new_hemf;
                }
                else
                    stat = OutOfMemory;

                heap_free(buffer);
            }
            else
                stat = OutOfMemory;

            if (stat == Ok)
                stat = GdipGetMetafileHeaderFromEmf(metafile->hemf, &header);
        }
        if (stat == Ok)
        {
            metafile->bounds.X = header.X;
            metafile->bounds.Y = header.Y;
            metafile->bounds.Width = header.Width;
            metafile->bounds.Height = header.Height;
        }
    }

    if (stat == Ok && metafile->record_stream)
    {
        BYTE *buffer;
        UINT buffer_size;

        buffer_size = GetEnhMetaFileBits(metafile->hemf, 0, NULL);

        buffer = heap_alloc(buffer_size);
        if (buffer)
        {
            HRESULT hr;

            GetEnhMetaFileBits(metafile->hemf, buffer_size, buffer);

            hr = IStream_Write(metafile->record_stream, buffer, buffer_size, NULL);

            if (FAILED(hr))
                stat = hresult_to_status(hr);

            heap_free(buffer);
        }
        else
            stat = OutOfMemory;
    }

    if (metafile->record_stream)
    {
        IStream_Release(metafile->record_stream);
        metafile->record_stream = NULL;
    }

    return stat;
}
Exemple #16
0
/*
 * clipboard_bytes_to_data - バイト列をデータに変換
 */
HANDLE clipboard_bytes_to_data(TCHAR *format_name, const BYTE *data, DWORD *size)
{
	HANDLE ret = NULL;
	BYTE *to_mem;

	if (data == NULL) {
		return NULL;
	}
	switch (clipboard_get_format(0, format_name)) {
	case CF_PALETTE:
		// パレット
		ret = CreatePalette((LOGPALETTE *)data);
		break;

	case CF_DSPBITMAP:
	case CF_BITMAP:
		// ビットマップ
		ret = dib_to_bitmap(data);
		break;

	case CF_OWNERDISPLAY:
		break;

	case CF_DSPMETAFILEPICT:
	case CF_METAFILEPICT:
		// メタファイル
		if ((ret = GlobalAlloc(GHND, sizeof(METAFILEPICT))) == NULL) {
			break;
		}
		if ((to_mem = GlobalLock(ret)) == NULL) {
			GlobalFree(ret);
			ret = NULL;
			break;
		}

		CopyMemory(to_mem, data, sizeof(METAFILEPICT));
		if ((((METAFILEPICT *)to_mem)->hMF = SetMetaFileBitsEx(*size - sizeof(METAFILEPICT), data + sizeof(METAFILEPICT))) == NULL) {
			GlobalUnlock(ret);
			GlobalFree(ret);
			ret = NULL;
			break;
		}
		GlobalUnlock(ret);
		break;

	case CF_DSPENHMETAFILE:
	case CF_ENHMETAFILE:
		ret = SetEnhMetaFileBits(*size, data);
		break;

	default:
		// その他
		// コピー先確保
		if ((ret = GlobalAlloc(GHND, *size)) == NULL) {
			return NULL;
		}
		// コピー先ロック
		if ((to_mem = GlobalLock(ret)) == NULL) {
			GlobalFree(ret);
			return NULL;
		}
		// コピー
		CopyMemory(to_mem, data, *size);
		// ロック解除
		GlobalUnlock(ret);
		break;
	}
	return ret;
}
Exemple #17
0
// Создает (или возвращает уже созданный) HDC (CompatibleDC) для mp_BkImgData
bool CBackground::PutPluginBackgroundImage(/*CBackground* pBack,*/ LONG X, LONG Y, LONG Width, LONG Height)
{
	if (!this) return NULL;

	_ASSERTE(isMainThread());

	// Сразу
	mb_BkImgChanged = FALSE;

	/*if (mb_BkImgDelete && mp_BkImgData)
	{
		free(mp_BkImgData); mp_BkImgData = NULL;
		mb_BkImgExist = FALSE;
		return false;
	}*/
	if (!mb_BkImgExist)
		return false;

	MSectionLock SC;
	SC.Lock(mcs_BkImgData, FALSE);

	if (mb_BkEmfChanged)
	{
		// Сразу сброс
		mb_BkEmfChanged = FALSE;

		if (!mp_BkEmfData)
		{
			_ASSERTE(mp_BkEmfData!=NULL);
			return false;
		}

		// Нужно перекинуть EMF в mp_BkImgData
		BITMAPINFOHEADER bi = mp_BkEmfData->bi;
		size_t nBitSize = bi.biWidth*bi.biHeight*sizeof(COLORREF);
		size_t nWholeSize = sizeof(CESERVER_REQ_SETBACKGROUND)+nBitSize; //-V103 //-V119
		if (!mp_BkImgData || (mn_BkImgDataMax < nWholeSize))
		{
			if (mp_BkImgData)
				free(mp_BkImgData);
			mp_BkImgData = (CESERVER_REQ_SETBACKGROUND*)malloc(nWholeSize);
			if (!mp_BkImgData)
			{
				_ASSERTE(mp_BkImgData!=NULL);
				return false;
			}
		}

		*mp_BkImgData = *mp_BkEmfData;
		mp_BkImgData->bmp.bfType = 0x4D42/*BM*/;
		mp_BkImgData->bmp.bfSize = nBitSize+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); //-V119

		// Теперь нужно сформировать DIB и нарисовать в нем EMF
		HDC hScreen = GetDC(NULL);
		//RECT rcMeta = {0,0, mn_BkImgWidth, mn_BkImgHeight}; // (in pixels)
		//RECT rcMetaMM = {0,0, mn_BkImgWidth*10, mn_BkImgHeight*10}; // (in .01-millimeter units)
		//HDC hdcEmf = CreateEnhMetaFile(NULL, NULL, &rcMetaMM, L"ConEmu\0Far Background\0\0");
		//if (!hdcEmf)
		//{
		//	_ASSERTE(hdcEmf!=NULL);
		//	return;
		//}

		HDC hdcDib = CreateCompatibleDC(hScreen);
		if (!hdcDib)
		{
			_ASSERTE(hdcDib!=NULL);
			//DeleteEnhMetaFile(hdcEmf);
			return false;
		}
		COLORREF* pBits = NULL;
		HBITMAP hDib = CreateDIBSection(hScreen, (BITMAPINFO*)&bi, DIB_RGB_COLORS, (void**)&pBits, NULL, 0);
		ReleaseDC(NULL, hScreen); hScreen = NULL;
		if (!hDib || !pBits)
		{
			_ASSERTE(hDib && pBits);
			return false;
		}

		HBITMAP hOld = (HBITMAP)SelectObject(hdcDib, hDib);

		size_t nBitsSize = bi.biWidth*bi.biHeight*sizeof(COLORREF);
		// Залить черным - по умолчанию
		#ifdef _DEBUG
			memset(pBits, 128, nBitSize);
		#else
			memset(pBits, 0, nBitsSize);
		#endif

		DWORD nEmfBits = mp_BkEmfData->bmp.bfSize - sizeof(BITMAPFILEHEADER) - sizeof(BITMAPINFOHEADER);
		LPBYTE pEmfBits = (LPBYTE)(mp_BkEmfData+1);
		HENHMETAFILE hdcEmf = SetEnhMetaFileBits(nEmfBits, pEmfBits);
		RECT rcPlay = {0,0, bi.biWidth, bi.biHeight};
		DWORD nPlayErr = 0;
		if (hdcEmf)
		{
			#ifdef _DEBUG
			ENHMETAHEADER	emh = {0};
			DWORD			PixelsX, PixelsY, MMX, MMY, cx, cy;
			emh.nSize = sizeof(ENHMETAHEADER);
			if( GetEnhMetaFileHeader( hdcEmf, sizeof( ENHMETAHEADER ), &emh ) )
			{
				// Get the characteristics of the output device
				HDC hDC = GetDC(NULL);
				PixelsX = GetDeviceCaps( hDC, HORZRES );
				PixelsY = GetDeviceCaps( hDC, VERTRES );
				MMX = GetDeviceCaps( hDC, HORZSIZE ) * 100;
				MMY = GetDeviceCaps( hDC, VERTSIZE ) * 100;
				ReleaseDC(NULL, hDC);

				// Calculate the rect in which to draw the metafile based on the
				// intended size and the current output device resolution
				// Remember that the intended size is given in 0.01mm units, so
				// convert those to device units on the target device
				cx = (int)((float)(emh.rclFrame.right - emh.rclFrame.left) * PixelsX / (MMX));
				cy = (int)((float)(emh.rclFrame.bottom - emh.rclFrame.top) * PixelsY / (MMY));
				//pw->PreferredSize.cx = ip.MulDivI32((emh.rclFrame.right - emh.rclFrame.left), PixelsX, MMX);
				//pw->PreferredSize.cy = ip.MulDivI32((emh.rclFrame.bottom - emh.rclFrame.top), PixelsY, MMY);
				_ASSERTE(cx>0 && cy>0);
				//if (pw->PreferredSize.cx < 0) pw->PreferredSize.cx = -pw->PreferredSize.cx;
				//if (pw->PreferredSize.cy < 0) pw->PreferredSize.cy = -pw->PreferredSize.cy;
				//rcPlay = MakeRect(emh.rclBounds.left,emh.rclBounds.top,emh.rclBounds.right,emh.rclBounds.bottom);
			}
			#endif

			if (!PlayEnhMetaFile(hdcDib, hdcEmf, &rcPlay))
			{
				nPlayErr = GetLastError();
				_ASSERTE(FALSE && (nPlayErr == 0));
			}

			GdiFlush();
			memmove(mp_BkImgData+1, pBits, nBitSize);
		}
		UNREFERENCED_PARAMETER(nPlayErr);

		SelectObject(hdcDib, hOld);
		DeleteObject(hDib);
		DeleteDC(hdcDib);
		if (hdcEmf)
		{
			DeleteEnhMetaFile(hdcEmf);
		}
		else
		{
			return false;
		}
	}

	if (!mp_BkImgData)
	{
		// Нужен ли тут? Или допустимая ситуация?
		_ASSERTE(mp_BkImgData!=NULL);
		return false;
	}

	bool lbFade = false;

	if (gpSet->isFadeInactive && !gpConEmu->isMeForeground(false))
		lbFade = true;

	bool lbRc = FillBackground(&mp_BkImgData->bmp, X, Y, Width, Height, eUpLeft, lbFade);

	//mb_BkImgChanged = FALSE;
	return lbRc;
}
Exemple #18
0
// main entry for decompiling from a memory buffer
bool KEmfDC::DeCompileBuffer(const TCHAR * outfilename, const void * buffer, KTreeView * pTree, HENHMETAFILE & hEmf)
{
	const EMR * emr = (const EMR *) buffer;
	
	// if not normal EMF file
	while ( ! IsEMFHeader(emr) )
	{
		if ( IsEMFHeader(emr+1) )
		{
			emr ++;

			if ( hEmf==NULL )
				hEmf = SetEnhMetaFileBits(emr[-1].nSize, (const BYTE *) emr);
			
			break;
		}
		else
			emr = (const EMR *) ( ( const char * ) emr + emr->nSize );
	}

	const ENHMETAHEADER * pHeader = (const ENHMETAHEADER *) emr;
	
	if ( pTree==NULL )
	{
		fmt.Open(outfilename);

		HRSRC hRsc = FindResource(hModule, MAKEINTRESOURCE(IDR_PRE), RT_RCDATA);
		
		if ( hRsc )
		{
			HGLOBAL hResData  = LoadResource(hModule, hRsc);
			const char * pPgm = (const char *) LockResource(hResData);

			fmt.Write(pPgm);
		}

		fmt.Indent(1);
		fmt.Newline(); fmt.Write("HGDIOBJ hObj["); fmt.WriteDec((long) pHeader->nHandles); fmt.Write("] = { NULL };");
		fmt.Newline();
	}
	m_nSeq = 1;

	bool bOptimize = false;

	// enumuerate all EMF records
	while ( (emr->iType>=EMR_MIN) && (emr->iType<=EMR_MAX) )
	{
		bool rslt = true;

		if ( bOptimize )
		{
			const EMR * next = (const EMR *) ( ( const char * ) emr + emr->nSize );

			if ( next->iType == emr->iType )
				switch ( emr->iType )
				{
					case EMR_SETWINDOWORGEX:
					case EMR_SETWINDOWEXTEX:
					case EMR_SETVIEWPORTORGEX:
					case EMR_SETVIEWPORTEXTEX:
					case EMR_SETTEXTCOLOR:
					case EMR_SETBKCOLOR:
					case EMR_SETBRUSHORGEX:
					case EMR_SELECTCLIPPATH:
					case EMR_SETTEXTALIGN:
	    
					case EMR_SETBKMODE:
					case EMR_SETARCDIRECTION:
					case EMR_SETPOLYFILLMODE:
					case EMR_SETMAPMODE:
					case EMR_SETSTRETCHBLTMODE:
					case EMR_SETMAPPERFLAGS:
					case EMR_SETICMMODE:
					case EMR_SETROP2:

					case EMR_SETMITERLIMIT:
					case EMR_SETWORLDTRANSFORM:
					case EMR_MOVETOEX:
						fmt.Write("/* */");
						break;
				
					default:
						rslt = Decode(emr, pTree);
				}
			else 
				rslt = Decode(emr, pTree);
		}
		else
			rslt = Decode(emr, pTree);
		
		if (! rslt ) 
			break;

		if ( emr->iType== EMR_EOF )
			break;

		emr = (const EMR *) ( ( const char * ) emr + emr->nSize );
	}
	
	if ( pTree==NULL )
	{
		fmt.Indent(-1);

		HRSRC hRsc = FindResource(hModule, MAKEINTRESOURCE(IDR_POST), RT_RCDATA);
		
		if ( hRsc )
		{
			HGLOBAL hResData  = LoadResource(hModule, hRsc);
			const char * pPgm = (const char *) LockResource(hResData);

			fmt.Write(pPgm);
		}

		fmt.Close();
	}
	
	return true;
}