| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @package php-font-lib |
| 5 |
* @link https://github.com/dompdf/php-font-lib |
| 6 |
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
| 7 |
*/ |
| 8 |
namespace WCPOS\Vendor\FontLib; |
| 9 |
|
| 10 |
use WCPOS\Vendor\FontLib\Exception\FontNotFoundException; |
| 11 |
/** |
| 12 |
* Generic font file. |
| 13 |
* |
| 14 |
* @package php-font-lib |
| 15 |
*/ |
| 16 |
class Font |
| 17 |
{ |
| 18 |
static $debug = \false; |
| 19 |
/** |
| 20 |
* @param string $file The font file |
| 21 |
* |
| 22 |
* @return TrueType\File|null $file |
| 23 |
*/ |
| 24 |
public static function load($file) |
| 25 |
{ |
| 26 |
if (!\file_exists($file)) { |
| 27 |
throw new FontNotFoundException($file); |
| 28 |
} |
| 29 |
$header = \file_get_contents($file, \false, null, 0, 4); |
| 30 |
$class = null; |
| 31 |
switch ($header) { |
| 32 |
case "\x00\x01\x00\x00": |
| 33 |
case "true": |
| 34 |
case "typ1": |
| 35 |
$class = "TrueType\\File"; |
| 36 |
break; |
| 37 |
case "OTTO": |
| 38 |
$class = "OpenType\\File"; |
| 39 |
break; |
| 40 |
case "wOFF": |
| 41 |
$class = "WOFF\\File"; |
| 42 |
break; |
| 43 |
case "ttcf": |
| 44 |
$class = "TrueType\\Collection"; |
| 45 |
break; |
| 46 |
// Unknown type or EOT |
| 47 |
default: |
| 48 |
$magicNumber = \file_get_contents($file, \false, null, 34, 2); |
| 49 |
if ($magicNumber === "LP") { |
| 50 |
$class = "EOT\\File"; |
| 51 |
} |
| 52 |
} |
| 53 |
if ($class) { |
| 54 |
$class = "WCPOS\\Vendor\\FontLib\\{$class}"; |
| 55 |
/** @var TrueType\File $obj */ |
| 56 |
$obj = new $class(); |
| 57 |
$obj->load($file); |
| 58 |
return $obj; |
| 59 |
} |
| 60 |
return null; |
| 61 |
} |
| 62 |
static function d($str) |
| 63 |
{ |
| 64 |
if (!self::$debug) { |
| 65 |
return; |
| 66 |
} |
| 67 |
echo "{$str}\n"; |
| 68 |
} |
| 69 |
static function UTF16ToUTF8($str) |
| 70 |
{ |
| 71 |
return \mb_convert_encoding($str, "utf-8", "utf-16"); |
| 72 |
} |
| 73 |
static function UTF8ToUTF16($str) |
| 74 |
{ |
| 75 |
return \mb_convert_encoding($str, "utf-16", "utf-8"); |
| 76 |
} |
| 77 |
} |
| 78 |
|