Software: Apache. PHP/5.5.15 uname -a: Windows NT SVR-DMZ 6.1 build 7600 (Windows Server 2008 R2 Enterprise Edition) i586 SYSTEM Safe-mode: OFF (not secure) C:\dmz\php\pear\fpdf\tutorial\ drwxrwxrwx |
Viewing file: tuto7.htm (11.16 KB) -rw-rw-rw- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) | Adding new fonts and encoding supportThis tutorial explains how to use TrueType, OpenType and Type1 fonts so that you are not limited to the standard fonts any more. The other benefit is that you can choose the font encoding, which allows you to use other languages than the Western ones (the standard fonts having too few available characters).Remark: for OpenType, only the format based on TrueType is supported (not the one based on Type1). There are two ways to use a new font: embedding it in the PDF or not. When a font is not embedded, it is searched in the system. The advantage is that the PDF file is lighter; on the other hand, if it's not available, a substitution font is used. So it's preferable to ensure that the needed font is installed on the client systems. If the file is to be viewed by a large audience, it's highly recommended to embed. Adding a new font requires two steps:
Generation of the font definition fileThe first step consists in generating a PHP file containing all the information needed by FPDF; in addition, the font file is compressed. To do this, a helper script is provided in the makefont directory of the package: makefont.php. It contains the following function:MakeFont(string fontfile, [, string enc [, boolean embed]])
For Type1 fonts, the corresponding .afm file must be present in the same directory. The encoding defines the association between a code (from 0 to 255) and a character. The first 128 are always the same and correspond to ASCII; the following are variable. Encodings are stored in .map files. The available ones are:
Remark: the standard fonts use cp1252. After you have called the function (create a new file for this and include makefont.php), a .php file is created, with the same name as the font file. You may rename it if you wish. If the case of embedding, the font file is compressed and gives a second file with .z as extension (except if the compression function is not available, it requires Zlib). You may rename it too, but in this case you have to change the variable $file in the .php file accordingly.
Example:
Then copy the generated files to the font directory. If the font file could not be compressed, copy it directly instead of the .z version. Another way to call MakeFont() is through the command line: php makefont\makefont.php c:\Windows\Fonts\comic.ttf cp1252 Finally, for TrueType and OpenType fonts, you can also generate the files online instead of doing it manually. Declaration of the font in the scriptThe second step is simple. You just need to call the AddFont() method:
ExampleLet's now see a complete example. We will use the font Calligrapher. The first step is the generation of the font files:
Warning: character Euro is missing Warning: character zcaron is missing Font file compressed: calligra.z Font definition file generated: calligra.php The euro character is not present in the font (it's too old). Another character is missing too. Alternatively we could have used the command line: php makefont\makefont.php calligra.ttf cp1252 or used the online generator. We can now copy the two generated files to the font directory and write the script:
About the euro symbolThe euro character is not present in all encodings, and is not always placed at the same position:
Reducing the size of TrueType fontsFont files are often quite voluminous; this is due to the fact that they contain the characters corresponding to many encodings. Zlib compression reduces them but they remain fairly big. A technique exists to reduce them further. It consists in converting the font to the Type1 format with ttf2pt1 (the Windows binary is available here) while specifying the encoding you are interested in; all other characters will be discarded.For example, the arial.ttf font that ships with Windows Vista weights 748 KB (it contains 3381 characters). After compression it drops to 411. Let's convert it to Type1 by keeping only cp1250 characters: ttf2pt1 -b -L cp1250.map c:\Windows\Fonts\arial.ttf arial The .map files are located in the makefont directory of the package. The command produces arial.pfb and arial.afm. The arial.pfb file weights only 57 KB, and 53 after compression. It's possible to go even further. If you are interested only by a subset of the encoding (you probably don't need all 217 characters), you can open the .map file and remove the lines you are not interested in. This will reduce the file size accordingly. |
:: Command execute :: | |
--[ c99shell v. 1.0 pre-release build #13 powered by Captain Crunch Security Team | http://ccteam.ru | Generation time: 0.0312 ]-- |