public class TextGenerator extends NativeObject implements java.lang.AutoCloseable
Constructor and Description |
---|
TextGenerator(Text text,
Font font,
double fontSize,
Point location)
Create a new text generator for appending text to a text content object.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the object
|
static TextGenerator |
createDynamicObject(long handle) |
double |
getWidth(java.lang.String text)
Get the width of a text string.
|
void |
moveTo(Point target)
Move the current position.
|
void |
setCharacterSpacing(double value)
the current character spacing.
|
void |
setFill(Paint value)
The paint for filling (Setter)
|
void |
setFont(Font value)
the current font.
|
void |
setFontSize(double value)
the current font size.
|
void |
setHorizontalScaling(double value)
the current horizontal scaling.
|
void |
setLeading(double value)
the current leading.
|
void |
setRise(double value)
the current rise of the baseline.
|
void |
setStroke(Stroke value)
The stroke properties (Setter)
|
void |
setWordSpacing(double value)
the current word spacing.
|
void |
show(java.lang.String text)
Show a text string.
|
void |
showLine(java.lang.String text)
Show a text string and go to the next line.
|
equals, hashCode
public TextGenerator(Text text, Font font, double fontSize, Point location)
fontSize
(The font
's Font.getLeading()
is not used.)
null
false
text
- the text objectfont
- the initial fontfontSize
- the initial font size and leadinglocation
- the initial position. If position is null
,
the default position [0, 0] is used.java.lang.IllegalArgumentException
- if the text
argument is null
java.lang.IllegalArgumentException
- if the text
object has already been closedjava.lang.IllegalArgumentException
- if the text
and font
objects are associated with different documentsjava.lang.IllegalArgumentException
- if the font
argument is null
java.lang.IllegalArgumentException
- if the font
object has already been closedjava.lang.IllegalArgumentException
- if the owning document of the font
object has already been closedpublic static TextGenerator createDynamicObject(long handle)
public double getWidth(java.lang.String text)
text
- the text fragmentjava.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closedjava.lang.IllegalArgumentException
- if the text
argument is null
public void show(java.lang.String text)
text
- the text to be shownjava.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closedjava.lang.IllegalArgumentException
- if the text
argument is null
public void showLine(java.lang.String text)
text
- the text to be shownjava.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closedjava.lang.IllegalArgumentException
- if the text
argument is null
public void moveTo(Point target)
showLine(java.lang.String)
method.target
- the target positionjava.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closedjava.lang.IllegalArgumentException
- if target
is null
public void setFill(Paint value)
null
if the text should not be filled.java.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closedjava.lang.IllegalArgumentException
- if the given Paint
object has already been closed.java.lang.IllegalArgumentException
- if the given Paint
object belongs to a different document.public void setStroke(Stroke value)
null
if the text should not be stroked.java.lang.IllegalStateException
- if the object has already been closed.java.lang.IllegalStateException
- if the underlying text object has already been closed.java.lang.IllegalArgumentException
- if the given Stroke
object has already been closed.java.lang.IllegalArgumentException
- if the given Stroke
object argument belongs to a different document.public void setFont(Font value)
show(java.lang.String)
and showLine(java.lang.String)
calls.java.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closedjava.lang.IllegalArgumentException
- if the given Font
object is null
java.lang.IllegalArgumentException
- if the given Font
object has already been closedjava.lang.IllegalArgumentException
- if the given Font
object is associated with a different documentpublic void setFontSize(double value)
The font size is used for all subsequent show(java.lang.String)
and showLine(java.lang.String)
calls.
Note that this sets the font size only.
Also use setLeading(double)
to set the leading.
java.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closedjava.lang.IllegalArgumentException
- if the given value is smaller than 0.public void setCharacterSpacing(double value)
When the glyph for each character in the string is rendered, the character spacing is added to the horizontal or vertical component of the glyph’s displacement, depending on the writing mode. It is subject to scaling by the horizontal scaling if the writing mode is horizontal.
Default value: 0
java.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closedpublic void setWordSpacing(double value)
Word spacing works the same way as character spacing, but applies only to the space character, code 32.
Default value: 0
java.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closedpublic void setHorizontalScaling(double value)
The horizontal scaling parameter adjusts the width of glyphs by stretching or compressing them in the horizontal direction. Its value is specified relative to the normal width of the glyphs, with 1 being the normal width.
Default value: 1
java.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closedpublic void setLeading(double value)
The leading parameter specifies the vertical distance between the
baselines of adjacent lines of text.
It affects only the method showLine(java.lang.String)
.
Default value: 1.2 times the initial font size.
See also Font.getLeading()
.
java.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closedpublic void setRise(double value)
Text rise specifies the distance to move the baseline up or down from its default location. Positive values of text rise move the baseline up. Adjustments to the baseline are useful for drawing superscripts or subscripts.
Default: 0
java.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closedpublic void close() throws PdfToolboxException, java.io.IOException
close
in interface java.lang.AutoCloseable
PdfToolboxException
- only explicitly stated in a superclassjava.io.IOException