提取TTF字库字模

本文介绍了如何在FPGA上实现OSD(On-Screen Display)文字显示,通过利用Windows的TTF字库,创建自定义字体库,实现字体多样化的文字叠加到视频信号上。通过VC++代码示例展示了如何提取字模并进行显示,对于嵌入式系统的文字显示提供了有效的方法。
摘要由CSDN通过智能技术生成

最近想在FPGA上做OSD, 既在视频信号上叠加上文字信息,考虑到使用点阵字库提取的办法样式比较单一,因此选择利用Windows的TTF字库,参考了网上的一些资料,现己试验成功,主要的VC++代码分享如下:

 LOGFONT lf;
 CFont newfont;

 lf.lfHeight = 10;        //字体宽
 lf.lfWidth  = 10;        //字体高
 lf.lfUnderline = 0;    //下划线
 lf.lfStrikeOut = 0;    //删除线

 CFontDialog cf(&lf);
 if(cf.DoModal() == IDOK)
 {
  cf.GetCurrentFont(&lf);
  newfont.CreateFontIndirect(&lf);
 }          //选择并创建字体

 CDC* pdc=this->GetDC();
 CFont *poldfont=pdc->SelectObject(&newfont);    //把字体选入当前的设备上下文
 MAT2 mmat2={0,1,0,0,0,0,0,1};   //字符信息转换矩阵
 GLYPHMETRICS glpm;              //用于描述字表在字符单元的放置

 DWORD nLen;
 UINT chartemp;
 BYTE temp;
    CString str="字";

对于ttf字库的解析和处理,你可以使用Python的fontTools库来实现。下面是一个示例代码,用于解析ttf字库提取编码和字符: ```python from fontTools.ttLib import TTFont import json def toUnicode(oneStr): t = oneStr if t[:3 == 'uni': t = t.replace('uni', '\\u') if t[:2 == 'uF': t = t.replace('uF', '\\u') return json.loads(f'"{t}"') def printUNI(fontName): font = TTFont(fontName) glyphNames = font.getGlyphNames() for i in glyphNames: if i == '.': continue print(i, toUnicode(i)) fontName = "font/FSung-F.ttf" printUNI(fontName) ``` 这段代码使用了fontTools库中的TTFont类来加载ttf字库文件,然后通过getGlyphNames()方法获取字库中所有的字形名称。通过遍历字形名称列表,可以获取每个字形的编码和字符信息。其中,toUnicode函数用于将字形名称转换为Unicode字符。 请注意,你需要提前安装fontTools库,并将要解析的ttf字库文件的路径传递给fontName变量。 希望这个代码对你有所帮助!如果你对其他代码实现也感兴趣,可以继续关注我的专栏。 <span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [python 代码库之遍历ttf字库编码和字符(含demo)](https://blog.csdn.net/iCloudEnd/article/details/97581243)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Python实现点阵字体读取与转换的方法](https://download.csdn.net/download/weixin_38517095/12864674)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值