public int GlyphIndexToPdfWidth(int glyphIndex)
{
try
{
int numberOfHMetrics = this.fontData.hhea.numberOfHMetrics;
int unitsPerEm = this.fontData.head.unitsPerEm;
// glyphIndex >= numberOfHMetrics means the font is mono-spaced and all glyphs have the same width
if (glyphIndex >= numberOfHMetrics)
glyphIndex = numberOfHMetrics - 1;
int width = this.fontData.hmtx.metrics[glyphIndex].advanceWidth;
// Sometimes the unitsPerEm is 1000, sometimes a power of 2.
if (unitsPerEm == 1000)
return width;
return width * 1000 / unitsPerEm;
}
catch (Exception ex)
{
throw ex;
}
}