很重要的图
(1)首先是读取字模的函数
GetGlyphOutline
函数原型:DWORD GetGlyphOutline(HDC hdc, UINT uChar, UINT uFormat, LPGLYPHMETRICS lpgm, DWORD cbBuffer, LPVOID lpvBuffer, CONST MAT2 *lpmat2);
UINT gmBlackBoxX; //指定完全包围字体结构的最小矩阵的宽度
UINT gmBlackBoxY; //指定完全包围字体结构的最小矩阵的高度
POINT gmptGlyphOrigin; //指定完全包围字体结构的最小矩阵左上角的点坐标
short gmCellIncX; //指定当前的起点到下一个字符的起点的水平距离
short gmCellIncY; //指定当前的起点到下一个字符的起点的垂直距离
} GLYPHMETRICS, *LPGLYPHMETRICS;
FIXED eM11; FIXED eM12; FIXED eM21; FIXED eM22; } MAT2, *LPMAT2;
-
A fixed-point value for the M11 component of a 3 by 3 transformation matrix.
eM12
-
A fixed-point value for the M12 component of a 3 by 3 transformation matrix.
eM21
-
A fixed-point value for the M21 component of a 3 by 3 transformation matrix.
eM22
-
A fixed-point value for the M22 component of a 3 by 3 transformation matrix.
Remark
Member
eM11
The identity matrix produces a transformation in which the transformed graphical object is identical to the source object. In the identity matrix, the value ofeM11 is 1, the value of eM12 is zero, the value of eM21 is zero, and the value of eM22 is 1.
/***********************************************************
** 功能描述: 创建字体
** 参 数: CFont& font 要创建字体的CFont
int nFontHeight 以逻辑单位方式指定字体的高度
CString szFontName 字体名称
** 返 回 值: TRUE 成功
FALSE 失败
************************************************************/
BOOL CReadZhiMoDlg::createFont(CFont& font, int nFontHeight, CString szFontName)
{
int nError;
nError = font.CreateFont(
nFontHeight,
0,
0,
0,
0,
FALSE,
FALSE,
FALSE,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH,
szFontName);
if (!nError)
{
AfxMessageBox(_T("创建字体失败!"));
return FALSE;
}
else
{
return TRUE;
}
}
/***********************************************************
** 功能描述: 显示读取到字符的字模数据
** 参 数: BYTE* pData 读取到的字模数据
int nFontHeight 以逻辑单位方式指定字体的高度
UINT nCharHeight 字符高度
************************************************************/
void CReadZhiMoDlg::showZhiMoData(BYTE* pData, int nFontHeight, int nCharHeight)
{
CString szShowData = _T("");
int nRow = nCharHeight;
int nColumn = nFontHeight / 8;
nColumn = (nColumn + 4)/4*4;//4个字节对齐
//以上计算文字字模数据数组中一行数据占的字节的宽度,。
//例:FontHeight为24,即24/8=3,4个字节对齐,所以一行为4个字节,那么读取到的字模数据数组就以4个字节区分一行行
for (int i = 0; i < nRow; i++ )
{
for (int j = 0; j < nColumn; j++)
{
BYTE btCode = pData[i * 4 + j];//一个字节有8位,一个位代表1个点
for (int k = 0; k < 8; k++)
{
if(btCode & (0x80>>k))
{
szShowData += _T("1");
}
else
{
szShowData += _T("0");
}
}
}
szShowData += _T("\n");
}
AfxMessageBox(szShowData);
}
这里只是通过对话框来显示字模的数据,你可以通过画图等方式更具体的展示
程序地址:链接:https://pan.baidu.com/s/1eTzJCWi 密码:o6fy
源码请联系QQ:1715257750