Class Font
Used to create font objects. The font objects must be added to the PDF before they can be used to draw text.
public class Font
- Inheritance
-
Font
- Inherited Members
Constructors
Font(PDF, CJKFont)
Creates a Chinese, Japanese or Korean font and adds it to the PDF, not embedded: the viewer supplies it.
public Font(PDF pdf, CJKFont font)
Parameters
Font(PDF, Stream)
Constructor for OpenType and TrueType fonts, .otf and .ttf.
public Font(PDF pdf, Stream inputStream)
Parameters
pdfPDFthe PDF object that requires this font.
inputStreamStreamthe input stream to read this font from.
Font(PDF, int)
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);
...
public Font(PDF pdf, int coreFont)
Parameters
pdfPDFthe PDF to add this font to.
coreFontintthe core font. Must be one the names defined in the CoreFont class.
Font(PDF, string)
Constructor for OpenType and TrueType fonts, .otf and .ttf files. A path to a .ttf.stream or .otf.stream file, the fonts PDFjet shipped before 9.0.5, opens the .ttf or else the .otf file of the same name beside it.
public Font(PDF pdf, string fontPath)
Parameters
Exceptions
- Exception
thrown if the font file is not found.
Font(List<PDFobj>, Stream)
Creates a font from an OpenType or TrueType font, a .otf or a .ttf, and adds it to the objects of an existing PDF. It is embedded as a subset of the glyphs drawn, when the objects are added to the PDF, unless SetSubset(false) keeps it whole.
public Font(List<PDFobj> objects, Stream inputStream)
Parameters
Methods
GetAscent()
Returns the ascent at the current font size.
public float GetAscent()
Returns
GetAscent(float)
Returns the ascent at the specified font size.
public float GetAscent(float fontSize)
Parameters
fontSizefloat
Returns
GetBodyHeight()
Returns the height of the body of this font.
public float GetBodyHeight()
Returns
- float
the height of the body of the font.
GetBodyHeight(float)
Returns the ascent plus the descent at the specified font size.
public float GetBodyHeight(float fontSize)
Parameters
fontSizefloat
Returns
GetDescent()
Returns the descent at the current font size.
public float GetDescent()
Returns
GetDescent(float)
Returns the descent at the specified font size.
public float GetDescent(float fontSize)
Parameters
fontSizefloat
Returns
GetFitChars(string, float)
Returns how many characters of the string fit within the specified width, counted in the UTF-16 chars of the string, so that it can be passed to Substring.
public int GetFitChars(string str, float width)
Parameters
Returns
GetLineGap(float)
Returns the line gap at the specified font size: the space the font puts between the descent of a line and the ascent of the next one. It is 0 for most fonts, which leave that space in their ascent and descent, and 1 em for the Japanese and Chinese IBM Plex fonts, whose ascent and descent add up to 1 em.
public float GetLineGap(float fontSize)
Parameters
fontSizefloat
Returns
GetName()
Returns the name of the font.
public string GetName()
Returns
GetSize()
Returns the font size.
public float GetSize()
Returns
GetUnderlinePosition()
Returns the underline position at the current font size.
public float GetUnderlinePosition()
Returns
GetUnderlinePosition(float)
Returns the underline position at the specified font size.
public float GetUnderlinePosition(float fontSize)
Parameters
fontSizefloat
Returns
GetUnderlineThickness()
Returns the underline thickness at the current font size.
public float GetUnderlineThickness()
Returns
GetUnderlineThickness(float)
Returns the underline thickness at the specified font size.
public float GetUnderlineThickness(float fontSize)
Parameters
fontSizefloat
Returns
SetItalic(bool)
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.
public Font SetItalic(bool skew15)
Parameters
skew15boolthe skew flag.
Returns
- Font
this Font object.
SetKernPairs(bool)
Enables or disables kerning. Kerning is only supported for the 14 standard fonts.
public Font SetKernPairs(bool kernPairs)
Parameters
kernPairsbool
Returns
SetSize(float)
public Font SetSize(float fontSize)
Parameters
fontSizefloat
Returns
SetSubset(bool)
Sets whether this font is embedded as a subset, the outlines of the glyphs the document does not draw left out, which is the default for a .ttf or a .otf. A font whose license does not allow subsetting, by the fsType of its OS/2 table, is embedded whole. Fonts read from one file are one font program in the PDF: kept whole for one, the program is whole for all of them. It must be called before Complete(), and for a font added to the objects of an existing PDF, before the objects are added to the PDF.
public Font SetSubset(bool subset)
Parameters
subsetboolfalse to embed the font whole.
Returns
- Font
this Font object.
StringWidth(Font, float, string)
Returns the width of a string drawn using two fonts.
public float StringWidth(Font fallbackFont, float fontSize, string str)
Parameters
Returns
- float
the width.
StringWidth(Font, string)
Returns the width of the string at the current font size, using the fallback font for characters this font does not have.
public float StringWidth(Font fallbackFont, string str)
Parameters
Returns
StringWidth(float, string)
Returns the width of the string at the specified font size.
public float StringWidth(float fontSize, string str)
Parameters
Returns
StringWidth(string)
Returns the width of the string at the current font size.
public float StringWidth(string str)
Parameters
strstring