VC字模读取 MFC字模读取 上位机字模读取

很重要的图


(1)首先是读取字模的函数

GetGlyphOutline

函数原型:DWORD GetGlyphOutline(HDC hdc, UINT uChar, UINT uFormat, LPGLYPHMETRICS lpgm, DWORD cbBuffer, LPVOID lpvBuffer, CONST MAT2 *lpmat2);

(2) GetGlyphOutline里的成员 LPGLYPHMETRICS 

typedef struct _GLYPHMETRICS {   
  UINT  gmBlackBoxX;     //指定完全包围字体结构的最小矩阵的宽度   
  UINT  gmBlackBoxY;     //指定完全包围字体结构的最小矩阵的高度  
  POINT gmptGlyphOrigin; //指定完全包围字体结构的最小矩阵左上角的点坐标  
  short gmCellIncX;      //指定当前的起点到下一个字符的起点的水平距离  
  short gmCellIncY;      //指定当前的起点到下一个字符的起点的垂直距离   
} GLYPHMETRICS, *LPGLYPHMETRICS;   

该结构如下图所示:
(3)GetGlyphOutline里的成员 MAT2,变换 矩阵结构

typedef struct _MAT2 {
 
  
  FIXED eM11;
  FIXED eM12;
  FIXED eM21;
  FIXED eM22;
} MAT2, *LPMAT2;

Member
eM11

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

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.


(4)VC测试代码

/***********************************************************
** 功能描述: 创建字体

** 参    数: 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

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶恭介叶恭介

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值