Package com.openhtmltopdf.layout
Class BoxBuilder
- java.lang.Object
-
- com.openhtmltopdf.layout.BoxBuilder
-
public class BoxBuilder extends java.lang.ObjectThis class is responsible for creating the box tree from the DOM. This is mostly just a one-to-one translation from theElementto anInlineBoxor aBlockBox(or some subclass ofBlockBox), but the tree is reorganized according to the CSS rules. This includes inserting anonymous block and inline boxes, anonymous table content, and:beforeand:aftercontent. White space is also normalized at this point. Table columns and table column groups are added to the table which owns them, but are not created as regular boxes. Floated and absolutely positioned content is always treated as inline content for purposes of inserting anonymous block boxes and calculating the kind of content contained in a given block box.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classBoxBuilder.ChildBoxInfoprivate static classBoxBuilder.CreateChildrenContext
-
Field Summary
Fields Modifier and Type Field Description private static intCONTENT_LIST_DOCUMENTprivate static intCONTENT_LIST_MARGIN_BOXstatic intMARGIN_BOX_HORIZONTALstatic intMARGIN_BOX_VERTICAL
-
Constructor Summary
Constructors Constructor Description BoxBuilder()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static voidaddColumnOrColumnGroup(LayoutContext c, TableBox table, org.w3c.dom.Element e, CalculatedStyle style)private static voidaddColumns(LayoutContext c, TableBox table, TableColumn parent)private static booleancontainsOrphanedTableContent(java.util.List<Styleable> children)private static voidcreateAnonymousBlock(SharedContext c, Box parent, java.util.List<Styleable> inline, java.util.List<InlineBox> savedParents)private static voidcreateAnonymousBlock(SharedContext c, Box parent, java.util.List<Styleable> inline, java.util.List<InlineBox> savedParents, IdentValue display)private static voidcreateAnonymousTableContent(LayoutContext c, BlockBox source, IdentValue next, java.util.List<Styleable> childrenForAnonymous, java.util.List<Styleable> childrenWithAnonymous)private static BlockBoxcreateBlockBox(CalculatedStyle style, BoxBuilder.ChildBoxInfo info, boolean generated)private static StyleablecreateChildBlockBox(LayoutContext c, BoxBuilder.ChildBoxInfo info, org.w3c.dom.Element element, CalculatedStyle style)static voidcreateChildren(LayoutContext c, BlockBox parent)private static voidcreateChildren(LayoutContext c, BlockBox blockParent, org.w3c.dom.Element parent, java.util.List<Styleable> children, BoxBuilder.ChildBoxInfo info, boolean inline)private static voidcreateColumnContainer(LayoutContext c, Styleable child, org.w3c.dom.Element element, CalculatedStyle style)private static voidcreateElementChild(LayoutContext c, org.w3c.dom.Element parent, BlockBox blockParent, org.w3c.dom.Node working, java.util.List<Styleable> children, BoxBuilder.ChildBoxInfo info, BoxBuilder.CreateChildrenContext context)private static BlockBoxcreateFootnoteBody(LayoutContext c, org.w3c.dom.Element element, CalculatedStyle style)Creates the footnote body to put at the bottom of the page inside a page's footnote area.private static org.w3c.dom.ElementcreateFootnoteCallAnchor(LayoutContext c, org.w3c.dom.Element parent)Used to create the anchor element to link to the footnote body for the footnote-call pseudo element.private static org.w3c.dom.ElementcreateFootnoteTarget(LayoutContext c, org.w3c.dom.Element parent)Creates an element with id for the footnote-marker pseudo element so we can link to it from the footnote-call pseduo element.private static java.util.List<Styleable>createGeneratedContent(LayoutContext c, org.w3c.dom.Element element, java.lang.String peName, CalculatedStyle style, PropertyValue property, BoxBuilder.ChildBoxInfo info)Creates generated content boxes for pseudo elements such as::before.private static java.util.List<Styleable>createGeneratedContentList(LayoutContext c, org.w3c.dom.Element element, java.util.List<PropertyValue> values, java.lang.String peName, CalculatedStyle style, int mode, BoxBuilder.ChildBoxInfo info, java.util.List<Styleable> result)private static java.util.List<Styleable>createGeneratedMarginBoxContent(LayoutContext c, org.w3c.dom.Element element, PropertyValue property, CalculatedStyle style, BoxBuilder.ChildBoxInfo info)private static InlineBoxcreateInlineBox(java.lang.String text, org.w3c.dom.Element parent, CalculatedStyle parentStyle, org.w3c.dom.Text node)private static voidcreateInlineChildren(LayoutContext c, org.w3c.dom.Element parent, java.util.List<Styleable> children, BoxBuilder.ChildBoxInfo info, BoxBuilder.CreateChildrenContext context, org.w3c.dom.Element element)private static TableCellBoxcreateMarginBox(LayoutContext c, CascadedStyle cascadedStyle, boolean alwaysCreate)static TableBoxcreateMarginTable(LayoutContext c, PageInfo pageInfo, MarginBoxName[] names, int height, int direction)static BlockBoxcreateRootBox(LayoutContext c, org.w3c.dom.Document document)private static InlineBoxdoBidi(LayoutContext c, org.w3c.dom.Text textNode, org.w3c.dom.Element parent, CalculatedStyle parentStyle, InlineBox previousIB, java.util.List<Styleable> children)Attempts to divide a Text node further into directional text runs, either LTR or RTL.private static InlineBoxdoFakeBidi(LayoutContext c, org.w3c.dom.Text textNode, org.w3c.dom.Element parent, CalculatedStyle parentStyle, InlineBox previousIB, java.util.List<Styleable> children)private static java.lang.StringgetAttributeValue(FSFunction attrFunc, org.w3c.dom.Element e)private static IdentValuegetNextTableNestingLevel(IdentValue display)private static IdentValuegetPreviousTableNestingLevel(IdentValue display)static BlockBoxgetRunningBlock(LayoutContext c, PropertyValue value)private static voidinsertAnonymousBlocks(SharedContext c, Box parent, java.util.List<Styleable> children, boolean layoutRunningBlocks)private static voidinsertGeneratedContent(LayoutContext c, org.w3c.dom.Element element, CalculatedStyle parentStyle, java.lang.String peName, java.util.List<Styleable> children, BoxBuilder.ChildBoxInfo info)private static booleanisAllProperTableNesting(IdentValue parentDisplay, java.util.List<Styleable> children)private static booleanisAttrFunction(FSFunction function)static booleanisElementFunction(FSFunction function)private static booleanisGeneratedElement(org.w3c.dom.Element element)Don't output elements that have been artificially created to support footnotes and content property images.private static booleanisInsertedBoxIgnored(org.w3c.dom.Element element)private static booleanisNestingTableContent(IdentValue display)private static booleanisParentInline(BlockBox box)private static booleanisProperTableNesting(IdentValue parent, IdentValue child)private static booleanisTableRowOrRowGroup(Styleable child)private static booleanisValidFootnote(LayoutContext c, org.w3c.dom.Element element, CalculatedStyle style)private static booleanisValidFootnotePseudo(CalculatedStyle style)private static voidlogInvalidFootnotePseudo(java.lang.String peName, CalculatedStyle style)private static voidlogInvalidFootnoteStyle(LayoutContext c, org.w3c.dom.Element element, CalculatedStyle style)private static BoxBuilder.ChildBoxInfolookForBlockContent(java.util.List<Styleable> styleables)private static CounterFunctionmakeCounterFunction(FSFunction function, LayoutContext c, CalculatedStyle style)private static booleanmatchesTableLevel(IdentValue target, IdentValue value)private static voidrebalanceInlineContent(java.util.List<Styleable> content)Makes sure that anyInlineBoxincontentboth starts and ends withincontent.private static BlockBoxreorderTableContent(LayoutContext c, TableBox table)Reorganizes a table so that the header is the first row group and the footer the last.private static voidresolveChildren(LayoutContext c, BlockBox owner, java.util.List<Styleable> children, BoxBuilder.ChildBoxInfo info)private static voidresolveChildTableContent(LayoutContext c, BlockBox parent, java.util.List<Styleable> children, BoxBuilder.ChildBoxInfo info, IdentValue target)Handles the situation when we find table content, but our parent is not table related.private static voidresolveElementCounters(LayoutContext c, org.w3c.dom.Node working, org.w3c.dom.Element element, CalculatedStyle style)private static voidresolveTableContent(LayoutContext c, BlockBox parent, java.util.List<Styleable> children, BoxBuilder.ChildBoxInfo info)Handles the situation when our current parent is table related.private static InlineBoxsetupInlineChild(InlineBox child, InlineBox previousIB)private static voidsplitParagraphs(LayoutContext c, org.w3c.dom.Document document)Split the document into paragraphs for use in analyzing bi-directional text runs.private static voidstripAllWhitespace(java.util.List<Styleable> content)private static java.util.List<Styleable>wrapGeneratedContent(LayoutContext c, org.w3c.dom.Element element, java.lang.String peName, CalculatedStyle style, BoxBuilder.ChildBoxInfo info, BoxBuilder.ChildBoxInfo childInfo, java.util.List<Styleable> inlineBoxes)
-
-
-
Field Detail
-
MARGIN_BOX_VERTICAL
public static final int MARGIN_BOX_VERTICAL
- See Also:
- Constant Field Values
-
MARGIN_BOX_HORIZONTAL
public static final int MARGIN_BOX_HORIZONTAL
- See Also:
- Constant Field Values
-
CONTENT_LIST_DOCUMENT
private static final int CONTENT_LIST_DOCUMENT
- See Also:
- Constant Field Values
-
CONTENT_LIST_MARGIN_BOX
private static final int CONTENT_LIST_MARGIN_BOX
- See Also:
- Constant Field Values
-
-
Method Detail
-
splitParagraphs
private static void splitParagraphs(LayoutContext c, org.w3c.dom.Document document)
Split the document into paragraphs for use in analyzing bi-directional text runs.- Parameters:
c-document-
-
createRootBox
public static BlockBox createRootBox(LayoutContext c, org.w3c.dom.Document document)
-
createChildren
public static void createChildren(LayoutContext c, BlockBox parent)
-
isInsertedBoxIgnored
private static boolean isInsertedBoxIgnored(org.w3c.dom.Element element)
-
createMarginTable
public static TableBox createMarginTable(LayoutContext c, PageInfo pageInfo, MarginBoxName[] names, int height, int direction)
-
createMarginBox
private static TableCellBox createMarginBox(LayoutContext c, CascadedStyle cascadedStyle, boolean alwaysCreate)
-
resolveChildren
private static void resolveChildren(LayoutContext c, BlockBox owner, java.util.List<Styleable> children, BoxBuilder.ChildBoxInfo info)
-
isAllProperTableNesting
private static boolean isAllProperTableNesting(IdentValue parentDisplay, java.util.List<Styleable> children)
-
resolveChildTableContent
private static void resolveChildTableContent(LayoutContext c, BlockBox parent, java.util.List<Styleable> children, BoxBuilder.ChildBoxInfo info, IdentValue target)
Handles the situation when we find table content, but our parent is not table related. For example,div->td. Anonymous tables are then constructed by repeatedly pulling together consecutive same-table-level siblings and wrapping them in the next highest table level (e.g. consecutivetdelements will be wrapped in an anonymoustr, then atbody, and finally atable).
-
matchesTableLevel
private static boolean matchesTableLevel(IdentValue target, IdentValue value)
-
rebalanceInlineContent
private static void rebalanceInlineContent(java.util.List<Styleable> content)
Makes sure that anyInlineBoxincontentboth starts and ends withincontent. Used to ensure that it is always possible to construct anonymous blocks once an element's children has been distributed among anonymous table objects.
-
stripAllWhitespace
private static void stripAllWhitespace(java.util.List<Styleable> content)
-
resolveTableContent
private static void resolveTableContent(LayoutContext c, BlockBox parent, java.util.List<Styleable> children, BoxBuilder.ChildBoxInfo info)
Handles the situation when our current parent is table related. If everything is properly nested (e.g. atrcontains onlytdelements), nothing is done. Otherwise anonymous boxes are inserted to ensure the integrity of the table model.
-
isTableRowOrRowGroup
private static boolean isTableRowOrRowGroup(Styleable child)
-
containsOrphanedTableContent
private static boolean containsOrphanedTableContent(java.util.List<Styleable> children)
-
isParentInline
private static boolean isParentInline(BlockBox box)
-
createAnonymousTableContent
private static void createAnonymousTableContent(LayoutContext c, BlockBox source, IdentValue next, java.util.List<Styleable> childrenForAnonymous, java.util.List<Styleable> childrenWithAnonymous)
-
reorderTableContent
private static BlockBox reorderTableContent(LayoutContext c, TableBox table)
Reorganizes a table so that the header is the first row group and the footer the last. If the table has caption boxes, they will be pulled out and added to an anonymous block box along with the table itself. If not, the table is returned.
-
lookForBlockContent
private static BoxBuilder.ChildBoxInfo lookForBlockContent(java.util.List<Styleable> styleables)
-
getNextTableNestingLevel
private static IdentValue getNextTableNestingLevel(IdentValue display)
-
getPreviousTableNestingLevel
private static IdentValue getPreviousTableNestingLevel(IdentValue display)
-
isProperTableNesting
private static boolean isProperTableNesting(IdentValue parent, IdentValue child)
-
isNestingTableContent
private static boolean isNestingTableContent(IdentValue display)
-
isAttrFunction
private static boolean isAttrFunction(FSFunction function)
-
isElementFunction
public static boolean isElementFunction(FSFunction function)
-
makeCounterFunction
private static CounterFunction makeCounterFunction(FSFunction function, LayoutContext c, CalculatedStyle style)
-
getAttributeValue
private static java.lang.String getAttributeValue(FSFunction attrFunc, org.w3c.dom.Element e)
-
createGeneratedContentList
private static java.util.List<Styleable> createGeneratedContentList(LayoutContext c, org.w3c.dom.Element element, java.util.List<PropertyValue> values, java.lang.String peName, CalculatedStyle style, int mode, BoxBuilder.ChildBoxInfo info, java.util.List<Styleable> result)
-
createFootnoteTarget
private static org.w3c.dom.Element createFootnoteTarget(LayoutContext c, org.w3c.dom.Element parent)
Creates an element with id for the footnote-marker pseudo element so we can link to it from the footnote-call pseduo element.
SeecreateFootnoteCallAnchor(LayoutContext, Element)
-
createFootnoteCallAnchor
private static org.w3c.dom.Element createFootnoteCallAnchor(LayoutContext c, org.w3c.dom.Element parent)
Used to create the anchor element to link to the footnote body for the footnote-call pseudo element.
SeecreateFootnoteTarget(LayoutContext, Element)
-
getRunningBlock
public static BlockBox getRunningBlock(LayoutContext c, PropertyValue value)
-
insertGeneratedContent
private static void insertGeneratedContent(LayoutContext c, org.w3c.dom.Element element, CalculatedStyle parentStyle, java.lang.String peName, java.util.List<Styleable> children, BoxBuilder.ChildBoxInfo info)
-
createGeneratedContent
private static java.util.List<Styleable> createGeneratedContent(LayoutContext c, org.w3c.dom.Element element, java.lang.String peName, CalculatedStyle style, PropertyValue property, BoxBuilder.ChildBoxInfo info)
Creates generated content boxes for pseudo elements such as::before.- Parameters:
element- The containing element where the pseudo element appears. Forspan::beforethe element would be aspan.peName- Examples includebefore,after,footnote-callandfootnote-marker.style- The child style for this pseudo element. Forspan::beforethis would include all the styles set explicitly on::beforeas well as those that inherit fromspanfollowing the cascade rules.property- The values of thecontentCSS property.info- In/out param. Whether the resultant box(es) contain block level content.- Returns:
- The generated box(es). Typically one
BlockBoxor multiple inline boxes.
-
wrapGeneratedContent
private static java.util.List<Styleable> wrapGeneratedContent(LayoutContext c, org.w3c.dom.Element element, java.lang.String peName, CalculatedStyle style, BoxBuilder.ChildBoxInfo info, BoxBuilder.ChildBoxInfo childInfo, java.util.List<Styleable> inlineBoxes)
-
createGeneratedMarginBoxContent
private static java.util.List<Styleable> createGeneratedMarginBoxContent(LayoutContext c, org.w3c.dom.Element element, PropertyValue property, CalculatedStyle style, BoxBuilder.ChildBoxInfo info)
-
createBlockBox
private static BlockBox createBlockBox(CalculatedStyle style, BoxBuilder.ChildBoxInfo info, boolean generated)
-
addColumns
private static void addColumns(LayoutContext c, TableBox table, TableColumn parent)
-
addColumnOrColumnGroup
private static void addColumnOrColumnGroup(LayoutContext c, TableBox table, org.w3c.dom.Element e, CalculatedStyle style)
-
createInlineBox
private static InlineBox createInlineBox(java.lang.String text, org.w3c.dom.Element parent, CalculatedStyle parentStyle, org.w3c.dom.Text node)
-
isValidFootnote
private static boolean isValidFootnote(LayoutContext c, org.w3c.dom.Element element, CalculatedStyle style)
-
logInvalidFootnoteStyle
private static void logInvalidFootnoteStyle(LayoutContext c, org.w3c.dom.Element element, CalculatedStyle style)
-
isValidFootnotePseudo
private static boolean isValidFootnotePseudo(CalculatedStyle style)
-
logInvalidFootnotePseudo
private static void logInvalidFootnotePseudo(java.lang.String peName, CalculatedStyle style)
-
isGeneratedElement
private static boolean isGeneratedElement(org.w3c.dom.Element element)
Don't output elements that have been artificially created to support footnotes and content property images.
-
createElementChild
private static void createElementChild(LayoutContext c, org.w3c.dom.Element parent, BlockBox blockParent, org.w3c.dom.Node working, java.util.List<Styleable> children, BoxBuilder.ChildBoxInfo info, BoxBuilder.CreateChildrenContext context)
-
createInlineChildren
private static void createInlineChildren(LayoutContext c, org.w3c.dom.Element parent, java.util.List<Styleable> children, BoxBuilder.ChildBoxInfo info, BoxBuilder.CreateChildrenContext context, org.w3c.dom.Element element)
-
createChildBlockBox
private static Styleable createChildBlockBox(LayoutContext c, BoxBuilder.ChildBoxInfo info, org.w3c.dom.Element element, CalculatedStyle style)
-
createFootnoteBody
private static BlockBox createFootnoteBody(LayoutContext c, org.w3c.dom.Element element, CalculatedStyle style)
Creates the footnote body to put at the bottom of the page inside a page's footnote area.
-
createColumnContainer
private static void createColumnContainer(LayoutContext c, Styleable child, org.w3c.dom.Element element, CalculatedStyle style)
-
resolveElementCounters
private static void resolveElementCounters(LayoutContext c, org.w3c.dom.Node working, org.w3c.dom.Element element, CalculatedStyle style)
-
createChildren
private static void createChildren(LayoutContext c, BlockBox blockParent, org.w3c.dom.Element parent, java.util.List<Styleable> children, BoxBuilder.ChildBoxInfo info, boolean inline)
-
doFakeBidi
private static InlineBox doFakeBidi(LayoutContext c, org.w3c.dom.Text textNode, org.w3c.dom.Element parent, CalculatedStyle parentStyle, InlineBox previousIB, java.util.List<Styleable> children)
-
doBidi
private static InlineBox doBidi(LayoutContext c, org.w3c.dom.Text textNode, org.w3c.dom.Element parent, CalculatedStyle parentStyle, InlineBox previousIB, java.util.List<Styleable> children)
Attempts to divide a Text node further into directional text runs, either LTR or RTL.- Parameters:
c-textNode-parent-parentStyle-- Returns:
- the previousIB.
-
insertAnonymousBlocks
private static void insertAnonymousBlocks(SharedContext c, Box parent, java.util.List<Styleable> children, boolean layoutRunningBlocks)
-
createAnonymousBlock
private static void createAnonymousBlock(SharedContext c, Box parent, java.util.List<Styleable> inline, java.util.List<InlineBox> savedParents)
-
createAnonymousBlock
private static void createAnonymousBlock(SharedContext c, Box parent, java.util.List<Styleable> inline, java.util.List<InlineBox> savedParents, IdentValue display)
-
-