通过提取楷体的字形轮廓可以获得汉字笔画。只不过选⽤的字体必须是楷体。其他字体不⾏。 这功能没什么⽤途吧,我只是好玩⽽已。
int GetCharStrokes(UINT ch)chief是什么意思
{
HFONT hFont;
nally { // create font;
LOGFONT lfFont;
memt(&lfFont, 0, sizeof(lfFont));
lstrcpy(lfFont.lfFaceName, "楷体_GB2312");
lfFont.lfHeight = 72;
lfFont.lfWeight = FW_NORMAL;
lfFont.lfItalic = FALSE;
when there was me and you
amphetamine lfFont.lfStrikeOut = FALSE;
lfFont.lfCharSet = DEFAULT_CHARSET;
lfFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
lfFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lfFont.lfQuality = DRAFT_QUALITY;
lfFont.lfPitchAndFamily = DEFAULT_PITCH;
hFont = CreateFontIndirect(&lfFont);
}
HDC hDC = GetDC(NULL);
th if (hDC==NULL) return 0;
HGDIOBJ hOldFont = SelectObject(hDC,hFont);
MAT2 mat;
memt(&mat,0,sizeof(mat));
mat.eM11.value = 1;
mat.eM22.value = -1;
GLYPHMETRICS gm;
memt(&gm,0,sizeof(gm));
DWORD dwSize = GetGlyphOutline(hDC,ch,GGO_NATIVE,&gm,0,NULL,&mat);
int cnt = 0;
LPVOID pBuff = NULL;
if (dwSize>0)
6669
{
pBuff = malloc(dwSize);
wideband memt(&gm,0,sizeof(gm));
umts DWORD res = GetGlyphOutline(hDC,ch,GGO_NATIVE,&gm,dwSize,pBuff,&mat);
if (res!=dwSize)
{
free(pBuff);
pBuff = NULL;
}
}
if (pBuff)
{
BYTE * ptr = (BYTE *)pBuff;
while (dwSize>0)
{
TTPOLYGONHEADER * header = (TTPOLYGONHEADER *)ptr;
cnt ++;
ptr += header->cb;
美丽英文
dwSize -= header->cb;
}
free(pBuff);
}
SelectObject(hDC,hOldFont);intact是什么意思
ReleaDC(NULL,hDC);
return cnt;
}
测试:
union {
UINT ch;
char szText[4];
} a;
char * szText = "疆";
a.ch = 0;
a.szText[1] = szText[0];
a.szText[0] = szText[1];
int cnt = GetCharStrokes(a.ch);
TRACE("\"%s\"的笔画%d\n",szText,cnt); 运⾏结果:
"疆"的笔画19