The basic knowledge of TTF font and its application in QT

Source: Internet
Author: User

Font Type in Windows, for example, there are 4 font technologies:Raster: Raster type, which is to use bitmaps to draw glyphs (glyph), each word is saved as a bitmapvectors: Vector type, that is, the end point of a series of lines to represent glyphsTrueType: Use a series of lines, curves, and some hint (hint) commands to draw glyphsMicrosoft OpenType: Consistent with TrueTypebecause the hint of fonts such as TrueType can adjust the length and shape of the curve, it can perform well in different sizes of fonts. While raster fonts are related to device-specific resolution, vector fonts are better, but they are less efficient to draw and much slower than other fonts. for raster and vector fonts, In general, the file name of its resource files ends with a. Fon and is internally divided into the header that describes the font metrics and the actual glyph data, and for TrueType and OpenType, it is divided into two files, the first ending with a. fot, the corresponding header is described, and the other is named after the. TTF, which contains The real content.   fonts and Character sets The character set is character sets. Each character in a character set has a number corresponding to it. There are several character sets in use in Windows. Windows Character set: Essentially the same as US ASCII Character set, the number of the first character is 0x20, and the most one is 0xFF. For characters that do not exist on the character set, the default font is displayed, such as raster and vector fonts, which are used to display, while TTF is represented by a box. Unicode Character Set: Uses 2-byte numbers to represent up to 2^16 characters (as if they were later added to 4 bytes), each character having a separate numeric representation. Note that this is the character set, not the encoding. also available are OEM Character set, Symbol Character set, and vendor-specific characters sets, among others  TTF File Structure TTF font is the meaning of TrueType fonts, the general file suffix is Ttf,ttf also allows different fonts in a file, when the suffix of TTC, is the meaning of TrueType collect. TTF files are made up of a series of tables. The first table is the font directory, which is special and is designed to indicate other tables, and the advanced one is the other table that contains the font data. Each table has a four-character defined table name, and some of these tables are required for each font file. such as:
CMap Defines the correspondence between the character-to-glyph index, which is the index used in the table Loca by the word code. Includes multiple sub-tables to support different platforms and encoding sets
Glyf Contains glyph data, which is the outline definition and adjustment directives for glyphs
Head Defines the font header, global information for fonts
Hhea Defines the horizontal header
Hmtx Defines the horizontal metric
Loca Defines the offset of each glyph in the Glyf table, based on the glyph index obtained in the CMAP, where the corresponding glyphs can be offset in the Glyf table.
Maxp Defines the maximum profile, which is used to allocate memory for the font
Name Define font names, style names, and copyright descriptions
Post PostScript
There is a question of how characters find their own glyphs in the TTF file, see the following instructions:explain the CMap table in detail, because this table is the most important. Due to the existence of different systems and encoding sets, the CMAP table has multiple sub-tables, and each child table contains basic information about the system ID, the encoding set, and the offset in the table. The general system ID has 3 and 1, the former is Windows, the latter is the Macintosh. In general, the TTF file contains at least two sub-tables, the Macintosh Roman system (platformid=1, encoding=0) and the UGI system of Windows (platformid=3, encoding=1), Where encoding=1 is Unicode encoding. These sub-tables hold the corresponding characters inside the code to glyph index. Get the value of glyph index to find the offset in the glyf of the corresponding Glyph table in table Loca.  in Windows, you can get font information using the following WIN32 API.
DWORD GetFontData (HDC hdc, DWORD dwtable, DWORD DwOffset, LPVOID Lpbbuffer, DWORD cbdata)

Concrete Visible http://bbs.chinaunix.net/thread-2041402-1-1.html

  FontForge: Development tools for Fonts Open source tools for developing and editing fonts, see http://fontforge.sourceforge.net/  the fonts in Qt QTE (Qt for Embedded) uses the FreeType 2 font engine to support font display. such as TrueType (TTF), Postscript Type (PFA/PFB), Bitmap distrubution Format fonts (BDF), etc. At the same time Qte also supports QT prerendered font (QPF) fonts, which are bitmap fonts and are not scalable as Qte local fonts.  TrueType is developed by Apple and Microsoft-based vector font technology (corresponding to the bitmap font), can not be distorted to zoom in and out, the file name is generally *.fon, *.ttf and *.TTC,TTC are TTF's new standard, And Fon is the old standard of the past. There is currently a FreeType font engine that, as a software library, can help with the display of TrueType fonts.  The BDF font is a bitmap font format for the X Window System whose file is divided into two parts, the first part is the header that describes the overall attribute, and the second part is the attribute and bitmap data for each font.  The QPF font format is used only for qt/embedded non-scalable fonts, QTE official fonts, tools MAKEQPF, and TTF files can be generated QPF font files.  using TTF fonts or pfa/pfb these vector fonts directly in QT, the application will need to compute the vector information in a bitmap form when it is displayed, which can take up a lot of computational power and RAM. If you choose the BDF font, it is very slow and requires more resources. QPF is a bitmap font, do not need to display when the calculation of the lattice, and due to non-scalable, bitmap directly take to display, speed and resource consumption is the best.  when the Qte app starts, it goes to the $qt/lib/fonts directory to look for the corresponding font file, including the QBF and TTF font files, and continues to read the Fontdir file under that directory for compatibility. Use Qfont in your code to apply the font, and if the selected font does not exist, Qfont has an intrinsic match policy that automatically selects the default font.

The basic knowledge of TTF font and its application in QT

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.