/
Font.php
96 lines (83 loc) · 2.33 KB
/
Font.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/*
* This file is part of the Thinreports PHP package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Thinreports\Generator\PDF;
/**
* @access private
*/
class Font
{
/**
* @var string[]
*/
static public $installed_builtin_fonts = array();
static public $builtin_unicode_fonts = array(
'IPAMincho' => 'ipam.ttf',
'IPAPMincho' => 'ipamp.ttf',
'IPAGothic' => 'ipag.ttf',
'IPAPGothic' => 'ipagp.ttf'
);
static public $builtin_font_aliases = array(
'Courier New' => 'Courier',
'Times New Roman' => 'Times'
);
/**
* @param string $name
* @return string
*/
static public function getFontName($name)
{
if (array_key_exists($name, self::$builtin_font_aliases)) {
return self::$builtin_font_aliases[$name];
}
if (array_key_exists($name, self::$builtin_unicode_fonts)) {
if (self::isInstalledFont($name)) {
return static::$installed_builtin_fonts[$name];
} else {
return self::installBuiltinFont($name);
}
}
return $name;
}
/**
* @param string $name
* @return string
* @see http://www.tcpdf.org/doc/code/classTCPDF__FONTS.html
*/
static public function installBuiltinFont($name)
{
$filename = self::getBuiltinFontPath($name);
$font_name = \TCPDF_FONTS::addTTFFont($filename, 'TrueTypeUnicode', '', 32);
static::$installed_builtin_fonts[$name] = $font_name;
return $font_name;
}
/**
* @param string $name
* @return boolean
*/
static public function isInstalledFont($name)
{
return array_key_exists($name, static::$installed_builtin_fonts);
}
/**
* @param string $name
* @return string
*/
static public function getBuiltinFontPath($name)
{
$font_directory = realpath(__DIR__ . '/../../../../fonts');
return $font_directory . '/' . self::$builtin_unicode_fonts[$name];
}
/**
* @param string $name
* @return boolean
*/
static public function isBuiltinUnicodeFont($name)
{
return in_array($name, array_keys(static::$builtin_unicode_fonts));
}
}