Class FontMetrics

java.lang.Object
com.itextpdf.io.font.FontMetrics

public class FontMetrics extends Object
Holds the typographic metrics parsed from a font program.

Unless stated otherwise, dimensional values are normalized to the PDF glyph space of 1000 units per em when they are assigned by the font readers.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected float
    Multiplier that converts values expressed in the source font's units per em to normalized 1000-unit glyph space.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Gets the largest horizontal advance width in the font.
    int
    Gets the horizontal ascender.
    int[]
    Gets the font bounding box.
    int
    Gets the capital letters height.
    int
    Gets the horizontal descender.
    int[]
    Gets the glyph width array.
    float
    Gets the PostScript italic angle.
    int
    Gets the line spacing.
    int
    Gets the number of glyphs declared by the font.
    int
    Gets the dominant horizontal stem width.
    int
    Gets the dominant vertical stem width.
    int
    Gets the strikeout position relative to the baseline.
    int
    Gets the strikeout thickness.
    int
    Gets the subscript baseline offset.
    int
    Gets the recommended vertical size for subscripts.
    int
    Gets the superscript baseline offset.
    int
    Gets the recommended vertical size for superscripts.
    int
    Gets typo (a.k.a.
    int
    Gets typo (a.k.a.
    int
    Gets the underline center position relative to the baseline.
    int
    Gets the recommended underline thickness.
    int
    Gets the units per em value declared by the source font.
    int
    Gets the Windows ascender metric.
    int
    Gets the Windows descender metric.
    int
    Gets the height of lowercase flat characters above the baseline.
    boolean
    Checks whether all glyphs use a common width.
    protected void
    setAdvanceWidthMax(int advanceWidthMax)
    Sets the largest horizontal advance width declared by the source font.
    protected void
    setAscender(int ascender)
    Sets the source horizontal ascender.
    void
    setBbox(int llx, int lly, int urx, int ury)
    Replaces the normalized font bounding box.
    protected void
    setCapHeight(int capHeight)
    Sets the capital letters height.
    protected void
    setDescender(int descender)
    Sets the source horizontal descender.
    protected void
    setGlyphWidths(int[] glyphWidths)
    Stores the glyph width table.
    protected void
    setIsFixedPitch(boolean isFixedPitch)
    Sets whether the font declares a common width for all glyphs.
    protected void
    setItalicAngle(float italicAngle)
    Sets the PostScript italic angle without unit normalization.
    protected void
    setLineGap(int lineGap)
    Sets the line space.
    protected void
    setNumberOfGlyphs(int numOfGlyphs)
    Sets the glyph count declared by the font.
    protected void
    setStemH(int stemH)
    Sets the dominant horizontal stem width.
    void
    setStemV(int stemV)
    Sets the dominant vertical stem width.
    protected void
    setStrikeoutPosition(int strikeoutPosition)
    Sets the source strikeout position.
    protected void
    setStrikeoutSize(int strikeoutSize)
    Sets the source strikeout thickness.
    protected void
    setSubscriptOffset(int subscriptOffset)
    Sets the source subscript vertical offset.
    protected void
    setSubscriptSize(int subscriptSize)
    Sets the source subscript vertical size.
    protected void
    setSuperscriptOffset(int superscriptOffset)
    Sets the source superscript vertical offset.
    protected void
    setSuperscriptSize(int superscriptSize)
    Sets the superscript vertical size.
    protected void
    setTypoAscender(int typoAscender)
    Sets typo (a.k.a.
    protected void
    setTypoDescender(int typoDescender)
    Sets typo (a.k.a.
    protected void
    setUnderlinePosition(int underlinePosition)
    Sets the source underline position.
    protected void
    setUnderlineThickness(int underlineThickness)
    Sets the underline thickness.
    protected void
    setUnitsPerEm(int unitsPerEm)
    Sets source units per em.
    protected void
    setWinAscender(int winAscender)
    Sets the source Windows ascender metric.
    protected void
    setWinDescender(int winDescender)
    Sets the source Windows descender metric.
    protected void
    setXHeight(int xHeight)
    Sets the source font x-height.
    protected void
    updateBbox(float llx, float lly, float urx, float ury)
    Converts and stores a font bounding box in source units.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • normalizationCoef

      protected float normalizationCoef
      Multiplier that converts values expressed in the source font's units per em to normalized 1000-unit glyph space. Font readers update it after reading head.unitsPerEm.
  • Constructor Details

    • FontMetrics

      public FontMetrics()
  • Method Details

    • getUnitsPerEm

      public int getUnitsPerEm()
      Gets the units per em value declared by the source font.
      Returns:
      source font design units in one em
    • getNumberOfGlyphs

      public int getNumberOfGlyphs()
      Gets the number of glyphs declared by the font.
      Returns:
      glyph count
    • getGlyphWidths

      public int[] getGlyphWidths()
      Gets the glyph width array.
      Returns:
      glyph widths indexed by glyph ID
    • getTypoAscender

      public int getTypoAscender()
      Gets typo (a.k.a. sTypo or OS/2) vertical metric corresponding to ascender.

      Typo vertical metrics are the primary source for iText ascender/descender calculations.

      Returns:
      typo ascender value in normalized 1000-units
    • getTypoDescender

      public int getTypoDescender()
      Gets typo (a.k.a. sTypo or OS/2) vertical metric corresponding to descender.

      Typo vertical metrics are the primary source for iText ascender/descender calculations.

      Returns:
      typo descender value in normalized 1000-units
    • getCapHeight

      public int getCapHeight()
      Gets the capital letters height.

      This property defines the vertical coordinate of the top of flat capital letters, measured from the baseline.

      Returns:
      cap height in 1000-units
    • getXHeight

      public int getXHeight()
      Gets the height of lowercase flat characters above the baseline.
      Returns:
      x-height in normalized glyph units, or zero when not present
    • getItalicAngle

      public float getItalicAngle()
      Gets the PostScript italic angle.
      Returns:
      counterclockwise degrees from vertical; negative values lean right
    • getBbox

      public int[] getBbox()
      Gets the font bounding box.
      Returns:
      array containing lower-left x/y and upper-right x/y in normalized glyph units
    • setBbox

      public void setBbox (int llx, int lly, int urx, int ury)
      Replaces the normalized font bounding box.
      Parameters:
      llx - lower-left x coordinate
      lly - lower-left y coordinate
      urx - upper-right x coordinate
      ury - upper-right y coordinate
    • getAscender

      public int getAscender()
      Gets the horizontal ascender.
      Returns:
      ascender in normalized glyph units
    • getDescender

      public int getDescender()
      Gets the horizontal descender.
      Returns:
      descender in normalized glyph units
    • getLineGap

      public int getLineGap()
      Gets the line spacing.
      Returns:
      horizontal line gap in normalized glyph units
    • getWinAscender

      public int getWinAscender()
      Gets the Windows ascender metric.
      Returns:
      OS/2 usWinAscent in normalized glyph units
    • getWinDescender

      public int getWinDescender()
      Gets the Windows descender metric.
      Returns:
      OS/2 usWinDescent in normalized glyph units
    • getAdvanceWidthMax

      public int getAdvanceWidthMax()
      Gets the largest horizontal advance width in the font.
      Returns:
      maximum advance width in normalized glyph units
    • getUnderlinePosition

      public int getUnderlinePosition()
      Gets the underline center position relative to the baseline.
      Returns:
      normalized underline position, adjusted from the stored edge by half its thickness
    • getUnderlineThickness

      public int getUnderlineThickness()
      Gets the recommended underline thickness.
      Returns:
      stored thickness value; readers currently supply it in source font units
    • getStrikeoutPosition

      public int getStrikeoutPosition()
      Gets the strikeout position relative to the baseline.
      Returns:
      OS/2 strikeout position in normalized glyph units
    • getStrikeoutSize

      public int getStrikeoutSize()
      Gets the strikeout thickness.
      Returns:
      OS/2 strikeout size in normalized glyph units
    • getSubscriptSize

      public int getSubscriptSize()
      Gets the recommended vertical size for subscripts.
      Returns:
      subscript y-size in normalized glyph units
    • getSubscriptOffset

      public int getSubscriptOffset()
      Gets the subscript baseline offset.
      Returns:
      subscript y-offset in normalized glyph units
    • getSuperscriptSize

      public int getSuperscriptSize()
      Gets the recommended vertical size for superscripts.
      Returns:
      superscript y-size in source font units
    • getSuperscriptOffset

      public int getSuperscriptOffset()
      Gets the superscript baseline offset.
      Returns:
      superscript y-offset in normalized glyph units
    • getStemV

      public int getStemV()
      Gets the dominant vertical stem width.
      Returns:
      Type 1/CFF StdVW value, or the reader's fallback, in glyph units
    • getStemH

      public int getStemH()
      Gets the dominant horizontal stem width.
      Returns:
      Type 1/CFF StdHW value, or the reader's fallback, in glyph units
    • isFixedPitch

      public boolean isFixedPitch()
      Checks whether all glyphs use a common width.
      Returns:
      true when the font declares fixed pitch
    • setUnitsPerEm

      protected void setUnitsPerEm (int unitsPerEm)
      Sets source units per em.

      It recalculates the normalization multiplier used by subsequent setters.

      Parameters:
      unitsPerEm - positive number of design units in an em
    • updateBbox

      protected void updateBbox (float llx, float lly, float urx, float ury)
      Converts and stores a font bounding box in source units.
      Parameters:
      llx - lower-left x coordinate in source units
      lly - lower-left y coordinate in source units
      urx - upper-right x coordinate in source units
      ury - upper-right y coordinate in source units
    • setNumberOfGlyphs

      protected void setNumberOfGlyphs (int numOfGlyphs)
      Sets the glyph count declared by the font.
      Parameters:
      numOfGlyphs - number of glyphs
    • setGlyphWidths

      protected void setGlyphWidths (int[] glyphWidths)
      Stores the glyph width table.
      Parameters:
      glyphWidths - width array indexed by glyph ID
    • setTypoAscender

      protected void setTypoAscender (int typoAscender)
      Sets typo (a.k.a. sTypo or OS/2) vertical metric corresponding to ascender.

      Typo vertical metrics are the primary source for iText ascender/descender calculations.

      Parameters:
      typoAscender - typo ascender value in normalized 1000-units
    • setTypoDescender

      protected void setTypoDescender (int typoDescender)
      Sets typo (a.k.a. sTypo or OS/2) vertical metric corresponding to descender.

      Typo vertical metrics are the primary source for iText ascender/descender calculations.

      Parameters:
      typoDescender - typo descender value in normalized 1000-units
    • setCapHeight

      protected void setCapHeight (int capHeight)
      Sets the capital letters height.

      This property defines the vertical coordinate of the top of flat capital letters, measured from the baseline.

      Parameters:
      capHeight - cap height in 1000-units
    • setXHeight

      protected void setXHeight (int xHeight)
      Sets the source font x-height.
      Parameters:
      xHeight - OS/2 sxHeight in source units
    • setItalicAngle

      protected void setItalicAngle (float italicAngle)
      Sets the PostScript italic angle without unit normalization.
      Parameters:
      italicAngle - counterclockwise degrees from vertical
    • setAscender

      protected void setAscender (int ascender)
      Sets the source horizontal ascender.
      Parameters:
      ascender - hhea.Ascender in source units
    • setDescender

      protected void setDescender (int descender)
      Sets the source horizontal descender.
      Parameters:
      descender - hhea.Descender in source units
    • setLineGap

      protected void setLineGap (int lineGap)
      Sets the line space.
      Parameters:
      lineGap - hhea.LineGap in source units
    • setWinAscender

      protected void setWinAscender (int winAscender)
      Sets the source Windows ascender metric.
      Parameters:
      winAscender - OS/2 usWinAscent in source units
    • setWinDescender

      protected void setWinDescender (int winDescender)
      Sets the source Windows descender metric.
      Parameters:
      winDescender - OS/2 usWinDescent in source units
    • setAdvanceWidthMax

      protected void setAdvanceWidthMax (int advanceWidthMax)
      Sets the largest horizontal advance width declared by the source font.
      Parameters:
      advanceWidthMax - hhea.advanceWidthMax in source units
    • setUnderlinePosition

      protected void setUnderlinePosition (int underlinePosition)
      Sets the source underline position.
      Parameters:
      underlinePosition - post.underlinePosition in source units
    • setUnderlineThickness

      protected void setUnderlineThickness (int underlineThickness)
      Sets the underline thickness.
      Parameters:
      underlineThickness - post.underlineThickness; stored without normalization
    • setStrikeoutPosition

      protected void setStrikeoutPosition (int strikeoutPosition)
      Sets the source strikeout position.
      Parameters:
      strikeoutPosition - OS/2 yStrikeoutPosition in source units
    • setStrikeoutSize

      protected void setStrikeoutSize (int strikeoutSize)
      Sets the source strikeout thickness.
      Parameters:
      strikeoutSize - OS/2 yStrikeoutSize in source units
    • setSubscriptSize

      protected void setSubscriptSize (int subscriptSize)
      Sets the source subscript vertical size.
      Parameters:
      subscriptSize - OS/2 ySubscriptYSize in source units
    • setSubscriptOffset

      protected void setSubscriptOffset (int subscriptOffset)
      Sets the source subscript vertical offset.
      Parameters:
      subscriptOffset - OS/2 ySubscriptYOffset in source units
    • setSuperscriptSize

      protected void setSuperscriptSize (int superscriptSize)
      Sets the superscript vertical size.
      Parameters:
      superscriptSize - OS/2 ySuperscriptYSize; stored without normalization
    • setSuperscriptOffset

      protected void setSuperscriptOffset (int superscriptOffset)
      Sets the source superscript vertical offset.
      Parameters:
      superscriptOffset - OS/2 ySuperscriptYOffset in source units
    • setStemV

      public void setStemV (int stemV)
      Sets the dominant vertical stem width.
      Parameters:
      stemV - Type 1/CFF StdVW value in glyph units
    • setStemH

      protected void setStemH (int stemH)
      Sets the dominant horizontal stem width.
      Parameters:
      stemH - Type 1/CFF StdHW value in glyph units
    • setIsFixedPitch

      protected void setIsFixedPitch (boolean isFixedPitch)
      Sets whether the font declares a common width for all glyphs.
      Parameters:
      isFixedPitch - true for fixed pitch fonts