diff --git a/include/class.i18n.php b/include/class.i18n.php index d3362e5d33b66ff5eaf401de17278cc54a894f0c..4a9540520c26816b0c405ccfe318402ecf6ef840 100644 --- a/include/class.i18n.php +++ b/include/class.i18n.php @@ -332,6 +332,29 @@ class Internationalization { return self::getDefaultLanguage(); } + static function getTtfFonts() { + if (!class_exists('Phar')) + return; + $fonts = $subs = array(); + foreach (self::availableLanguages() as $code=>$info) { + if (!$info['phar'] || !isset($info['fonts'])) + continue; + foreach ($info['fonts'] as $simple => $collection) { + foreach ($collection as $type => $name) { + list($name, $url) = $name; + $ttffile = 'phar://' . $info['path'] . '/fonts/' . $name; + if (file_exists($ttffile)) + $fonts[$simple][$type] = $ttffile; + } + if (@$collection[':sub']) + $subs[] = $simple; + } + } + $rv = array($fonts, $subs); + Signal::send('config.ttfonts', null, $rv); + return $rv; + } + static function bootstrap() { require_once INCLUDE_DIR . 'class.translation.php'; diff --git a/include/i18n/langs.php b/include/i18n/langs.php index 205ba63fdcfb82b0bf9d77bb791c3dd5c7543b74..f48058009fb70d51aabcd144716a8972ea8baa1a 100644 --- a/include/i18n/langs.php +++ b/include/i18n/langs.php @@ -641,7 +641,22 @@ return array( ), "th" => array( "name" => "Thai", - "nativeName" => "ไทย" + "nativeName" => "ไทย", + "fonts" => array( + "garuda" => array( + 'R' => array("Garuda.ttf","http://www.osticket.com/sites/default/files/fonts/Garuda.ttf"), + 'B' => array("Garuda-Bold.ttf","http://www.osticket.com/sites/default/files/fonts/Garuda-Bold.ttf"), + 'I' => array("Garuda-Oblique.ttf","http://www.osticket.com/sites/default/files/fonts/Garuda-Oblique.ttf"), + 'BI' => array("Garuda-BoldOblique.ttf","http://www.osticket.com/sites/default/files/fonts/Garuda-BoldOblique.ttf"), + ':sub' => true, + ), + "norasi" => array( + 'R' => array("Norasi.ttf","http://www.osticket.com/sites/default/files/fonts/Norasi.ttf"), + 'B' => array("Norasi-Bold.ttf","http://www.osticket.com/sites/default/files/fonts/Norasi-Bold.ttf"), + 'I' => array("Norasi-Oblique.ttf","http://www.osticket.com/sites/default/files/fonts/Norasi-Oblique.ttf"), + 'BI' => array("Norasi-BoldOblique.ttf","http://www.osticket.com/sites/default/files/fonts/Norasi-BoldOblique.ttf"), + ), + ), ), "ti" => array( "name" => "Tigrinya", diff --git a/include/mpdf/config.php b/include/mpdf/config.php index f0cd3569e5a10e5b4393a42bda5b8f7f0e4a64c1..e85795b699baef06efab105b66395da2bc875d3b 100755 --- a/include/mpdf/config.php +++ b/include/mpdf/config.php @@ -77,7 +77,7 @@ $this->biDirectional=false; // automatically determine BIDI text in LTR page $this->autoFontGroupSize = 2; // 1: individual words are spanned; 2: words+; 3: as big chunks as possible. $this->useLang = true; // Default changed in mPDF 4.0 -$this->useSubstitutions = false; // Substitute missing characters in UTF-8(multibyte) documents - from other fonts +$this->useSubstitutions = true; // Substitute missing characters in UTF-8(multibyte) documents - from other fonts $this->falseBoldWeight = 5; // Weight for bold text when using an artificial (outline) bold; value 0 (off) - 10 (rec. max) // CONFIGURATION diff --git a/include/mpdf/config_fonts.php b/include/mpdf/config_fonts.php index ab6c8a7247299b92484904e755c0ce1635e2987f..31c4e3015c289a003309130f9731ec82d52bf257 100755 --- a/include/mpdf/config_fonts.php +++ b/include/mpdf/config_fonts.php @@ -129,7 +129,7 @@ $this->fontdata = array( 'R' => "ocrb10.ttf", ), -/* Thai fonts */ +/* Thai fonts "garuda" => array( 'R' => "Garuda.ttf", 'B' => "Garuda-Bold.ttf", @@ -301,4 +301,12 @@ $this->mono_fonts = array('dejavusansmono','freemono','liberationmono','courier' 'couriernew','monotypecorsiva' ); -?> \ No newline at end of file +// Add fonts from language packs + +list($phar_fonts, $phar_subs) = Internationalization::getTtfFonts(); +$this->fontdata += $phar_fonts; +foreach ($phar_subs as $simple) { + if (!in_array($simple, $this->backupSubsFont)) + $this->backupSubsFont[] = $simple; +} +?> diff --git a/include/mpdf/mpdf.php b/include/mpdf/mpdf.php index 81cdfe5e5ac64cd583d37578eabb65aa38f17c98..af04fa3b483c53e838bd8f4835d2443dbe073764 100755 --- a/include/mpdf/mpdf.php +++ b/include/mpdf/mpdf.php @@ -1220,7 +1220,9 @@ function mPDF($mode='',$format='A4',$default_font_size=0,$default_font='',$mgl=1 $this->useSubstitutions = true; $this->SetSubstitutions(); } - else { $this->useSubstitutions = false; } + // osTicket custom — seems that substitions are necessary for eastern + // languages to work with packaged fonts + //else { $this->useSubstitutions = false; } /*-- HTML-CSS --*/ @@ -3148,7 +3150,10 @@ function AddFont($family,$style='') { if (!file_exists($ttffile)) { $ttffile = ''; } } if (!$ttffile) { - $ttffile = _MPDF_TTFONTPATH.$this->fontdata[$family][$stylekey]; + $ttffile = $this->fontdata[$family][$stylekey]; + if ($ttffile[0] != '/' && $ttffile[1] != ':' && strpos($ttffile, 'phar://') !== 0) + // Not an absolute path + $ttffile = _MPDF_TTFONTPATH.$ttffile; if (!file_exists($ttffile)) { die("mPDF Error - cannot find TTF TrueType font file - ".$ttffile); } } $ttfstat = stat($ttffile); diff --git a/setup/cli/modules/i18n.php b/setup/cli/modules/i18n.php index 269386dfd55097de993e3d6bbc0309e474d9cc67..57a8bd0abf91f0d5fc6d016c22c56928bfeb9199 100644 --- a/setup/cli/modules/i18n.php +++ b/setup/cli/modules/i18n.php @@ -41,6 +41,7 @@ class i18n_Compiler extends Module { static $crowdin_api_url = 'http://i18n.osticket.com/api/project/{project}/{command}'; function _http_get($url) { + $this->stdout->write(">>> Downloading $url\n"); #curl post $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); @@ -198,6 +199,25 @@ class i18n_Compiler extends Module { $this->stderr->write(str_replace('_','-',$lang) .": Unable to fetch jQuery UI Datepicker locale file\n"); + // True type fonts for PDF printing + $langs = (include I18N_DIR . 'langs.php'); + $info = $langs[$lang]; + if (isset($info['fonts'])) { + foreach ($info['fonts'] as $name => $types) { + foreach ($types as $code => $fullname) { + list($ttf, $url) = $fullname; + if (!$url) + continue; + list($code, $file) = $this->_http_get($url); + if ($code == 200) + $phar->addFromString('fonts/'.$ttf, $file); + else + $this->stderr->write( + "*** Unable to fetch $url\n"); + } + } + } + // Add in the messages.mo.php file if ($po_file) { $pipes = array();