src/OtlDump.php
function getCMAP4($unicode_cmap_offset, &$glyphToChar, &$charToGlyph)
	{
		$this->maxUniChar = 0;
		$this->seek($unicode_cmap_offset + 2);
		$length = $this->read_ushort();
		$limit = $unicode_cmap_offset + $length;
		$this->skip(2);

		$segCount = $this->read_ushort() / 2;
		$this->skip(6);
		$endCount = [];
		for ($i = 0; $i < $segCount; $i++) {
			$endCount[] = $this->read_ushort();
		}
		$this->skip(2);
		$startCount = [];
		for ($i = 0; $i < $segCount; $i++) {
			$startCount[] = $this->read_ushort();
		}
		$idDelta = [];
		for ($i = 0; $i < $segCount; $i++) {
			$idDelta[] = $this->read_short();
		}  // ???? was unsigned short
		$idRangeOffset_start = $this->_pos;
		$idRangeOffset = [];
		for ($i = 0; $i < $segCount; $i++) {
			$idRangeOffset[] = $this->read_ushort();
		}

		for ($n = 0; $n < $segCount; $n++) {
			$endpoint = ($endCount[$n] + 1);
			for ($unichar = $startCount[$n]; $unichar < $endpoint; $unichar++) {
				if ($idRangeOffset[$n] == 0) {
					$glyph = ($unichar + $idDelta[$n]) & 0xFFFF;
				} else {
					$offset = ($unichar - $startCount[$n]) * 2 + $idRangeOffset[$n];
					$offset = $idRangeOffset_start + 2 * $n + $offset;
					if ($offset >= $limit) {
						$glyph = 0;
					} else {
						$glyph = $this->get_ushort($offset);
						if ($glyph != 0) {
							$glyph = ($glyph + $idDelta[$n]) & 0xFFFF;
						}
					}
				}
				$charToGlyph[$unichar] = $glyph;
				if ($unichar < 196608) {
					$this->maxUniChar = max($unichar, $this->maxUniChar);
				}
				$glyphToChar[$glyph][] = $unichar;
			}
		}
	}
function getCMAP4($unicode_cmap_offset, &$glyphToChar, &$charToGlyph)
	{
		$this->maxUniChar = 0;
		$this->seek($unicode_cmap_offset + 2);
		$length = $this->read_ushort();
		$limit = $unicode_cmap_offset + $length;
		$this->skip(2);

		$segCount = $this->read_ushort() / 2;
		$this->skip(6);
		$endCount = [];
		for ($i = 0; $i < $segCount; $i++) {
			$endCount[] = $this->read_ushort();
		}
		$this->skip(2);
		$startCount = [];
		for ($i = 0; $i < $segCount; $i++) {
			$startCount[] = $this->read_ushort();
		}
		$idDelta = [];
		for ($i = 0; $i < $segCount; $i++) {
			$idDelta[] = $this->read_short();
		}  // ???? was unsigned short
		$idRangeOffset_start = $this->_pos;
		$idRangeOffset = [];
		for ($i = 0; $i < $segCount; $i++) {
			$idRangeOffset[] = $this->read_ushort();
		}

		for ($n = 0; $n < $segCount; $n++) {
			$endpoint = ($endCount[$n] + 1);
			for ($unichar = $startCount[$n]; $unichar < $endpoint; $unichar++) {
				if ($idRangeOffset[$n] == 0) {
					$glyph = ($unichar + $idDelta[$n]) & 0xFFFF;
				} else {
					$offset = ($unichar - $startCount[$n]) * 2 + $idRangeOffset[$n];
					$offset = $idRangeOffset_start + 2 * $n + $offset;
					if ($offset >= $limit) {
						$glyph = 0;
					} else {
						$glyph = $this->get_ushort($offset);
						if ($glyph != 0) {
							$glyph = ($glyph + $idDelta[$n]) & 0xFFFF;
						}
					}
				}
				$charToGlyph[$unichar] = $glyph;
				if ($unichar < 196608) {
					$this->maxUniChar = max($unichar, $this->maxUniChar);
				}
				$glyphToChar[$glyph][] = $unichar;
			}
		}
	}
function getCMAP4 ( $ unicode_cmap_offset , & $ glyphToChar , & $ charToGlyph ) { $ this -> maxUniChar = 0 ; $ this -> seek ( $ unicode_cmap_offset + 2 ) ; $ length = $ this -> read_ushort ( ) ; $ limit = $ unicode_cmap_offset + $ length ; $ this -> skip ( 2 ) ; $ segCount = $ this -> read_ushort ( ) / 2 ; $ this -> skip ( 6 ) ; $ endCount = [ ] ; for ( $ i = 0 ; $ i < $ segCount ; $ i ++ ) { $ endCount [ ] = $ this -> read_ushort ( ) ; } $ this -> skip ( 2 ) ; $ startCount = [ ] ; for ( $ i = 0 ; $ i < $ segCount ; $ i ++ ) { $ startCount [ ] = $ this -> read_ushort ( ) ; } $ idDelta = [ ] ; for ( $ i = 0 ; $ i < $ segCount ; $ i ++ ) { $ idDelta [ ] = $ this -> read_short ( ) ; } // ???? was unsigned short $ idRangeOffset_start = $ this -> _pos ; $ idRangeOffset = [ ] ; for ( $ i = 0 ; $ i < $ segCount ; $ i ++ ) { $ idRangeOffset [ ] = $ this -> read_ushort ( ) ; } for ( $ n = 0 ; $ n < $ segCount ; $ n ++ ) { $ endpoint = ( $ endCount [ $ n ] + 1 ) ; for ( $ unichar = $ startCount [ $ n ] ; $ unichar < $ endpoint ; $ unichar ++ ) { if ( $ idRangeOffset [ $ n ] == 0 ) { $ glyph = ( $ unichar + $ idDelta [ $ n ] ) & 0xFFFF ; } else { $ offset = ( $ unichar - $ startCount [ $ n ] ) * 2 + $ idRangeOffset [ $ n ] ; $ offset = $ idRangeOffset_start + 2 * $ n + $ offset ; if ( $ offset >= $ limit ) { $ glyph = 0 ; } else { $ glyph = $ this -> get_ushort ( $ offset ) ; if ( $ glyph != 0 ) { $ glyph = ( $ glyph + $ idDelta [ $ n ] ) & 0xFFFF ; } } } $ charToGlyph [ $ unichar ] = $ glyph ; if ( $ unichar < 196608 ) { $ this -> maxUniChar = max ( $ unichar , $ this -> maxUniChar ) ; } $ glyphToChar [ $ glyph ] [ ] = $ unichar ; } } }
CMAP Format 4
CMAP Format 4