1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
inline void MaptoGray(COLORREF & cr)
{
if ( (cr & 0xFF000000) != PALETTEINDEX(0) ) // not paletteindex
{
BYTE gray = ( GetRValue(cr) * 77 + GetGValue(cr) * 150 + GetBValue(cr) * 29 + 128 ) / 256;
cr = (cr & 0xFF000000) | RGB(gray, gray, gray);
}
}
class CGrayEMF : public CEnumEMF
{
// virtual function to process every EMF record, return 0 to terminate
virtual int ProcessRecord(HDC hDC, HANDLETABLE * pHTable, const ENHMETARECORD * pEMFR, int nObj)
{
int rslt;
switch ( pEMFR->iType )
{
case EMR_CREATEBRUSHINDIRECT:
{
EMRCREATEBRUSHINDIRECT cbi;
cbi = * (const EMRCREATEBRUSHINDIRECT *) pEMFR;
MaptoGray(cbi.lb.lbColor);
rslt = PlayEnhMetaFileRecord(hDC, pHTable, (const ENHMETARECORD *) & cbi, nObj);
}
break;
case EMR_CREATEPEN:
{
EMRCREATEPEN cp;
cp = * (const EMRCREATEPEN *) pEMFR;
MaptoGray(cp.lopn.lopnColor);
rslt = PlayEnhMetaFileRecord(hDC, pHTable, (const ENHMETARECORD *) & cp, nObj);
}
break;
case EMR_SETTEXTCOLOR:
case EMR_SETBKCOLOR:
{
EMRSETTEXTCOLOR stc;
stc = * (const EMRSETTEXTCOLOR *) pEMFR;
MaptoGray(stc.crColor);
rslt = PlayEnhMetaFileRecord(hDC, pHTable, (const ENHMETARECORD *) & stc, nObj);
}
break;
case EMR_RESERVED_105:
case EMR_RESERVED_106:
case EMR_RESERVED_107:
case EMR_RESERVED_108:
case EMR_RESERVED_109:
case EMR_RESERVED_110:
case EMR_RESERVED_119:
case EMR_RESERVED_120:
rslt = PlayEnhMetaFileRecord(hDC, pHTable, pEMFR, nObj);
break;
default:
rslt = PlayEnhMetaFileRecord(hDC, pHTable, pEMFR, nObj);
}
return rslt;
}
};
|