]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/libraries/tcpdf/tools/tcpdf_addfont.php
3 //============================================================+
4 // File name : tcpdf_addfont.php
7 // Last Update : 2013-08-05
8 // Authors : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
10 // License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
11 // -------------------------------------------------------------------
12 // Copyright (C) 2011-2013 Nicola Asuni - Tecnick.com LTD
14 // This file is part of TCPDF software library.
16 // TCPDF is free software: you can redistribute it and/or modify it
17 // under the terms of the GNU Lesser General Public License as
18 // published by the Free Software Foundation, either version 3 of the
19 // License, or (at your option) any later version.
21 // TCPDF is distributed in the hope that it will be useful, but
22 // WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 // See the GNU Lesser General Public License for more details.
26 // You should have received a copy of the License
27 // along with TCPDF. If not, see
28 // <http://www.tecnick.com/pagefiles/tcpdf/LICENSE.TXT>.
30 // See LICENSE.TXT file for more information.
31 // -------------------------------------------------------------------
33 // Description : This is a command line script to generate TCPDF fonts.
35 //============================================================+
39 * This is a command line script to generate TCPDF fonts.<br>
40 * @package com.tecnick.tcpdf
44 if (php_sapi_name() != 'cli') {
45 echo 'You need to run this command from console.';
49 $tcpdf_include_dirs = array(realpath(dirname(__FILE__
).'/../tcpdf.php'), '/usr/share/php/tcpdf/tcpdf.php', '/usr/share/tcpdf/tcpdf.php', '/usr/share/php-tcpdf/tcpdf.php', '/var/www/tcpdf/tcpdf.php', '/var/www/html/tcpdf/tcpdf.php', '/usr/local/apache2/htdocs/tcpdf/tcpdf.php');
50 foreach ($tcpdf_include_dirs as $tcpdf_include_path) {
51 if (@file_exists($tcpdf_include_path)) {
52 require_once($tcpdf_include_path);
58 * Display help guide for this command.
62 tcpdf_addfont - command line tool to convert fonts for the TCPDF library.
64 Usage: tcpdf_addfont.php [ options ] -i fontfile[,fontfile]...
69 --type Font type. Leave empty for autodetect mode.
74 CID0JP = CID-0 Japanese
76 CID0CS = CID-0 Chinese Simplified
77 CID0CT = CID-0 Chinese Traditional
80 --enc Name of the encoding table to use. Leave empty for
81 default mode. Omit this parameter for TrueType Unicode
82 and symbolic fonts like Symbol or ZapfDingBats.
85 --flags Unsigned 32-bit integer containing flags specifying
86 various characteristics of the font (PDF32000:2008 -
87 9.8.2 Font Descriptor Flags): +1 for fixed font; +4 for
88 symbol or +32 for non-symbol; +64 for italic. Fixed and
89 Italic mode are generally autodetected so you have to
90 set it to 32 = non-symbolic font (default) or 4 =
94 --outpath Output path for generated font files (must be writeable
95 by the web server). Leave empty for default font folder.
98 --platid Platform ID for CMAP table to extract (when building a
99 Unicode font for Windows this value should be 3, for
100 Macintosh should be 1).
103 --encid Encoding ID for CMAP table to extract (when building a
104 Unicode font for Windows this value should be 1, for
105 Macintosh should be 0). When Platform ID is 3, legal
106 values for Encoding ID are: 0=Symbol, 1=Unicode,
107 2=ShiftJIS, 3=PRC, 4=Big5, 5=Wansung, 6=Johab,
108 7=Reserved, 8=Reserved, 9=Reserved, 10=UCS-4.
111 --addcbbox Includes the character bounding box information on the
115 --link Link to system font instead of copying the font data #
116 (not transportable) - Note: do not work with Type1 fonts.
119 --fonts Comma-separated list of input font files.
122 --help Display this help and exit.
128 // remove the name of the executing script
132 if (!is_array($argv)) {
136 // initialize the array of options
137 $options = array('type'=>'', 'enc'=>'', 'flags'=>32, 'outpath'=>K_PATH_FONTS
, 'platid'=>3, 'encid'=>1, 'addcbbox'=>false, 'link'=>false);
139 // short input options
152 // long input options
157 $lopt[] = 'outpath:';
160 $lopt[] = 'addcbbox';
165 // parse input options
166 $inopt = getopt($sopt, $lopt);
168 // import options (with some sanitization)
169 foreach ($inopt as $opt => $val) {
173 if (in_array($val, array('TrueTypeUnicode', 'TrueType', 'Type1', 'CID0JP', 'CID0KR', 'CID0CS', 'CID0CT'))) {
174 $options['type'] = $val;
180 $options['enc'] = $val;
185 $options['flags'] = intval($val);
190 $options['outpath'] = realpath($val);
191 if (substr($options['outpath'], -1) != '/') {
192 $options['outpath'] .= '/';
198 $options['platid'] = min(max(1, intval($val)), 3);
203 $options['encid'] = min(max(0, intval($val)), 10);
208 $options['addcbbox'] = true;
213 $options['link'] = true;
218 $options['fonts'] = explode(',', $val);
228 } // end of while loop
230 if (empty($options['fonts'])) {
231 echo "ERROR: missing input fonts (try --help for usage)\n\n";
235 // check the output path
236 if (!is_dir($options['outpath']) OR !is_writable($options['outpath'])) {
237 echo "ERROR: Can't write to ".$options['outpath']."\n\n";
241 echo "\n>>> Converting fonts for TCPDF:\n";
243 echo '*** Output dir set to '.$options['outpath']."\n";
245 // check if there are conversion errors
248 foreach ($options['fonts'] as $font) {
249 $fontfile = realpath($font);
250 $fontname = TCPDF_FONTS
::addTTFfont($fontfile, $options['type'], $options['enc'], $options['flags'], $options['outpath'], $options['platid'], $options['encid'], $options['addcbbox'], $options['link']);
251 if ($fontname === false) {
253 echo "--- ERROR: can't add ".$font."\n";
255 echo "+++ OK : ".$fontfile.' added as '.$fontname."\n";
260 echo "--- Process completed with ERRORS!\n\n";
264 echo ">>> Process successfully completed!\n\n";
267 //============================================================+
269 //============================================================+