Package org.apache.poi.hslf.usermodel
Class HSLFTextShape
- java.lang.Object
-
- org.apache.poi.hslf.usermodel.HSLFShape
-
- org.apache.poi.hslf.usermodel.HSLFSimpleShape
-
- org.apache.poi.hslf.usermodel.HSLFTextShape
-
- All Implemented Interfaces:
Iterable<HSLFTextParagraph>
,IAdjustableShape
,PlaceableShape<HSLFShape,HSLFTextParagraph>
,Shape<HSLFShape,HSLFTextParagraph>
,SimpleShape<HSLFShape,HSLFTextParagraph>
,TextShape<HSLFShape,HSLFTextParagraph>
- Direct Known Subclasses:
HSLFAutoShape
,HSLFLine
,HSLFTextBox
public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape<HSLFShape,HSLFTextParagraph>
A common superclass of all shapes that can hold text.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.poi.sl.usermodel.TextShape
TextShape.TextAutofit, TextShape.TextDirection, TextShape.TextPlaceholder
-
-
Field Summary
Fields Modifier and Type Field Description static int
WrapByPoints
Specifies a wrapping rule that is equivalent to that of WrapSquare Excel 97, Excel 2000, Excel 2002, and Office Excel 2003 use this value.static int
WrapNone
Specifies that a line of text will extend into or beyond a margin instead of continuing on subsequent lines.static int
WrapSquare
Specifies that a line of text will continue on subsequent lines instead of extending into or beyond a margin.static int
WrapThrough
Specifies a wrapping rule that is undefined and MUST be ignored.static int
WrapTopBottom
Specifies a wrapping rule that is undefined and MUST be ignored.-
Fields inherited from class org.apache.poi.hslf.usermodel.HSLFSimpleShape
DEFAULT_LINE_WIDTH
-
-
Constructor Summary
Constructors Constructor Description HSLFTextShape()
Create a new TextBox.HSLFTextShape(ShapeContainer<HSLFShape,HSLFTextParagraph> parent)
Create a new TextBox.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HSLFTextRun
appendText(String text, boolean newParagraph)
Adds the supplied text onto the end of the TextParagraphs, creating a new RichTextRun for it to sit in.double
getBottomInset()
Returns the distance (in points) between the bottom of the text frame and the bottom of the inscribed rectangle of the shape that contains the text.RoundTripHFPlaceholder12
getHFPlaceholderAtom()
ReturnRoundTripHFPlaceholder12
, the atom that describes a header/footer placeholder.List<HSLFHyperlink>
getHyperlinks()
Returns the array of all hyperlinks in this text runInsets2D
getInsets()
double
getLeftInset()
Returns the distance (in points) between the left edge of the text frame and the left edge of the inscribed rectangle of the shape that contains the text.TextShape<?,? extends TextParagraph<?,?,? extends TextRun>>
getMetroShape()
Get alternative representation of text shape stored as metro blob escher property.OEPlaceholderAtom
getPlaceholderAtom()
ReturnOEPlaceholderAtom
, the atom that describes a placeholder.String
getRawText()
Returns the raw text content of the shape.double
getRightInset()
Returns the distance (in points) between the right edge of the text frame and the right edge of the inscribed rectangle of the shape that contains the text.int
getRunType()
Returns the type of the text, from the TextHeaderAtom.String
getText()
Returns the text contained in this text frame, which has been made safe for printing and other use.TextShape.TextDirection
getTextDirection()
double
getTextHeight()
Compute the cumulative height occupied by the textdouble
getTextHeight(Graphics2D graphics)
Compute the cumulative height occupied by the textint
getTextId()
List<HSLFTextParagraph>
getTextParagraphs()
TextShape.TextPlaceholder
getTextPlaceholder()
Double
getTextRotation()
The text rotation can be independent specified from the shape rotation.double
getTopInset()
Returns the distance (in points) between the top of the text frame and the top of the inscribed rectangle of the shape that contains the text.VerticalAlignment
getVerticalAlignment()
Returns the type of vertical alignment for the text.boolean
getWordWrap()
int
getWordWrapEx()
Returns the value indicating word wrap.boolean
isAlignToBaseline()
boolean
isHorizontalCentered()
Returns if the text is centered.boolean
isPlaceholder()
Checks if the shape is a placeholder.Iterator<HSLFTextParagraph>
iterator()
Rectangle2D
resizeToFitText()
Adjust the size of the shape so it encompasses the text inside it.Rectangle2D
resizeToFitText(Graphics2D graphics)
Adjust the size of the shape so it encompasses the text inside it.void
setAlignToBaseline(boolean alignToBaseline)
Sets the vertical alignment relative to the baselinevoid
setBottomInset(double margin)
Sets the botom margin.void
setHorizontalCentered(Boolean isCentered)
Sets if the paragraphs are horizontal centeredvoid
setInsets(Insets2D insets)
Sets the shape marginsvoid
setLeftInset(double margin)
Sets the left margin.void
setRightInset(double margin)
Sets the right margin.void
setRunType(int type)
Changes the type of the text.void
setSheet(HSLFSheet sheet)
Assign theSlideShow
this shape belongs toHSLFTextRun
setText(String text)
Sets (overwrites) the current text.void
setTextDirection(TextShape.TextDirection orientation)
sets the vertical orientationvoid
setTextId(int id)
Sets text IDvoid
setTextPlaceholder(TextShape.TextPlaceholder placeholder)
Sets the text placeholdervoid
setTextRotation(Double rotation)
Sets the text rotation.void
setTopInset(double margin)
Sets the top margin.void
setVerticalAlignment(VerticalAlignment vAlign)
Sets the type of vertical alignment for the text.void
setWordWrap(boolean wrap)
void
setWordWrapEx(int wrap)
Specifies how the text should be wrapped-
Methods inherited from class org.apache.poi.hslf.usermodel.HSLFSimpleShape
createHyperlink, getAdjustValue, getFillColor, getGeometry, getHyperlink, getLineBackgroundColor, getLineCap, getLineColor, getLineCompound, getLineDash, getLineDecoration, getLineHeadDecoration, getLineHeadLength, getLineHeadWidth, getLineTailDecoration, getLineTailLength, getLineTailWidth, getLineWidth, getPlaceholder, getPlaceholderDetails, getShadow, getShadowAngle, getShadowColor, getShadowDistance, getStrokeStyle, setFillColor, setLineBackgroundColor, setLineCap, setLineColor, setLineCompound, setLineDash, setLineHeadDecoration, setLineHeadLength, setLineHeadWidth, setLineTailDecoration, setLineTailLength, setLineTailWidth, setLineWidth, setPlaceholder, setStrokeStyle
-
Methods inherited from class org.apache.poi.hslf.usermodel.HSLFShape
draw, getAnchor, getClientDataRecord, getEscherChild, getEscherChild, getEscherChild, getEscherChild, getEscherOptRecord, getEscherProperty, getEscherProperty, getEscherProperty, getFill, getFillStyle, getFlipHorizontal, getFlipVertical, getParent, getRotation, getShapeId, getShapeName, getShapeType, getSheet, getSpContainer, moveTo, setAnchor, setEscherProperty, setEscherProperty, setFlipHorizontal, setFlipVertical, setRotation, setShapeId, setShapeType
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.poi.sl.draw.geom.IAdjustableShape
getAdjustValue
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface org.apache.poi.sl.usermodel.PlaceableShape
getAnchor, getFlipHorizontal, getFlipVertical, getParent, getRotation, getSheet, setAnchor, setFlipHorizontal, setFlipVertical, setRotation
-
Methods inherited from interface org.apache.poi.sl.usermodel.Shape
draw, getAnchor, getParent, getShapeId, getShapeName, getSheet
-
Methods inherited from interface org.apache.poi.sl.usermodel.SimpleShape
createHyperlink, getFillColor, getFillStyle, getGeometry, getHyperlink, getLineDecoration, getPlaceholder, getPlaceholderDetails, getShadow, getShapeType, getStrokeStyle, setFillColor, setPlaceholder, setShapeType, setStrokeStyle
-
-
-
-
Field Detail
-
WrapSquare
public static final int WrapSquare
Specifies that a line of text will continue on subsequent lines instead of extending into or beyond a margin. Office Excel 2007, Excel 2010, PowerPoint 97, and PowerPoint 2010 read and use this value properly but do not write it.- See Also:
- Constant Field Values
-
WrapByPoints
public static final int WrapByPoints
Specifies a wrapping rule that is equivalent to that of WrapSquare Excel 97, Excel 2000, Excel 2002, and Office Excel 2003 use this value. All other product versions listed at the beginning of this appendix ignore this value.- See Also:
- Constant Field Values
-
WrapNone
public static final int WrapNone
Specifies that a line of text will extend into or beyond a margin instead of continuing on subsequent lines. Excel 97, Word 97, Excel 2000, Word 2000, Excel 2002, and Office Excel 2003 do not use this value.- See Also:
- Constant Field Values
-
WrapTopBottom
public static final int WrapTopBottom
Specifies a wrapping rule that is undefined and MUST be ignored.- See Also:
- Constant Field Values
-
WrapThrough
public static final int WrapThrough
Specifies a wrapping rule that is undefined and MUST be ignored.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HSLFTextShape
public HSLFTextShape(ShapeContainer<HSLFShape,HSLFTextParagraph> parent)
Create a new TextBox. This constructor is used when a new shape is created.- Parameters:
parent
- the parent of this Shape. For example, if this text box is a cell in a table then the parent is Table.
-
HSLFTextShape
public HSLFTextShape()
Create a new TextBox. This constructor is used when a new shape is created.
-
-
Method Detail
-
resizeToFitText
public Rectangle2D resizeToFitText()
Description copied from interface:TextShape
Adjust the size of the shape so it encompasses the text inside it.- Specified by:
resizeToFitText
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Returns:
- a
Rectangle2D
that is the bounds of this shape.
-
resizeToFitText
public Rectangle2D resizeToFitText(Graphics2D graphics)
Description copied from interface:TextShape
Adjust the size of the shape so it encompasses the text inside it.- Specified by:
resizeToFitText
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Parameters:
graphics
- a customized graphics context, e.g. which contains font mappings- Returns:
- a
Rectangle2D
that is the bounds of this shape.
-
getRunType
public int getRunType()
Returns the type of the text, from the TextHeaderAtom. Possible values can be seen from TextHeaderAtom- See Also:
TextHeaderAtom
-
setRunType
public void setRunType(int type)
Changes the type of the text. Values should be taken from TextHeaderAtom. No checking is done to ensure you set this to a valid value!- See Also:
TextHeaderAtom
-
isAlignToBaseline
public boolean isAlignToBaseline()
- Returns:
- true, if vertical alignment is relative to baseline this is only used for older versions less equals Office 2003
-
setAlignToBaseline
public void setAlignToBaseline(boolean alignToBaseline)
Sets the vertical alignment relative to the baseline- Parameters:
alignToBaseline
- if true, vertical alignment is relative to baseline
-
isHorizontalCentered
public boolean isHorizontalCentered()
Description copied from interface:TextShape
Returns if the text is centered. If true and if the individual paragraph settings allow it, the whole text block will be displayed centered, i.e. its left and right margin will be maximized while still keeping the alignment of the paragraphs- Specified by:
isHorizontalCentered
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Returns:
- true, if the text anchor is horizontal centered
-
setHorizontalCentered
public void setHorizontalCentered(Boolean isCentered)
Description copied from interface:TextShape
Sets if the paragraphs are horizontal centered- Specified by:
setHorizontalCentered
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Parameters:
isCentered
- true, if the paragraphs are horizontal centered Anull
values unsets this property.
-
getVerticalAlignment
public VerticalAlignment getVerticalAlignment()
Description copied from interface:TextShape
Returns the type of vertical alignment for the text.- Specified by:
getVerticalAlignment
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Returns:
- the type of vertical alignment
-
setVerticalAlignment
public void setVerticalAlignment(VerticalAlignment vAlign)
Description copied from interface:TextShape
Sets the type of vertical alignment for the text.- Specified by:
setVerticalAlignment
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Parameters:
vAlign
- - the type of alignment. Anull
values unsets this property.
-
getBottomInset
public double getBottomInset()
Returns the distance (in points) between the bottom of the text frame and the bottom of the inscribed rectangle of the shape that contains the text. Default value is 1/20 inch.- Returns:
- the botom margin
-
setBottomInset
public void setBottomInset(double margin)
Sets the botom margin.- Parameters:
margin
- the bottom margin- See Also:
getBottomInset()
-
getLeftInset
public double getLeftInset()
Returns the distance (in points) between the left edge of the text frame and the left edge of the inscribed rectangle of the shape that contains the text. Default value is 1/10 inch.- Returns:
- the left margin
-
setLeftInset
public void setLeftInset(double margin)
Sets the left margin.- Parameters:
margin
- the left margin- See Also:
getLeftInset()
-
getRightInset
public double getRightInset()
Returns the distance (in points) between the right edge of the text frame and the right edge of the inscribed rectangle of the shape that contains the text. Default value is 1/10 inch.- Returns:
- the right margin
-
setRightInset
public void setRightInset(double margin)
Sets the right margin.- Parameters:
margin
- the right margin- See Also:
getRightInset()
-
getTopInset
public double getTopInset()
Returns the distance (in points) between the top of the text frame and the top of the inscribed rectangle of the shape that contains the text. Default value is 1/20 inch.- Returns:
- the top margin
-
setTopInset
public void setTopInset(double margin)
Sets the top margin.- Parameters:
margin
- the top margin- See Also:
getTopInset()
-
getWordWrapEx
public int getWordWrapEx()
Returns the value indicating word wrap.- Returns:
- the value indicating word wrap.
Must be one of the
Wrap*
constants defined in this class. - See Also:
- MSOWRAPMODE
-
setWordWrapEx
public void setWordWrapEx(int wrap)
Specifies how the text should be wrapped- Parameters:
wrap
- the value indicating how the text should be wrapped. Must be one of theWrap*
constants defined in this class.
-
getWordWrap
public boolean getWordWrap()
- Specified by:
getWordWrap
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Returns:
- whether to wrap words within the bounding rectangle
-
setWordWrap
public void setWordWrap(boolean wrap)
- Specified by:
setWordWrap
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Parameters:
wrap
- whether to wrap words within the bounding rectangle
-
getTextId
public int getTextId()
- Returns:
- id for the text.
-
setTextId
public void setTextId(int id)
Sets text ID- Parameters:
id
- of the text
-
getTextParagraphs
public List<HSLFTextParagraph> getTextParagraphs()
- Specified by:
getTextParagraphs
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Returns:
- the TextParagraphs for this text box
-
setSheet
public void setSheet(HSLFSheet sheet)
Description copied from class:HSLFShape
Assign theSlideShow
this shape belongs to
-
getPlaceholderAtom
public OEPlaceholderAtom getPlaceholderAtom()
ReturnOEPlaceholderAtom
, the atom that describes a placeholder.- Returns:
OEPlaceholderAtom
ornull
if not found
-
getHFPlaceholderAtom
public RoundTripHFPlaceholder12 getHFPlaceholderAtom()
ReturnRoundTripHFPlaceholder12
, the atom that describes a header/footer placeholder. Compare theRoundTripHFPlaceholder12.getPlaceholderId()
withPlaceholder.HEADER
orPlaceholder.FOOTER
, to find out what kind of placeholder this is.- Returns:
RoundTripHFPlaceholder12
ornull
if not found- Since:
- POI 3.14-Beta2
-
isPlaceholder
public boolean isPlaceholder()
Description copied from interface:SimpleShape
Checks if the shape is a placeholder. (placeholders aren't normal shapes, they are visible only in the Edit Master mode)- Specified by:
isPlaceholder
in interfaceSimpleShape<HSLFShape,HSLFTextParagraph>
- Overrides:
isPlaceholder
in classHSLFSimpleShape
- Returns:
true
if the shape is a placeholder
-
iterator
public Iterator<HSLFTextParagraph> iterator()
- Specified by:
iterator
in interfaceIterable<HSLFTextParagraph>
-
getInsets
public Insets2D getInsets()
- Specified by:
getInsets
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Returns:
- text shape margin
-
setInsets
public void setInsets(Insets2D insets)
Description copied from interface:TextShape
Sets the shape margins- Specified by:
setInsets
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Parameters:
insets
- the new shape margins
-
getTextHeight
public double getTextHeight()
Description copied from interface:TextShape
Compute the cumulative height occupied by the text- Specified by:
getTextHeight
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Returns:
- the cumulative height occupied by the text
-
getTextHeight
public double getTextHeight(Graphics2D graphics)
Description copied from interface:TextShape
Compute the cumulative height occupied by the text- Specified by:
getTextHeight
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Parameters:
graphics
- a customized graphics context, e.g. which contains font mappings- Returns:
- the cumulative height occupied by the text
-
getTextDirection
public TextShape.TextDirection getTextDirection()
- Specified by:
getTextDirection
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Returns:
- vertical orientation of the text
-
setTextDirection
public void setTextDirection(TextShape.TextDirection orientation)
Description copied from interface:TextShape
sets the vertical orientation- Specified by:
setTextDirection
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Parameters:
orientation
- vertical orientation of the text
-
getTextRotation
public Double getTextRotation()
Description copied from interface:TextShape
The text rotation can be independent specified from the shape rotation. For XSLF this can be an arbitrary degree, for HSLF the degree is given in steps of 90 degrees- Specified by:
getTextRotation
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Returns:
- text rotation in degrees, returns null if no rotation is given
-
setTextRotation
public void setTextRotation(Double rotation)
Description copied from interface:TextShape
Sets the text rotation. For XSLF this can ben an arbitrary degree, for HSLF the rotation is rounded to next 90 degree step- Specified by:
setTextRotation
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Parameters:
rotation
- the text rotation, or null to unset the rotation
-
getRawText
public String getRawText()
Returns the raw text content of the shape. This hasn't had any changes applied to it, and so is probably unlikely to print out nicely.
-
getText
public String getText()
Description copied from interface:TextShape
Returns the text contained in this text frame, which has been made safe for printing and other use.- Specified by:
getText
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Returns:
- the text string for this textbox.
-
appendText
public HSLFTextRun appendText(String text, boolean newParagraph)
Description copied from interface:TextShape
Adds the supplied text onto the end of the TextParagraphs, creating a new RichTextRun for it to sit in.- Specified by:
appendText
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Parameters:
text
- the text string to be appended.newParagraph
- if true, a new paragraph will be added, which will contain the added text
-
setText
public HSLFTextRun setText(String text)
Description copied from interface:TextShape
Sets (overwrites) the current text. Uses the properties of the first paragraph / textrun. Text paragraphs are split by \\r or \\n. New lines within text run are split by \\u000b- Specified by:
setText
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Parameters:
text
- the text string used by this object.- Returns:
- the last text run of the - potential split - text
-
getHyperlinks
public List<HSLFHyperlink> getHyperlinks()
Returns the array of all hyperlinks in this text run- Returns:
- the array of all hyperlinks in this text run or
null
if not found.
-
setTextPlaceholder
public void setTextPlaceholder(TextShape.TextPlaceholder placeholder)
Description copied from interface:TextShape
Sets the text placeholder- Specified by:
setTextPlaceholder
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
-
getTextPlaceholder
public TextShape.TextPlaceholder getTextPlaceholder()
- Specified by:
getTextPlaceholder
in interfaceTextShape<HSLFShape,HSLFTextParagraph>
- Returns:
- the text placeholder
-
getMetroShape
public TextShape<?,? extends TextParagraph<?,?,? extends TextRun>> getMetroShape()
Get alternative representation of text shape stored as metro blob escher property. The returned shape is the first shape in stored group shape of the metro blob- Returns:
- null, if there's no alternative representation, otherwise the text shape
-
-