Skip to content
Snippets Groups Projects
Commit a9bd2395 authored by Jared Hancock's avatar Jared Hancock
Browse files

i18n: Package fonts with the Thai language pack

This patch also makes a slight edit to mPDF to allow better detection of
substitions in characters, as the DejaVu fonts shipped do not support Thai
glyphs.
parent b4520569
No related branches found
No related tags found
No related merge requests found
......@@ -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';
......
......@@ -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",
......
......@@ -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
......
......@@ -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;
}
?>
......@@ -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);
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment