Font File format_analysis FreeType open source Library

Source: Internet
Author: User

 

To sum up, there is a lack of passion and motivation recently. Take things as they are, take things as they are, and do what is necessary. First, we will summarize the FreeType framework and then some TrueType data. ========================================================== I feel that these things need to be accumulated step by step, it's not far away.

Let's summarize the FreeType framework first. FreeType uses C to implement object-oriented functions. After a simple analysis, FreeType finds that the entire library is simple, practical, and does not have to be too cumbersome. It is easy to use it, and there are not many deliberate encapsulation and cumbersome interface calls, it's easy to use and looks comfortable!


FreeType has several well-designed modules. Stream, system, module, library, face
1. The Library manages multiple modules (except for the base modules in the sfnt, type1, and SRC folders .) 2. The module manages the interfaces of analysis files of each module. For example, sfnt_interface can be load_loca, load_cmap, lookup_table, goto_table. 3. stream and system encapsulate a series of underlying related APIs, while the stream provided by the upper layer is used for analysis by the module interface. 4. ft_face, tt_face, and tt_face are encapsulated by ft_face for internal use. external users only have ft_face, while tt_face can be used for data analysis. In the middle layer, the conversion is used for isolation encapsulation. -----------------------------------------------------------------------
For TrueType file format analysis: 1. Note that the TrueType file is stored in the byte order in the big-end order, and must be converted when reading data. 2. the most surprising thing is that the cmap table is analyzed, and character encoding is used for ing. Finally, it still flows to the metadata instruction set. In fact, if the font supports GBK encoding, it can be displayed without Unicode conversion. However, it seems that the plotting API only supports Unicode. Format0 stores the metadata index ing of the ANSI table, and format4 stores the metadata index ing of the Unicode section. When format4 idrangeoffset is not 0, it is calculated based on * (idrangeoffset [I]/2 + (c-startcount [I]) + & idrangeoffset [I, note that the number of bytes offset must be converted to two bytes. 3. Another interesting point is the glyf table, which replaces the glyf table of two font files. It may be capable of forging fonts and other things. 4. An epiphany of File analysis. The file format stores a data structure. ------------------------------------------------------------------------- Analyzes the file format. After all, the file format is the unit of storage and the aggregation of data. With the cmap Table Analysis Code Section: Void parsercmap (char * buff, char * buffend) <br/>{< br/> char * buff_start = Buff; <br/> ushort version = readunsignedshort (buff ); <br/> buff + = 2; <br/> ushort tables = readunsignedshort (buff); <br/> buff + = 2; <br/> printf ("version: % d, tables: % d/N ", version, tables); <br/> int ntbindex = 0; <br/> for (; ntbindex <tables; ++ ntbindex) <br/>{< br/> ushort flatformid = readunsignedshort (buff); <br/> buff + = 2; <br/> ushort encodingid = readunsignedshort (buff ); <br/> buff + = 2; <br/> ulong offset = readunsignedlong (buff); <br/> buff + = 4; <br/> printf ("flatformid: % d, encodingid: % d, offset: % d/N ", flatformid, <br/> encodingid, offset); <br/> char * table_start = buff_start + offset; <br/> ushort formatid = readunsignedshort (table_start); <br/> table_start + = 2; <br/> If (formatid = 0) <br/> {<br/> printf ("========================== format 0 ==== =====================/N "); <br/> ushort length = readunsignedshort (table_start); <br/> table_start + = 2; <br/> ushort version = readunsignedshort (table_start ); <br/> table_start + = 2; <br/> printf ("Length: % d, version: % d/N", length, version ); <br/> printf ("Byte:/N"); <br/> int I = 0; <br/> for (; I <length; ++ I) <br/>{< br/> printf ("% C: 0x % x", I, (* table_start & 0xff); <br/> table_start ++; <br/>}< br/> printf ("/N"); <br/>}< br/> else if (formatid = 4) <br/> {<br/> printf ("========================== format 4 ====== ===================/N "); <br/> ushort length = readunsignedshort (table_start); <br/> table_start + = 2; <br/> ushort version = readunsignedshort (table_start ); <br/> table_start + = 2; <br/> ushort segdblcounts = readunsignedshort (table_start); <br/> table_start + = 2; <br/> ushort searchrange = readunsignedshort (table_start); <br/> table_start + = 2; <br/> ushort entryselector = readunsignedshort (table_start ); <br/> table_start + = 2; <br/> ushort rangeshift = readunsignedshort (table_start); <br/> table_start + = 2; <br/> printf ("length: % d, version: % d, segdblcounts: % d, searchrange: % d, <br/> entryselector: % d, rangeshift: % d/N ", <br/> length, version, segdblcounts, searchrange, entryselector, rangeshift); <br/> char * endcounts = table_start; <br/> char * startcounts = table_start + segdblcounts + 2; <br/> char * Delta = startcounts + segdblcounts; <br/> char * rangeoffset = delta + segdblcounts; <br/> char * glyfid = rangeoffset + segdblcounts; <br/> ushort segcounts = segdblcounts> 1; <br/> ushort segindex = 0; <br/> printf ("endcounts startcounts Delta rangeoffset/N"); <br/> for (; segindex <segcounts; ++ segindex) <br/>{ <br/> ushort endcode = readunsignedshort (endcounts); <br/> endcounts + = 2; <br/> ushort startcode = readunsignedshort (startcounts ); <br/> startcounts + = 2; <br/> ushort del = readunsignedshort (DELTA); <br/> Delta + = 2; <br/> ushort offset = readunsignedshort (rangeoffset); <br/> rangeoffset + = 2; </P> <p> // For wingdings find 0xf031 match 49: '1' <br/>/* If (segindex = 0) <br/> {<br/> ushort Dis = offset/2 + 0xf031-0xf020; <br/> rangeoffset + = Dis * 2-2; <br/> ushort id = readunsignedshort (rangeoffset); <br/> printf ("0xf031: 0x % x/N ", ID ); <br/>}< br/> */<br/> printf ("0x % x 0x % x % d/N", endcode, startcode, Del, offset); <br/>}< br/> int glyfindex = 0; <br/> while (glyfid <buffend) <br/>{< br/> ushort glyf = readunsignedshort (glyfid); <br/> glyfid + = 2; <br/> printf ("% d: 0x % x ", glyfindex, (glyf & 0 xFFFF); <br/> glyfindex ++; <br/>}< br/> printf ("/N "); <br/>}< br/>} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.