/* (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);
        }
        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()));
            }
        }