private IElement ProcessMarginBoxContent(PageMarginBoxContextNode marginBoxContentNode, int pageNumber, ProcessorContext context) { IElementNode dummyMarginBoxNode = new PageMarginBoxDummyElement(); dummyMarginBoxNode.SetStyles(marginBoxContentNode.GetStyles()); ITagWorker marginBoxWorker = context.GetTagWorkerFactory().GetTagWorker(dummyMarginBoxNode, context); for (int i = 0; i < marginBoxContentNode.ChildNodes().Count; i++) { INode childNode = marginBoxContentNode.ChildNodes()[i]; if (childNode is ITextNode) { String text = ((ITextNode)marginBoxContentNode.ChildNodes()[i]).WholeText(); marginBoxWorker.ProcessContent(text, context); } else { if (childNode is IElementNode) { ITagWorker childTagWorker = context.GetTagWorkerFactory().GetTagWorker((IElementNode)childNode, context); if (childTagWorker != null) { childTagWorker.ProcessEnd((IElementNode)childNode, context); marginBoxWorker.ProcessTagChild(childTagWorker, context); } } else { if (childNode is PageMarginRunningElementNode) { PageMarginRunningElementNode runningElementNode = (PageMarginRunningElementNode)childNode; RunningElementContainer runningElement = context.GetCssContext().GetRunningManager().GetRunningElement(runningElementNode .GetRunningElementName(), runningElementNode.GetRunningElementOccurrence(), pageNumber); if (runningElement != null) { marginBoxWorker.ProcessTagChild(runningElement.GetProcessedElementWorker(), context); } } else { LogManager.GetLogger(GetType()).Error(iText.Html2pdf.LogMessageConstant.UNKNOWN_MARGIN_BOX_CHILD); } } } } marginBoxWorker.ProcessEnd(dummyMarginBoxNode, context); if (!(marginBoxWorker.GetElementResult() is IElement)) { throw new InvalidOperationException("Custom tag worker implementation for margin boxes shall return IElement for #getElementResult() call." ); } ICssApplier cssApplier = context.GetCssApplierFactory().GetCssApplier(dummyMarginBoxNode); cssApplier.Apply(context, marginBoxContentNode, marginBoxWorker); return((IElement)marginBoxWorker.GetElementResult()); }
private DimensionContainer RetrievePageMarginBoxHeights(PageMarginBoxContextNode pmbcNode, IRenderer renderer , float marginWidth, float maxHeight, float additionalHeightFix) { if (pmbcNode == null) { return(null); } else { return(new HeightDimensionContainer(pmbcNode, marginWidth, maxHeight, renderer, additionalHeightFix)); } }
private DimensionContainer RetrievePageMarginBoxWidths(PageMarginBoxContextNode pmbcNode, IRenderer renderer , float maxWidth, float additionalWidthFix) { if (pmbcNode == null) { return(null); } else { return(new WidthDimensionContainer(pmbcNode, maxWidth, renderer, additionalWidthFix)); } }
/* (non-Javadoc) * @see com.itextpdf.styledxmlparser.css.selector.ICssSelector#matches(com.itextpdf.styledxmlparser.html.node.INode) */ public virtual bool Matches(INode node) { if (!(node is PageMarginBoxContextNode)) { return(false); } PageMarginBoxContextNode marginBoxNode = (PageMarginBoxContextNode)node; if (pageMarginBoxName.Equals(marginBoxNode.GetMarginBoxName())) { INode parent = node.ParentNode(); return(pageSelector.Matches(parent)); } return(false); }
/// <summary>Gets the resolved margin boxes.</summary> /// <param name="pageClassNode">the page contex node</param> /// <param name="cssResolver">the CSS resolver</param> /// <param name="context">the CSS context</param> /// <returns>the resolved margin boxes</returns> private static IList <PageMarginBoxContextNode> GetResolvedMarginBoxes(PageContextNode pageClassNode, ICssResolver cssResolver, CssContext context) { IList <PageMarginBoxContextNode> resolvedMarginBoxes = new List <PageMarginBoxContextNode>(); foreach (String pageMarginBoxName in pageMarginBoxNames) { PageMarginBoxContextNode marginBoxNode = new PageMarginBoxContextNode(pageClassNode, pageMarginBoxName); IDictionary <String, String> marginBoxStyles = cssResolver.ResolveStyles(marginBoxNode, context); if (!marginBoxNode.ChildNodes().IsEmpty()) { marginBoxNode.SetStyles(marginBoxStyles); resolvedMarginBoxes.Add(marginBoxNode); } context.SetQuotesDepth(0); } return(resolvedMarginBoxes); }
private void Draw(IRenderer renderer, PageMarginBoxContextNode node, PdfDocument pdfDocument, PdfPage page , DocumentRenderer documentRenderer, int pageNumber) { LayoutResult result = renderer.Layout(new LayoutContext(new LayoutArea(pageNumber, node.GetPageMarginBoxRectangle ()))); IRenderer rendererToDraw = result.GetStatus() == LayoutResult.FULL ? renderer : result.GetSplitRenderer(); if (rendererToDraw != null) { TagTreePointer tagPointer = null; TagTreePointer backupPointer = null; PdfPage backupPage = null; if (pdfDocument.IsTagged()) { tagPointer = pdfDocument.GetTagStructureContext().GetAutoTaggingPointer(); backupPage = tagPointer.GetCurrentPage(); backupPointer = new TagTreePointer(tagPointer); tagPointer.MoveToRoot(); tagPointer.SetPageForTagging(page); } rendererToDraw.SetParent(documentRenderer).Draw(new DrawContext(page.GetDocument(), new PdfCanvas(page), pdfDocument .IsTagged())); if (pdfDocument.IsTagged()) { tagPointer.SetPageForTagging(backupPage); tagPointer.MoveToPointer(backupPointer); } } else { // marginBoxElements have overflow property set to HIDDEN, therefore it is not expected to neither get // LayoutResult other than FULL nor get no split renderer (result NOTHING) even if result is not FULL LOGGER.Error(MessageFormatUtil.Format(iText.Html2pdf.LogMessageConstant.PAGE_MARGIN_BOX_CONTENT_CANNOT_BE_DRAWN , node.GetMarginBoxName())); } }