📄 meta.hpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// This source code is licensed under Microsoft Shared Source License
// Version 1.0 for Windows CE.
// For a copy of the license visit http://go.microsoft.com/fwlink/?LinkId=3223.
//
#include "gdiobj.h"
#include "engine.h"
//
// Misc replacements from random NT headers. These items may not
// live through the porting process.
//
//
// Semi-private helper function for SelectClipRgn. Also
// called by metafile code.
//
extern const RECT g_rectEmpty;
//
// From \NT\private\ntos\w32\ntgdi\inc\hmgshare.h
//
//
// status flags used by metafile in user and kernel
//
#define MRI_ERROR 0
#define MRI_NULLBOX 1
#define MRI_OK 2
//
// From \NT\private\ntos\w32\ntgdi\client\local.h
//
VOID CopyCoreToInfoHeader(LPBITMAPINFOHEADER pbmih,LPBITMAPCOREHEADER pbmch);
#define NEG_INFINITY 0x80000000
#define POS_INFINITY 0x7fffffff
//
// Check if a source is needed in a 3-way bitblt operation.
// This works on both rop and rop3. We assume that a rop contains zero
// in the high byte.
//
// This is tested by comparing the rop result bits with source (column A
// below) vs. those without source (column B). If the two cases are
// identical, then the effect of the rop does not depend on the source
// and we don't need a source device. Recall the rop construction from
// input (pattern, source, target --> result):
//
// P S T | R A B mask for A = 0CCh
// ------+-------- mask for B = 33h
// 0 0 0 | x 0 x
// 0 0 1 | x 0 x
// 0 1 0 | x x 0
// 0 1 1 | x x 0
// 1 0 0 | x 0 x
// 1 0 1 | x 0 x
// 1 1 0 | x x 0
// 1 1 1 | x x 0
#define ISSOURCEINROP3(rop3) \
(((rop3) & 0xCCCC0000) != (((rop3) << 2) & 0xCCCC0000))
#define HdcFromIhdc(i) ((HDC)GdiHandleTable_t::HANDLE_FROM_INDEX_ONLY(i))
#define PmdcFromIhdc(i) PmdcFromHdc(HdcFromIhdc(i))
/**************************************************************************\
*
* LINK stuff
*
\**************************************************************************/
#define INVALID_INDEX 0xffffffff
#define LINK_HASH_SIZE 128
// H_INDEX was ((USHORT)(h)), but SH-3 compiler generates bad code!
#define H_INDEX(h) ((USHORT)(((DWORD)(h)) & 0xffff))
#define LINK_HASH_INDEX(h) (H_INDEX(h) & (LINK_HASH_SIZE-1))
typedef struct tagLINK
{
DWORD metalink;
struct tagLINK *plinkNext;
HANDLE hobj;
} LINK, *PLINK;
extern PLINK aplHash[LINK_HASH_SIZE];
PLINK plinkGet(HANDLE h);
PLINK plinkCreate(HANDLE h,ULONG ulSize);
BOOL bDeleteLink(HANDLE h);
void CleanEnhMetaFileRecords(PBYTE);
//
// Get RECTL et al.
//
/**************************************************************************\
*
* <----------------------------------------------\
* hash \
* \
* +-----+ |
* 0| I16 | metalink16 |
* 1| | |
* 2| | +--------+ +--------+ |
* 3| |------>|idc/iobj| /->|metalink| |
* 4| | |hobj | / |hobj | |
* 5| | |pmlNext |---/ |pmlNext |--/ |
* | | |16bit mf| |16bit mf| |
* .| | +--------+ +--------+ |
* .| | | |
* .| | | |
* | | /--/ |
* n-1| | / |
* +-----+ | |
* | LDC(idc) MDC |
* | |
* \->+--------+ +--------+ MHE[iobj] |
* | | | | |
* | | /->| | +--------+ |
* | | / | | |hobj |---/
* |pmdc |--/ |pmhe |-->|idc/iobj|
* +--------+ | | +--------+
* +--------+
*
*
*
\**************************************************************************/
typedef struct tagMETALINK16
{
DWORD metalink;
struct tagMETALINK16 *pmetalink16Next;
HANDLE hobj;
//
// WARNING: fields before this must match the LINK structure.
//
DWORD cMetaDC16;
HDC ahMetaDC16[1];
} METALINK16, *PMETALINK16;
#define pmetalink16Get(h) ((PMETALINK16) plinkGet(h))
#define pmetalink16Create(h) ((PMETALINK16)plinkCreate(h,sizeof(METALINK16)))
#define bDeleteMetalink16(h) bDeleteLink(h)
/*************************************************************************\
* Module Name: metapriv.h
*
* This file contains metafile-related definitions that are public
* in NT GDI, but are private in MGDI.
*
* These definitions came from wingdi.h, and may have been **modified**.
* Do **not** assume that structs which have the same name (in NT and MGDI)
* have the same members!
\*************************************************************************/
//
// Stock object flag used in the object handle index in the enhanced
// metafile records.
// E.g. The object handle index (META_STOCK_OBJECT | BLACK_BRUSH)
// represents the stock object BLACK_BRUSH.
//
#define ENHMETA_STOCK_OBJECT 0x80000000
//
// EMR is the base record type for enhanced metafiles.
//
typedef struct tagEMR
{
DWORD iType; // Enhanced metafile record type
DWORD nSize; // Length of the record in bytes.
// This must be a multiple of 4.
int yTop; // Clipping info
int yBottom; // Clipping info
} EMR, *PEMR;
//
// Record structures for the enhanced metafile.
//
typedef struct tagEMRRESTOREDC
{
EMR emr;
LONG iRelative; // Specifies a relative instance
} EMRRESTOREDC, *PEMRRESTOREDC;
/* Enhanced Metafile structures */
typedef struct tagENHMETARECORD
{
DWORD iType; // Record type EMR_XXX
DWORD nSize; // Record size in bytes
int yTop; // Clipping info
int yBottom; // Clipping info
DWORD dParm[1]; // Parameters
} ENHMETARECORD, *PENHMETARECORD, *LPENHMETARECORD;
typedef struct tagENHMETAHEADER
{
DWORD iType; // Record type EMR_HEADER
DWORD nSize; // Record size in bytes. This may be greater
// than the sizeof(ENHMETAHEADER).
int yTop; // Clipping info
int yBottom; // Clipping info
DWORD nBytes; // Size of the metafile in bytes
DWORD nRecords; // Number of records in the metafile
WORD nHandles; // Number of handles in the handle table
// Handle index zero is reserved.
} ENHMETAHEADER, *PENHMETAHEADER;
#define MDC_IDENTIFIER 0x0043444D /* 'MDC' */
#define MF_IDENTIFIER 0x0000464D /* 'MF' */
BOOL bMetaResetDC(HDC hdc);
/*********************************Class************************************\
* class METALINK
*
* Define a link for metafile friends.
*
* A metafile link begins with the metalink field of the LHE entry of an
* object. If there is no link, this field is zero. Otherwise, it begins
* with a 16-bit metafile object-link, whose first element points to the
* begining of the METALINK link list.
*
* The 16-bit metafile object-link should be created as necessary when the
* first METALINK is created. It should be removed as necessary when the
* last METALINK is removed.
*
* We assume that the imhe object index cannot be zero. Otherwise, bValid()
* will not work.
*
* History:
* Wed Jul 31 21:09:28 1991 -by- Hock San Lee [hockl]
* Wrote it.
\**************************************************************************/
class METALINK
{
public:
USHORT imhe; // MHE index of object of next friend.
USHORT ihdc; // Local index of metafile DC of next friend.
public:
//
// Constructor -- This one is to allow METALINKs inside other classes.
//
METALINK() {}
//
// Constructor -- Fills the METALINK.
//
METALINK(USHORT imhe_, USHORT ihdc_)
{
imhe = imhe_;
ihdc = ihdc_;
}
METALINK(PMETALINK16 pmetalink16)
{
if (*(PULONG) this = (ULONG)pmetalink16)
*(PULONG) this = pmetalink16->metalink;
}
//
// Destructor -- Does nothing.
//
~METALINK() {}
//
// Initializer -- Initialize the METALINK.
//
VOID vInit(USHORT imhe_, USHORT ihdc_)
{
imhe = imhe_;
ihdc = ihdc_;
}
VOID vInit(ULONG metalink)
{
imhe = ((METALINK *) &metalink)->imhe;
ihdc = ((METALINK *) &metalink)->ihdc;
}
VOID vInit(PMETALINK16 pmetalink16)
{
if (*(PULONG) this = (ULONG)pmetalink16)
*(PULONG) this = pmetalink16->metalink;
}
//
// operator ULONG -- Return the long equivalent value.
//
operator ULONG() { return(*(PULONG) this); }
//
// bValid -- Is this a valid metalink?
// imhe object index cannot be zero.
//
BOOL bValid()
{
ASSERT(*(PULONG) this == 0L || imhe != 0);
return(*(PULONG) this != 0L);
}
//
// bEqual -- does this metalink refer to imhe and hdc?
//
BOOL bEqual(USHORT imhe_, USHORT ihdc_)
{
return(imhe == imhe_ && ihdc == ihdc_);
}
//
// vNext -- Update *this to the next metalink.
//
VOID vNext();
//
// pmetalinkNext -- Return the pointer to the next metalink.
//
METALINK * pmetalinkNext();
};
typedef METALINK *PMETALINK;
/*********************************Class************************************\
* class MHE
*
* Define a Metafile Handle Entry. Our Metafile Handle Table is an array
* of these. The MHT is used to keep track of object handles at record time.
*
* Note that the first entry (index zero) is reserved. See METALINK comment.
*
* History:
* Wed Jul 31 21:09:28 1991 -by- Hock San Lee [hockl]
* Wrote it.
\**************************************************************************/
class MHE
{
public:
HANDLE lhObject; // Handle to the GDI object.
METALINK metalink; // Links to the next "metafile friend".
// Also links the free list.
};
typedef MHE *PMHE;
//
// Metafile Handle Table size
//
#define MHT_HANDLE_SIZE 1024
#define MHT_MAX_HANDLE_SIZE ((unsigned) 0xFFFF) // ENHMETAHEADER.nHandles is a USHORT.
//
// Metafile palette initial size and increment
//
#define MF_PALETTE_SIZE 256
//
// Metafile memory buffer size
//
#define MF_BUFSIZE_INIT (16*1024)
#define MF_BUFSIZE_INC (16*1024)
//
// Metafile DC flags
//
#define MDC_FATALERROR 0x0002 // Fatal error in recording.
/*********************************Class************************************\
* class MDC
*
* Metafile DC structure.
*
* There is no constructor or destructor for this object. We do the
* initialization in pmdcAllocMDC and cleanup in vFreeMDC.
*
* History:
* Wed Jul 17 17:10:28 1991 -by- Hock San Lee [hockl]
* Wrote it.
\**************************************************************************/
//
// Enhanced metafile record types.
//
// Since we don't need to be compatible with the standard Win32, this list
// has been renumbered to yield a contiguous set of values. This means
// that these EMR_xxx values are different than on the desktop!
//
#define EMR_HEADER 1
#define EMR_POLYGON 2
#define EMR_POLYLINE 3
#define EMR_SETBRUSHORGEX 4
#define EMR_EOF 5
#define EMR_SETPIXELV 6
#define EMR_SETBKMODE 7
#define EMR_SETROP2 8
#define EMR_SETTEXTCOLOR 9
#define EMR_SETBKCOLOR 10
#define EMR_EXCLUDECLIPRECT 11
#define EMR_INTERSECTCLIPRECT 12
#define EMR_SAVEDC 13
#define EMR_RESTOREDC 14
#define EMR_SELECTOBJECT 15
#define EMR_CREATEPEN 16
#define EMR_DELETEOBJECT 17
#define EMR_FOCUSRECT 18
#define EMR_ELLIPSE 19
#define EMR_RECTANGLE 20
#define EMR_ROUNDRECT 21
#define EMR_DRAWEDGE 22
#define EMR_SELECTPALETTE 23
#define EMR_CREATEPALETTE 24
#define EMR_SETPALETTEENTRIES 25
#define EMR_REALIZEPALETTE 26
#define EMR_FILLRGN 27
#define EMR_EXTSELECTCLIPRGN 28
#define EMR_BITBLT 29
#define EMR_STRETCHBLT 30
#define EMR_MASKBLT 31
#define EMR_EXTCREATEFONTINDIRECTW 32
#define EMR_EXTTEXTOUTW 33
#define EMR_CREATEDIBPATTERNBRUSHPT 34
#define EMR_SMALLTEXTOUT 35
#define EMR_SETVIEWPORTORGEX 36
#define EMR_TRANSPARENTIMAGE 37
#define EMR_CREATEBRUSHINDIRECT 38
#define EMR_SETTEXTALIGN 39
#define EMR_MOVETOEX 40
#define EMR_STRETCHDIBITS 41
#define EMR_SETDIBITSTODEVICE 42
#define EMR_SETLAYOUT 43
#define EMR_ALPHABLEND 44
#define EMR_GRADFILL 45
#define EMR_SETTEXTCHARACTEREXTRA 46
#define EMR_FILLRECT 47
#define EMR_MIN 1
#define EMR_MAX 47
class MDC
{
friend class METALINK;
friend HENHMETAFILE WINAPI CloseEnhMetaFile_I(HDC hdc);
friend MDC * pmdcAllocMDC(HDC hdcRef);
friend VOID vFreeMDC(MDC *pmdc);
friend ULONG imheAllocMHE(HDC hdc, HANDLE lhObject);
friend VOID vFreeMHE(HDC hdc, ULONG imhe);
friend BOOL MF_DeleteObject(HANDLE h);
friend BOOL MF_RealizePalette(HPALETTE hpal);
friend BOOL MF_SetPaletteEntries(HPALETTE hpal, UINT iStart, UINT cEntries,
CONST PALETTEENTRY *pPalEntries);
private:
#ifdef DEBUG
ULONG ident; // Identifier 'MDC'
#endif
HANDLE hMem; // Handle to the memory metafile/buffer.
ULONG nMem; // Size of the memory buffer.
ULONG iMem; // Current memory index pointer.
BOOL fFatalError; // Fatal error occurred?
ENHMETAHEADER mrmf; // MRMETAFILE record.
ULONG cmhe; // Size of the metafile handle table.
ULONG imheFree; // Identifies a free MHE index.
PMHE pmhe; // Metafile handle table.
public:
HDC hdcRef; // Info DC associated with metafile
public:
//
// pvNewRecord -- Allocate a metafile record from memory buffer.
// Also set the size field in the metafile record. If a fatal error
// has occurred, do not allocate new record.
//
void * pvNewRecord(DWORD nSize);
//
// vUpdateNHandles -- Update number of handles in the metafile
// header record.
//
VOID vUpdateNHandles(ULONG imhe)
{
ASSERT(imhe < (ULONG) MHT_MAX_HANDLE_SIZE && HIWORD(imhe) == 0);
if (mrmf.nHandles < (WORD) (imhe + 1))
mrmf.nHandles = (WORD) (imhe + 1); // imhe is zero based.
}
//
// bFatalError -- Have we encountered a fatal error?
//
BOOL bFatalError() { return fFatalError; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -