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



边栏推荐
- Paddle框架:PaddleNLP概述【飛槳自然語言處理開發庫】
- Paging of a scratch (page turning processing)
- Leetcode1961. Check whether the string is an array prefix
- Hcip---ipv6 experiment
- ClickOnce does not support request execution level 'requireAdministrator'
- ThreeDPoseTracker项目解析
- Yii console method call, Yii console scheduled task
- JMeter BeanShell的基本用法 一下语法只能在beanshell中使用
- yii中console方法调用,yii console定时任务
- Some features of ECMAScript
猜你喜欢

ThreeDPoseTracker项目解析

Force buckle 1020 Number of enclaves

Basic operations of databases and tables ----- unique constraints

SSH login is stuck and disconnected

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

c#网页打开winform exe
![[technology development -28]: overview of information and communication network, new technology forms, high-quality development of information and communication industry](/img/94/05b2ff62a8a11340cc94c69645db73.png)
[technology development -28]: overview of information and communication network, new technology forms, high-quality development of information and communication industry

Basic process and testing idea of interface automation

Yii console method call, Yii console scheduled task

3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
随机推荐
【Flask】官方教程(Tutorial)-part2:蓝图-视图、模板、静态文件
什么是弱引用?es6中有哪些弱引用数据类型?js中的弱引用是什么?
c#网页打开winform exe
A Cooperative Approach to Particle Swarm Optimization
ctf. Show PHP feature (89~110)
基於DVWA的文件上傳漏洞測試
Internship: unfamiliar annotations involved in the project code and their functions
Use of crawler manual 02 requests
Leetcode1961. 检查字符串是否为数组前缀
Paging of a scratch (page turning processing)
VMware Tools installation error: unable to automatically install vsock driver
[Yu Yue education] Liaoning Vocational College of Architecture Web server application development reference
How does the crystal oscillator vibrate?
Recommended areas - ways to explore users' future interests
How to get all sequences in Oracle database- How can I get all sequences in an Oracle database?
SSH login is stuck and disconnected
黄金价格走势k线图如何看?
leetcode刷题_反转字符串中的元音字母
Win10 add file extension
关于softmax函数的见解
图一:TrueType
图二:OpenType