3 * @package php-font-lib
4 * @link https://github.com/PhenX/php-font-lib
5 * @author Fabien Ménager <fabien.menager@gmail.com>
6 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
9 namespace FontLib\TrueType
;
12 use FontLib\BinaryStream
;
14 use OutOfBoundsException
;
17 * TrueType collection font file.
19 * @package php-font-lib
21 class Collection
extends BinaryStream
implements Iterator
, Countable
{
23 * Current iterator position.
27 private $position = 0;
29 protected $collectionOffsets = array();
30 protected $collection = array();
35 if (isset($this->numFonts
)) {
39 $this->read(4); // tag name
41 $this->version
= $this->readFixed();
42 $this->numFonts
= $this->readUInt32();
44 for ($i = 0; $i < $this->numFonts
; $i++
) {
45 $this->collectionOffsets
[] = $this->readUInt32();
52 * @throws OutOfBoundsException
55 function getFont($fontId) {
58 if (!isset($this->collectionOffsets
[$fontId])) {
59 throw new OutOfBoundsException();
62 if (isset($this->collection
[$fontId])) {
63 return $this->collection
[$fontId];
68 $font->setTableOffset($this->collectionOffsets
[$fontId]);
70 return $this->collection
[$fontId] = $font;
74 return $this->getFont($this->position
);
78 return $this->position
;
82 return ++
$this->position
;
92 return isset($this->collectionOffsets
[$this->position
]);
98 return $this->numFonts
;