void CtestdlgDlg::OnBnClickedButton6()
{
CDC * pDC;
CString cStr;
CHAR c;
GLYPHMETRICS GpMtic;
BYTE * pBuffer;
DWORD dwBufSize;
MAT2 mat;
CFont font;
CFont * pOldFont;
LOGFONT lf;
DWORD dwRetVal;
int x, y;
BOOL bBit;
c = 'X';
cStr = c;
pDC = this->GetWindowDC();
memset(&lf,0,sizeof(LOGFONT));
lf.lfHeight=180;
lstrcpy(lf.lfFaceName,_T("Times New Roman"));
font.CreateFontIndirect(&lf);
pOldFont = pDC->SelectObject(&font);
pDC->TextOut(0, 0, cStr);
NSys::IdleSleep(200);
memset(&GpMtic, 0, sizeof(GpMtic));
memset(&mat, 0, sizeof(mat));
mat.eM11.value = 1;
mat.eM22.value = 1;
pBuffer = NULL;
dwBufSize = 0;
dwRetVal = pDC->GetGlyphOutline(c, GGO_BITMAP, &GpMtic, dwBufSize, pBuffer, &mat);
if(dwRetVal == -1)
{
NMsg::MsgErr();
goto Done;
}
dwBufSize = dwRetVal;
pBuffer = new BYTE[dwBufSize];
memset(pBuffer, 0, dwBufSize);
dwRetVal = pDC->GetGlyphOutline(c, GGO_BITMAP, &GpMtic, dwBufSize, pBuffer, &mat);
if(dwRetVal == -1)
{
delete [] pBuffer;
goto Done;
}
int nWidth, nHeight;
BYTE *pData;
DWORD dwOneLine;
int dx, dy;
nWidth = GpMtic.gmBlackBoxX;
nHeight = GpMtic.gmBlackBoxY;
TEXTMETRIC TxtMtic;
pDC->GetTextMetrics(&TxtMtic);
dx = GpMtic.gmptGlyphOrigin.x;
dy = TxtMtic.tmAscent - GpMtic.gmptGlyphOrigin.y;
dwOneLine = (nWidth/8 + 3) / 4 * 4;
for(y=0; y<nHeight; y++)
{
for(x=0; x<nWidth; x++)
{
pData = pBuffer + dwOneLine*y + x/8;
bBit = *pData & (1 << 7-(x%8));
if(bBit)
pDC->SetPixel(x+dx, y+dy, RGB(255, 0, 0));
// else
// pDC->SetPixel(x+dx, y+dy, RGB(0, 255, 0));
}
}
delete [] pBuffer;
Done:
pDC->SelectObject(pOldFont);
this->ReleaseDC(pDC);
}