public class Font extends NativeObject
Modifier and Type | Method and Description |
---|---|
static Font |
create(Document targetDocument,
Stream stream,
boolean embedded)
Create a new font object from font file data.
|
static Font |
createDynamicObject(long handle) |
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.
|
equals, hashCode
public static Font createDynamicObject(long handle)
public static Font create(Document targetDocument, Stream stream, boolean embedded) throws java.io.IOException, UnknownFormatException, CorruptException, ConformanceException
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 be true
for PDF/A documents.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
- Parameter embedded
is false
for PDF/A documentjava.lang.IllegalArgumentException
- if the targetDocument
argument is null
java.lang.IllegalArgumentException
- if the targetDocument
argument has already been closedjava.lang.IllegalArgumentException
- if the targetDocument
argument is read-onlyjava.lang.IllegalArgumentException
- if the stream
argument is null
public static Font createFromSystem(Document targetDocument, java.lang.String family, java.lang.String style, boolean embedded) throws java.io.IOException, NotFoundException, UnknownFormatException, CorruptException, ConformanceException
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 be true
for PDF/A documents.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
- Parameter embedded
is false
for PDF/A documentjava.lang.IllegalArgumentException
- if the targetDocument
argument is null
java.lang.IllegalArgumentException
- if the targetDocument
argument has already been closedjava.lang.IllegalArgumentException
- if the targetDocument
argument is read-onlyjava.lang.IllegalArgumentException
- if the family
argument is null
public double getCharacterWidth(int character)
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 is already closed) this method returns 0. But a return value of 0 is not generally an indication for failure.
character
- the unicode character code.public java.lang.String getBaseFont() throws CorruptException
java.lang.IllegalStateException
- if the font has already been closedCorruptException
- if the font's base name is missing or cannot be decodedpublic double getItalicAngle()
java.lang.IllegalStateException
- if the font has already been closedpublic double getAscent()
java.lang.IllegalStateException
- if the font has already been closedpublic double getDescent()
java.lang.IllegalStateException
- if the font has already been closedpublic double getCapHeight()
java.lang.IllegalStateException
- if the font has already been closedpublic java.lang.Double getLeading()
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.TextGenerator(com.pdf_tools.fourheights.pdftoolbox.pdf.content.Text text, com.pdf_tools.fourheights.pdftoolbox.pdf.content.Font font, double fontSize, com.pdf_tools.fourheights.pdftoolbox.geometry.real.Point location)
uses a fixed value of 1.2
instead of this property to initialize the TextGenerator.setLeading(double)
in order to maintain backward compatibility with earlier versions.
java.lang.IllegalStateException
- if the font has already been closed