当前位置:网站首页>TrueType字体文件提取关键信息
TrueType字体文件提取关键信息
2022-07-06 01:31:00 【做1个快乐的程序员】
该文章以提取head模块属性中的修订版本fontRevision为例。
TrueType字体文件相关属性参考文章:TrueType
字体解释器opentype.js源码下载地址:opentype.js源码
![]() | ![]() |
TrueType字体一般包含在单个TrueType字体文件里,后缀为.TTF。
OpenType字体是一种类似于TrueType字体的文件,其格式编码为POSTSCRIPT字体,后缀为.OTF。
1、需求分析
我们要提取众多参数中的固定参数:修订版本,并且明确修订版本是在head属性中,此时要看Font Inspector如何把各个属性模块进行拆分,并且找到我们的head属性,进而在head属性模块中提取到修订版本fontRevision参数。
首先我们创建了各种属性字段的类,每一个类中包含众多参数,像head、name等就是一个个类对象,而像version、fontRevision等就是类中的变量属性。
2、读取文件
读取文件,将二进制文件进行读取,加载到数组中,并作为参数传递到后续的接口里。
读取文件的前x位,根据不同文件类型的特征,读取作为文件类型的标识位,来获取当前文件类型。
不同文件类型也许有不同的属性模块和字段列表,我们以ttf文件为例,他就包含了如下的类属性字段,然后这些不同的类属性下还有各种变量。
3、查看head相关属性
我们以head为例,在该类下有许多的变量参数,这些参数有默认的数据类型和默认值。
4、查看Font Inspector如何把各个属性模块进行拆分
我们的TrueType是一种字体文件,该字体文件有一个特性,它字体表中所有属性模块都是4个字符,如图所示:对于我们要找的head,我们用红色实线标记出来。
现在我们应该怎么把各个属性字段拆分呢?又怎么把head字段属性从这些字体表中分离出来呢?通过getTag()接口,该接口是从DataView视图中检索4个字符的标记。也就是将字段属性对应的4字符进行返回。
至此我们已经找到了head属性字段,head属性字段在整个二进制文件起始偏移量300的位置,长度为54,我们得到了有效信息。接下来要做的就是从head中提取fontRevision属性,此时直接从其实偏移量300的位置开始读取,每次读取固定字节数,找到要读取的目标。
我们在head的中构建了相关的视图结构,该视图中包含了多个属性参数,我们要提取的参数也用红视线标记了出来。
我们在headTable结构中提取fontRevision参数,我们把数据data和head相对二进制文件的起始偏移量start作为参数传递到接口中,然后new Parser对象,把数据传递进去,以对象的形式保存。
其实就相当于创建了一个试图,该视图中有数据data,起始偏移量offset,当前偏移量relativeOffset。HeadTable结构如下图:
我们接下来就是利用当前偏移量一个个读取,除了head中的参数字段,还规定了该参数字段的类型,决定了他在当前字段的偏移量,我们就利用parseFixed()接口,根据每个参数字段的类型,不断把当前偏移量relativeOffset不断进行递增,直到读取到fontRevision参数,然后利用Math库中的round函数四舍五入,进行数据截断。
边栏推荐
- 【Flask】获取请求信息、重定向、错误处理
- ThreeDPoseTracker项目解析
- [机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。
- leetcode刷题_反转字符串中的元音字母
- Leetcode1961. 检查字符串是否为数组前缀
- 剑指 Offer 12. 矩阵中的路径
- 2022 Guangxi Autonomous Region secondary vocational group "Cyberspace Security" competition and its analysis (super detailed)
- Leetcode skimming questions_ Verify palindrome string II
- C web page open WinForm exe
- c#网页打开winform exe
猜你喜欢
[detailed] several ways to quickly realize object mapping
Hcip---ipv6 experiment
3D model format summary
A Cooperative Approach to Particle Swarm Optimization
yii中console方法调用,yii console定时任务
UE4 unreal engine, editor basic application, usage skills (IV)
ThreeDPoseTracker项目解析
dried food! Accelerating sparse neural network through hardware and software co design
Basic operations of databases and tables ----- primary key constraints
How does the crystal oscillator vibrate?
随机推荐
Recommended areas - ways to explore users' future interests
【网络攻防实训习题】
Leetcode skimming questions_ Invert vowels in a string
Netease smart enterprises enter the market against the trend, and there is a new possibility for game industrialization
[flask] response, session and message flashing
General operation method of spot Silver
Ordinary people end up in Global trade, and a new round of structural opportunities emerge
Hcip---ipv6 experiment
File upload vulnerability test based on DVWA
Huawei Hrbrid interface and VLAN division based on IP
[le plus complet du réseau] | interprétation complète de MySQL explicite
Redis' cache penetration, cache breakdown, cache avalanche
Cadre du Paddle: aperçu du paddlelnp [bibliothèque de développement pour le traitement du langage naturel des rames volantes]
Unity | 实现面部驱动的两种方式
Development trend of Ali Taobao fine sorting model
Huawei converged VLAN principle and configuration
剑指 Offer 12. 矩阵中的路径
VMware Tools安装报错:无法自动安装VSock驱动程序
500 lines of code to understand the principle of mecached cache client driver
Leetcode sword finger offer 59 - ii Maximum value of queue