Name : perl-Font-TTFMetrics
| |
Version : 0.1
| Vendor : obs://build_opensuse_org/devel:languages:perl
|
Release : 7.69
| Date : 2024-08-05 18:20:35
|
Group : Development/Libraries/Perl
| Source RPM : perl-Font-TTFMetrics-0.1-7.69.src.rpm
|
Size : 0.06 MB
| |
Packager : (none)
| |
Summary : Parser for the TTF file
|
Description :
\'Font::TTFMetrics\' encapsulates the font metrics of a true type font file. A true type font file contains several tables which need to be parsed before any useful information could be gathered about the font. There is the excellent module for parsing TTF font in CPAN by Martin Hosken, \'Font::TTF\'. But in my opinion the use of \'Font::TTF\' requires intimate knowledge of TTF font format. This module was written to support the use of TTF in \'Pastel\' 2D graphics library in Perl. Three factors prompted me to write this module: first, I required a fast module to access TTF file. Second, all the access required was read-only. Last, I wanted a user friendly, higher level API to access TTF file.
Each font file actually contains several informations the most important information is how a particular character will display on screen. The shape of a character (glyph) is determined by a series of points. The points are generally lines or points on curved path. For details see the TTF specification. Remember, the points actually determines the outline of the curve.TTF file stores the glyph shape in the \"glyf\" table of the font. The first glyph described in this table will be always a particular glyph, called \"missing-glyph\" which is shown in case the font file doesnot contains the glyph that a software wants.
Each character in computer is actually a number. You can find what number corresponds to the character, you can call \'ord()\' on the character. This value is called the ordinal value of the character. If you just use common english typically the number of any character falls between 32-126, commonly called as ASCII. If you use some more extra character not commonly found in key-board like \"degree\" then your character code will fall between 0-255, commonly called LATIN-1 character set. Unicode is a way to use charaters with ordinal values beyond 255. The good thing about it is that the UTF8 encoding in perl works silently in the backdrop and you can intermix characters with any ordinal value. This ofcourse does not mean that you will be able to use character with any ordinal values for display. The font file must contains the corresponding glyph.
The way to extract the glyph for a character is done by looking into \"cmap\" table of the font. This table contains the character ordinal number and a correspoding index. This index is used to look into the \"glyf\" table to extract the shape of the character. Thar means if you just substitute another index for a particular ordinal number you can actually display a different character, a mechanism known as \"glyph substitution\". As you can guess there is one more way to display a particular character instead of what if should display in a more font specific manner. If you just add a particular offset to a glyph ordinal value and provide the index for this added value in the \"cmap\" table, you can generate a completely different glyph. This mechanism works for a particular type of fonts supplied by Microsoft called symbol fonts. Example of these are symbol.ttf and wingding. Both these fonts does not supply any glyphs corresponding to LATIN-1 character sets but with ordinal values in the range of 61472-61695. But notice if you fire up your word-processor and change the font to symbol and type any character on the key board you get a display. For example, if you type A (ordinal value 65) what you get is greek capital alpha. This works this way: as soon as the word-processor find that you are using a symbol font (you can call \'is_symbol()\' method to find that) it just adds 61440 to any character you type and then queries the \"cmap\" table for the glyph.
One more important aspect of using a TTF file is to find the width of a string. The easiest way to find this to query \"htmx\" table, which contains advanced width of each character, add up all the advance widths of the individual characters in the string and then go look into \"kern\" table, which contains the kerning value for pair of glyphs add deduct these values from the total width. You need to deduct also the left-side bearing of the first character and the right-side bearing of the last character from the total width.
User of this module should keep in mind that all the values returned from this modules are in font-units and should be converted to pixel unit by:
fIUnits * pointsize * resolution /(72 * units_per_em)
An example from the true type specification at http://www.microsoft.com/typography/otspec/TTCH01.htm:
A font-feature of 550 units when used with 18 pt on screen (typically 72 dpi resolution) will be
550 * 18 * 72 / ( 72 * 2048 ) = 4.83 pixels long.
Note that the \'units_per_em\' value is 2048 which is typical for a TTF file. This value can be obtained by calling \'get_units_per_em()\' call.
This module also takes full advantage of the unicode support of Perl. Any strings that you pass to any function call in this module can have unicode built into into it. That means a string like:
\"Something \\x{70ff}\" is perfectly valid.
|
RPM found in directory: /packages/linux-pbone/ftp5.gwdg.de/pub/opensuse/repositories/devel:/languages:/perl:/CPAN-F/openSUSE_Tumbleweed/noarch |