近周练习用QT取文字的点阵,用了扫描方法、字库方法效果总不理想,再在终于找到一种和WIN API函数可取字模的方法,效果很好。
可问题出来了,WIN API好多参数都是传句柄的,且句柄又是不同类型,不知在QT中怎处理。
如取字模中我用到下面两个API函数:
HFONT CreateFont(
int nHeight, // height of font
int nWidth, // average character width
int nEscapement, // angle of escapement
int nOrientation, // base-line orientation angle
int fnWeight, // font weight
DWORD fdwItalic, // italic attribute option
DWORD fdwUnderline, // underline attribute option
DWORD fdwStrikeOut, // strikeout attribute option
DWORD fdwCharSet, // character set identifier
DWORD fdwOutputPrecision, // output precision
DWORD fdwClipPrecision, // clipping precision
DWORD fdwQuality, // output quality
DWORD fdwPitchAndFamily, // pitch and family
LPCTSTR lpszFace // typeface name
);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
DWORD GetGlyphOutline(
HDC hdc, // handle to DC
UINT uChar, // character to query
UINT uFormat, // data format
LPGLYPHMETRICS lpgm, // glyph metrics
DWORD cbBuffer, // size of data buffer
LPVOID lpvBuffer, // data buffer
CONST MAT2 *lpmat2 // transformation matrix
);
我的思路是,首先CreateFont中建立
字体,然后GetGlyphOutline根据CreateFont中建立的字体取出点阵数据存在lpvBuffer中,
照这样,问题出来了:
1、我能不能直接用QFont 表示HFONT ,用时即是 QFont font = CreateFont(.........)
2.、CreateFont中最后一个参数LPCTSTR lpszFace ,要求是字体类型,我传字符串QString m_lpszFace= "Arial",中m_lpszFace过去,会出现类型不正确错误.那么我应该用什么类型表示字体
3、GetGlyphOutline中要求一个HDC hdc句柄,这个句柄我从哪来呢?如我想直接将CreateFont建设立的HFONT作为句柄传过来,行不行的呢?我试了,行不通的。
主要就是上面三个问题了,下面是别人用VC取字模的一些资料,我也只是一知半解:
http://blog.csdn.net/caimouse/archive/2007/12/16/1941978.aspxhttp://www.vckbase.com/document/viewdoc/?id=1614http://www.vckbase.com/document/viewdoc/?id=1757