protected function getGlyphWidths(\Pop\Font\TrueType\Table\Cmap $cmap)
{
$gw = array('encoding' => null, 'widths' => array());
$uniTable = null;
$msTable = null;
$macTable = null;
foreach ($cmap->subTables as $index => $table) {
if ($table->encoding == 'Microsoft Unicode') {
$msTable = $index;
}
if ($table->encoding == 'Unicode') {
$uniTable = $index;
}
if ($table->encoding == 'Mac Roman' && $table->format == 0) {
$macTable = $index;
}
}
if (null !== $msTable) {
$gw['encoding'] = 'WinAnsiEncoding';
foreach ($cmap->subTables[$msTable]->parsed['glyphNumbers'] as $key => $value) {
$gw['widths'][$key] = $this->font->glyphWidths[$value];
}
} else {
if (null !== $uniTable) {
$gw['encoding'] = 'WinAnsiEncoding';
foreach ($cmap->subTables[$uniTable]->parsed['glyphNumbers'] as $key => $value) {
$gw['widths'][$key] = $this->font->glyphWidths[$value];
}
} else {
if (null !== $macTable) {
$gw['encoding'] = 'MacRomanEncoding';
foreach ($cmap->subTables[$macTable]->parsed as $key => $value) {
if ($this->font->glyphWidths[$value->ascii] != 0 && $this->font->glyphWidths[$value->ascii] != $this->font->missingWidth) {
$gw['widths'][$key] = $this->font->glyphWidths[$value->ascii];
}
}
}
}
}
return $gw;
}