Class Text


public class Text extends Element
A container that represents a series of text elements and characters. A Text object is container that represents both a series of TextRun elements and a series of text characters. Operations can be performed on individual TextRuns within a Text or on individual characters within a Text by specifying the index of the individual TextRun or character. All indices start at 0.
  • Constructor Details

    • Text

      public Text()
  • Method Details

    • delete

      public void delete()
      Overrides:
      delete in class Element
    • getNumberOfRuns

      public int getNumberOfRuns()
      The number of text runs in this text element.
    • getRun

      public TextRun getRun(int index)
      Obtains the TextRun at the specified index.
    • addRun

      public void addRun(TextRun run)
      Adds a TextRun to the end of this text element.
    • addRun

      public void addRun(TextRun run, int index)
      Adds a TextRun at the specified index.

      Parameters:
      run - TextRun to be added
      index - Index, where TextRun should be placed
    • removeRuns

      public void removeRuns(int index, int count)
      Removes a count of TextRuns, starting from index

      Parameters:
      index - Start position of range to delete
      count - Count of TextRuns to delete
    • addGlyphs

      public void addGlyphs(List<Character> glyphIDs, List<Character> uniText, Font font, GraphicState gState, TextState state, Matrix matrix, EnumSet<TextFlags> flags)
      Adds Unicode text to a Text object

      Parameters:
      glyphIDs - Glyphs IDs in the specified font for adding to the page's content
      uniText - Unicode codes for the specified glyph IDs
      font - Font for wich GlyphIDs were specified
      gState - The GraphicsState for Text element
      state - TextState flags
      matrix - matrix for the Text element
      flags - TextFlags that specifies what kind of text to add
    • addGlyphs

      public void addGlyphs(List<Character> glyphIDs, List<Character> uniText, Font font, GraphicState gState, TextState state, Matrix matrix, EnumSet<TextFlags> flags, int index)
      Adds Unicode text to a Text object

      Parameters:
      glyphIDs - Glyphs IDs in the specified font to add to the page's content
      uniText - Unicode codes for the specified glyph IDs
      font - Font for wich GlyphIDs were specified
      gState - The GraphicsState for Text element
      state - TextState flags
      matrix - matrix for the Text element
      flags - TextFlags that specifies what kind of text to add
      index - The index after which to add the character or text run.
    • clone

      public Text clone()
      Makes a copy of the text.

      Make a copy of an text to obtain a new text that has a distinct set of attributes.

      Overrides:
      clone in class Element
      Returns:
      The copied text.
    • clone

      public Text clone(EnumSet<ElementCloneFlags> cloneFlags)
      Makes a copy of the text.

      Make a copy of an text to obtain a new text that has a distinct set of attributes.

      Overrides:
      clone in class Element
      Parameters:
      cloneFlags - Flags that modify the cloning operation.
      Returns:
      The copied text.
    • pointIntersectsCharacter

      public boolean pointIntersectsCharacter(Point p, int index)
      Tests whether a point is on a specified character within this Text object.

      Parameters:
      p - The point to test, in user space coordinates.
      index - The index of the character. The first character in the Text has an index of 0.
      Returns:
      true if the point is on the character, false if the point is not on the character.
    • pointIntersectsTextRun

      public boolean pointIntersectsTextRun(Point p, int index)
      Tests whether a point is on a specified TextRun within this Text object.

      Parameters:
      p - The point to test, in user space coordinates.
      index - The index of the TextRun. The first TextRun in the Text has an index of 0.
      Returns:
      true if the point is on the TextRun, false if the point is not on the TextRun.
    • rectIntersectsCharacter

      public boolean rectIntersectsCharacter(Rect r, int index)
      Tests whether any part of a rectangle is on a specified character within this Text object.

      Parameters:
      r - The rect to test, in user space coordinates.
      index - The index of the character. The first character in the Text has an index of 0.
      Returns:
      true if any part of the rectangle is on the character, false if no part of the rectangle is on the character.
    • rectIntersectsTextRun

      public boolean rectIntersectsTextRun(Rect r, int index)
      Tests whether any part of a rectangle is on a specified TextRun within this Text object.

      Parameters:
      r - The rect to test, in user space coordinates.
      index - The index of the TextRun. The first TextRun in the Text has an index of 0.
      Returns:
      true if any part of the rectangle is on the TextRun, false if no part of the rectangle is on the TextRun.
    • splitTextRunAtCharacter

      public void splitTextRunAtCharacter(int splitLocation)
      Splits the TextRun containing the character at the specified location into two contiguous TextRuns. The character at the specified index will be part of the first TextRun.

      Parameters:
      splitLocation - The split location, relative to the Text object.
    • findTextRunIndexForCharacter

      public int findTextRunIndexForCharacter(int characterIndex)
      Finds the index of the TextRun that contains the nth character in a Text object.

      Parameters:
      characterIndex - The index of a character, relative to the Text object (the first character in the Text object is at index 0).
      Returns:
      The index of the TextRun that contains the character specified by characterIndex.
    • getTextMatrixForCharacter

      public Matrix getTextMatrixForCharacter(int characterIndex)
      Gets the transformation matrix from user space to the current text space for the specified character. The H and V values of the matrix indicate the origin of the first character.

      Parameters:
      characterIndex - The index of a character, relative to the Text object (the first character in the Text object is at index 0).
      Returns:
      The transformation matrix for the character specified by characterIndex.
    • getTextMatrixForTextRun

      public Matrix getTextMatrixForTextRun(int textRunIndex)
      Gets the transformation matrix from user space to the current text space for the specified TextRun. The H and V values of the matrix indicate the origin of the first character.

      Parameters:
      textRunIndex - The index of a TextRun, relative to the Text object (the first TextRun in the Text object is at index 0).
      Returns:
      The transformation matrix for the TextRun specified by TextRunIndex.
    • changeTextMatrixForTextRun

      public void changeTextMatrixForTextRun(Matrix newMatrix, int textRunIndex)
      Changes the transformation matrix from user space to the current text space for the specified TextRun. The H and V values of the matrix indicate the origin of the first character.

      Parameters:
      newMatrix - The new transformation matrix to use for the TextRun.
      textRunIndex - The index of a TextRun, relative to the Text object (the first TextRun in the Text object is at index 0).
    • changeMatrixForTextRun

      public void changeMatrixForTextRun(Matrix newMatrix, int textRunIndex)
      Changes the transformation matrix from user space to the current text space for the specified TextRun. Unlike ChangeTextMatrixForTextRun(), this function does not change fontSize, hScale, and textRise in the textState of PDEText. The H and V values of the matrix indicate the origin of the first character.

      Parameters:
      newMatrix - The new transformation matrix to use for the TextRun.
      textRunIndex - The index of a TextRun, relative to the Text object (the first TextRun in the Text object is at index 0).
    • getAdvanceForCharacter

      public Point getAdvanceForCharacter(int characterIndex)
      Gets the advance width of a character, in user space. The advance width is the amount by which the current point advances when the character is drawn.

      Advance width may be horizontal or vertical, depending on the writing style. Thus, the return value has both a horizontal and a vertical component.

      Parameters:
      characterIndex - The index of a character, relative to the Text object (the first character in the Text object is at index 0).
      Returns:
      A value specifying both the horizontal and vertical components of the advance width of a character in user space.
    • getAdvanceForTextRun

      public Point getAdvanceForTextRun(int textRunIndex)
      Gets the advance width of a TextRun, in user space. The advance width is the amount by which the current point advances when the TextRun is drawn.

      Advance width may be horizontal or vertical, depending on the writing style. Thus, the return value has both a horizontal and a vertical component.

      Parameters:
      textRunIndex - The index of a TextRun, relative to the Text object (the first TextRun in the Text object is at index 0).
      Returns:
      A value specifying both the horizontal and vertical components of the advance width of a TextRun in user space.
    • getNumberOfCharacters

      public int getNumberOfCharacters()
      The number of characters in this text element.
    • getBoundingBoxForCharacter

      public Rect getBoundingBoxForCharacter(int characterIndex)
      The bounding box for a character in this text element.

      Parameters:
      characterIndex - The index of a character, relative to the Text object (the first character in the Text object is at index 0)
      Returns:
      A Rect specifying the bounding box for the character.
    • colorConvert

      public Text colorConvert(Document document, ColorProfile prof, RenderIntent intent, boolean embed)
      Applies the specified ICC ColorProfile to the Text object

      Parameters:
      document - The document the element belongs to.
      prof - The ICC ColorProfile to be applied.
      intent - The ICC Rendering Intent for the ColorProfile
      embed - If true, embed the color space and make the object calibrated. If it is false and the target profile is CMYK, RGB, or Gray, the colors space of the resulting object, after conversion, will be DeviceCMYK, DeviceRGB, or DeviceGray, respectively.
      Returns:
      A new Text object with the applied ICC ColorProfile.