本人用以下代码获取TTF字符轮廓,用vc6运行成功,但是获得的点数太少。造成字体不太圆滑。求大神指点怎样增多获取的点数?
HDC hDC = pDC->GetSafeHdc();
//创建字体
CFont font;
VERIFY(font.CreateFont(m_iFontHeight, 0, 0, 0,FW_NORMAL, FALSE, FALSE, 0, ANSI_CHARSET,OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS,m_sFontFaceName));
CFont *pOldFont = pDC->SelectObject(&font);
//定义并初始化变换矩阵
MAT2 mat2;
memset(&mat2, 0, sizeof(mat2));
mat2.eM11 = 1;
mat2.eM22 = 1;
GLYPHMETRICS metrics; //保存字符相关信息
DWORD dwDataSize = 0; //初始化字符数据缓冲区大小
//……
//通过函数GetGlyphOutline()确定存储字符结构的空间
dwDataSize = pDC->GetGlyphOutline(nChar, GGO_NATIVE, &metrics, 0, NULL, &mat2);
if ((dwDataSize != 0) && (dwDataSize != GDI_ERROR))
{
//创建保存字符数据缓冲区大小
LPBYTE pPixels = new BYTE[dwDataSize];
ASSERT( pPixels != NULL );
TTPOLYGONHEADER pHeader = (TTPOLYGONHEADER)pPixels;
dwDataSize = pDC->GetGlyphOutline(nChar,GGO_NATIVE,&metrics, dwDataSize, pPixels, &mat2);
while(dwDataSize > 0)
{
//计算字符轮廓的起点,转换坐标
int xOld = MapFXY(pHeader->pfxStart.x);
int yOld = MapFXY(pHeader->pfxStart.y);
//根据TTF字体结构获取字符轮廓
::MoveToEx(hDC,iXpos + xOld,iYpos - yOld,NULL);
TTPOLYCURVE pCurrentCurve = (TTPOLYCURVE)(pHeader + 1);
int remainByte = pHeader->cb - sizeof(TTPOLYGONHEADER);
while (remainByte > 0)
{
CPoint lpPoint[1000];
CPoint bezi[2];
int index;
for (index = 0; index < pCurrentCurve->cpfx; ++index)
{
lpPoint[index].x = iXpos + MapFXY(pCurrentCurve->apfx[index].x);
lpPoint[index].y = iYpos - MapFXY(pCurrentCurve->apfx[index].y);
}
switch (pCurrentCurve->wType)
{
case TT_PRIM_LINE:
case TT_PRIM_QSPLINE:
for (index =0; index < pCurrentCurve->cpfx; index++)
{
::LineTo(hDC,lpPoint[index].x,lpPoint[index].y);
}
break;
default:
MessageBox(_T("字体不支持"));
break;
}
int count = sizeof(TTPOLYCURVE) + (pCurrentCurve->cpfx -1)*sizeof(POINTFX);
pCurrentCurve = (TTPOLYCURVE*)((char*)pCurrentCurve + count);
remainByte -= count;
}
::LineTo(hDC,iXpos + xOld, iYpos - yOld);
dwDataSize -= pHeader->cb;
pHeader = (TTPOLYGONHEADER*)((char*)pHeader + pHeader->cb);
}
delete [] pPixels;
}
}