Skip to content

Commit

Permalink
Fix issue load Local Font in PHP 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Oct 14, 2022
1 parent 7bc5c87 commit 5e41a24
Show file tree
Hide file tree
Showing 35 changed files with 76 additions and 66 deletions.
6 changes: 3 additions & 3 deletions framework/library/FontLib/AdobeFontMetrics.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace FontLib;
Expand Down Expand Up @@ -35,7 +35,7 @@ function write($file, $encoding = null) {
$encoding = preg_replace("/[^a-z0-9-_]/", "", $encoding);
$map_file = dirname(__FILE__) . "/../maps/$encoding.map";
if (!file_exists($map_file)) {
throw new \Exception("Unkown encoding ($encoding)");
throw new \Exception("Unknown encoding ($encoding)");
}

$map = new EncodingMap($map_file);
Expand Down Expand Up @@ -139,7 +139,7 @@ function write($file, $encoding = null) {
$this->endSection("CharMetrics");

$kern = $font->getData("kern", "subtable");
$tree = $kern["tree"];
$tree = is_array($kern) ? $kern["tree"] : null;

if (!$encoding && is_array($tree)) {
$this->startSection("KernData");
Expand Down
4 changes: 2 additions & 2 deletions framework/library/FontLib/Autoloader.php
Expand Up @@ -2,8 +2,8 @@
/**
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien M�nager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace FontLib;
Expand Down
13 changes: 9 additions & 4 deletions framework/library/FontLib/BinaryStream.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace FontLib;
Expand Down Expand Up @@ -63,7 +63,7 @@ public function load($filename) {
*/
public function open($filename, $mode = self::modeRead) {
if (!in_array($mode, array(self::modeRead, self::modeWrite, self::modeReadWrite))) {
throw new \Exception("Unkown file open mode");
throw new \Exception("Unknown file open mode");
}

$this->f = fopen($filename, $mode);
Expand Down Expand Up @@ -137,12 +137,17 @@ public function skip($n) {
fseek($this->f, $n, SEEK_CUR);
}

/**
* @param int $n The number of bytes to read
*
* @return string
*/
public function read($n) {
if ($n < 1) {
return "";
}

return fread($this->f, $n);
return (string) fread($this->f, $n);
}

public function write($data, $length = null) {
Expand Down Expand Up @@ -282,7 +287,7 @@ public function readLongDateTime() {
$date = 0;
}

return strftime("%Y-%m-%d %H:%M:%S", $date);
return date("Y-m-d H:i:s", $date);
}

public function writeLongDateTime($data) {
Expand Down
21 changes: 10 additions & 11 deletions framework/library/FontLib/EOT/File.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace FontLib\EOT;
Expand Down Expand Up @@ -61,22 +61,21 @@ function parse() {
// TODO Read font data ...
}

/**
* Little endian version of the read method
*
* @param int $n The number of bytes to read
*
* @return string
*/
/**
* Little endian version of the read method
*
* @param int $n The number of bytes to read
*
* @return string
*/
public function read($n) {
if ($n < 1) {
return "";
}

$string = fread($this->f, $n);
$chunks = str_split($string, 2);
$string = (string) fread($this->f, $n);
$chunks = mb_str_split($string, 2, '8bit');
$chunks = array_map("strrev", $chunks);

return implode("", $chunks);
}

Expand Down
2 changes: 1 addition & 1 deletion framework/library/FontLib/EOT/Header.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace FontLib\EOT;
Expand Down
2 changes: 1 addition & 1 deletion framework/library/FontLib/EncodingMap.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace FontLib;
Expand Down
4 changes: 2 additions & 2 deletions framework/library/FontLib/Font.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace FontLib;
Expand All @@ -28,7 +28,7 @@ public static function load($file) {
throw new FontNotFoundException($file);
}

$header = file_get_contents($file, false, null, null, 4);
$header = file_get_contents($file, false, null, 0, 4);
$class = null;

switch ($header) {
Expand Down
13 changes: 6 additions & 7 deletions framework/library/FontLib/Glyph/Outline.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @version $Id: Font_Table_glyf.php 46 2012-04-02 20:22:38Z fabien.menager $
*/
namespace FontLib\Glyph;
Expand Down Expand Up @@ -33,6 +33,9 @@ class Outline extends BinaryStream {
public $xMax;
public $yMax;

/**
* @var string|null
*/
public $raw;

/**
Expand Down Expand Up @@ -75,11 +78,7 @@ function __construct(glyf $table, $offset = null, $size = null) {
function parse(BinaryStream $font) {
$font->seek($this->offset);

if (!$this->size) {
return;
}

$this->raw = $font->read($this->size);
$this->raw = $font->read($this->size);
}

function parseData() {
Expand All @@ -96,7 +95,7 @@ function parseData() {
function encode() {
$font = $this->getFont();

return $font->write($this->raw, strlen($this->raw));
return $font->write($this->raw, mb_strlen((string) $this->raw, '8bit'));
}

function getSVGContours() {
Expand Down
2 changes: 1 addition & 1 deletion framework/library/FontLib/Glyph/OutlineComponent.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @version $Id: Font_Table_glyf.php 46 2012-04-02 20:22:38Z fabien.menager $
*/

Expand Down
2 changes: 1 addition & 1 deletion framework/library/FontLib/Glyph/OutlineComposite.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @version $Id: Font_Table_glyf.php 46 2012-04-02 20:22:38Z fabien.menager $
*/

Expand Down
6 changes: 3 additions & 3 deletions framework/library/FontLib/Glyph/OutlineSimple.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @version $Id: Font_Table_glyf.php 46 2012-04-02 20:22:38Z fabien.menager $
*/

Expand Down Expand Up @@ -265,7 +265,7 @@ public function getSVGContours($points = null) {
$points = $this->points;
}

$length = count($points);
$length = (empty($points) ? 0 : count($points));
$firstIndex = 0;
$count = 0;

Expand Down Expand Up @@ -332,4 +332,4 @@ protected function getSVGPath($points, $startIndex, $count) {
function midValue($a, $b) {
return $a + ($b - $a) / 2;
}
}
}
2 changes: 1 addition & 1 deletion framework/library/FontLib/Header.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace FontLib;

Expand Down
2 changes: 1 addition & 1 deletion framework/library/FontLib/OpenType/File.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace FontLib\OpenType;
Expand Down
2 changes: 1 addition & 1 deletion framework/library/FontLib/OpenType/TableDirectoryEntry.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace FontLib\OpenType;
Expand Down
11 changes: 8 additions & 3 deletions framework/library/FontLib/Table/DirectoryEntry.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace FontLib\Table;

Expand Down Expand Up @@ -36,15 +36,20 @@ class DirectoryEntry extends BinaryStream {

protected $origF;

/**
* @param string $data
*
* @return int
*/
static function computeChecksum($data) {
$len = strlen($data);
$len = mb_strlen($data, '8bit');
$mod = $len % 4;

if ($mod) {
$data = str_pad($data, $len + (4 - $mod), "\0");
}

$len = strlen($data);
$len = mb_strlen($data, '8bit');

$hi = 0x0000;
$lo = 0x0000;
Expand Down
2 changes: 1 addition & 1 deletion framework/library/FontLib/Table/Table.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace FontLib\Table;

Expand Down
2 changes: 1 addition & 1 deletion framework/library/FontLib/Table/Type/cmap.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace FontLib\Table\Type;
Expand Down
2 changes: 1 addition & 1 deletion framework/library/FontLib/Table/Type/glyf.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace FontLib\Table\Type;
Expand Down
2 changes: 1 addition & 1 deletion framework/library/FontLib/Table/Type/head.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace FontLib\Table\Type;
Expand Down
2 changes: 1 addition & 1 deletion framework/library/FontLib/Table/Type/hhea.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace FontLib\Table\Type;
Expand Down
2 changes: 1 addition & 1 deletion framework/library/FontLib/Table/Type/hmtx.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace FontLib\Table\Type;
Expand Down
2 changes: 1 addition & 1 deletion framework/library/FontLib/Table/Type/kern.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace FontLib\Table\Type;
Expand Down
2 changes: 1 addition & 1 deletion framework/library/FontLib/Table/Type/loca.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace FontLib\Table\Type;
Expand Down
2 changes: 1 addition & 1 deletion framework/library/FontLib/Table/Type/maxp.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace FontLib\Table\Type;
Expand Down
2 changes: 1 addition & 1 deletion framework/library/FontLib/Table/Type/name.php
Expand Up @@ -3,7 +3,7 @@
* @package php-font-lib
* @link https://github.com/PhenX/php-font-lib
* @author Fabien Ménager <fabien.menager@gmail.com>
* @license https://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace FontLib\Table\Type;
Expand Down

0 comments on commit 5e41a24

Please sign in to comment.