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



边栏推荐
- [flask] obtain request information, redirect and error handling
- LeetCode 322. Change exchange (dynamic planning)
- Basic operations of databases and tables ----- unique constraints
- 2022 Guangxi Autonomous Region secondary vocational group "Cyberspace Security" competition and its analysis (super detailed)
- Test de vulnérabilité de téléchargement de fichiers basé sur dvwa
- [flask] response, session and message flashing
- 国家级非遗传承人高清旺《四大美人》皮影数字藏品惊艳亮相!
- 2022年广西自治区中职组“网络空间安全”赛题及赛题解析(超详细)
- Yii console method call, Yii console scheduled task
- A picture to understand! Why did the school teach you coding but still not
猜你喜欢
![[detailed] several ways to quickly realize object mapping](/img/e5/70c7f8fee4556d14f969fe33938971.gif)
[detailed] several ways to quickly realize object mapping
![[Jiudu OJ 09] two points to find student information](/img/35/25aac51fa3e08558b1f6e2541762b6.jpg)
[Jiudu OJ 09] two points to find student information

MySQL learning notes 2

Docker compose配置MySQL并实现远程连接

General operation method of spot Silver

Huawei converged VLAN principle and configuration

3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
![[solved] how to generate a beautiful static document description page](/img/c1/6ad935c1906208d81facb16390448e.png)
[solved] how to generate a beautiful static document description page

500 lines of code to understand the principle of mecached cache client driver

Basic operations of database and table ----- delete data table
随机推荐
How to get the PHP version- How to get the PHP Version?
[机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。
[Jiudu OJ 09] two points to find student information
Paddle framework: paddlenlp overview [propeller natural language processing development library]
【详细】快速实现对象映射的几种方式
[technology development -28]: overview of information and communication network, new technology forms, high-quality development of information and communication industry
How does the crystal oscillator vibrate?
Mathematical modeling learning from scratch (2): Tools
c#网页打开winform exe
Ordinary people end up in Global trade, and a new round of structural opportunities emerge
SPIR-V初窥
竞赛题 2022-6-26
About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)
Basic operations of databases and tables ----- unique constraints
Alibaba-Canal使用详解(排坑版)_MySQL与ES数据同步
[detailed] several ways to quickly realize object mapping
Blue Bridge Cup embedded stm32g431 - the real topic and code of the eighth provincial competition
internship:项目代码所涉及陌生注解及其作用
电气数据|IEEE118(含风能太阳能)
【全网最全】 |MySQL EXPLAIN 完全解读
图一:TrueType
图二:OpenType