当前位置:网站首页>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函数四舍五入,进行数据截断。



边栏推荐
- Basic operations of databases and tables ----- non empty constraints
- SPIR-V初窺
- [flask] official tutorial -part1: project layout, application settings, definition and database access
- CocoaPods could not find compatible versions for pod 'Firebase/CoreOnly'
- Code Review关注点
- SPIR-V初窥
- Idea sets the default line break for global newly created files
- Mongodb problem set
- Folio. Ink is a free, fast and easy-to-use image sharing tool
- VMware Tools安装报错:无法自动安装VSock驱动程序
猜你喜欢

Redis-字符串类型

VMware Tools installation error: unable to automatically install vsock driver

Test de vulnérabilité de téléchargement de fichiers basé sur dvwa

Basic operations of database and table ----- delete data table

VMware Tools安装报错:无法自动安装VSock驱动程序

Unity | 实现面部驱动的两种方式

国家级非遗传承人高清旺《四大美人》皮影数字藏品惊艳亮相!

Force buckle 1020 Number of enclaves

Threedposetracker project resolution

Basic operations of database and table ----- set the fields of the table to be automatically added
随机推荐
Basic operations of databases and tables ----- primary key constraints
C web page open WinForm exe
【网络攻防实训习题】
Huawei Hrbrid interface and VLAN division based on IP
Loop structure of program (for loop)
剑指 Offer 38. 字符串的排列
Idea sets the default line break for global newly created files
Docker compose配置MySQL并实现远程连接
ClickOnce 不支持请求执行级别“requireAdministrator”
Paddle framework: paddlenlp overview [propeller natural language processing development library]
[flask] official tutorial -part3: blog blueprint, project installability
Basic operations of databases and tables ----- default constraints
Electrical data | IEEE118 (including wind and solar energy)
Unity | 实现面部驱动的两种方式
leetcode刷题_平方数之和
Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
Use of crawler manual 02 requests
You are using pip version 21.1.1; however, version 22.0.3 is available. You should consider upgradin
A picture to understand! Why did the school teach you coding but still not
[technology development -28]: overview of information and communication network, new technology forms, high-quality development of information and communication industry
图一:TrueType
图二:OpenType