Class XSLFTextRun

java.lang.Object
org.apache.poi.xslf.usermodel.XSLFTextRun
All Implemented Interfaces:
HighlightColorSupport, TextRun

@Beta public class XSLFTextRun extends Object implements TextRun, HighlightColorSupport
Represents a run of text within the containing text body. The run element is the lowest level text separation mechanism within a text body.
  • Constructor Details

  • Method Details

    • getRawText

      public String getRawText()
      Specified by:
      getRawText in interface TextRun
    • setText

      public void setText(String text)
      Specified by:
      setText in interface TextRun
    • getXmlObject

      @Internal public XmlObject getXmlObject()
      Return the text run xmlbeans object. Depending on the type of text run, this can be CTTextField, CTTextLineBreak or usually a CTRegularTextRun
      Returns:
      the xmlbeans object
    • setFontColor

      public void setFontColor(Color color)
      Specified by:
      setFontColor in interface TextRun
    • setFontColor

      public void setFontColor(PaintStyle color)
      Specified by:
      setFontColor in interface TextRun
    • getFontColor

      public PaintStyle getFontColor()
      Specified by:
      getFontColor in interface TextRun
    • getHighlightColor

      public PaintStyle getHighlightColor()
      Returns the font highlight (background) color for this text run. This returns a PaintStyle.SolidPaint, or null if no highlight is set.
      Specified by:
      getHighlightColor in interface HighlightColorSupport
      Returns:
      The font highlight (background) colour associated with the run, null if no highlight.
      Since:
      5.2.4
      See Also:
    • setHighlightColor

      public void setHighlightColor(Color color)
      Sets the font highlight (background) color for this text run - convenience function
      Specified by:
      setHighlightColor in interface HighlightColorSupport
      Parameters:
      color - The highlight (background) color to set.
      Since:
      5.2.4
    • setHighlightColor

      public void setHighlightColor(PaintStyle color)
      Set the highlight (background) color for this text run.
      Specified by:
      setHighlightColor in interface HighlightColorSupport
      Parameters:
      color - The highlight (background) color to set.
      Throws:
      IllegalArgumentException - If the supplied paint style is not null or a SolidPaint.
      Since:
      5.2.4
      See Also:
    • setFontSize

      public void setFontSize(Double fontSize)
      Specified by:
      setFontSize in interface TextRun
    • getFontSize

      public Double getFontSize()
      Specified by:
      getFontSize in interface TextRun
    • getCharacterSpacing

      public double getCharacterSpacing()
      Returns:
      the spacing between characters within a text run, If this attribute is omitted than a value of 0 or no adjustment is assumed.
    • setCharacterSpacing

      public void setCharacterSpacing(double spc)
      Set the spacing between characters within a text run.

      The spacing is specified in points. Positive values will cause the text to expand, negative values to condense.

      Parameters:
      spc - character spacing in points.
    • setFontFamily

      public void setFontFamily(String typeface)
      Specified by:
      setFontFamily in interface TextRun
    • setFontFamily

      public void setFontFamily(String typeface, FontGroup fontGroup)
      Specified by:
      setFontFamily in interface TextRun
    • setFontInfo

      public void setFontInfo(FontInfo fontInfo, FontGroup fontGroup)
      Specified by:
      setFontInfo in interface TextRun
    • getFontFamily

      public String getFontFamily()
      Specified by:
      getFontFamily in interface TextRun
    • getFontFamily

      public String getFontFamily(FontGroup fontGroup)
      Specified by:
      getFontFamily in interface TextRun
    • getFontInfo

      public FontInfo getFontInfo(FontGroup fontGroup)
      Specified by:
      getFontInfo in interface TextRun
    • getPitchAndFamily

      public byte getPitchAndFamily()
      Specified by:
      getPitchAndFamily in interface TextRun
    • setStrikethrough

      public void setStrikethrough(boolean strike)
      Specified by:
      setStrikethrough in interface TextRun
    • isStrikethrough

      public boolean isStrikethrough()
      Specified by:
      isStrikethrough in interface TextRun
    • isSuperscript

      public boolean isSuperscript()
      Specified by:
      isSuperscript in interface TextRun
    • setBaselineOffset

      public void setBaselineOffset(double baselineOffset)
      Set the baseline for both the superscript and subscript fonts.

      The size is specified using a percentage. Positive values indicate superscript, negative values indicate subscript.

    • setSuperscript

      public void setSuperscript(boolean flag)
      Set whether the text in this run is formatted as superscript. Default base line offset is 30%
      See Also:
    • setSubscript

      public void setSubscript(boolean flag)
      Set whether the text in this run is formatted as subscript. Default base line offset is -25%.
      See Also:
    • isSubscript

      public boolean isSubscript()
      Specified by:
      isSubscript in interface TextRun
    • getTextCap

      public TextRun.TextCap getTextCap()
      Specified by:
      getTextCap in interface TextRun
      Returns:
      whether a run of text will be formatted as a superscript text. Default is false.
    • setBold

      public void setBold(boolean bold)
      Specified by:
      setBold in interface TextRun
    • isBold

      public boolean isBold()
      Specified by:
      isBold in interface TextRun
    • setItalic

      public void setItalic(boolean italic)
      Specified by:
      setItalic in interface TextRun
    • isItalic

      public boolean isItalic()
      Specified by:
      isItalic in interface TextRun
    • setUnderlined

      public void setUnderlined(boolean underline)
      Specified by:
      setUnderlined in interface TextRun
    • isUnderlined

      public boolean isUnderlined()
      Specified by:
      isUnderlined in interface TextRun
    • getRPr

      @Internal public org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties getRPr(boolean create)
      Return the character properties
      Parameters:
      create - if true, create an empty character properties object if it doesn't exist
      Returns:
      the character properties or null if create was false and the properties haven't exist
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • createHyperlink

      public XSLFHyperlink createHyperlink()
      Specified by:
      createHyperlink in interface TextRun
    • getHyperlink

      public XSLFHyperlink getHyperlink()
      Specified by:
      getHyperlink in interface TextRun
    • getFieldType

      public TextRun.FieldType getFieldType()
      Specified by:
      getFieldType in interface TextRun
    • getParagraph

      public XSLFTextParagraph getParagraph()
      Specified by:
      getParagraph in interface TextRun