当前位置:网站首页>Extracting key information from TrueType font files
Extracting key information from TrueType font files
2022-07-06 01:39:00 【Be a happy programmer】
This article extracts head Revision in module properties fontRevision For example .
TrueType Font file related attributes reference article :TrueType
Font interpreter opentype.js Source code download address :opentype.js Source code
TrueType Fonts are generally contained in a single TrueType In the font file , The suffix is .TTF.
OpenType Font is a kind of similar to TrueType Font file , Its format code is POSTSCRIPT typeface , The suffix is .OTF.
1、 Demand analysis
We need to extract fixed parameters among many parameters : Revision , And it is clear that the revised version is in head Properties of the , At this point, it depends on Font Inspector How to split each attribute module , And find our head attribute , And then in head The revision is extracted from the attribute module fontRevision Parameters .
First, we create classes for various attribute fields , Each class contains many parameters , image head、name And so on are class objects , And like version、fontRevision And so on are variable attributes in the class .
2、 Read the file
Read the file , Read the binary file , Load into the array , And pass it as a parameter to the subsequent interface .
Before reading the file x position , According to the characteristics of different file types , Read the identification bit as the file type , To get the current file type .
Different file types may have different attribute modules and field lists , We use ttf File as an example , It contains the following class attribute fields , Then there are various variables under these different class attributes .
3、 see head Related properties
We use head For example , There are many variable parameters under this class , These parameters have default data types and default values .
4、 see Font Inspector How to split each attribute module
our TrueType Is a font file , The font file has a feature , All attribute modules in its font table are 4 Characters , As shown in the figure : For what we are looking for head, We mark it with a solid red line .
Now how can we split each attribute field ? How to head Field attributes are separated from these font tables ? adopt getTag() Interface , This interface is from DataView Retrieve in view 4 A mark of characters . That is, corresponding to the field attribute 4 Characters to return .
So far we have found head attribute field ,head The starting offset of the attribute field in the whole binary file 300 The location of , The length is 54, We got effective information . The next thing to do is start from head Extract from fontRevision attribute , At this time, offset directly from the actual amount 300 Start reading from the location of , A fixed number of bytes are read each time , Find the target to read .
We are head The related view structure is built in , This view contains multiple attribute parameters , The parameters we want to extract are also marked with red line of sight .
We are headTable Extract from the structure fontRevision Parameters , We put the data data and head The starting offset from the binary file start Pass it to the interface as a parameter , then new Parser object , Pass the data in , Save as an object .
In fact, it is equivalent to creating an attempt , There is data in this view data, Starting offset offset, Current offset relativeOffset.HeadTable The structure is as follows: :
Next, we use the current offset to read one by one , except head Parameter fields in , It also specifies the type of the parameter field , Determines its offset in the current field , We'll use it parseFixed() Interface , According to the type of each parameter field , Keep the current offset relativeOffset Continue to increase , Until I read fontRevision Parameters , And then use it Math In the library round The function is rounded , Perform data truncation .
边栏推荐
- Paddle框架:PaddleNLP概述【飞桨自然语言处理开发库】
- leetcode刷题_验证回文字符串 Ⅱ
- [network attack and defense training exercises]
- Kubernetes stateless application expansion and contraction capacity
- Leetcode skimming questions_ Verify palindrome string II
- Initialize MySQL database when docker container starts
- [机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。
- leetcode刷题_平方数之和
- Folio. Ink is a free, fast and easy-to-use image sharing tool
- 正则表达式:示例(1)
猜你喜欢
2 power view
False breakthroughs in the trend of London Silver
Leetcode skimming questions_ Sum of squares
A Cooperative Approach to Particle Swarm Optimization
Une image! Pourquoi l'école t'a - t - elle appris à coder, mais pourquoi pas...
国家级非遗传承人高清旺《四大美人》皮影数字藏品惊艳亮相!
XSS learning XSS lab problem solution
Leetcode skimming questions_ Invert vowels in a string
【Flask】官方教程(Tutorial)-part1:项目布局、应用程序设置、定义和访问数据库
Folio. Ink is a free, fast and easy-to-use image sharing tool
随机推荐
Leetcode sum of two numbers
ClickOnce 不支持请求执行级别“requireAdministrator”
2022年PMP项目管理考试敏捷知识点(8)
Une image! Pourquoi l'école t'a - t - elle appris à coder, mais pourquoi pas...
【SSRF-01】服务器端请求伪造漏洞原理及利用实例
Code review concerns
【Flask】官方教程(Tutorial)-part1:项目布局、应用程序设置、定义和访问数据库
Unity VR resource flash surface in scene
[understanding of opportunity-39]: Guiguzi - Chapter 5 flying clamp - warning 2: there are six types of praise. Be careful to enjoy praise as fish enjoy bait.
Alibaba-Canal使用详解(排坑版)_MySQL与ES数据同步
阿里测开面试题
PHP error what is an error?
Folio. Ink is a free, fast and easy-to-use image sharing tool
dried food! Accelerating sparse neural network through hardware and software co design
CocoaPods could not find compatible versions for pod 'Firebase/CoreOnly'
【Flask】获取请求信息、重定向、错误处理
[Jiudu OJ 09] two points to find student information
01.Go语言介绍
国家级非遗传承人高清旺《四大美人》皮影数字藏品惊艳亮相!
About error 2003 (HY000): can't connect to MySQL server on 'localhost' (10061)