org.apache.poi.xslf.usermodel
Class XSLFTextRun

java.lang.Object
  extended by org.apache.poi.xslf.usermodel.XSLFTextRun
All Implemented Interfaces:
TextRun

@Beta
public class XSLFTextRun
extends java.lang.Object
implements TextRun

Represents a run of text within the containing text body. The run element is the lowest level text separation mechanism within a text body.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.poi.sl.usermodel.TextRun
TextRun.FieldType, TextRun.TextCap
 
Constructor Summary
protected XSLFTextRun(org.apache.xmlbeans.XmlObject r, XSLFTextParagraph p)
           
 
Method Summary
 XSLFHyperlink createHyperlink()
          Creates a new hyperlink and assigns it to this text run.
 double getCharacterSpacing()
           
 TextRun.FieldType getFieldType()
          Experimental method to determine the field type, e.g.
 PaintStyle getFontColor()
          Returns the font color.
 java.lang.String getFontFamily()
          Get the font family - convenience method for TextRun.getFontInfo(FontGroup)
 java.lang.String getFontFamily(FontGroup fontGroup)
          Get the font family - convenience method for TextRun.getFontInfo(FontGroup)
 FontInfo getFontInfo(FontGroup fontGroup)
          Get the font info for the given font group
 java.lang.Double getFontSize()
          Returns the font size which is either set directly on this text run or given from the slide layout
 XSLFHyperlink getHyperlink()
          Return the associated hyperlink
 byte getPitchAndFamily()
           
 java.lang.String getRawText()
           
protected  org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties getRPr(boolean create)
          Return the character properties
 TextRun.TextCap getTextCap()
           
 org.apache.xmlbeans.XmlObject getXmlObject()
          Return the text run xmlbeans object.
 boolean isBold()
           
 boolean isItalic()
           
 boolean isStrikethrough()
           
 boolean isSubscript()
           
 boolean isSuperscript()
           
 boolean isUnderlined()
           
 void setBaselineOffset(double baselineOffset)
          Set the baseline for both the superscript and subscript fonts.
 void setBold(boolean bold)
          Sets the bold state
 void setCharacterSpacing(double spc)
          Set the spacing between characters within a text run.
 void setFontColor(java.awt.Color color)
          Sets the (solid) font color - convenience function
 void setFontColor(PaintStyle color)
          Sets the font color
 void setFontFamily(java.lang.String typeface)
          Specifies the typeface, or name of the font that is to be used for this text run - convenience method for calling TextRun.setFontInfo(FontInfo, FontGroup) with just a font name
 void setFontFamily(java.lang.String typeface, FontGroup fontGroup)
          Specifies the typeface, or name of the font that is to be used for this text run - convenience method for calling TextRun.setFontInfo(FontInfo, FontGroup) with just a font name
 void setFontInfo(FontInfo fontInfo, FontGroup fontGroup)
          Specifies the font to be used for this text run.
 void setFontSize(java.lang.Double fontSize)
          Sets the font size directly on this text run, if null is given, the font size defaults to the values given from the slide layout
 void setItalic(boolean italic)
          Sets the italic state
 void setStrikethrough(boolean strike)
          Sets the strikethrough state
 void setSubscript(boolean flag)
          Set whether the text in this run is formatted as subscript.
 void setSuperscript(boolean flag)
          Set whether the text in this run is formatted as superscript.
 void setText(java.lang.String text)
           
 void setUnderlined(boolean underline)
          Sets the underlined state
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XSLFTextRun

protected XSLFTextRun(org.apache.xmlbeans.XmlObject r,
                      XSLFTextParagraph p)
Method Detail

getRawText

public java.lang.String getRawText()
Specified by:
getRawText in interface TextRun

setText

public void setText(java.lang.String text)
Specified by:
setText in interface TextRun

getXmlObject

public org.apache.xmlbeans.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(java.awt.Color color)
Description copied from interface: TextRun
Sets the (solid) font color - convenience function

Specified by:
setFontColor in interface TextRun
Parameters:
color - the color

setFontColor

public void setFontColor(PaintStyle color)
Description copied from interface: TextRun
Sets the font color

Specified by:
setFontColor in interface TextRun
Parameters:
color - the color
See Also:
DrawPaint.createSolidPaint(Color)

getFontColor

public PaintStyle getFontColor()
Description copied from interface: TextRun
Returns the font color. This usually returns a PaintStyle.SolidPaint, but but also other classes are possible

Specified by:
getFontColor in interface TextRun
Returns:
the font color/paint
See Also:
DrawPaint.getPaint(java.awt.Graphics2D, PaintStyle), PaintStyle.SolidPaint.getSolidColor(), DrawPaint.applyColorTransform(ColorStyle)

setFontSize

public void setFontSize(java.lang.Double fontSize)
Description copied from interface: TextRun
Sets the font size directly on this text run, if null is given, the font size defaults to the values given from the slide layout

Specified by:
setFontSize in interface TextRun
Parameters:
fontSize - font size in points, if null the underlying fontsize will be unset

getFontSize

public java.lang.Double getFontSize()
Description copied from interface: TextRun
Returns the font size which is either set directly on this text run or given from the slide layout

Specified by:
getFontSize in interface TextRun
Returns:
font size in points or null if font size is not set.

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(java.lang.String typeface)
Description copied from interface: TextRun
Specifies the typeface, or name of the font that is to be used for this text run - convenience method for calling TextRun.setFontInfo(FontInfo, FontGroup) with just a font name

Specified by:
setFontFamily in interface TextRun
Parameters:
typeface - the font to apply to this text run. The value of null removes the run specific font setting, so the default setting is activated again.

setFontFamily

public void setFontFamily(java.lang.String typeface,
                          FontGroup fontGroup)
Description copied from interface: TextRun
Specifies the typeface, or name of the font that is to be used for this text run - convenience method for calling TextRun.setFontInfo(FontInfo, FontGroup) with just a font name

Specified by:
setFontFamily in interface TextRun
Parameters:
typeface - the font to apply to this text run. The value of null removes the run specific font setting, so the default setting is activated again.
fontGroup - the font group, i.e. the range of glpyhs to be covered. if null, the font group matching the first character will be returned

setFontInfo

public void setFontInfo(FontInfo fontInfo,
                        FontGroup fontGroup)
Description copied from interface: TextRun
Specifies the font to be used for this text run.

Specified by:
setFontInfo in interface TextRun
Parameters:
fontInfo - the font to apply to this text run. The value of null removes the run specific font setting, so the default setting is activated again.
fontGroup - the font group, i.e. the range of glpyhs to be covered. defaults to latin, if null.

getFontFamily

public java.lang.String getFontFamily()
Description copied from interface: TextRun
Get the font family - convenience method for TextRun.getFontInfo(FontGroup)

Specified by:
getFontFamily in interface TextRun
Returns:
font family or null if not set

getFontFamily

public java.lang.String getFontFamily(FontGroup fontGroup)
Description copied from interface: TextRun
Get the font family - convenience method for TextRun.getFontInfo(FontGroup)

Specified by:
getFontFamily in interface TextRun
Parameters:
fontGroup - the font group, i.e. the range of glpyhs to be covered. if null, the font group matching the first character will be returned
Returns:
font family or null if not set

getFontInfo

public FontInfo getFontInfo(FontGroup fontGroup)
Description copied from interface: TextRun
Get the font info for the given font group

Specified by:
getFontInfo in interface TextRun
Parameters:
fontGroup - the font group, i.e. the range of glpyhs to be covered. if null, the font group matching the first character will be returned
Returns:
font info or null if not set

getPitchAndFamily

public byte getPitchAndFamily()
Specified by:
getPitchAndFamily in interface TextRun
Returns:
the pitch and family id or -1 if not applicable

setStrikethrough

public void setStrikethrough(boolean strike)
Description copied from interface: TextRun
Sets the strikethrough state

Specified by:
setStrikethrough in interface TextRun
Parameters:
strike - set to true for stroked text, false for no stroking

isStrikethrough

public boolean isStrikethrough()
Specified by:
isStrikethrough in interface TextRun
Returns:
true, if text is stroked

isSuperscript

public boolean isSuperscript()
Specified by:
isSuperscript in interface TextRun
Returns:
true, if text is super scripted

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.

Parameters:
baselineOffset -

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:
setBaselineOffset(double)

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:
setBaselineOffset(double)

isSubscript

public boolean isSubscript()
Specified by:
isSubscript in interface TextRun
Returns:
true, if text is sub scripted

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)
Description copied from interface: TextRun
Sets the bold state

Specified by:
setBold in interface TextRun
Parameters:
bold - set to true for bold text, false for normal weight

isBold

public boolean isBold()
Specified by:
isBold in interface TextRun
Returns:
true, if text is bold

setItalic

public void setItalic(boolean italic)
Description copied from interface: TextRun
Sets the italic state

Specified by:
setItalic in interface TextRun
Parameters:
italic - set to true for italic text, false for non-italics

isItalic

public boolean isItalic()
Specified by:
isItalic in interface TextRun
Returns:
true, if text is italic

setUnderlined

public void setUnderlined(boolean underline)
Description copied from interface: TextRun
Sets the underlined state

Specified by:
setUnderlined in interface TextRun
Parameters:
underline - set to true for underlined text, false for no underlining

isUnderlined

public boolean isUnderlined()
Specified by:
isUnderlined in interface TextRun
Returns:
true, if text is underlined

getRPr

protected 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 java.lang.String toString()
Overrides:
toString in class java.lang.Object

createHyperlink

public XSLFHyperlink createHyperlink()
Description copied from interface: TextRun
Creates a new hyperlink and assigns it to this text run. If the text run has already a hyperlink assigned, return it instead

Specified by:
createHyperlink in interface TextRun
Returns:
the associated hyperlink

getHyperlink

public XSLFHyperlink getHyperlink()
Description copied from interface: TextRun
Return the associated hyperlink

Specified by:
getHyperlink in interface TextRun
Returns:
the associated hyperlink or null if no hyperlink was set

getFieldType

public TextRun.FieldType getFieldType()
Description copied from interface: TextRun
Experimental method to determine the field type, e.g. slide number

Specified by:
getFieldType in interface TextRun
Returns:
the field type or null if text run is not a field


Copyright 2017 The Apache Software Foundation or its licensors, as applicable.