Class BoxBuilder
java.lang.Object
com.openhtmltopdf.layout.BoxBuilder
This class is responsible for creating the box tree from the DOM. This is
mostly just a one-to-one translation from the
Element to an
InlineBox or a BlockBox (or some subclass of
BlockBox), but the tree is reorganized according to the CSS rules.
This includes inserting anonymous block and inline boxes, anonymous table
content, and :before and :after content. 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 ClassesModifier and TypeClassDescriptionprivate static classprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidaddColumnOrColumnGroup(LayoutContext c, TableBox table, Element e, CalculatedStyle style) private static voidaddColumns(LayoutContext c, TableBox table, TableColumn parent) private static booleancontainsOrphanedTableContent(List<Styleable> children) private static voidcreateAnonymousBlock(SharedContext c, Box parent, List<Styleable> inline, List<InlineBox> savedParents) private static voidcreateAnonymousBlock(SharedContext c, Box parent, List<Styleable> inline, List<InlineBox> savedParents, IdentValue display) private static voidcreateAnonymousTableContent(LayoutContext c, BlockBox source, IdentValue next, List<Styleable> childrenForAnonymous, List<Styleable> childrenWithAnonymous) private static BlockBoxcreateBlockBox(CalculatedStyle style, BoxBuilder.ChildBoxInfo info, boolean generated) private static StyleablecreateChildBlockBox(LayoutContext c, BoxBuilder.ChildBoxInfo info, Element element, CalculatedStyle style) static voidcreateChildren(LayoutContext c, BlockBox parent) private static voidcreateChildren(LayoutContext c, BlockBox blockParent, Element parent, List<Styleable> children, BoxBuilder.ChildBoxInfo info, boolean inline) private static voidcreateColumnContainer(LayoutContext c, Styleable child, Element element, CalculatedStyle style) private static voidcreateElementChild(LayoutContext c, Element parent, BlockBox blockParent, Node working, List<Styleable> children, BoxBuilder.ChildBoxInfo info, BoxBuilder.CreateChildrenContext context) private static BlockBoxcreateFootnoteBody(LayoutContext c, Element element, CalculatedStyle style) Creates the footnote body to put at the bottom of the page inside a page's footnote area.private static ElementcreateFootnoteCallAnchor(LayoutContext c, Element parent) Used to create the anchor element to link to the footnote body for the footnote-call pseudo element.private static ElementcreateFootnoteTarget(LayoutContext c, 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.createGeneratedContent(LayoutContext c, Element element, String peName, CalculatedStyle style, PropertyValue property, BoxBuilder.ChildBoxInfo info) Creates generated content boxes for pseudo elements such as::before.createGeneratedContentList(LayoutContext c, Element element, List<PropertyValue> values, String peName, CalculatedStyle style, int mode, BoxBuilder.ChildBoxInfo info, List<Styleable> result) createGeneratedMarginBoxContent(LayoutContext c, Element element, PropertyValue property, CalculatedStyle style, BoxBuilder.ChildBoxInfo info) private static InlineBoxcreateInlineBox(String text, Element parent, CalculatedStyle parentStyle, Text node) private static voidcreateInlineChildren(LayoutContext c, Element parent, List<Styleable> children, BoxBuilder.ChildBoxInfo info, BoxBuilder.CreateChildrenContext context, 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, Document document) private static InlineBoxdoBidi(LayoutContext c, Text textNode, Element parent, CalculatedStyle parentStyle, InlineBox previousIB, List<Styleable> children) Attempts to divide a Text node further into directional text runs, either LTR or RTL.private static InlineBoxdoFakeBidi(LayoutContext c, Text textNode, Element parent, CalculatedStyle parentStyle, InlineBox previousIB, List<Styleable> children) private static StringgetAttributeValue(FSFunction attrFunc, 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, List<Styleable> children, boolean layoutRunningBlocks) private static voidinsertGeneratedContent(LayoutContext c, Element element, CalculatedStyle parentStyle, String peName, List<Styleable> children, BoxBuilder.ChildBoxInfo info) private static booleanisAllProperTableNesting(IdentValue parentDisplay, List<Styleable> children) private static booleanisAttrFunction(FSFunction function) static booleanisElementFunction(FSFunction function) private static booleanisGeneratedElement(Element element) Don't output elements that have been artificially created to support footnotes and content property images.private static booleanisInsertedBoxIgnored(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, Element element, CalculatedStyle style) private static booleanprivate static voidlogInvalidFootnotePseudo(String peName, CalculatedStyle style) private static voidlogInvalidFootnoteStyle(LayoutContext c, Element element, CalculatedStyle style) private static BoxBuilder.ChildBoxInfolookForBlockContent(List<Styleable> styleables) private static CounterFunctionmakeCounterFunction(FSFunction function, LayoutContext c, CalculatedStyle style) private static booleanmatchesTableLevel(IdentValue target, IdentValue value) private static voidrebalanceInlineContent(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, List<Styleable> children, BoxBuilder.ChildBoxInfo info) private static voidresolveChildTableContent(LayoutContext c, BlockBox parent, 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, Node working, Element element, CalculatedStyle style) private static voidresolveTableContent(LayoutContext c, BlockBox parent, 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, Document document) Split the document into paragraphs for use in analyzing bi-directional text runs.private static voidstripAllWhitespace(List<Styleable> content) wrapGeneratedContent(LayoutContext c, Element element, String peName, CalculatedStyle style, BoxBuilder.ChildBoxInfo info, BoxBuilder.ChildBoxInfo childInfo, List<Styleable> inlineBoxes)
-
Field Details
-
MARGIN_BOX_VERTICAL
public static final int MARGIN_BOX_VERTICAL- See Also:
-
MARGIN_BOX_HORIZONTAL
public static final int MARGIN_BOX_HORIZONTAL- See Also:
-
CONTENT_LIST_DOCUMENT
private static final int CONTENT_LIST_DOCUMENT- See Also:
-
CONTENT_LIST_MARGIN_BOX
private static final int CONTENT_LIST_MARGIN_BOX- See Also:
-
-
Constructor Details
-
BoxBuilder
public BoxBuilder()
-
-
Method Details
-
splitParagraphs
Split the document into paragraphs for use in analyzing bi-directional text runs.- Parameters:
c-document-
-
createRootBox
-
createChildren
-
isInsertedBoxIgnored
-
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, List<Styleable> children, BoxBuilder.ChildBoxInfo info) -
isAllProperTableNesting
-
resolveChildTableContent
private static void resolveChildTableContent(LayoutContext c, BlockBox parent, 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
-
rebalanceInlineContent
-
stripAllWhitespace
-
resolveTableContent
private static void resolveTableContent(LayoutContext c, BlockBox parent, 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
-
containsOrphanedTableContent
-
isParentInline
-
createAnonymousTableContent
private static void createAnonymousTableContent(LayoutContext c, BlockBox source, IdentValue next, List<Styleable> childrenForAnonymous, List<Styleable> childrenWithAnonymous) -
reorderTableContent
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
-
getNextTableNestingLevel
-
getPreviousTableNestingLevel
-
isProperTableNesting
-
isNestingTableContent
-
isAttrFunction
-
isElementFunction
-
makeCounterFunction
private static CounterFunction makeCounterFunction(FSFunction function, LayoutContext c, CalculatedStyle style) -
getAttributeValue
-
createGeneratedContentList
private static List<Styleable> createGeneratedContentList(LayoutContext c, Element element, List<PropertyValue> values, String peName, CalculatedStyle style, int mode, BoxBuilder.ChildBoxInfo info, List<Styleable> result) -
createFootnoteTarget
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
Used to create the anchor element to link to the footnote body for the footnote-call pseudo element.
SeecreateFootnoteTarget(LayoutContext, Element) -
getRunningBlock
-
insertGeneratedContent
private static void insertGeneratedContent(LayoutContext c, Element element, CalculatedStyle parentStyle, String peName, List<Styleable> children, BoxBuilder.ChildBoxInfo info) -
createGeneratedContent
private static List<Styleable> createGeneratedContent(LayoutContext c, Element element, 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 List<Styleable> wrapGeneratedContent(LayoutContext c, Element element, String peName, CalculatedStyle style, BoxBuilder.ChildBoxInfo info, BoxBuilder.ChildBoxInfo childInfo, List<Styleable> inlineBoxes) -
createGeneratedMarginBoxContent
private static List<Styleable> createGeneratedMarginBoxContent(LayoutContext c, Element element, PropertyValue property, CalculatedStyle style, BoxBuilder.ChildBoxInfo info) -
createBlockBox
private static BlockBox createBlockBox(CalculatedStyle style, BoxBuilder.ChildBoxInfo info, boolean generated) -
addColumns
-
addColumnOrColumnGroup
private static void addColumnOrColumnGroup(LayoutContext c, TableBox table, Element e, CalculatedStyle style) -
createInlineBox
private static InlineBox createInlineBox(String text, Element parent, CalculatedStyle parentStyle, Text node) -
isValidFootnote
-
logInvalidFootnoteStyle
private static void logInvalidFootnoteStyle(LayoutContext c, Element element, CalculatedStyle style) -
isValidFootnotePseudo
-
logInvalidFootnotePseudo
-
isGeneratedElement
Don't output elements that have been artificially created to support footnotes and content property images. -
createElementChild
private static void createElementChild(LayoutContext c, Element parent, BlockBox blockParent, Node working, List<Styleable> children, BoxBuilder.ChildBoxInfo info, BoxBuilder.CreateChildrenContext context) -
createInlineChildren
private static void createInlineChildren(LayoutContext c, Element parent, List<Styleable> children, BoxBuilder.ChildBoxInfo info, BoxBuilder.CreateChildrenContext context, Element element) -
createChildBlockBox
private static Styleable createChildBlockBox(LayoutContext c, BoxBuilder.ChildBoxInfo info, Element element, CalculatedStyle style) -
createFootnoteBody
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, Element element, CalculatedStyle style) -
resolveElementCounters
private static void resolveElementCounters(LayoutContext c, Node working, Element element, CalculatedStyle style) -
createChildren
private static void createChildren(LayoutContext c, BlockBox blockParent, Element parent, List<Styleable> children, BoxBuilder.ChildBoxInfo info, boolean inline) -
setupInlineChild
-
doFakeBidi
private static InlineBox doFakeBidi(LayoutContext c, Text textNode, Element parent, CalculatedStyle parentStyle, InlineBox previousIB, List<Styleable> children) -
doBidi
private static InlineBox doBidi(LayoutContext c, Text textNode, Element parent, CalculatedStyle parentStyle, InlineBox previousIB, 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.
-