Class 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 object
      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.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, toString, wait, wait, wait
    • 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 object
        font - the initial font
        fontSize - the initial font size and leading
        location - the initial position. If position is null, 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 closed
        java.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 documents
        java.lang.IllegalArgumentException - if the document associated with the {@link com.pdftools.toolbox.pdf.content.TextGenerator# font} object has already been closed
        java.lang.IllegalArgumentException - if the {@link com.pdftools.toolbox.pdf.content.TextGenerator# font} has been obtained from TextFragment.getFont()
        java.lang.IllegalArgumentException - if text is null
        java.lang.IllegalArgumentException - if font is null
    • 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 closed
        java.lang.IllegalStateException - if the underlying text object has already been closed
        java.lang.IllegalArgumentException - if the text argument is null
      • 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 closed
        java.lang.IllegalStateException - if the underlying text object has already been closed
        java.lang.IllegalArgumentException - if the text argument is null
      • 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 closed
        java.lang.IllegalStateException - if the underlying text object has already been closed
        java.lang.IllegalArgumentException - if the text argument is null
      • 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 the showLine(java.lang.String) method.
        Parameters:
        target - the target position
        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 target is null
      • setFill

        public void setFill​(Paint value)

        The paint for filling (Setter)

        The fill paint or null if the text should not be filled.
        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 given Paint object has already been closed.
        java.lang.IllegalArgumentException - if the given Paint object belongs to a different document.
      • setStroke

        public void setStroke​(Stroke value)

        The stroke properties (Setter)

        The stroke properties or null 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 given Stroke object has already been closed
        java.lang.IllegalArgumentException - if the given Stroke object argument belongs to a different document.
      • setFont

        public void setFont​(Font value)

        the current font. (Setter)

        The font is used for all subsequent show(java.lang.String) and showLine(java.lang.String) calls.
        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 given Font object has already been closed
        java.lang.IllegalArgumentException - if the given Font object is associated with a different document
        java.lang.IllegalArgumentException - if the given Font object has been obtained from TextFragment.getFont()
        java.lang.IllegalArgumentException - if value is null
      • setFontSize

        public void setFontSize​(double value)

        the current font size. (Setter)

        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.

        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 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 closed
        java.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 closed
        java.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 closed
        java.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 closed
        java.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 closed
        java.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 interface java.lang.AutoCloseable
        Throws:
        ToolboxException - only explicitly stated in a superclass
        java.io.IOException