$g
$char
$name
";
if ($type == "composite") {
foreach ($glyph->getGlyphIDs() as $_id) {
$s .= "
$_id ";
}
}
$s .= "
";
}
return $s;
}
protected function _encode() {
$font = $this->getFont();
$subset = $font->getSubset();
$data = $this->data;
$loca = array();
$length = 0;
foreach ($subset as $gid) {
$loca[] = $length;
$length += $data[$gid]->encode();
}
$loca[] = $length; // dummy loca
$font->getTableObject("loca")->data = $loca;
return $length;
}
} php-font-lib/src/FontLib/Table/Type/loca.php 0000644 00000003426 14716424002 0014573 0 ustar 00
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace FontLib\Table\Type;
use FontLib\Table\Table;
/**
* `loca` font table.
*
* @package php-font-lib
*/
class loca extends Table {
protected function _parse() {
$font = $this->getFont();
$offset = $font->pos();
$indexToLocFormat = $font->getData("head", "indexToLocFormat");
$numGlyphs = $font->getData("maxp", "numGlyphs");
$font->seek($offset);
$data = array();
// 2 bytes
if ($indexToLocFormat == 0) {
$d = $font->read(($numGlyphs + 1) * 2);
$loc = unpack("n*", $d);
for ($i = 0; $i <= $numGlyphs; $i++) {
$data[] = isset($loc[$i + 1]) ? $loc[$i + 1] * 2 : 0;
}
}
// 4 bytes
else {
if ($indexToLocFormat == 1) {
$d = $font->read(($numGlyphs + 1) * 4);
$loc = unpack("N*", $d);
for ($i = 0; $i <= $numGlyphs; $i++) {
$data[] = isset($loc[$i + 1]) ? $loc[$i + 1] : 0;
}
}
}
$this->data = $data;
}
function _encode() {
$font = $this->getFont();
$data = $this->data;
$indexToLocFormat = $font->getData("head", "indexToLocFormat");
$numGlyphs = $font->getData("maxp", "numGlyphs");
$length = 0;
// 2 bytes
if ($indexToLocFormat == 0) {
for ($i = 0; $i <= $numGlyphs; $i++) {
$length += $font->writeUInt16($data[$i] / 2);
}
}
// 4 bytes
else {
if ($indexToLocFormat == 1) {
for ($i = 0; $i <= $numGlyphs; $i++) {
$length += $font->writeUInt32($data[$i]);
}
}
}
return $length;
}
} php-font-lib/src/FontLib/Table/Type/nameRecord.php 0000644 00000002204 14716424002 0015725 0 ustar 00
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace FontLib\Table\Type;
use FontLib\Font;
use FontLib\BinaryStream;
/**
* Font table name record.
*
* @package php-font-lib
*/
class nameRecord extends BinaryStream {
public $platformID;
public $platformSpecificID;
public $languageID;
public $nameID;
public $length;
public $offset;
public $string;
public static $format = array(
"platformID" => self::uint16,
"platformSpecificID" => self::uint16,
"languageID" => self::uint16,
"nameID" => self::uint16,
"length" => self::uint16,
"offset" => self::uint16,
);
public function map($data) {
foreach ($data as $key => $value) {
$this->$key = $value;
}
}
public function getUTF8() {
return $this->string;
}
public function getUTF16() {
return Font::UTF8ToUTF16($this->string);
}
function __toString() {
return $this->string;
}
} php-font-lib/src/FontLib/Table/Type/hmtx.php 0000644 00000002755 14716424002 0014641 0 ustar 00
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace FontLib\Table\Type;
use FontLib\Table\Table;
/**
* `hmtx` font table.
*
* @package php-font-lib
*/
class hmtx extends Table {
protected function _parse() {
$font = $this->getFont();
$offset = $font->pos();
$numOfLongHorMetrics = $font->getData("hhea", "numOfLongHorMetrics");
$numGlyphs = $font->getData("maxp", "numGlyphs");
$font->seek($offset);
$data = array();
$metrics = $font->readUInt16Many($numOfLongHorMetrics * 2);
for ($gid = 0, $mid = 0; $gid < $numOfLongHorMetrics; $gid++) {
$advanceWidth = isset($metrics[$mid]) ? $metrics[$mid] : 0;
$mid += 1;
$leftSideBearing = isset($metrics[$mid]) ? $metrics[$mid] : 0;
$mid += 1;
$data[$gid] = array($advanceWidth, $leftSideBearing);
}
if ($numOfLongHorMetrics < $numGlyphs) {
$lastWidth = end($data);
$data = array_pad($data, $numGlyphs, $lastWidth);
}
$this->data = $data;
}
protected function _encode() {
$font = $this->getFont();
$subset = $font->getSubset();
$data = $this->data;
$length = 0;
foreach ($subset as $gid) {
$length += $font->writeUInt16($data[$gid][0]);
$length += $font->writeUInt16($data[$gid][1]);
}
return $length;
}
} php-font-lib/src/FontLib/Table/Type/hhea.php 0000644 00000002266 14716424002 0014563 0 ustar 00
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace FontLib\Table\Type;
use FontLib\Table\Table;
/**
* `hhea` font table.
*
* @package php-font-lib
*/
class hhea extends Table {
protected $def = array(
"version" => self::Fixed,
"ascent" => self::FWord,
"descent" => self::FWord,
"lineGap" => self::FWord,
"advanceWidthMax" => self::uFWord,
"minLeftSideBearing" => self::FWord,
"minRightSideBearing" => self::FWord,
"xMaxExtent" => self::FWord,
"caretSlopeRise" => self::int16,
"caretSlopeRun" => self::int16,
"caretOffset" => self::FWord,
self::int16,
self::int16,
self::int16,
self::int16,
"metricDataFormat" => self::int16,
"numOfLongHorMetrics" => self::uint16,
);
function _encode() {
$font = $this->getFont();
$this->data["numOfLongHorMetrics"] = count($font->getSubset());
return parent::_encode();
}
} php-font-lib/src/FontLib/Table/Type/maxp.php 0000644 00000002334 14716424002 0014617 0 ustar 00
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace FontLib\Table\Type;
use FontLib\Table\Table;
/**
* `maxp` font table.
*
* @package php-font-lib
*/
class maxp extends Table {
protected $def = array(
"version" => self::Fixed,
"numGlyphs" => self::uint16,
"maxPoints" => self::uint16,
"maxContours" => self::uint16,
"maxComponentPoints" => self::uint16,
"maxComponentContours" => self::uint16,
"maxZones" => self::uint16,
"maxTwilightPoints" => self::uint16,
"maxStorage" => self::uint16,
"maxFunctionDefs" => self::uint16,
"maxInstructionDefs" => self::uint16,
"maxStackElements" => self::uint16,
"maxSizeOfInstructions" => self::uint16,
"maxComponentElements" => self::uint16,
"maxComponentDepth" => self::uint16,
);
function _encode() {
$font = $this->getFont();
$this->data["numGlyphs"] = count($font->getSubset());
return parent::_encode();
}
} php-font-lib/src/FontLib/Table/Type/os2.php 0000644 00000003046 14716424002 0014356 0 ustar 00
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace FontLib\Table\Type;
use FontLib\Table\Table;
/**
* `OS/2` font table.
*
* @package php-font-lib
*/
class os2 extends Table {
protected $def = array(
"version" => self::uint16,
"xAvgCharWidth" => self::int16,
"usWeightClass" => self::uint16,
"usWidthClass" => self::uint16,
"fsType" => self::int16,
"ySubscriptXSize" => self::int16,
"ySubscriptYSize" => self::int16,
"ySubscriptXOffset" => self::int16,
"ySubscriptYOffset" => self::int16,
"ySuperscriptXSize" => self::int16,
"ySuperscriptYSize" => self::int16,
"ySuperscriptXOffset" => self::int16,
"ySuperscriptYOffset" => self::int16,
"yStrikeoutSize" => self::int16,
"yStrikeoutPosition" => self::int16,
"sFamilyClass" => self::int16,
"panose" => array(self::uint8, 10),
"ulCharRange" => array(self::uint32, 4),
"achVendID" => array(self::char, 4),
"fsSelection" => self::uint16,
"fsFirstCharIndex" => self::uint16,
"fsLastCharIndex" => self::uint16,
"typoAscender" => self::int16,
"typoDescender" => self::int16,
"typoLineGap" => self::int16,
"winAscent" => self::int16,
"winDescent" => self::int16,
);
} php-font-lib/src/FontLib/Table/Type/name.php 0000644 00000011352 14716424002 0014572 0 ustar 00
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace FontLib\Table\Type;
use FontLib\Table\Table;
use FontLib\Font;
/**
* `name` font table.
*
* @package php-font-lib
*/
class name extends Table {
private static $header_format = array(
"format" => self::uint16,
"count" => self::uint16,
"stringOffset" => self::uint16,
);
const NAME_COPYRIGHT = 0;
const NAME_NAME = 1;
const NAME_SUBFAMILY = 2;
const NAME_SUBFAMILY_ID = 3;
const NAME_FULL_NAME = 4;
const NAME_VERSION = 5;
const NAME_POSTSCRIPT_NAME = 6;
const NAME_TRADEMARK = 7;
const NAME_MANUFACTURER = 8;
const NAME_DESIGNER = 9;
const NAME_DESCRIPTION = 10;
const NAME_VENDOR_URL = 11;
const NAME_DESIGNER_URL = 12;
const NAME_LICENSE = 13;
const NAME_LICENSE_URL = 14;
const NAME_PREFERRE_FAMILY = 16;
const NAME_PREFERRE_SUBFAMILY = 17;
const NAME_COMPAT_FULL_NAME = 18;
const NAME_SAMPLE_TEXT = 19;
static $nameIdCodes = array(
0 => "Copyright",
1 => "FontName",
2 => "FontSubfamily",
3 => "UniqueID",
4 => "FullName",
5 => "Version",
6 => "PostScriptName",
7 => "Trademark",
8 => "Manufacturer",
9 => "Designer",
10 => "Description",
11 => "FontVendorURL",
12 => "FontDesignerURL",
13 => "LicenseDescription",
14 => "LicenseURL",
// 15
16 => "PreferredFamily",
17 => "PreferredSubfamily",
18 => "CompatibleFullName",
19 => "SampleText",
);
static $platforms = array(
0 => "Unicode",
1 => "Macintosh",
// 2 => Reserved
3 => "Microsoft",
);
static $platformSpecific = array(
// Unicode
0 => array(
0 => "Default semantics",
1 => "Version 1.1 semantics",
2 => "ISO 10646 1993 semantics (deprecated)",
3 => "Unicode 2.0 or later semantics",
),
// Macintosh
1 => array(
0 => "Roman",
1 => "Japanese",
2 => "Traditional Chinese",
3 => "Korean",
4 => "Arabic",
5 => "Hebrew",
6 => "Greek",
7 => "Russian",
8 => "RSymbol",
9 => "Devanagari",
10 => "Gurmukhi",
11 => "Gujarati",
12 => "Oriya",
13 => "Bengali",
14 => "Tamil",
15 => "Telugu",
16 => "Kannada",
17 => "Malayalam",
18 => "Sinhalese",
19 => "Burmese",
20 => "Khmer",
21 => "Thai",
22 => "Laotian",
23 => "Georgian",
24 => "Armenian",
25 => "Simplified Chinese",
26 => "Tibetan",
27 => "Mongolian",
28 => "Geez",
29 => "Slavic",
30 => "Vietnamese",
31 => "Sindhi",
),
// Microsoft
3 => array(
0 => "Symbol",
1 => "Unicode BMP (UCS-2)",
2 => "ShiftJIS",
3 => "PRC",
4 => "Big5",
5 => "Wansung",
6 => "Johab",
// 7 => Reserved
// 8 => Reserved
// 9 => Reserved
10 => "Unicode UCS-4",
),
);
protected function _parse() {
$font = $this->getFont();
$tableOffset = $font->pos();
$data = $font->unpack(self::$header_format);
$records = array();
for ($i = 0; $i < $data["count"]; $i++) {
$record = new nameRecord();
$record_data = $font->unpack(nameRecord::$format);
$record->map($record_data);
$records[] = $record;
}
$names = array();
foreach ($records as $record) {
$font->seek($tableOffset + $data["stringOffset"] + $record->offset);
$s = $font->read($record->length);
$record->string = Font::UTF16ToUTF8($s);
$names[$record->nameID] = $record;
}
$data["records"] = $names;
$this->data = $data;
}
protected function _encode() {
$font = $this->getFont();
/** @var nameRecord[] $records */
$records = $this->data["records"];
$count_records = count($records);
$this->data["count"] = $count_records;
$this->data["stringOffset"] = 6 + $count_records * 12; // 6 => uint16 * 3, 12 => sizeof self::$record_format
$length = $font->pack(self::$header_format, $this->data);
$offset = 0;
foreach ($records as $record) {
$record->length = mb_strlen($record->getUTF16(), "8bit");
$record->offset = $offset;
$offset += $record->length;
$length += $font->pack(nameRecord::$format, (array)$record);
}
foreach ($records as $record) {
$str = $record->getUTF16();
$length += $font->write($str, mb_strlen($str, "8bit"));
}
return $length;
}
}
php-font-lib/src/FontLib/Table/Type/head.php 0000644 00000002510 14716424002 0014547 0 ustar 00
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace FontLib\Table\Type;
use FontLib\Table\Table;
use Exception;
/**
* `head` font table.
*
* @package php-font-lib
*/
class head extends Table {
protected $def = array(
"tableVersion" => self::Fixed,
"fontRevision" => self::Fixed,
"checkSumAdjustment" => self::uint32,
"magicNumber" => self::uint32,
"flags" => self::uint16,
"unitsPerEm" => self::uint16,
"created" => self::longDateTime,
"modified" => self::longDateTime,
"xMin" => self::FWord,
"yMin" => self::FWord,
"xMax" => self::FWord,
"yMax" => self::FWord,
"macStyle" => self::uint16,
"lowestRecPPEM" => self::uint16,
"fontDirectionHint" => self::int16,
"indexToLocFormat" => self::int16,
"glyphDataFormat" => self::int16,
);
protected function _parse() {
parent::_parse();
if ($this->data["magicNumber"] != 0x5F0F3CF5) {
throw new Exception("Incorrect magic number (" . dechex($this->data["magicNumber"]) . ")");
}
}
} php-font-lib/src/FontLib/Table/Type/kern.php 0000644 00000003476 14716424002 0014621 0 ustar 00
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace FontLib\Table\Type;
use FontLib\Table\Table;
/**
* `kern` font table.
*
* @package php-font-lib
*/
class kern extends Table {
protected function _parse() {
$font = $this->getFont();
$data = $font->unpack(array(
"version" => self::uint16,
"nTables" => self::uint16,
// only the first subtable will be parsed
"subtableVersion" => self::uint16,
"length" => self::uint16,
"coverage" => self::uint16,
));
$data["format"] = ($data["coverage"] >> 8);
$subtable = array();
switch ($data["format"]) {
case 0:
$subtable = $font->unpack(array(
"nPairs" => self::uint16,
"searchRange" => self::uint16,
"entrySelector" => self::uint16,
"rangeShift" => self::uint16,
));
$pairs = array();
$tree = array();
$values = $font->readUInt16Many($subtable["nPairs"] * 3);
for ($i = 0, $idx = 0; $i < $subtable["nPairs"]; $i++) {
$left = $values[$idx++];
$right = $values[$idx++];
$value = $values[$idx++];
if ($value >= 0x8000) {
$value -= 0x10000;
}
$pairs[] = array(
"left" => $left,
"right" => $right,
"value" => $value,
);
$tree[$left][$right] = $value;
}
//$subtable["pairs"] = $pairs;
$subtable["tree"] = $tree;
break;
case 1:
case 2:
case 3:
break;
}
$data["subtable"] = $subtable;
$this->data = $data;
}
} php-font-lib/src/FontLib/Table/Table.php 0000644 00000003424 14716424002 0013761 0 ustar 00
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace FontLib\Table;
use FontLib\TrueType\File;
use FontLib\Font;
use FontLib\BinaryStream;
/**
* Generic font table.
*
* @package php-font-lib
*/
class Table extends BinaryStream {
/**
* @var DirectoryEntry
*/
protected $entry;
protected $def = array();
public $data;
final public function __construct(DirectoryEntry $entry) {
$this->entry = $entry;
$entry->setTable($this);
}
/**
* @return File
*/
public function getFont() {
return $this->entry->getFont();
}
protected function _encode() {
if (empty($this->data)) {
Font::d(" >> Table is empty");
return 0;
}
return $this->getFont()->pack($this->def, $this->data);
}
protected function _parse() {
$this->data = $this->getFont()->unpack($this->def);
}
protected function _parseRaw() {
$this->data = $this->getFont()->read($this->entry->length);
}
protected function _encodeRaw() {
return $this->getFont()->write($this->data, $this->entry->length);
}
public function toHTML() {
return "