Class Font
- java.lang.Object
-
- com.pdftools.toolbox.internal.NativeBase
-
- com.pdftools.toolbox.internal.NativeObject
-
- com.pdftools.toolbox.pdf.content.Font
-
public class Font extends NativeObject
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Font
create(Document targetDocument, Stream stream, boolean embedded)
Create a new font object from font file data.static Font
createFromSystem(Document targetDocument, java.lang.String family, java.lang.String style, boolean embedded)
Create a new font object from an installed font.double
getAscent()
the ascent of the font.java.lang.String
getBaseFont()
the PostScript name of the font (Getter)double
getCapHeight()
the cap height of the font.double
getCharacterWidth(int character)
the width of a single glyph.double
getDescent()
the descent of the font.double
getItalicAngle()
the italic angle of the font.java.lang.Double
getLeading()
the leading of the font.FontWeight
getWeight()
the visual weight of the font.-
Methods inherited from class com.pdftools.toolbox.internal.NativeObject
equals, hashCode
-
-
-
-
Method Detail
-
create
public static Font create(Document targetDocument, Stream stream, boolean embedded) throws java.io.IOException, UnknownFormatException, CorruptException, ConformanceException
Create a new font object from font file data.
Supported formats are:- Type1
- CFF
- TrueType
- OpenType
- Parameters:
targetDocument
- the output document with which the returned object is associatedstream
- the font file data streamembedded
-true
if the font shall be embedded in the document. Note that this parameter must betrue
for PDF/A documents.- Returns:
- the newly created font object
- Throws:
java.io.IOException
- Error reading from the font file or writing to the documentUnknownFormatException
- The font data has an unknown formatCorruptException
- The font data is corruptConformanceException
- Parameterembedded
isfalse
for PDF/A documentjava.lang.IllegalArgumentException
- if thetargetDocument
argument has already been closedjava.lang.IllegalArgumentException
- if thetargetDocument
argument is read-onlyjava.lang.IllegalArgumentException
- if thestream
argument isnull
java.lang.IllegalArgumentException
- iftargetDocument
isnull
java.lang.IllegalArgumentException
- ifstream
isnull
-
createFromSystem
public static Font createFromSystem(Document targetDocument, java.lang.String family, java.lang.String style, boolean embedded) throws java.io.IOException, NotFoundException, UnknownFormatException, CorruptException, ConformanceException
Create a new font object from an installed font.
The returned font object is not yet used on any page, but it is associated with the given target document.- Parameters:
targetDocument
- the output document with which the returned object is associatedfamily
- the font family name (e.g. "Arial")style
- the font style (e.g. "Bold")embedded
-true
if the font shall be embedded in the document. Note that this parameter must betrue
for PDF/A documents.- Returns:
- the newly created font object
- Throws:
NotFoundException
- There is no such font installedjava.io.IOException
- Error reading the font file or writing to the documentUnknownFormatException
- The font data has an unknown formatCorruptException
- The font data is corruptConformanceException
- Parameterembedded
isfalse
for PDF/A documentjava.lang.IllegalArgumentException
- if thetargetDocument
argument has already been closedjava.lang.IllegalArgumentException
- if thetargetDocument
argument is read-onlyjava.lang.IllegalArgumentException
- if thefamily
argument isnull
java.lang.IllegalArgumentException
- iftargetDocument
isnull
-
getCharacterWidth
public double getCharacterWidth(int character)
the width of a single glyph.
The width of a unicode character (in pt) relative to a font size of 1 pt.
If an error occurs (because the font or the owning document has already been closed) this method returns 0. But a return value of 0 is not generally an indication for failure.
- Parameters:
character
- the unicode character code.- Returns:
- the width of the character
-
getBaseFont
public java.lang.String getBaseFont() throws CorruptException
the PostScript name of the font (Getter)
- Throws:
java.lang.IllegalStateException
- if the font has already been closedCorruptException
- if the font's base name is missing or cannot be decoded
-
getWeight
public FontWeight getWeight()
the visual weight of the font. (Getter)
Indicates the visual weight (degree of blackness or thickness of strokes) of the characters in the font. If the font does not define this value,null
is returned.- Throws:
java.lang.IllegalStateException
- if the font has already been closed
-
getItalicAngle
public double getItalicAngle()
the italic angle of the font. (Getter)
The angle is expressed in degrees counterclockwise from the vertical, of the dominant vertical strokes of the font. (For example, the 9-o’clock position is 90 degrees, and the 3-o’clock position is –90 degrees.) The value is negative for fonts that slope to the right, as almost all italic fonts do.- Throws:
java.lang.IllegalStateException
- if the font has already been closed
-
getAscent
public double getAscent()
the ascent of the font. (Getter)
The maximum height above the baseline reached by glyphs in this font, excluding the height of glyphs for accented characters.- Throws:
java.lang.IllegalStateException
- if the font has already been closed
-
getDescent
public double getDescent()
the descent of the font. (Getter)
The maximum depth below the baseline reached by glyphs in this font. The value is a negative number.- Throws:
java.lang.IllegalStateException
- if the font has already been closed
-
getCapHeight
public double getCapHeight()
the cap height of the font. (Getter)
The vertical coordinate of the top of flat capital letters, measured from the baseline.- Throws:
java.lang.IllegalStateException
- if the font has already been closed
-
getLeading
public java.lang.Double getLeading()
the leading of the font. (Getter)
The vertical distance between two adjacent base lines in multiline text.
This is a recomended value when generating several lines of text. If the font does not define this value,
null
is returned.Note that
TextGenerator(com.pdftools.toolbox.pdf.content.Text text, com.pdftools.toolbox.pdf.content.Font font, double fontSize, com.pdftools.toolbox.geometry.real.Point location)
uses a fixed value of 1.2 instead of this property to initialize theTextGenerator.setLeading(double)
in order to maintain backward compatibility with earlier versions.- Throws:
java.lang.IllegalStateException
- if the font has already been closed
-
-