当前位置:网站首页>TrueType字体文件提取关键信息
TrueType字体文件提取关键信息
2022-07-06 01:31:00 【做1个快乐的程序员】
该文章以提取head模块属性中的修订版本fontRevision为例。
TrueType字体文件相关属性参考文章:TrueType
字体解释器opentype.js源码下载地址:opentype.js源码
图一:TrueType | 图二:OpenType |
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函数四舍五入,进行数据截断。



边栏推荐
- How does the crystal oscillator vibrate?
- [Jiudu OJ 09] two points to find student information
- 记一个 @nestjs/typeorm^8.1.4 版本不能获取.env选项问题
- NLP第四范式:Prompt概述【Pre-train,Prompt(提示),Predict】【刘鹏飞】
- 网易智企逆势进场,游戏工业化有了新可能
- 黄金价格走势k线图如何看?
- Unity VR solves the problem that the handle ray keeps flashing after touching the button of the UI
- Mathematical modeling learning from scratch (2): Tools
- LeetCode 322. Change exchange (dynamic planning)
- Tcpdump: monitor network traffic
猜你喜欢

Basic process and testing idea of interface automation

yii中console方法调用,yii console定时任务

3D model format summary

晶振是如何起振的?

VMware Tools installation error: unable to automatically install vsock driver
![[flask] official tutorial -part3: blog blueprint, project installability](/img/fd/fc922b41316338943067469db958e2.png)
[flask] official tutorial -part3: blog blueprint, project installability

UE4 unreal engine, editor basic application, usage skills (IV)

Loop structure of program (for loop)

NLP第四范式:Prompt概述【Pre-train,Prompt(提示),Predict】【刘鹏飞】

ORA-00030
随机推荐
The basic usage of JMeter BeanShell. The following syntax can only be used in BeanShell
Vulhub vulnerability recurrence 75_ XStream
Poj2315 football games
Ordinary people end up in Global trade, and a new round of structural opportunities emerge
Netease smart enterprises enter the market against the trend, and there is a new possibility for game industrialization
Unity VR solves the problem that the handle ray keeps flashing after touching the button of the UI
UE4 unreal engine, editor basic application, usage skills (IV)
Hcip---ipv6 experiment
3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
Leetcode skimming questions_ Verify palindrome string II
2022年广西自治区中职组“网络空间安全”赛题及赛题解析(超详细)
剑指 Offer 12. 矩阵中的路径
关于softmax函数的见解
3D视觉——4.手势识别(Gesture Recognition)入门——使用MediaPipe含单帧(Singel Frame)和实时视频(Real-Time Video)
Leetcode 208. 实现 Trie (前缀树)
How does the crystal oscillator vibrate?
伦敦银走势中的假突破
Yii console method call, Yii console scheduled task
Redis' cache penetration, cache breakdown, cache avalanche
[le plus complet du réseau] | interprétation complète de MySQL explicite
图一:TrueType
图二:OpenType