Ejemplo n.º 1
0
        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());
        }