PdfSharp.Fonts.TrueType.TrueTypeDescriptor.GlyphIndexToPdfWidth C# (CSharp) Method

GlyphIndexToPdfWidth() public method

Converts the width of a glyph identified by its index to PDF design units.
public GlyphIndexToPdfWidth ( int glyphIndex ) : int
glyphIndex int
return int
    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;
      }
    }