#!/usr/bin/env php . // // See LICENSE.TXT file for more information. // ------------------------------------------------------------------- // // Description : This is a command line script to generate TCPDF fonts. // //============================================================+ /** * @file * This is a command line script to generate TCPDF fonts.
* @package com.tecnick.tcpdf * @version 1.0.000 */ if (PHP_SAPI != 'cli') { echo 'You need to run this command from console.'; exit(1); } $tcpdf_include_dirs = [\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']; foreach ($tcpdf_include_dirs as $tcpdf_include_path) { if (@\file_exists($tcpdf_include_path)) { require_once($tcpdf_include_path); break; } } /** * Display help guide for this command. */ function showHelp() : void { $help = <<'', 'enc'=>'', 'flags'=>32, 'outpath'=>K_PATH_FONTS, 'platid'=>3, 'encid'=>1, 'addcbbox'=>false, 'link'=>false]; // short input options $sopt = ''; $sopt .= 't:'; $sopt .= 'e:'; $sopt .= 'f:'; $sopt .= 'o:'; $sopt .= 'p:'; $sopt .= 'n:'; $sopt .= 'b'; $sopt .= 'l'; $sopt .= 'i:'; $sopt .= 'h'; // long input options $lopt = []; $lopt[] = 'type:'; $lopt[] = 'enc:'; $lopt[] = 'flags:'; $lopt[] = 'outpath:'; $lopt[] = 'platid:'; $lopt[] = 'encid:'; $lopt[] = 'addcbbox'; $lopt[] = 'link'; $lopt[] = 'fonts:'; $lopt[] = 'help'; // parse input options $inopt = \getopt($sopt, $lopt); // import options (with some sanitization) foreach ($inopt as $opt => $val) { switch ($opt) { case 't': case 'type': { if (\in_array($val, ['TrueTypeUnicode', 'TrueType', 'Type1', 'CID0JP', 'CID0KR', 'CID0CS', 'CID0CT'])) { $options['type'] = $val; } break; } case 'e': case 'enc': { $options['enc'] = $val; break; } case 'f': case 'flags': { $options['flags'] = (int) $val; break; } case 'o': case 'outpath': { $options['outpath'] = \realpath($val); if (\substr($options['outpath'], -1) != '/') { $options['outpath'] .= '/'; } break; } case 'p': case 'platid': { $options['platid'] = \min(\max(1, (int) $val), 3); break; } case 'n': case 'encid': { $options['encid'] = \min(\max(0, (int) $val), 10); break; } case 'b': case 'addcbbox': { $options['addcbbox'] = true; break; } case 'l': case 'link': { $options['link'] = true; break; } case 'i': case 'fonts': { $options['fonts'] = \explode(',', $val); break; } case 'h': case 'help': default: { \showHelp(); break; } } // end of switch } // end of while loop if (empty($options['fonts'])) { echo "ERROR: missing input fonts (try --help for usage)\n\n"; exit(2); } // check the output path if (!\is_dir($options['outpath']) || !\is_writable($options['outpath'])) { echo "ERROR: Can't write to ".$options['outpath']."\n\n"; exit(3); } echo "\n>>> Converting fonts for TCPDF:\n"; echo '*** Output dir set to '.$options['outpath']."\n"; // check if there are conversion errors $errors = false; foreach ($options['fonts'] as $font) { $fontfile = \realpath($font); $fontname = TCPDF_FONTS::addTTFfont($fontfile, $options['type'], $options['enc'], $options['flags'], $options['outpath'], $options['platid'], $options['encid'], $options['addcbbox'], $options['link']); if ($fontname === false) { $errors = true; echo "--- ERROR: can't add ".$font."\n"; } else { echo "+++ OK : ".$fontfile.' added as '.$fontname."\n"; } } if ($errors) { echo "--- Process completed with ERRORS!\n\n"; exit(4); } echo ">>> Process successfully completed!\n\n"; exit(0); //============================================================+ // END OF FILE //============================================================+