com.pdfjet
Class Font

java.lang.Object
  extended by com.pdfjet.Font

public class Font
extends java.lang.Object

Used to create font objects. The font objects must added to the PDF before they can be used to draw text.


Field Summary
static java.lang.String AdobeMingStd_Light
           
static java.lang.String AdobeMyungjoStd_Medium
           
 boolean isDevanagari
           
static java.lang.String KozMinProVI_Regular
           
static java.lang.String STHeitiSC_Light
           
static boolean STREAM
           
 
Constructor Summary
Font(PDF pdf, CoreFont coreFont)
          Constructor for the 14 standard fonts.
Font(PDF pdf, java.io.InputStream inputStream)
           
Font(PDF pdf, java.io.InputStream inputStream, boolean flag)
           
Font(PDF pdf, java.io.InputStream inputStream, int codePage, boolean embed)
          Constructor for OpenType and TrueType fonts.
Font(PDF pdf, java.lang.String fontName)
           
Font(PDF pdf, java.lang.String fontName, int codePage)
          Constructor for CJK - Chinese, Japanese and Korean fonts.
 
Method Summary
 float getAscent()
          Returns the ascent of this font.
 float getBodyHeight()
          Returns the height of the body of the font.
 float getDescent()
          Returns the descent of this font.
 int getFitChars(java.lang.String str, double width)
          Returns the number of characters from the specified string that will fit within the specified width.
 int getFitChars(java.lang.String str, float width)
          Returns the number of characters from the specified string that will fit within the specified width.
 float getHeight()
          Returns the height of this font.
 float getSize()
          Returns the current font size.
 float getUnderlinePosition()
           
 float getUnderlineThickness()
           
 void setItalic(boolean skew15)
          Sets the skew15 private variable.
 void setKernPairs(boolean kernPairs)
          Sets the kerning for the selected font to 'true' or 'false' depending on the passed value of kernPairs parameter.
 Font setSize(double fontSize)
          Sets the size of this font.
 Font setSize(float fontSize)
          Sets the size of this font.
 float stringWidth(Font font2, java.lang.String str)
          Returns the width of a string drawn using two fonts.
 float stringWidth(java.lang.String str)
          Returns the width of the specified string when drawn on the page with this font using the current font size.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AdobeMingStd_Light

public static final java.lang.String AdobeMingStd_Light
See Also:
Constant Field Values

STHeitiSC_Light

public static final java.lang.String STHeitiSC_Light
See Also:
Constant Field Values

KozMinProVI_Regular

public static final java.lang.String KozMinProVI_Regular
See Also:
Constant Field Values

AdobeMyungjoStd_Medium

public static final java.lang.String AdobeMyungjoStd_Medium
See Also:
Constant Field Values

STREAM

public static final boolean STREAM
See Also:
Constant Field Values

isDevanagari

public boolean isDevanagari
Constructor Detail

Font

public Font(PDF pdf,
            CoreFont coreFont)
     throws java.lang.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:
java.lang.Exception

Font

public Font(PDF pdf,
            java.lang.String fontName)
     throws java.lang.Exception
Throws:
java.lang.Exception

Font

public Font(PDF pdf,
            java.lang.String fontName,
            int codePage)
     throws java.lang.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:
java.lang.Exception

Font

public Font(PDF pdf,
            java.io.InputStream inputStream,
            boolean flag)
     throws java.lang.Exception
Throws:
java.lang.Exception

Font

public Font(PDF pdf,
            java.io.InputStream inputStream)
     throws java.lang.Exception
Throws:
java.lang.Exception

Font

public Font(PDF pdf,
            java.io.InputStream inputStream,
            int codePage,
            boolean embed)
     throws java.lang.Exception
Constructor for OpenType and TrueType fonts. Please see Example_06 and Example_07.

Parameters:
pdf - the PDF object that requires this font.
inputStream - the input stream to read this font from.
codePage - must be:
      CodePage.UNICODE
  
embed - specifies if this font must be embedded in the PDF file.
Throws:
java.lang.Exception
Method Detail

getUnderlinePosition

public float getUnderlinePosition()

getUnderlineThickness

public float getUnderlineThickness()

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(java.lang.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(java.lang.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(java.lang.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,
                         java.lang.String str)
Returns the width of a string drawn using two fonts.

Parameters:
font2 - the fallback font.
str - the string.
Returns:
the width.