Package com.openhtmltopdf.layout
Class Layer
- java.lang.Object
-
- com.openhtmltopdf.layout.Layer
-
public class Layer extends java.lang.ObjectAll positioned content as well as content with an overflow value other than visible creates a layer. Layers which define stacking contexts provide the entry for rendering the box tree to an output device. The main purpose of this class is to provide an implementation of Appendix E of the spec, but it also provides additional utility services including page management and mapping boxes to coordinates (for e.g. links). When rendering to a paged output device, the layer is also responsible for laying out absolute content (which is layed out after its containing block has completed layout).
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<Layer>_childrenprivate java.awt.geom.AffineTransform_ctmprivate Box_endprivate java.util.List<BlockBox>_floatsprivate boolean_forDeletionprivate boolean_hasFixedAncesterprivate boolean_hasLocalTransformprivate boolean_inlineprivate boolean_isolatedprivate PageBox_lastRequestedPageprivate Box_masterprivate java.util.List<PageBox>_pagesprivate java.util.Set<BlockBox>_pageSequencesprivate Layer_parentprivate boolean_requiresLayoutprivate java.util.Map<java.lang.String,java.util.List<BlockBox>>_runningBlocksprivate Box_selectionEndprivate int_selectionEndXprivate int_selectionEndYprivate Box_selectionStartprivate int_selectionStartXprivate int_selectionStartYprivate java.util.List<BlockBox>_sortedPageSequencesprivate boolean_stackingContextstatic intAUTOstatic intNEGATIVEstatic shortPAGED_MODE_PRINTstatic shortPAGED_MODE_SCREENstatic intPOSITIVEstatic intZERO
-
Constructor Summary
Constructors Constructor Description Layer(Layer parent, Box master, CssContext c)Creates a child layer.Layer(Box master, CssContext c)Creates the root layer.Layer(Box master, CssContext c, boolean isolated)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddChild(Layer layer)voidaddFloat(BlockBox floater, BlockFormattingContext bfc)voidaddPage(CssContext c)voidaddPageSequence(BlockBox start)private voidaddPagesUntilPosition(CssContext c, int position)voidaddRunningBlock(BlockBox block)protected java.util.List<java.awt.geom.AffineTransform>applyTranform(RenderingContext c, Box box)Deprecated.private voidapplyTransformFunctions(float flipFactor, java.util.List<PropertyValue> transformList, java.util.List<java.awt.geom.AffineTransform> resultTransforms)Deprecated.voidassignPagePaintingPositions(CssContext cssCtx, int mode, int additionalClearance)voidassignPagePaintingPositions(CssContext cssCtx, short mode)private PaintingInfocalcPaintingDimension(LayoutContext c)private java.util.Map<TableCellBox,java.util.List<CollapsedBorderSide>>collectCollapsedTableBorders(RenderingContext c, java.util.List<Box> blocks)Deprecated.java.util.List<Layer>collectLayers(int which)Called recusively to collect all descendant layers in a layer tree so they can be painted in correct order.private floatconvertAngleToRadians(PropertyValue param)Deprecated.static PageBoxcreatePageBox(CssContext c, java.lang.String pseudoPage)booleancrossesPageBreak(LayoutContext c, int top, int bottom)Returns whether the a box with the given top and bottom would cross a page break.voiddetach()voidensureHasPage(CssContext c, Box box)Boxfind(CssContext cssCtx, int absX, int absY, boolean findAnonymous)Deprecated.private Boxfind(CssContext cssCtx, int absX, int absY, java.util.List<Layer> layers, boolean findAnonymous)Deprecated.private BlockBoxfindPageSequence(java.util.List<BlockBox> sequences, int absY)LayerfindRoot()voidfinish(LayoutContext c)java.util.List<Layer>getChildren()The resulting list should not be modified.java.awt.geom.AffineTransformgetCurrentTransformMatrix()The document coordinates current transform, this is cumulative from layer to child layer.BoxgetEnd()PageBoxgetFirstPage(CssContext c, int absY)Returns the page box for a Y position.PageBoxgetFirstPage(CssContext c, Box box)java.util.List<BlockBox>getFloats()PageBoxgetLastPage()PageBoxgetLastPage(CssContext c, Box box)private PageBoxgetLastRequestedPage()BoxgetMaster()intgetMaxPageWidth(CssContext cssCtx, int additionalClearance)PageBoxgetPage(CssContext c, int yOffset)Gets the page box for the given document y offset.java.util.List<PageBox>getPages()java.util.List<PageBox>getPages(CssContext c, int top, int bottom)Tries to return a list of pages that cover top to bottom.private intgetPageSequenceStart(RenderingContext c, java.util.List<BlockBox> sequences, PageBox page)java.awt.DimensiongetPaintingDimension(LayoutContext c)LayergetParent()intgetRelativePageCount(RenderingContext c)intgetRelativePageNo(RenderingContext c)intgetRelativePageNo(RenderingContext c, int absY)BlockBoxgetRunningBlock(java.lang.String identifer, PageBox page, PageElementPosition which)BoxgetSelectionEnd()intgetSelectionEndX()intgetSelectionEndY()BoxgetSelectionStart()intgetSelectionStartX()intgetSelectionStartY()java.util.List<Layer>getSortedLayers(int which)private java.util.List<BlockBox>getSortedPageSequences()private java.util.List<Layer>getStackingContextLayers(int which)intgetZIndex()booleanhasFixedAncester()booleanhasLocalTransform()booleanisForDeletion()booleanisInline()booleanisIsolated()booleanisLastPage(PageBox pageBox)booleanisRequiresLayout()booleanisRootLayer()booleanisStackingContext()booleanisZIndexAuto()private voidlayoutAbsoluteChild(LayoutContext c, Layer child)private voidlayoutAbsoluteChildren(LayoutContext c)voidlayoutPages(LayoutContext c)private voidmoveIfGreater(java.awt.Dimension result, java.awt.Dimension test)private SearchUtil.IntComparatorpageFinder(java.util.List<PageBox> pages, int yOffset, java.util.function.Predicate<PageBox> matcher)Returns a comparator that determines if the given pageBox is a match, too late or too early.private java.util.function.Predicate<PageBox>pagePredicate(int yOffset)Returns a predicate that determines if yOffset sits on the given page.voidpaint(RenderingContext c)Deprecated.voidpaintAsLayer(RenderingContext c, BlockBox startingPoint)Deprecated.private voidpaintBackgroundsAndBorders(RenderingContext c, java.util.List<Box> blocks, java.util.Map<TableCellBox,java.util.List<CollapsedBorderSide>> collapsedTableBorders, BoxRangeLists rangeLists)Deprecated.private voidpaintCollapsedTableBorders(RenderingContext c, java.util.List<CollapsedBorderSide> borders)Deprecated.private voidpaintFloats(RenderingContext c)Deprecated.private voidpaintInlineContent(RenderingContext c, java.util.List<Box> lines, BoxRangeLists rangeLists)Deprecated.private voidpaintLayerBackgroundAndBorder(RenderingContext c)Deprecated.private voidpaintLayers(RenderingContext c, java.util.List<Layer> layers)Deprecated.private voidpaintListMarkers(RenderingContext c, java.util.List<Box> blocks, BoxRangeLists rangeLists)Deprecated.private voidpaintReplacedElement(RenderingContext c, BlockBox replaced)Deprecated.private voidpaintReplacedElements(RenderingContext c, java.util.List<Box> blocks, BoxRangeLists rangeLists)Deprecated.private voidpaintSelection(RenderingContext c, java.util.List<Box> lines)Deprecated.private voidposition(LayoutContext c)voidpositionChildren(LayoutContext c)voidpositionFixedLayer(RenderingContext c)voidpropagateCurrentTransformationMatrix(CssContext c)Recursively propagates the transformation matrix.private voidremove(Layer layer)voidremoveFloat(BlockBox floater)FIXME: Only used when we reset a box, so trying to remove at sometime in the future.voidremoveLastPage()voidremoveRunningBlock(BlockBox block)voidsetEnd(Box end)voidsetForDeletion(boolean forDeletion)voidsetInline(boolean inline)private voidsetIsolated(boolean b)private voidsetLastRequestedPage(PageBox lastRequestedPage)voidsetPages(java.util.List<PageBox> pages)voidsetRequiresLayout(boolean requiresLayout)voidsetSelectionEnd(Box selectionEnd)voidsetSelectionEndX(int selectionEndX)voidsetSelectionEndY(int selectionEndY)voidsetSelectionStart(Box selectionStart)voidsetSelectionStartX(int selectionStartX)voidsetSelectionStartY(int selectionStartY)voidsetStackingContext(boolean stackingContext)voidtrimEmptyPages(CssContext c, int maxYHeight)voidtrimPageCount(int newPageCount)
-
-
-
Field Detail
-
PAGED_MODE_SCREEN
public static final short PAGED_MODE_SCREEN
- See Also:
- Constant Field Values
-
PAGED_MODE_PRINT
public static final short PAGED_MODE_PRINT
- See Also:
- Constant Field Values
-
_parent
private Layer _parent
-
_stackingContext
private boolean _stackingContext
-
_children
private java.util.List<Layer> _children
-
_master
private Box _master
-
_end
private Box _end
-
_floats
private java.util.List<BlockBox> _floats
-
_inline
private boolean _inline
-
_requiresLayout
private boolean _requiresLayout
-
_pages
private java.util.List<PageBox> _pages
-
_lastRequestedPage
private PageBox _lastRequestedPage
-
_pageSequences
private java.util.Set<BlockBox> _pageSequences
-
_sortedPageSequences
private java.util.List<BlockBox> _sortedPageSequences
-
_runningBlocks
private java.util.Map<java.lang.String,java.util.List<BlockBox>> _runningBlocks
-
_selectionStart
private Box _selectionStart
-
_selectionEnd
private Box _selectionEnd
-
_selectionStartX
private int _selectionStartX
-
_selectionStartY
private int _selectionStartY
-
_selectionEndX
private int _selectionEndX
-
_selectionEndY
private int _selectionEndY
-
_forDeletion
private boolean _forDeletion
-
_hasFixedAncester
private boolean _hasFixedAncester
-
_ctm
private java.awt.geom.AffineTransform _ctm
-
_hasLocalTransform
private final boolean _hasLocalTransform
-
_isolated
private boolean _isolated
-
POSITIVE
public static final int POSITIVE
- See Also:
- Constant Field Values
-
ZERO
public static final int ZERO
- See Also:
- Constant Field Values
-
NEGATIVE
public static final int NEGATIVE
- See Also:
- Constant Field Values
-
AUTO
public static final int AUTO
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Layer
public Layer(Box master, CssContext c)
Creates the root layer.
-
Layer
public Layer(Box master, CssContext c, boolean isolated)
-
Layer
public Layer(Layer parent, Box master, CssContext c)
Creates a child layer.
-
-
Method Detail
-
setIsolated
private void setIsolated(boolean b)
-
propagateCurrentTransformationMatrix
public void propagateCurrentTransformationMatrix(CssContext c)
Recursively propagates the transformation matrix. This must be done after layout of the master box and its children as this method relies on the box width and height for relative units in the transforms and transform origins.
-
getCurrentTransformMatrix
public java.awt.geom.AffineTransform getCurrentTransformMatrix()
The document coordinates current transform, this is cumulative from layer to child layer. May be null, if identity transform is in effect. Used to check if a box belonging to this layer sits on a particular page after the transform is applied. This method can only be used afterpropagateCurrentTransformationMatrix(CssContext)has been called on the root layer.- Returns:
- null or affine transform.
-
hasLocalTransform
public boolean hasLocalTransform()
-
setForDeletion
public void setForDeletion(boolean forDeletion)
-
isForDeletion
public boolean isForDeletion()
-
hasFixedAncester
public boolean hasFixedAncester()
-
getParent
public Layer getParent()
-
isStackingContext
public boolean isStackingContext()
-
setStackingContext
public void setStackingContext(boolean stackingContext)
-
getZIndex
public int getZIndex()
-
isZIndexAuto
public boolean isZIndexAuto()
-
getMaster
public Box getMaster()
-
addChild
public void addChild(Layer layer)
-
createPageBox
public static PageBox createPageBox(CssContext c, java.lang.String pseudoPage)
-
removeFloat
public void removeFloat(BlockBox floater)
FIXME: Only used when we reset a box, so trying to remove at sometime in the future.
-
paintFloats
@Deprecated private void paintFloats(RenderingContext c)
Deprecated.
-
paintLayers
@Deprecated private void paintLayers(RenderingContext c, java.util.List<Layer> layers)
Deprecated.
-
addFloat
public void addFloat(BlockBox floater, BlockFormattingContext bfc)
-
collectLayers
public java.util.List<Layer> collectLayers(int which)
Called recusively to collect all descendant layers in a layer tree so they can be painted in correct order.- Parameters:
which- NEGATIVE ZERO POSITIVE AUTO corresponding to z-index property.
-
getStackingContextLayers
private java.util.List<Layer> getStackingContextLayers(int which)
-
getSortedLayers
public java.util.List<Layer> getSortedLayers(int which)
-
paintBackgroundsAndBorders
@Deprecated private void paintBackgroundsAndBorders(RenderingContext c, java.util.List<Box> blocks, java.util.Map<TableCellBox,java.util.List<CollapsedBorderSide>> collapsedTableBorders, BoxRangeLists rangeLists)
Deprecated.
-
paintSelection
@Deprecated private void paintSelection(RenderingContext c, java.util.List<Box> lines)
Deprecated.
-
getPaintingDimension
public java.awt.Dimension getPaintingDimension(LayoutContext c)
-
paintInlineContent
@Deprecated private void paintInlineContent(RenderingContext c, java.util.List<Box> lines, BoxRangeLists rangeLists)
Deprecated.
-
paint
@Deprecated public void paint(RenderingContext c)
Deprecated.
-
convertAngleToRadians
@Deprecated private float convertAngleToRadians(PropertyValue param)
Deprecated.
-
getFloats
public java.util.List<BlockBox> getFloats()
-
applyTranform
@Deprecated protected java.util.List<java.awt.geom.AffineTransform> applyTranform(RenderingContext c, Box box)
Deprecated.Applies the transforms specified for the box and returns a list of inverse transforms that should be applied once the transformed element has been output.
-
applyTransformFunctions
@Deprecated private void applyTransformFunctions(float flipFactor, java.util.List<PropertyValue> transformList, java.util.List<java.awt.geom.AffineTransform> resultTransforms)Deprecated.
-
find
@Deprecated private Box find(CssContext cssCtx, int absX, int absY, java.util.List<Layer> layers, boolean findAnonymous)
Deprecated.
-
find
@Deprecated public Box find(CssContext cssCtx, int absX, int absY, boolean findAnonymous)
Deprecated.
-
paintCollapsedTableBorders
@Deprecated private void paintCollapsedTableBorders(RenderingContext c, java.util.List<CollapsedBorderSide> borders)
Deprecated.
-
collectCollapsedTableBorders
@Deprecated private java.util.Map<TableCellBox,java.util.List<CollapsedBorderSide>> collectCollapsedTableBorders(RenderingContext c, java.util.List<Box> blocks)
Deprecated.
-
paintAsLayer
@Deprecated public void paintAsLayer(RenderingContext c, BlockBox startingPoint)
Deprecated.
-
paintListMarkers
@Deprecated private void paintListMarkers(RenderingContext c, java.util.List<Box> blocks, BoxRangeLists rangeLists)
Deprecated.
-
paintReplacedElements
@Deprecated private void paintReplacedElements(RenderingContext c, java.util.List<Box> blocks, BoxRangeLists rangeLists)
Deprecated.
-
paintLayerBackgroundAndBorder
@Deprecated private void paintLayerBackgroundAndBorder(RenderingContext c)
Deprecated.
-
positionFixedLayer
public void positionFixedLayer(RenderingContext c)
-
isRootLayer
public boolean isRootLayer()
-
moveIfGreater
private void moveIfGreater(java.awt.Dimension result, java.awt.Dimension test)
-
paintReplacedElement
@Deprecated private void paintReplacedElement(RenderingContext c, BlockBox replaced)
Deprecated.
-
positionChildren
public void positionChildren(LayoutContext c)
-
calcPaintingDimension
private PaintingInfo calcPaintingDimension(LayoutContext c)
-
getChildren
public java.util.List<Layer> getChildren()
The resulting list should not be modified.
-
remove
private void remove(Layer layer)
-
detach
public void detach()
-
isInline
public boolean isInline()
-
setInline
public void setInline(boolean inline)
-
getEnd
public Box getEnd()
-
setEnd
public void setEnd(Box end)
-
isRequiresLayout
public boolean isRequiresLayout()
-
setRequiresLayout
public void setRequiresLayout(boolean requiresLayout)
-
finish
public void finish(LayoutContext c)
-
layoutAbsoluteChildren
private void layoutAbsoluteChildren(LayoutContext c)
-
position
private void position(LayoutContext c)
-
getPages
public java.util.List<PageBox> getPages()
-
setPages
public void setPages(java.util.List<PageBox> pages)
-
isLastPage
public boolean isLastPage(PageBox pageBox)
-
layoutAbsoluteChild
private void layoutAbsoluteChild(LayoutContext c, Layer child)
-
removeLastPage
public void removeLastPage()
-
addPage
public void addPage(CssContext c)
-
getFirstPage
public PageBox getFirstPage(CssContext c, int absY)
Returns the page box for a Y position. If the y position is less than 0 then the first page will be returned if available. Only returns null if there are no pages available.
IMPORTANT: If absY is past the end of the last page, pages will be created as required to include absY and the last page will be returned.
-
getFirstPage
public PageBox getFirstPage(CssContext c, Box box)
-
getLastPage
public PageBox getLastPage(CssContext c, Box box)
-
ensureHasPage
public void ensureHasPage(CssContext c, Box box)
-
getPages
public java.util.List<PageBox> getPages(CssContext c, int top, int bottom)
Tries to return a list of pages that cover top to bottom. If top and bottom are less-than zero returns null.
IMPORTANT: If bottom is past the end of the last page, pages are created until bottom is included.
-
pageFinder
private SearchUtil.IntComparator pageFinder(java.util.List<PageBox> pages, int yOffset, java.util.function.Predicate<PageBox> matcher)
Returns a comparator that determines if the given pageBox is a match, too late or too early. For use withSearchUtil.intBinarySearch(IntComparator, int, int)
-
pagePredicate
private java.util.function.Predicate<PageBox> pagePredicate(int yOffset)
Returns a predicate that determines if yOffset sits on the given page.
-
getPage
public PageBox getPage(CssContext c, int yOffset)
Gets the page box for the given document y offset. If y offset is less-than zero returns null.
IMPORTANT: If y offset is past the end of the last page, pages are created until y offset is included and the last page is returned.
-
addPagesUntilPosition
private void addPagesUntilPosition(CssContext c, int position)
-
trimEmptyPages
public void trimEmptyPages(CssContext c, int maxYHeight)
-
trimPageCount
public void trimPageCount(int newPageCount)
-
assignPagePaintingPositions
public void assignPagePaintingPositions(CssContext cssCtx, short mode)
-
assignPagePaintingPositions
public void assignPagePaintingPositions(CssContext cssCtx, int mode, int additionalClearance)
-
getMaxPageWidth
public int getMaxPageWidth(CssContext cssCtx, int additionalClearance)
-
getLastPage
public PageBox getLastPage()
-
crossesPageBreak
public boolean crossesPageBreak(LayoutContext c, int top, int bottom)
Returns whether the a box with the given top and bottom would cross a page break.
Requirements: top is >= 0.
Important: This method will take into account anyfloat: bottomcontent when used in in-flow content. For example, if the top/bottom pair overlaps the footnote area, returns true. It also takes into account space set aside for paginated table header/footer.
SeeCssContext.isInFloatBottom()LayoutContext.getExtraSpaceBottom()
-
findRoot
public Layer findRoot()
-
addRunningBlock
public void addRunningBlock(BlockBox block)
-
removeRunningBlock
public void removeRunningBlock(BlockBox block)
-
getRunningBlock
public BlockBox getRunningBlock(java.lang.String identifer, PageBox page, PageElementPosition which)
-
layoutPages
public void layoutPages(LayoutContext c)
-
addPageSequence
public void addPageSequence(BlockBox start)
-
getSortedPageSequences
private java.util.List<BlockBox> getSortedPageSequences()
-
getRelativePageNo
public int getRelativePageNo(RenderingContext c, int absY)
-
getRelativePageNo
public int getRelativePageNo(RenderingContext c)
-
getRelativePageCount
public int getRelativePageCount(RenderingContext c)
-
getPageSequenceStart
private int getPageSequenceStart(RenderingContext c, java.util.List<BlockBox> sequences, PageBox page)
-
getSelectionEnd
public Box getSelectionEnd()
-
setSelectionEnd
public void setSelectionEnd(Box selectionEnd)
-
getSelectionStart
public Box getSelectionStart()
-
setSelectionStart
public void setSelectionStart(Box selectionStart)
-
getSelectionEndX
public int getSelectionEndX()
-
setSelectionEndX
public void setSelectionEndX(int selectionEndX)
-
getSelectionEndY
public int getSelectionEndY()
-
setSelectionEndY
public void setSelectionEndY(int selectionEndY)
-
getSelectionStartX
public int getSelectionStartX()
-
setSelectionStartX
public void setSelectionStartX(int selectionStartX)
-
getSelectionStartY
public int getSelectionStartY()
-
setSelectionStartY
public void setSelectionStartY(int selectionStartY)
-
getLastRequestedPage
private PageBox getLastRequestedPage()
-
setLastRequestedPage
private void setLastRequestedPage(PageBox lastRequestedPage)
-
isIsolated
public boolean isIsolated()
-
-