Class TextGenerator
- java.lang.Object
-
- com.pdftools.toolbox.internal.NativeBase
-
- com.pdftools.toolbox.internal.NativeObject
-
- com.pdftools.toolbox.pdf.content.TextGenerator
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class TextGenerator extends NativeObject implements java.lang.AutoCloseable
-
-
Constructor Summary
Constructors Constructor Description TextGenerator(Text text, Font font, double fontSize, Point location)
Create a new text generator for appending text to a text content object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the objectdouble
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.-
Methods inherited from class com.pdftools.toolbox.internal.NativeObject
equals, hashCode
-
-
-
-
Constructor Detail
-
TextGenerator
public TextGenerator(Text text, Font font, double fontSize, Point location)
Create a new text generator for appending text to a text content object.
All parameters that cannot be set in the constructor are set to default values:- Rendering: fill text with black paint
- CharacterSpacing: 0
- WordSpacing: 0
- HorizontalScaling: 1
-
Leading: 1.2 times the {@link com.pdftools.toolbox.pdf.content.TextGenerator# fontSize}
(The {@link com.pdftools.toolbox.pdf.content.TextGenerator# font}'s
Font.getLeading()
is not used.) - Rise: 0
-
Stroke:
null
-
IntersectClipping:
false
- Parameters:
text
- the text objectfont
- the initial fontfontSize
- the initial font size and leadinglocation
- the initial position. If position isnull
, the default position [0, 0] is used.- Throws:
java.lang.IllegalArgumentException
- if the document associated with the {@link com.pdftools.toolbox.pdf.content.TextGenerator# text} object has already been closedjava.lang.IllegalArgumentException
- if the {@link com.pdftools.toolbox.pdf.content.TextGenerator# text} and {@link com.pdftools.toolbox.pdf.content.TextGenerator# font} objects are associated with different documentsjava.lang.IllegalArgumentException
- if the document associated with the {@link com.pdftools.toolbox.pdf.content.TextGenerator# font} object has already been closedjava.lang.IllegalArgumentException
- if the {@link com.pdftools.toolbox.pdf.content.TextGenerator# font} has been obtained fromTextFragment.getFont()
java.lang.IllegalArgumentException
- iftext
isnull
java.lang.IllegalArgumentException
- iffont
isnull
-
-
Method Detail
-
getWidth
public double getWidth(java.lang.String text)
Get the width of a text string.
The width of a text string as if it would be shown with the current settings.- Parameters:
text
- the text fragment- Returns:
- the width of the text
- Throws:
java.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closedjava.lang.IllegalArgumentException
- if thetext
argument isnull
-
show
public void show(java.lang.String text)
Show a text string.
The text is shown using the current settings.- Parameters:
text
- the text to be shown- Throws:
java.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closedjava.lang.IllegalArgumentException
- if thetext
argument isnull
-
showLine
public void showLine(java.lang.String text)
Show a text string and go to the next line.
- Parameters:
text
- the text to be shown- Throws:
java.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closedjava.lang.IllegalArgumentException
- if thetext
argument isnull
-
moveTo
public void moveTo(Point target)
Move the current position.
This also also sets the beginning of the current line to the specified position, which will affect theshowLine(java.lang.String)
method.- Parameters:
target
- the target position- Throws:
java.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closedjava.lang.IllegalArgumentException
- iftarget
isnull
-
setFill
public void setFill(Paint value)
The paint for filling (Setter)
The fill paint ornull
if the text should not be filled.- Throws:
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 givenPaint
object has already been closed.java.lang.IllegalArgumentException
- if the givenPaint
object belongs to a different document.
-
setStroke
public void setStroke(Stroke value)
The stroke properties (Setter)
The stroke properties ornull
if the text should not be stroked.- Throws:
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 document associated with the givenStroke
object has already been closedjava.lang.IllegalArgumentException
- if the givenStroke
object argument belongs to a different document.
-
setFont
public void setFont(Font value)
the current font. (Setter)
The font is used for all subsequentshow(java.lang.String)
andshowLine(java.lang.String)
calls.- Throws:
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 document associated with the givenFont
object has already been closedjava.lang.IllegalArgumentException
- if the givenFont
object is associated with a different documentjava.lang.IllegalArgumentException
- if the givenFont
object has been obtained fromTextFragment.getFont()
java.lang.IllegalArgumentException
- ifvalue
isnull
-
setFontSize
public void setFontSize(double value)
the current font size. (Setter)
The font size is used for all subsequent
show(java.lang.String)
andshowLine(java.lang.String)
calls.Note that this sets the font size only. Also use
setLeading(double)
to set the leading.- Throws:
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.
-
setCharacterSpacing
public void setCharacterSpacing(double value)
the current character spacing. (Setter)
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
- Throws:
java.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closed
-
setWordSpacing
public void setWordSpacing(double value)
the current word spacing. (Setter)
Word spacing works the same way as character spacing, but applies only to the space character, code 32.
Default value: 0
- Throws:
java.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closed
-
setHorizontalScaling
public void setHorizontalScaling(double value)
the current horizontal scaling. (Setter)
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
- Throws:
java.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closed
-
setLeading
public void setLeading(double value)
the current leading. (Setter)
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()
.- Throws:
java.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closed
-
setRise
public void setRise(double value)
the current rise of the baseline. (Setter)
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
- Throws:
java.lang.IllegalStateException
- if the object has already been closedjava.lang.IllegalStateException
- if the underlying text object has already been closed
-
close
public void close() throws ToolboxException, java.io.IOException
Close the object
Release all native resources associated with the object.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
ToolboxException
- only explicitly stated in a superclassjava.io.IOException
-
-