Package com.openhtmltopdf.render
Class Box
java.lang.Object
com.openhtmltopdf.render.Box
- All Implemented Interfaces:
Styleable
,DisplayListItem
- Direct Known Subclasses:
BlockBox
,InlineLayoutBox
,LineBox
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Area
private int
private int
private Object
private boolean
private boolean
private Box
private Layer
private int
Box width.private Element
private int
Box height.private int
private Layer
private int
private PaintingInfo
private Box
private String
private Dimension
private int
private int
private CalculatedStyle
private int
Keeps track of the start of childrens containing block.private int
private RectPropertySet
private int
private int
static final int
static final int
static final int
static final int
static final int
protected static final String
static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAllChildren
(List<Box> children) void
void
addChildForLayout
(LayoutContext c, Box child) void
analyzePageBreaks
(LayoutContext c, ContentLimitContainer container) Get all ancestors, up until the root box.ancestorsWhile
(Predicate<Box> predicate) Creates a list of ancestors by walking up the chain of parent, grandparent, etc.private Area
abstract void
void
protected void
calcChildPaintingInfo
(CssContext c, PaintingInfo result, boolean useCache) private Rectangle
calcClipBox
(RenderingContext c, Layer layer) calcPaintingInfo
(CssContext c, boolean useCache) void
collectText
(RenderingContext c, StringBuilder buffer) void
boolean
Whether this box would cross a page break.void
abstract String
dump
(LayoutContext c, String indent, int which) protected void
dumpBoxes
(LayoutContext c, String indent, List<Box> boxes, int which, StringBuilder result) private void
ensureWorkingMargin
(CssContext cssContext) private void
exportPageBoxText
(RenderingContext c, Writer writer) protected void
exportPageBoxText
(RenderingContext c, Writer writer, int yPos) void
exportText
(RenderingContext c, Writer writer) find
(CssContext cssCtx, int absX, int absY, boolean findAnonymous) findAncestor
(Predicate<Box> predicate) Walks up the ancestor tree to the root testing ancestors agains the predicate.void
Recursive method to find column break opportunities.void
forcePageBreakAfter
(LayoutContext c, IdentValue pageBreakValue) Forces a page break after this box.int
forcePageBreakBefore
(LayoutContext c, IdentValue pageBreakValue, boolean pendingPageName) int
forcePageBreakBefore
(LayoutContext c, IdentValue pageBreakValue, boolean pendingPageName, int absY) Returns the absolute (ie transformed if needed) clip area for this box.int
getAbsX()
int
getAbsY()
getBorder
(CssContext cssCtx) Only to be called after layout, due to double use of getHeight().int
int
getBorderEdge
(int left, int top, CssContext cssCtx) int
getChild
(int i) int
<T> Iterator
<T> getChildIteratorOfType
(Class<T> type) Returns an iterator of boxes cast to type.getClipBox
(RenderingContext c, Layer layer) Gets the combined clip of this box relative to the containing layer.private Box
protected int
getContentAreaEdge
(int left, int top, CssContext cssCtx) int
int
getElementBoxes
(Element elem) int
Uh oh! This refers to content height during layout but total height after layout!protected int
getIndex()
The zero based index of this child amongst its fellow children of its parent.getLayer()
int
getMargin
(CssContext cssContext) int
getMarginBorderPadding
(CssContext cssCtx, int which) getMarginEdge
(int left, int top, CssContext cssCtx, int tx, int ty) getMarginEdge
(CssContext cssCtx, int tx, int ty) protected Box
getPadding
(CssContext cssCtx) getPaddingEdge
(int left, int top, CssContext cssCtx) protected int
getPaddingWidth
(CssContext cssCtx) getPaintingBorderEdge
(CssContext cssCtx) getPaintingClipEdge
(CssContext cssCtx) getPaintingPaddingEdge
(CssContext cssCtx) getParentClipBox
(RenderingContext c, Layer layer) Gets the layer relative clip for the parent box.protected Box
getPrevious
(Box child) int
int
getState()
final CalculatedStyle
getStyle()
protected RectPropertySet
getStyleMargin
(CssContext cssContext) protected RectPropertySet
getStyleMargin
(CssContext cssContext, boolean useCache) int
getTx()
int
getTy()
int
getWidth()
int
getX()
int
getY()
boolean
boolean
If the html or body box have a background return true.void
boolean
intersects
(CssContext cssCtx, Shape clip) NOTE: This method does not consider any children of this box but does consider the transformation matrix of the containing layer.boolean
boolean
isBody()
boolean
boolean
Is this box the first child of its parent?boolean
protected boolean
protected boolean
protected boolean
private boolean
boolean
isRoot()
boolean
isStyled()
boolean
Is this box unbreakable in regards to column break opportunities?protected void
moveIfGreater
(Dimension result, Dimension test) void
void
void
private void
positionRelative
(CssContext cssCtx) void
boolean
removeChild
(int index) Removes child by index and adjusts the index of subsequent children.boolean
removeChild
(Box target) Removes a child box if it is indeed a child and adjusts the index of subsequent children.void
Responsible for resetting the state of the box before a repeat call toBlockBox.layout(LayoutContext)
or other layout methods.protected void
void
resetChildren
(LayoutContext c, int start, int end) protected void
resetTopMargin
(CssContext cssContext) rootBox()
Returns the highest ancestor box.void
setAbsX
(int absX) void
setAbsY
(int absY) void
setAccessiblityObject
(Object object) void
setAnonymous
(boolean anonymous) protected void
setBorderBoxHeight
(CssContext c, int h) void
setBorderBoxWidth
(CssContext c, int borderBoxWidth) void
setBoxDimensions
(BoxDimensions dimensions) void
setContainingBlock
(Box containingBlock) void
setContainingLayer
(Layer containingLayer) void
setContentWidth
(int contentWidth) void
setElement
(Element element) void
setHeight
(int height) Uh oh! This refers to content height during layout but total height after layout!protected void
setIndex
(int index) SeegetIndex()
Must make sure this is correct when removing children/rearranging children.void
void
setLeftMBP
(int leftMBP) void
setMarginBottom
(CssContext cssContext, int marginBottom) void
setMarginLeft
(CssContext cssContext, int marginLeft) void
setMarginRight
(CssContext cssContext, int marginRight) void
setMarginTop
(CssContext cssContext, int marginTop) private void
setPaintingInfo
(PaintingInfo paintingInfo) void
void
setPseudoElementOrClass
(String pseudoElementOrClass) void
setRelativeOffset
(Dimension relativeOffset) void
setRightMBP
(int rightMBP) void
setState
(int state) void
setStyle
(CalculatedStyle style) void
setTx
(int tx) void
setTy
(int ty) void
setX
(int x) void
setY
(int y) static String
stateToString
(int state) toString()
-
Field Details
-
LINE_SEPARATOR
-
_element
-
_x
private int _x -
_y
private int _y -
_absY
private int _absY -
_absX
private int _absX -
_contentWidth
private int _contentWidthBox width. -
_rightMBP
private int _rightMBP -
_leftMBP
private int _leftMBP -
_height
private int _heightBox height. -
_layer
-
_containingLayer
-
_parent
-
_boxes
-
_tx
private int _txKeeps track of the start of childrens containing block. -
_ty
private int _ty -
_style
-
_containingBlock
-
_relativeOffset
-
_paintingInfo
-
_workingMargin
-
_index
private int _index -
_pseudoElementOrClass
-
_anonymous
private boolean _anonymous -
_absoluteClipBox
-
_clipBoxCalculated
private boolean _clipBoxCalculated -
_accessibilityObject
-
NOTHING
public static final int NOTHING- See Also:
-
FLUX
public static final int FLUX- See Also:
-
CHILDREN_FLUX
public static final int CHILDREN_FLUX- See Also:
-
DONE
public static final int DONE- See Also:
-
_state
private int _state -
DUMP_RENDER
public static final int DUMP_RENDER- See Also:
-
DUMP_LAYOUT
public static final int DUMP_LAYOUT- See Also:
-
-
Constructor Details
-
Box
protected Box()
-
-
Method Details
-
getClipBox
Gets the combined clip of this box relative to the containing layer. The returned clip is in document coordinate space (not transformed in any way). For example, if we have the following nesting: overflow hidden := transformed box := overflow hidden := overflow hidden := overflow visible this function called on the overflow visible box will return the combined clip of its two immediate ancestors in document coordinate space. It stops at the transformed box because the transform triggers a layer. Currently this method is used for getting the clip to apply to a float, which are nested in layers but taken out of the default block list and therefore clip stack. Since it is only used for floats, the result is not cached. Revisit this decision if using for every box. There are several other clip methods available: +getChildrenClipEdge(CssContext)
- gets the local clip for a single box. +getParentClipBox(RenderingContext, Layer)
- gets the layer relative clip for the parent box. +getAbsoluteClipBox(CssContext)
- gets the absolute clip box in document coordinates -
getClipParent
-
getParentClipBox
Gets the layer relative clip for the parent box. SeegetClipBox(RenderingContext, Layer)
-
calcClipBox
-
getAbsoluteClipBox
Returns the absolute (ie transformed if needed) clip area for this box. Cached as this will be needed on every box to check if the clip area is inside a page. -
calcAbsoluteClipBox
-
dump
-
dumpBoxes
protected void dumpBoxes(LayoutContext c, String indent, List<Box> boxes, int which, StringBuilder result) -
getWidth
public int getWidth() -
toString
-
addChildForLayout
-
addChild
-
addAllChildren
-
removeAllChildren
public void removeAllChildren() -
removeChild
Removes a child box if it is indeed a child and adjusts the index of subsequent children. Returns whether this was a child. -
getPreviousSibling
-
getNextSibling
-
getPrevious
-
getNext
-
removeChild
public boolean removeChild(int index) Removes child by index and adjusts the index of subsequent children. Returns true if this box has children, throws if the index is out-of-bounds.
IMPORTANT: This method must be kept in sync withremoveChild(Box)
-
setParent
-
getParent
-
getDocumentParent
-
getChildCount
public int getChildCount() -
getChild
-
getChildIterator
-
getChildren
-
getChildIteratorOfType
Returns an iterator of boxes cast to type. If a box is not of type, an error will be logged and null will be returned for that box. Therefore, this method should only be used when it is certain all children are of a particular type. Eg: TableBox has children only of type TableSectionBox. -
getState
public int getState() -
setState
public void setState(int state) -
stateToString
-
getStyle
-
setStyle
-
getContainingBlock
-
setContainingBlock
-
getMarginEdge
-
getMarginEdge
-
getPaintingBorderEdge
-
getPaintingPaddingEdge
-
getPaintingClipEdge
-
getChildrenClipEdge
-
intersects
NOTE: This method does not consider any children of this box but does consider the transformation matrix of the containing layer. -
getBorderEdge
-
getPaddingEdge
-
getPaddingWidth
-
getContentAreaEdge
-
getLayer
-
setLayer
-
positionRelative
-
isInlineBlock
protected boolean isInlineBlock() -
setAbsY
public void setAbsY(int absY) -
getAbsY
public int getAbsY() -
setAbsX
public void setAbsX(int absX) -
getAbsX
public int getAbsX() -
isStyled
public boolean isStyled() -
getBorderSides
public int getBorderSides() -
paintBorder
-
isPaintsRootElementBackground
private boolean isPaintsRootElementBackground() -
paintBackground
-
hasNonTextContent
-
setAccessiblityObject
-
getAccessibilityObject
-
paintRootElementBackground
-
paintRootElementBackground
-
hasRootElementBackground
If the html or body box have a background return true. -
getContainingLayer
-
setContainingLayer
-
initContainingLayer
-
connectChildrenToCurrentLayer
-
getElementBoxes
-
reset
Responsible for resetting the state of the box before a repeat call toBlockBox.layout(LayoutContext)
or other layout methods.
Any layout operation that is not idempotent MUST be reset in this method. Layout may be called several times on the one box. -
detach
-
resetChildren
-
resetChildren
-
calcCanvasLocation
public abstract void calcCanvasLocation() -
calcChildLocations
public void calcChildLocations() -
forcePageBreakBefore
public int forcePageBreakBefore(LayoutContext c, IdentValue pageBreakValue, boolean pendingPageName) -
forcePageBreakBefore
public int forcePageBreakBefore(LayoutContext c, IdentValue pageBreakValue, boolean pendingPageName, int absY) -
forcePageBreakAfter
Forces a page break after this box. -
crossesPageBreak
Whether this box would cross a page break.
SeeLayer.crossesPageBreak(LayoutContext, int, int)
for extra info. -
getRelativeOffset
-
setRelativeOffset
-
find
-
isRoot
public boolean isRoot() -
isBody
public boolean isBody() -
getElement
- Specified by:
getElement
in interfaceStyleable
-
setElement
- Specified by:
setElement
in interfaceStyleable
-
setMarginTop
-
setMarginBottom
-
setMarginLeft
-
setMarginRight
-
ensureWorkingMargin
-
getMargin
-
getStyleMargin
-
getStyleMargin
-
getPadding
-
getBorder
-
getContainingBlockWidth
protected int getContainingBlockWidth() -
resetTopMargin
-
calcPaintingInfo
-
calcChildPaintingInfo
-
getMarginBorderPadding
-
moveIfGreater
-
getIndex
protected int getIndex()The zero based index of this child amongst its fellow children of its parent. -
setIndex
protected void setIndex(int index) SeegetIndex()
Must make sure this is correct when removing children/rearranging children. -
getPseudoElementOrClass
- Specified by:
getPseudoElementOrClass
in interfaceStyleable
-
setPseudoElementOrClass
-
setX
public void setX(int x) -
getX
public int getX() -
setY
public void setY(int y) -
getY
public int getY() -
setTy
public void setTy(int ty) -
getTy
public int getTy() -
setTx
public void setTx(int tx) -
getTx
public int getTx() -
setRightMBP
public void setRightMBP(int rightMBP) -
getRightMBP
public int getRightMBP() -
setLeftMBP
public void setLeftMBP(int leftMBP) -
getLeftMBP
public int getLeftMBP() -
setHeight
public void setHeight(int height) Uh oh! This refers to content height during layout but total height after layout! -
getHeight
public int getHeight()Uh oh! This refers to content height during layout but total height after layout! -
setBorderBoxHeight
-
getBorderBoxHeight
-
getBorderBox
Only to be called after layout, due to double use of getHeight(). -
setContentWidth
public void setContentWidth(int contentWidth) -
getContentWidth
public int getContentWidth() -
getBorderBoxWidth
-
setBorderBoxWidth
-
getPaintingInfo
-
setPaintingInfo
-
isAnonymous
public boolean isAnonymous() -
setAnonymous
public void setAnonymous(boolean anonymous) -
getBoxDimensions
-
setBoxDimensions
-
collectText
-
exportText
- Throws:
IOException
-
exportPageBoxText
- Throws:
IOException
-
exportPageBoxText
- Throws:
IOException
-
isInDocumentFlow
public boolean isInDocumentFlow() -
analyzePageBreaks
-
getEffBackgroundColor
-
isMarginAreaRoot
protected boolean isMarginAreaRoot() -
isContainedInMarginBox
public boolean isContainedInMarginBox() -
getEffectiveWidth
public int getEffectiveWidth() -
isInitialContainingBlock
protected boolean isInitialContainingBlock() -
isFirstChild
public boolean isFirstChild()Is this box the first child of its parent? -
isTerminalColumnBreak
public boolean isTerminalColumnBreak()Is this box unbreakable in regards to column break opportunities? -
ancestorsWhile
Creates a list of ancestors by walking up the chain of parent, grandparent, etc. Stops when the provided predicate returns false or the root box otherwise. -
ancestors
Get all ancestors, up until the root box. -
findAncestor
Walks up the ancestor tree to the root testing ancestors agains the predicate. NOTE: Does not test against the current box (this).- Returns:
- the box for which predicate returned true or null if none found.
-
rootBox
Returns the highest ancestor box. May be current box (this). -
findColumnBreakOpportunities
Recursive method to find column break opportunities.- Parameters:
store
- - use to report break opportunities.
-