Package com.itextpdf.text
Class Rectangle
- java.lang.Object
-
- com.itextpdf.text.Rectangle
-
- All Implemented Interfaces:
Element
- Direct Known Subclasses:
Image
,PdfBody
,PdfPCell
,RectangleReadOnly
public class Rectangle extends java.lang.Object implements Element
ARectangle
is the representation of a geometric figure. Rectangles support constant width borders usingsetBorderWidth(float)
andsetBorder(int)
. They also support borders that vary in width/color on each side using methods likesetBorderWidthLeft(float)
orsetBorderColorLeft(BaseColor)
.- See Also:
Element
-
-
Field Summary
Fields Modifier and Type Field Description protected BaseColor
backgroundColor
This is the color of the background of this rectangle.protected int
border
This represents the status of the 4 sides of the rectangle.protected BaseColor
borderColor
The color of the border of this rectangle.protected BaseColor
borderColorBottom
The color of the bottom border of this rectangle.protected BaseColor
borderColorLeft
The color of the left border of this rectangle.protected BaseColor
borderColorRight
The color of the right border of this rectangle.protected BaseColor
borderColorTop
The color of the top border of this rectangle.protected float
borderWidth
This is the width of the border around this rectangle.protected float
borderWidthBottom
The width of the bottom border of this rectangle.protected float
borderWidthLeft
The width of the left border of this rectangle.protected float
borderWidthRight
The width of the right border of this rectangle.protected float
borderWidthTop
The width of the top border of this rectangle.static int
BOTTOM
This represents one side of the border of theRectangle
.static int
BOX
This represents a type of border.static int
LEFT
This represents one side of the border of theRectangle
.protected float
llx
the lower left x-coordinate.protected float
lly
the lower left y-coordinate.static int
NO_BORDER
This represents a rectangle without borders.static int
RIGHT
This represents one side of the border of theRectangle
.protected int
rotation
The rotation of the Rectanglestatic int
TOP
This represents one side of the border of theRectangle
.static int
UNDEFINED
This is the value that will be used as undefined .protected float
urx
the upper right x-coordinate.protected float
ury
the upper right y-coordinate.protected boolean
useVariableBorders
Whether variable width/color borders are used.-
Fields inherited from interface com.itextpdf.text.Element
ALIGN_BASELINE, ALIGN_BOTTOM, ALIGN_CENTER, ALIGN_JUSTIFIED, ALIGN_JUSTIFIED_ALL, ALIGN_LEFT, ALIGN_MIDDLE, ALIGN_RIGHT, ALIGN_TOP, ALIGN_UNDEFINED, ANCHOR, ANNOTATION, AUTHOR, BODY, CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFBLOCK, CCITT_ENDOFLINE, CCITTG3_1D, CCITTG3_2D, CCITTG4, CHAPTER, CHUNK, CREATIONDATE, CREATOR, DIV, HEADER, IMGRAW, IMGTEMPLATE, JBIG2, JPEG, JPEG2000, KEYWORDS, LANGUAGE, LIST, LISTITEM, MARKED, PARAGRAPH, PHRASE, PRODUCER, PTABLE, RECTANGLE, SECTION, SUBJECT, TITLE, WRITABLE_DIRECT, YMARK
-
-
Constructor Summary
Constructors Constructor Description Rectangle(float urx, float ury)
Constructs aRectangle
-object starting from the origin (0, 0).Rectangle(float llx, float lly, float urx, float ury)
Constructs aRectangle
-object.Rectangle(float llx, float lly, float urx, float ury, int rotation)
Constructs aRectangle
-object.Rectangle(float urx, float ury, int rotation)
Constructs aRectangle
-object starting from the origin (0, 0) and with a specific rotation (valid values are 0, 90, 180, 270).Rectangle(Rectangle rect)
Constructs aRectangle
-object based on acom.itextpdf.awt.geom.Rectangle
objectRectangle(Rectangle rect)
Constructs aRectangle
-object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cloneNonPositionParameters(Rectangle rect)
Copies each of the parameters, except the position, from aRectangle
objectvoid
disableBorderSide(int side)
Disables the border on the specified side.void
enableBorderSide(int side)
Enables the border on the specified side.boolean
equals(java.lang.Object obj)
BaseColor
getBackgroundColor()
Gets the backgroundcolor.int
getBorder()
Returns the exact type of the border.BaseColor
getBorderColor()
Gets the color of the border.BaseColor
getBorderColorBottom()
Gets the color of the bottom border.BaseColor
getBorderColorLeft()
Gets the color of the left border.BaseColor
getBorderColorRight()
Gets the color of the right border.BaseColor
getBorderColorTop()
Gets the color of the top border.float
getBorderWidth()
Gets the borderwidth.float
getBorderWidthBottom()
Gets the width of the bottom border.float
getBorderWidthLeft()
Gets the width of the left border.float
getBorderWidthRight()
Gets the width of the right border.float
getBorderWidthTop()
Gets the width of the top border.float
getBottom()
Returns the lower left y-coordinate.float
getBottom(float margin)
Returns the lower left y-coordinate, considering a given margin.java.util.List<Chunk>
getChunks()
Gets all the chunks in this element.float
getGrayFill()
Gets the grayscale.float
getHeight()
Returns the height of the rectangle.float
getLeft()
Returns the lower left x-coordinate.float
getLeft(float margin)
Returns the lower left x-coordinate, considering a given margin.float
getRight()
Returns the upper right x-coordinate.float
getRight(float margin)
Returns the upper right x-coordinate, considering a given margin.int
getRotation()
Gets the rotation of the rectanglefloat
getTop()
Returns the upper right y-coordinate.float
getTop(float margin)
Returns the upper right y-coordinate, considering a given margin.private float
getVariableBorderWidth(float variableWidthValue, int side)
Helper function returning the border width of a specific side.float
getWidth()
Returns the width of the rectangle.boolean
hasBorder(int type)
Indicates whether the specified type of border is set.boolean
hasBorders()
Indicates whether some type of border is set.boolean
isContent()
Checks if this element is a content object.boolean
isNestable()
Checks if this element is nestable.boolean
isUseVariableBorders()
Indicates whether variable width borders are being used.void
normalize()
Normalizes the rectangle.boolean
process(ElementListener listener)
Processes the element by adding it (or the different parts) to anElementListener
.Rectangle
rectangle(float top, float bottom)
Gets a Rectangle that is altered to fit on the page.Rectangle
rotate()
Rotates the rectangle.void
setBackgroundColor(BaseColor backgroundColor)
Sets the backgroundcolor of the rectangle.void
setBorder(int border)
Enables/Disables the border on the specified sides.void
setBorderColor(BaseColor borderColor)
Sets the color of the border.void
setBorderColorBottom(BaseColor borderColorBottom)
Sets the color of the bottom border.void
setBorderColorLeft(BaseColor borderColorLeft)
Sets the color of the left border.void
setBorderColorRight(BaseColor borderColorRight)
Sets the color of the right border.void
setBorderColorTop(BaseColor borderColorTop)
Sets the color of the top border.void
setBorderWidth(float borderWidth)
Sets the borderwidth of the table.void
setBorderWidthBottom(float borderWidthBottom)
Sets the width of the bottom border.void
setBorderWidthLeft(float borderWidthLeft)
Sets the width of the left border.void
setBorderWidthRight(float borderWidthRight)
Sets the width of the right border.void
setBorderWidthTop(float borderWidthTop)
Sets the width of the top border.void
setBottom(float lly)
Sets the lower left y-coordinate.void
setGrayFill(float value)
Sets the the background color to a grayscale value.void
setLeft(float llx)
Sets the lower left x-coordinate.void
setRight(float urx)
Sets the upper right x-coordinate.void
setRotation(int rotation)
Sets the rotation of the rectangle.void
setTop(float ury)
Sets the upper right y-coordinate.void
setUseVariableBorders(boolean useVariableBorders)
Sets a parameter indicating if the rectangle has variable bordersvoid
softCloneNonPositionParameters(Rectangle rect)
Copies each of the parameters, except the position, from aRectangle
object if the value is set therejava.lang.String
toString()
Gets the content of the text element.int
type()
Gets the type of the text element.private void
updateBorderBasedOnWidth(float width, int side)
Helper function updating the border flag for a side based on the specified width.
-
-
-
Field Detail
-
UNDEFINED
public static final int UNDEFINED
This is the value that will be used as undefined .- See Also:
- Constant Field Values
-
TOP
public static final int TOP
This represents one side of the border of theRectangle
.- See Also:
- Constant Field Values
-
BOTTOM
public static final int BOTTOM
This represents one side of the border of theRectangle
.- See Also:
- Constant Field Values
-
LEFT
public static final int LEFT
This represents one side of the border of theRectangle
.- See Also:
- Constant Field Values
-
RIGHT
public static final int RIGHT
This represents one side of the border of theRectangle
.- See Also:
- Constant Field Values
-
NO_BORDER
public static final int NO_BORDER
This represents a rectangle without borders.- See Also:
- Constant Field Values
-
BOX
public static final int BOX
This represents a type of border.- See Also:
- Constant Field Values
-
llx
protected float llx
the lower left x-coordinate.
-
lly
protected float lly
the lower left y-coordinate.
-
urx
protected float urx
the upper right x-coordinate.
-
ury
protected float ury
the upper right y-coordinate.
-
rotation
protected int rotation
The rotation of the Rectangle
-
backgroundColor
protected BaseColor backgroundColor
This is the color of the background of this rectangle.
-
border
protected int border
This represents the status of the 4 sides of the rectangle.
-
useVariableBorders
protected boolean useVariableBorders
Whether variable width/color borders are used.
-
borderWidth
protected float borderWidth
This is the width of the border around this rectangle.
-
borderWidthLeft
protected float borderWidthLeft
The width of the left border of this rectangle.
-
borderWidthRight
protected float borderWidthRight
The width of the right border of this rectangle.
-
borderWidthTop
protected float borderWidthTop
The width of the top border of this rectangle.
-
borderWidthBottom
protected float borderWidthBottom
The width of the bottom border of this rectangle.
-
borderColor
protected BaseColor borderColor
The color of the border of this rectangle.
-
borderColorLeft
protected BaseColor borderColorLeft
The color of the left border of this rectangle.
-
borderColorRight
protected BaseColor borderColorRight
The color of the right border of this rectangle.
-
borderColorTop
protected BaseColor borderColorTop
The color of the top border of this rectangle.
-
borderColorBottom
protected BaseColor borderColorBottom
The color of the bottom border of this rectangle.
-
-
Constructor Detail
-
Rectangle
public Rectangle(float llx, float lly, float urx, float ury)
Constructs aRectangle
-object.- Parameters:
llx
- lower left xlly
- lower left yurx
- upper right xury
- upper right y
-
Rectangle
public Rectangle(float llx, float lly, float urx, float ury, int rotation)
Constructs aRectangle
-object.- Parameters:
llx
- lower left xlly
- lower left yurx
- upper right xury
- upper right yrotation
- the rotation (0, 90, 180, or 270)- Since:
- iText 5.0.6
-
Rectangle
public Rectangle(float urx, float ury)
Constructs aRectangle
-object starting from the origin (0, 0).- Parameters:
urx
- upper right xury
- upper right y
-
Rectangle
public Rectangle(float urx, float ury, int rotation)
Constructs aRectangle
-object starting from the origin (0, 0) and with a specific rotation (valid values are 0, 90, 180, 270).- Parameters:
urx
- upper right xury
- upper right yrotation
- the rotation of the rectangle- Since:
- iText 5.0.6
-
Rectangle
public Rectangle(Rectangle rect)
Constructs aRectangle
-object.- Parameters:
rect
- anotherRectangle
-
Rectangle
public Rectangle(Rectangle rect)
Constructs aRectangle
-object based on acom.itextpdf.awt.geom.Rectangle
object- Parameters:
rect
- com.itextpdf.awt.geom.Rectangle
-
-
Method Detail
-
process
public boolean process(ElementListener listener)
Processes the element by adding it (or the different parts) to anElementListener
.
-
type
public int type()
Gets the type of the text element.
-
getChunks
public java.util.List<Chunk> getChunks()
Gets all the chunks in this element.
-
isContent
public boolean isContent()
Description copied from interface:Element
Checks if this element is a content object. If not, it's a metadata object.- Specified by:
isContent
in interfaceElement
- Returns:
- true if this is a 'content' element; false if this is a 'metadata' element
- Since:
- iText 2.0.8
- See Also:
Element.isContent()
-
isNestable
public boolean isNestable()
Description copied from interface:Element
Checks if this element is nestable.- Specified by:
isNestable
in interfaceElement
- Returns:
- true if this element can be nested inside other elements.
- Since:
- iText 2.0.8
- See Also:
Element.isNestable()
-
setLeft
public void setLeft(float llx)
Sets the lower left x-coordinate.- Parameters:
llx
- the new value
-
getLeft
public float getLeft()
Returns the lower left x-coordinate.- Returns:
- the lower left x-coordinate
-
getLeft
public float getLeft(float margin)
Returns the lower left x-coordinate, considering a given margin.- Parameters:
margin
- a margin- Returns:
- the lower left x-coordinate
-
setRight
public void setRight(float urx)
Sets the upper right x-coordinate.- Parameters:
urx
- the new value
-
getRight
public float getRight()
Returns the upper right x-coordinate.- Returns:
- the upper right x-coordinate
-
getRight
public float getRight(float margin)
Returns the upper right x-coordinate, considering a given margin.- Parameters:
margin
- a margin- Returns:
- the upper right x-coordinate
-
getWidth
public float getWidth()
Returns the width of the rectangle.- Returns:
- the width
-
setTop
public void setTop(float ury)
Sets the upper right y-coordinate.- Parameters:
ury
- the new value
-
getTop
public float getTop()
Returns the upper right y-coordinate.- Returns:
- the upper right y-coordinate
-
getTop
public float getTop(float margin)
Returns the upper right y-coordinate, considering a given margin.- Parameters:
margin
- a margin- Returns:
- the upper right y-coordinate
-
setBottom
public void setBottom(float lly)
Sets the lower left y-coordinate.- Parameters:
lly
- the new value
-
getBottom
public float getBottom()
Returns the lower left y-coordinate.- Returns:
- the lower left y-coordinate
-
getBottom
public float getBottom(float margin)
Returns the lower left y-coordinate, considering a given margin.- Parameters:
margin
- a margin- Returns:
- the lower left y-coordinate
-
getHeight
public float getHeight()
Returns the height of the rectangle.- Returns:
- the height
-
normalize
public void normalize()
Normalizes the rectangle. Switches lower left with upper right if necessary.
-
getRotation
public int getRotation()
Gets the rotation of the rectangle- Returns:
- a rotation value
-
setRotation
public void setRotation(int rotation)
Sets the rotation of the rectangle. Valid values are 0, 90, 180, and 270.- Parameters:
rotation
- the new rotation value- Since:
- iText 5.0.6
-
rotate
public Rectangle rotate()
Rotates the rectangle. Swaps the values of llx and lly and of urx and ury.- Returns:
- the rotated
Rectangle
-
getBackgroundColor
public BaseColor getBackgroundColor()
Gets the backgroundcolor.- Returns:
- a
BaseColor
-
setBackgroundColor
public void setBackgroundColor(BaseColor backgroundColor)
Sets the backgroundcolor of the rectangle.- Parameters:
backgroundColor
- aBaseColor
-
getGrayFill
public float getGrayFill()
Gets the grayscale.- Returns:
- the grayscale color of the background or 0 if the background has no grayscale color.
-
setGrayFill
public void setGrayFill(float value)
Sets the the background color to a grayscale value.- Parameters:
value
- the new grayscale value
-
getBorder
public int getBorder()
Returns the exact type of the border.- Returns:
- a value
-
hasBorders
public boolean hasBorders()
Indicates whether some type of border is set.- Returns:
- a boolean
-
hasBorder
public boolean hasBorder(int type)
Indicates whether the specified type of border is set.- Parameters:
type
- the type of border- Returns:
- a boolean
-
setBorder
public void setBorder(int border)
Enables/Disables the border on the specified sides. The border is specified as an integer bitwise combination of the constants:LEFT, RIGHT, TOP, BOTTOM
.- Parameters:
border
- the new value- See Also:
enableBorderSide(int)
,disableBorderSide(int)
-
isUseVariableBorders
public boolean isUseVariableBorders()
Indicates whether variable width borders are being used. Returns true ifsetBorderWidthLeft, setBorderWidthRight, setBorderWidthTop, or setBorderWidthBottom
has been called.- Returns:
- true if variable width borders are in use
-
setUseVariableBorders
public void setUseVariableBorders(boolean useVariableBorders)
Sets a parameter indicating if the rectangle has variable borders- Parameters:
useVariableBorders
- indication if the rectangle has variable borders
-
enableBorderSide
public void enableBorderSide(int side)
Enables the border on the specified side.- Parameters:
side
- the side to enable. One ofLEFT, RIGHT, TOP, BOTTOM
-
disableBorderSide
public void disableBorderSide(int side)
Disables the border on the specified side.- Parameters:
side
- the side to disable. One ofLEFT, RIGHT, TOP, BOTTOM
-
getBorderWidth
public float getBorderWidth()
Gets the borderwidth.- Returns:
- a value
-
setBorderWidth
public void setBorderWidth(float borderWidth)
Sets the borderwidth of the table.- Parameters:
borderWidth
- the new value
-
getVariableBorderWidth
private float getVariableBorderWidth(float variableWidthValue, int side)
Helper function returning the border width of a specific side.- Parameters:
variableWidthValue
- a variable width (could be undefined)side
- the border you want to check- Returns:
- the variableWidthValue if not undefined, otherwise the borderWidth
-
updateBorderBasedOnWidth
private void updateBorderBasedOnWidth(float width, int side)
Helper function updating the border flag for a side based on the specified width. A width of 0 will disable the border on that side. Any other width enables it.- Parameters:
width
- width of borderside
- border side constant
-
getBorderWidthLeft
public float getBorderWidthLeft()
Gets the width of the left border.- Returns:
- a width
-
setBorderWidthLeft
public void setBorderWidthLeft(float borderWidthLeft)
Sets the width of the left border.- Parameters:
borderWidthLeft
- a width
-
getBorderWidthRight
public float getBorderWidthRight()
Gets the width of the right border.- Returns:
- a width
-
setBorderWidthRight
public void setBorderWidthRight(float borderWidthRight)
Sets the width of the right border.- Parameters:
borderWidthRight
- a width
-
getBorderWidthTop
public float getBorderWidthTop()
Gets the width of the top border.- Returns:
- a width
-
setBorderWidthTop
public void setBorderWidthTop(float borderWidthTop)
Sets the width of the top border.- Parameters:
borderWidthTop
- a width
-
getBorderWidthBottom
public float getBorderWidthBottom()
Gets the width of the bottom border.- Returns:
- a width
-
setBorderWidthBottom
public void setBorderWidthBottom(float borderWidthBottom)
Sets the width of the bottom border.- Parameters:
borderWidthBottom
- a width
-
getBorderColor
public BaseColor getBorderColor()
Gets the color of the border.- Returns:
- a
BaseColor
-
setBorderColor
public void setBorderColor(BaseColor borderColor)
Sets the color of the border.- Parameters:
borderColor
- aBaseColor
-
getBorderColorLeft
public BaseColor getBorderColorLeft()
Gets the color of the left border.- Returns:
- a
BaseColor
-
setBorderColorLeft
public void setBorderColorLeft(BaseColor borderColorLeft)
Sets the color of the left border.- Parameters:
borderColorLeft
- aBaseColor
-
getBorderColorRight
public BaseColor getBorderColorRight()
Gets the color of the right border.- Returns:
- a
BaseColor
-
setBorderColorRight
public void setBorderColorRight(BaseColor borderColorRight)
Sets the color of the right border.- Parameters:
borderColorRight
- aBaseColor
-
getBorderColorTop
public BaseColor getBorderColorTop()
Gets the color of the top border.- Returns:
- a
BaseColor
-
setBorderColorTop
public void setBorderColorTop(BaseColor borderColorTop)
Sets the color of the top border.- Parameters:
borderColorTop
- aBaseColor
-
getBorderColorBottom
public BaseColor getBorderColorBottom()
Gets the color of the bottom border.- Returns:
- a
BaseColor
-
setBorderColorBottom
public void setBorderColorBottom(BaseColor borderColorBottom)
Sets the color of the bottom border.- Parameters:
borderColorBottom
- aBaseColor
-
rectangle
public Rectangle rectangle(float top, float bottom)
Gets a Rectangle that is altered to fit on the page.- Parameters:
top
- the top positionbottom
- the bottom position- Returns:
- a
Rectangle
-
cloneNonPositionParameters
public void cloneNonPositionParameters(Rectangle rect)
Copies each of the parameters, except the position, from aRectangle
object- Parameters:
rect
-Rectangle
to copy from
-
softCloneNonPositionParameters
public void softCloneNonPositionParameters(Rectangle rect)
Copies each of the parameters, except the position, from aRectangle
object if the value is set there- Parameters:
rect
-Rectangle
to copy from
-
toString
public java.lang.String toString()
Description copied from interface:Element
Gets the content of the text element.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
-