Class Font

java.lang.Object
net.atthegate.server.service.pdf.Font

public class Font extends Object
Used to create font objects. The font objects must added to the PDF before they can be used to draw text.
  • Field Details

    • AdobeMingStd_Light

      public static final String AdobeMingStd_Light
      See Also:
    • STHeitiSC_Light

      public static final String STHeitiSC_Light
      See Also:
    • KozMinProVI_Regular

      public static final String KozMinProVI_Regular
      See Also:
    • AdobeMyungjoStd_Medium

      public static final String AdobeMyungjoStd_Medium
      See Also:
    • STREAM

      public static final boolean STREAM
      See Also:
    • name

      protected String name
    • info

      protected String info
    • objNumber

      protected int objNumber
    • fileObjNumber

      protected int fileObjNumber
    • unitsPerEm

      protected int unitsPerEm
    • size

      protected float size
    • ascent

      protected float ascent
    • descent

      protected float descent
    • capHeight

      protected float capHeight
    • body_height

      protected float body_height
    • metrics

      protected int[][] metrics
    • isCoreFont

      protected boolean isCoreFont
    • isCJK

      protected boolean isCJK
    • firstChar

      protected int firstChar
    • lastChar

      protected int lastChar
    • skew15

      protected boolean skew15
    • kernPairs

      protected boolean kernPairs
    • bBoxLLx

      protected float bBoxLLx
    • bBoxLLy

      protected float bBoxLLy
    • bBoxURx

      protected float bBoxURx
    • bBoxURy

      protected float bBoxURy
    • underlinePosition

      protected float underlinePosition
    • underlineThickness

      protected float underlineThickness
    • compressed_size

      protected int compressed_size
    • uncompressed_size

      protected int uncompressed_size
    • advanceWidth

      protected int[] advanceWidth
    • glyphWidth

      protected int[] glyphWidth
    • unicodeToGID

      protected int[] unicodeToGID
    • cff

      protected boolean cff
    • fontID

      protected String fontID
  • Constructor Details

    • Font

      public Font(PDF pdf, CoreFont coreFont) throws Exception
      Constructor for the 14 standard fonts. Creates a font object and adds it to the PDF.
        Examples:
            Font font1 = new Font(pdf, CoreFont.HELVETICA);
            Font font2 = new Font(pdf, CoreFont.TIMES_ITALIC);
            Font font3 = new Font(pdf, CoreFont.ZAPF_DINGBATS);
            ...
        
      Parameters:
      pdf - the PDF to add this font to.
      coreFont - the core font. Must be one the names defined in the CoreFont class.
      Throws:
      Exception
    • Font

      protected Font(CoreFont coreFont)
    • Font

      public Font(PDF pdf, String fontName) throws Exception
      Throws:
      Exception
    • Font

      public Font(PDF pdf, String fontName, int codePage) throws Exception
      Constructor for CJK - Chinese, Japanese and Korean fonts. Please see Example_04.
      Parameters:
      pdf - the PDF to add this font to.
      fontName - the font name. Please see Example_04.
      codePage - the code page. Must be: CodePage.UNICODE
      Throws:
      Exception
    • Font

      public Font(PDF pdf, InputStream inputStream, boolean flag) throws Exception
      Throws:
      Exception
    • Font

      public Font(Map<Integer,PDFobj> objects, InputStream inputStream, boolean flag) throws Exception
      Throws:
      Exception
  • Method Details

    • getFontDescriptorObjNumber

      protected int getFontDescriptorObjNumber()
    • getCMapObjNumber

      protected int getCMapObjNumber()
    • getCidFontDictObjNumber

      protected int getCidFontDictObjNumber()
    • getToUnicodeCMapObjNumber

      protected int getToUnicodeCMapObjNumber()
    • getWidthsArrayObjNumber

      protected int getWidthsArrayObjNumber()
    • getEncodingObjNumber

      protected int getEncodingObjNumber()
    • getUnderlinePosition

      public float getUnderlinePosition()
    • getUnderlineThickness

      public float getUnderlineThickness()
    • setFontDescriptorObjNumber

      protected void setFontDescriptorObjNumber(int fontDescriptorObjNumber)
    • setCMapObjNumber

      protected void setCMapObjNumber(int cMapObjNumber)
    • setCidFontDictObjNumber

      protected void setCidFontDictObjNumber(int cidFontDictObjNumber)
    • setToUnicodeCMapObjNumber

      protected void setToUnicodeCMapObjNumber(int toUnicodeCMapObjNumber)
    • setWidthsArrayObjNumber

      protected void setWidthsArrayObjNumber(int widthsArrayObjNumber)
    • setEncodingObjNumber

      protected void setEncodingObjNumber(int encodingObjNumber)
    • setSize

      public Font setSize(double fontSize)
      Sets the size of this font.
      Parameters:
      fontSize - specifies the size of this font.
      Returns:
      the font.
    • setSize

      public Font setSize(float fontSize)
      Sets the size of this font.
      Parameters:
      fontSize - specifies the size of this font.
      Returns:
      the font.
    • getSize

      public float getSize()
      Returns the current font size.
      Returns:
      the current size of the font.
    • setKernPairs

      public void setKernPairs(boolean kernPairs)
      Sets the kerning for the selected font to 'true' or 'false' depending on the passed value of kernPairs parameter. The kerning is implemented only for the 14 standard fonts.
      Parameters:
      kernPairs - if 'true' the kerning for this font is enabled.
    • stringWidth

      public float stringWidth(String str)
      Returns the width of the specified string when drawn on the page with this font using the current font size.
      Parameters:
      str - the specified string.
      Returns:
      the width of the string when draw on the page with this font using the current selected size.
    • getAscent

      public float getAscent()
      Returns the ascent of this font.
      Returns:
      the ascent of the font.
    • getDescent

      public float getDescent()
      Returns the descent of this font.
      Returns:
      the descent of the font.
    • getHeight

      public float getHeight()
      Returns the height of this font.
      Returns:
      the height of the font.
    • getBodyHeight

      public float getBodyHeight()
      Returns the height of the body of the font.
      Returns:
      float the height of the body of the font.
    • getFitChars

      public int getFitChars(String str, double width)
      Returns the number of characters from the specified string that will fit within the specified width.
      Parameters:
      str - the specified string.
      width - the specified width.
      Returns:
      the number of characters that will fit.
    • getFitChars

      public int getFitChars(String str, float width)
      Returns the number of characters from the specified string that will fit within the specified width.
      Parameters:
      str - the specified string.
      width - the specified width.
      Returns:
      the number of characters that will fit.
    • setItalic

      public void setItalic(boolean skew15)
      Sets the skew15 private variable. When the variable is set to 'true' all glyphs in the font are skewed on 15 degrees. This makes a regular font look like an italic type font. Use this method when you don't have real italic font in the font family, or when you want to generate smaller PDF files. For example you could embed only the Regular and Bold fonts and synthesize the RegularItalic and BoldItalic.
      Parameters:
      skew15 - the skew flag.
    • stringWidth

      public float stringWidth(Font font2, String str)
      Returns the width of a string drawn using two fonts.
      Parameters:
      font2 - the fallback font.
      str - the string.
      Returns:
      the width.