예제 #1
0
 /// <summary>
 /// Creates a new
 /// <see cref="LiTagWorker"/>
 /// instance.
 /// </summary>
 /// <param name="element">the element</param>
 /// <param name="context">the context</param>
 public LiTagWorker(IElementNode element, ProcessorContext context)
 {
     listItem = new ListItem();
     if (element.GetAttribute(AttributeConstants.VALUE) != null)
     {
         int?indexValue = (int?)CssDimensionParsingUtils.ParseInteger(element.GetAttribute(AttributeConstants.VALUE
                                                                                           ));
         if (indexValue != null)
         {
             listItem.SetListSymbolOrdinalValue(indexValue.Value);
         }
     }
     if (!(context.GetState().Top() is UlOlTagWorker))
     {
         listItem.SetProperty(Property.LIST_SYMBOL_POSITION, ListSymbolPosition.INSIDE);
         float em = CssDimensionParsingUtils.ParseAbsoluteLength(element.GetStyles().Get(CssConstants.FONT_SIZE));
         if (TagConstants.LI.Equals(element.Name()))
         {
             ListStyleApplierUtil.SetDiscStyle(listItem, em);
         }
         else
         {
             listItem.SetProperty(Property.LIST_SYMBOL, null);
         }
         list = new List();
         list.Add(listItem);
     }
     inlineHelper = new WaitingInlineElementsHelper(element.GetStyles().Get(CssConstants.WHITE_SPACE), element.
                                                    GetStyles().Get(CssConstants.TEXT_TRANSFORM));
     AccessiblePropHelper.TrySetLangAttribute(listItem, element);
 }
예제 #2
0
        // TODO DEVSIX-1901
        private IRenderer CreateFlatRenderer(bool addAllOptionsToChildren)
        {
            AbstractSelectField   selectField = (AbstractSelectField)modelElement;
            IList <IBlockElement> options     = selectField.GetOptions();
            Div pseudoContainer = new Div();

            foreach (IBlockElement option in options)
            {
                pseudoContainer.Add(option);
            }
            IList <Paragraph> allOptions;
            IRenderer         pseudoRendererSubTree = pseudoContainer.CreateRendererSubTree();

            if (addAllOptionsToChildren)
            {
                allOptions = GetAllOptionsFlatElements(pseudoRendererSubTree);
            }
            else
            {
                allOptions = GetSingleSelectedOptionFlatRenderer(pseudoRendererSubTree);
            }
            if (allOptions.IsEmpty())
            {
                allOptions.Add(CreateComboBoxOptionFlatElement());
            }
            pseudoContainer.GetChildren().Clear();
            foreach (Paragraph option in allOptions)
            {
                pseudoContainer.Add(option);
            }
            AccessiblePropHelper.TrySetLangAttribute(pseudoContainer, GetLang());
            IRenderer rendererSubTree = pseudoContainer.CreateRendererSubTree();

            return(rendererSubTree);
        }
예제 #3
0
        protected internal override IRenderer CreateFlatRenderer()
        {
            AbstractSelectField   selectField = (AbstractSelectField)modelElement;
            IList <IBlockElement> options     = selectField.GetOptions();
            Div optionsContainer = new Div();

            foreach (IBlockElement option in options)
            {
                optionsContainer.Add(option);
            }
            AccessiblePropHelper.TrySetLangAttribute(optionsContainer, GetLang());
            IRenderer rendererSubTree;

            if (optionsContainer.GetChildren().IsEmpty())
            {
                Paragraph pStub = new Paragraph("\u00A0").SetMargin(0);
                pStub.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE);
                pStub.SetProperty(Property.OVERFLOW_Y, OverflowPropertyValue.VISIBLE);
                pStub.SetProperty(Html2PdfProperty.FORM_FIELD_SELECTED, false);
                // applying this property for the sake of finding this element as option
                optionsContainer.Add(pStub);
                rendererSubTree = optionsContainer.CreateRendererSubTree();
            }
            else
            {
                rendererSubTree = optionsContainer.CreateRendererSubTree();
                IList <IRenderer> selectedOptions = GetSelectedOptions(rendererSubTree);
                foreach (IRenderer selectedOption in selectedOptions)
                {
                    ApplySelectedStyle(selectedOption);
                }
            }
            return(rendererSubTree);
        }
예제 #4
0
        private void ProcessLangAttribute()
        {
            IPropertyContainer propertyContainer = flatRenderer.GetModelElement();

            if (propertyContainer is IAccessibleElement)
            {
                AccessiblePropHelper.TrySetLangAttribute((IAccessibleElement)propertyContainer, GetLang());
            }
        }
예제 #5
0
 public virtual void ProcessEnd(IElementNode element, ProcessorContext context)
 {
     if (context.GetPdfDocument() != null && processingResult != null)
     {
         SvgProcessingUtil util = new SvgProcessingUtil();
         svgImage = util.CreateImageFromProcessingResult(processingResult, context.GetPdfDocument());
         AccessiblePropHelper.TrySetLangAttribute(svgImage, element);
         context.EndProcessingInlineSvg();
     }
 }
예제 #6
0
        private void ProcessLangAttribute(Paragraph optionFlatElement, IRenderer originalOptionRenderer)
        {
            IPropertyContainer propertyContainer = originalOptionRenderer.GetModelElement();

            if (propertyContainer is IAccessibleElement)
            {
                String lang = ((IAccessibleElement)propertyContainer).GetAccessibilityProperties().GetLanguage();
                AccessiblePropHelper.TrySetLangAttribute(optionFlatElement, lang);
            }
        }
예제 #7
0
        /// <summary>
        /// Creates a new
        /// <see cref="DivTagWorker"/>
        /// instance.
        /// </summary>
        /// <param name="element">the element</param>
        /// <param name="context">the context</param>
        public DivTagWorker(IElementNode element, ProcessorContext context)
        {
            div = new Div();
            IDictionary <String, String> styles = element.GetStyles();

            inlineHelper = new WaitingInlineElementsHelper(styles == null ? null : styles.Get(CssConstants.WHITE_SPACE
                                                                                              ), styles == null ? null : styles.Get(CssConstants.TEXT_TRANSFORM));
            display = element.GetStyles() != null?element.GetStyles().Get(CssConstants.DISPLAY) : null;

            AccessiblePropHelper.TrySetLangAttribute(div, element);
        }
예제 #8
0
        /// <summary>
        /// Creates a new
        /// <see cref="BrTagWorker"/>
        /// instance.
        /// </summary>
        /// <param name="element">the element</param>
        /// <param name="context">the context</param>
        public BrTagWorker(IElementNode element, ProcessorContext context)
        {
            //There is no mappings for BR element in DefaultTagCssApplierMapping,
            // because only font-family should be applied to <br /> element.
            String fontFamily = element.GetStyles().Get(CssConstants.FONT_FAMILY);
            // TODO DEVSIX-2534
            IList <String> splitFontFamily = FontFamilySplitter.SplitFontFamily(fontFamily);

            newLine.SetFontFamily(splitFontFamily.ToArray(new String[splitFontFamily.Count]));
            AccessiblePropHelper.TrySetLangAttribute(newLine, element);
        }
        /* (non-Javadoc)
         * @see com.itextpdf.html2pdf.attach.ITagWorker#getElementResult()
         */
        public virtual IPropertyContainer GetElementResult()
        {
            TableWrapper tableWrapper = new TableWrapper();

            foreach (Cell cell in rowWrapper.GetCells())
            {
                AccessiblePropHelper.TrySetLangAttribute(cell, lang);
                tableWrapper.AddCell(cell);
            }
            return(tableWrapper.ToTable(null));
        }
예제 #10
0
 /* (non-Javadoc)
  * @see com.itextpdf.html2pdf.attach.ITagWorker#processTagChild(com.itextpdf.html2pdf.attach.ITagWorker, com.itextpdf.html2pdf.attach.ProcessorContext)
  */
 public virtual bool ProcessTagChild(ITagWorker childTagWorker, ProcessorContext context)
 {
     if (childTagWorker.GetElementResult() is Cell)
     {
         Cell cell = (Cell)childTagWorker.GetElementResult();
         AccessiblePropHelper.TrySetLangAttribute(cell, lang);
         rowWrapper.AddCell(cell);
         return(true);
     }
     return(false);
 }
예제 #11
0
 /* (non-Javadoc)
  * @see com.itextpdf.html2pdf.attach.ITagWorker#processEnd(com.itextpdf.html2pdf.html.node.IElementNode, com.itextpdf.html2pdf.attach.ProcessorContext)
  */
 public virtual void ProcessEnd(IElementNode element, ProcessorContext context)
 {
     inlineHelper.FlushHangingLeaves(lastParagraph);
     if (elementsContainer != null)
     {
         AccessiblePropHelper.TrySetLangAttribute(elementsContainer, element);
     }
     else
     {
         AccessiblePropHelper.TrySetLangAttribute(lastParagraph, element);
     }
 }
예제 #12
0
        /// <summary>
        /// Creates a new
        /// <see cref="ImgTagWorker"/>
        /// instance.
        /// </summary>
        /// <param name="element">the element</param>
        /// <param name="context">the context</param>
        public ImgTagWorker(IElementNode element, ProcessorContext context)
        {
            String     src          = element.GetAttribute(AttributeConstants.SRC);
            PdfXObject imageXObject = context.GetResourceResolver().RetrieveImageExtended(src);

            if (imageXObject != null)
            {
                if (imageXObject is PdfImageXObject)
                {
                    image = new ImgTagWorker.HtmlImage((PdfImageXObject)imageXObject);
                }
                else
                {
                    if (imageXObject is PdfFormXObject)
                    {
                        image = new ImgTagWorker.HtmlImage((PdfFormXObject)imageXObject);
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
            }
            display = element.GetStyles() != null?element.GetStyles().Get(CssConstants.DISPLAY) : null;

            if (element.GetStyles() != null && CssConstants.ABSOLUTE.Equals(element.GetStyles().Get(CssConstants.POSITION
                                                                                                    )))
            {
                // TODO DEVSIX-1393: we don't support absolute positioning in inline context.
                // This workaround allows to identify image as an element which needs to be processed outside of inline context.
                // See AbsoluteReplacedHeight001Test.
                display = CssConstants.BLOCK;
            }
            if (image != null)
            {
                String altText = element.GetAttribute(AttributeConstants.ALT);
                if (altText != null)
                {
                    image.GetAccessibilityProperties().SetAlternateDescription(altText);
                }
                AccessiblePropHelper.TrySetLangAttribute(image, element);
            }
            if (image != null)
            {
                String objectFitValue = element.GetStyles() != null?element.GetStyles().Get(CssConstants.OBJECT_FIT) : null;

                image.SetObjectFit(GetObjectFitValue(objectFitValue));
            }
        }
예제 #13
0
        /// <summary>
        /// Creates a new
        /// <see cref="TdTagWorker"/>
        /// instance.
        /// </summary>
        /// <param name="element">the element</param>
        /// <param name="context">the context</param>
        public TdTagWorker(IElementNode element, ProcessorContext context)
        {
            int?colspan = CssDimensionParsingUtils.ParseInteger(element.GetAttribute(AttributeConstants.COLSPAN));
            int?rowspan = CssDimensionParsingUtils.ParseInteger(element.GetAttribute(AttributeConstants.ROWSPAN));

            colspan = colspan != null ? colspan : 1;
            rowspan = rowspan != null ? rowspan : 1;
            cell    = new Cell((int)rowspan, (int)colspan);
            cell.SetPadding(0);
            inlineHelper = new WaitingInlineElementsHelper(element.GetStyles().Get(CssConstants.WHITE_SPACE), element.
                                                           GetStyles().Get(CssConstants.TEXT_TRANSFORM));
            display = element.GetStyles() != null?element.GetStyles().Get(CssConstants.DISPLAY) : null;

            AccessiblePropHelper.TrySetLangAttribute(cell, element);
        }
예제 #14
0
 /* (non-Javadoc)
  * @see com.itextpdf.html2pdf.attach.ITagWorker#processEnd(com.itextpdf.html2pdf.html.node.IElementNode, com.itextpdf.html2pdf.attach.ProcessorContext)
  */
 public virtual void ProcessEnd(IElementNode element, ProcessorContext context)
 {
     if (inlineHelper.GetWaitingLeaves().IsEmpty() && spanWrapper.GetElements().IsEmpty())
     {
         inlineHelper.Add("");
     }
     FlushInlineHelper();
     elements = spanWrapper.GetElements();
     foreach (IPropertyContainer elem in elements)
     {
         if (elem is IAccessibleElement)
         {
             AccessiblePropHelper.TrySetLangAttribute((IAccessibleElement)elem, element);
         }
     }
 }
예제 #15
0
 /// <summary>
 /// Creates a new
 /// <see cref="UlOlTagWorker"/>
 /// instance.
 /// </summary>
 /// <param name="element">the element</param>
 /// <param name="context">the context</param>
 public UlOlTagWorker(IElementNode element, ProcessorContext context)
 {
     list = new List().SetListSymbol("");
     //In the case of an ordered list, see if the start attribute can be found
     if (element.GetAttribute(AttributeConstants.START) != null)
     {
         int?startValue = CssDimensionParsingUtils.ParseInteger(element.GetAttribute(AttributeConstants.START));
         if (startValue != null)
         {
             list.SetItemStartIndex((int)startValue);
         }
     }
     inlineHelper = new WaitingInlineElementsHelper(element.GetStyles().Get(CssConstants.WHITE_SPACE), element.
                                                    GetStyles().Get(CssConstants.TEXT_TRANSFORM));
     AccessiblePropHelper.TrySetLangAttribute(list, element);
 }
예제 #16
0
 /* (non-Javadoc)
  * @see com.itextpdf.html2pdf.attach.ITagWorker#processEnd(com.itextpdf.html2pdf.html.node.IElementNode, com.itextpdf.html2pdf.attach.ProcessorContext)
  */
 public override void ProcessEnd(IElementNode element, ProcessorContext context)
 {
     if (parentTagWorker == null)
     {
         base.ProcessEnd(element, context);
         if (context.GetPdfDocument() == null)
         {
             foreach (IElement child in ((Div)base.GetElementResult()).GetChildren())
             {
                 if (child is IAccessibleElement)
                 {
                     AccessiblePropHelper.TrySetLangAttribute((IAccessibleElement)child, lang);
                 }
             }
         }
     }
 }
예제 #17
0
 public virtual void ProcessEnd(IElementNode element, ProcessorContext context)
 {
     if (context.GetPdfDocument() != null)
     {
         PdfDocument document = context.GetPdfDocument();
         //Create Image object
         if (res != null)
         {
             image = processUtil.CreateImageFromProcessingResult(res, document);
             AccessiblePropHelper.TrySetLangAttribute(image, element);
         }
     }
     else
     {
         LOGGER.Error(iText.Html2pdf.LogMessageConstant.PDF_DOCUMENT_NOT_PRESENT);
     }
 }
예제 #18
0
 public override bool ProcessTagChild(ITagWorker childTagWorker, ProcessorContext context)
 {
     if (childTagWorker is OptionTagWorker)
     {
         IPropertyContainer element           = childTagWorker.GetElementResult();
         IPropertyContainer propertyContainer = GetElementResult();
         if (propertyContainer is IAccessibleElement)
         {
             String lang = ((IAccessibleElement)propertyContainer).GetAccessibilityProperties().GetLanguage();
             AccessiblePropHelper.TrySetLangAttribute((Div)childTagWorker.GetElementResult(), lang);
         }
         return(AddBlockChild((IElement)element));
     }
     else
     {
         return(base.ProcessTagChild(childTagWorker, context));
     }
 }
예제 #19
0
 /* (non-Javadoc)
  * @see com.itextpdf.html2pdf.attach.ITagWorker#getElementResult()
  */
 public override IPropertyContainer GetElementResult()
 {
     if (formField == null)
     {
         if (hasChildren)
         {
             Button button = new Button(name);
             button.SetProperty(Html2PdfProperty.FORM_ACCESSIBILITY_LANGUAGE, lang);
             Div div = (Div)base.GetElementResult();
             foreach (IElement element in div.GetChildren())
             {
                 if (element is IAccessibleElement)
                 {
                     AccessiblePropHelper.TrySetLangAttribute((IAccessibleElement)element, lang);
                 }
                 if (element is IBlockElement)
                 {
                     button.Add((IBlockElement)element);
                 }
                 else
                 {
                     if (element is Image)
                     {
                         button.Add((Image)element);
                     }
                 }
             }
             div.GetChildren().Clear();
             formField = button;
         }
         else
         {
             InputButton inputButton = new InputButton(name);
             inputButton.SetProperty(Html2PdfProperty.FORM_ACCESSIBILITY_LANGUAGE, lang);
             inputButton.SetProperty(Html2PdfProperty.FORM_FIELD_VALUE, fallbackContent.ToString().Trim());
             formField = inputButton;
         }
     }
     formField.SetProperty(Html2PdfProperty.FORM_FIELD_FLATTEN, flatten);
     return(formField);
 }
예제 #20
0
        /// <summary>
        /// Creates a new
        /// <see cref="ImgTagWorker"/>
        /// instance.
        /// </summary>
        /// <param name="element">the element</param>
        /// <param name="context">the context</param>
        public ImgTagWorker(IElementNode element, ProcessorContext context)
        {
            String     src          = element.GetAttribute(AttributeConstants.SRC);
            PdfXObject imageXObject = context.GetResourceResolver().RetrieveImageExtended(src);

            if (imageXObject != null)
            {
                if (imageXObject is PdfImageXObject)
                {
                    image = new ImgTagWorker.HtmlImage((PdfImageXObject)imageXObject);
                }
                else
                {
                    if (imageXObject is PdfFormXObject)
                    {
                        image = new ImgTagWorker.HtmlImage((PdfFormXObject)imageXObject);
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
            }
            display = element.GetStyles() != null?element.GetStyles().Get(CssConstants.DISPLAY) : null;

            // TODO this is a workaround for now Imgto that image is not added as inline
            if (element.GetStyles() != null && CssConstants.ABSOLUTE.Equals(element.GetStyles().Get(CssConstants.POSITION
                                                                                                    )))
            {
                display = CssConstants.BLOCK;
            }
            if (image != null)
            {
                String altText = element.GetAttribute(AttributeConstants.ALT);
                if (altText != null)
                {
                    image.GetAccessibilityProperties().SetAlternateDescription(altText);
                }
                AccessiblePropHelper.TrySetLangAttribute(image, element);
            }
        }
예제 #21
0
        /// <summary>
        /// Renders all the rows to a
        /// <see cref="iText.Layout.Element.Table"/>
        /// object.
        /// </summary>
        /// <param name="colgroupsHelper">the colgroups helper class</param>
        /// <returns>the table</returns>
        public virtual Table ToTable(WaitingColgroupsHelper colgroupsHelper)
        {
            Table table;

            if (numberOfColumns > 0)
            {
                table = new Table(GetColWidths(colgroupsHelper));
            }
            else
            {
                // if table is empty, create empty table with single column
                table = new Table(1);
            }
            AccessiblePropHelper.TrySetLangAttribute(table, lang);
            if (headerRows != null)
            {
                for (int i = 0; i < headerRows.Count; i++)
                {
                    if (isRtl)
                    {
                        JavaCollectionsUtil.Reverse(headerRows[i]);
                    }
                    for (int j = 0; j < headerRows[i].Count; j++)
                    {
                        Cell       cell       = headerRows[i][j].cell;
                        ColWrapper colWrapper = colgroupsHelper.GetColWrapper(j);
                        if (colWrapper != null)
                        {
                            if (headerLang == null && cell.GetAccessibilityProperties().GetLanguage() == null)
                            {
                                if (colWrapper.GetLang() != null)
                                {
                                    cell.GetAccessibilityProperties().SetLanguage(colWrapper.GetLang());
                                }
                            }
                        }
                        table.AddHeaderCell(cell);
                    }
                    if (i != headerRows.Count - 1)
                    {
                        table.GetHeader().StartNewRow();
                    }
                }
                AccessiblePropHelper.TrySetLangAttribute(table.GetHeader(), headerLang);
            }
            if (footerRows != null)
            {
                for (int i = 0; i < footerRows.Count; i++)
                {
                    if (isRtl)
                    {
                        JavaCollectionsUtil.Reverse(footerRows[i]);
                    }
                    for (int j = 0; j < footerRows[i].Count; j++)
                    {
                        Cell       cell       = footerRows[i][j].cell;
                        ColWrapper colWrapper = colgroupsHelper.GetColWrapper(j);
                        if (colWrapper != null)
                        {
                            if (footerLang == null && cell.GetAccessibilityProperties().GetLanguage() == null)
                            {
                                if (colWrapper.GetLang() != null)
                                {
                                    cell.GetAccessibilityProperties().SetLanguage(colWrapper.GetLang());
                                }
                            }
                        }
                        table.AddFooterCell(cell);
                    }
                    if (i != footerRows.Count - 1)
                    {
                        table.GetFooter().StartNewRow();
                    }
                }
                AccessiblePropHelper.TrySetLangAttribute(table.GetFooter(), footerLang);
            }
            if (rows != null)
            {
                for (int i = 0; i < rows.Count; i++)
                {
                    if (isRtl)
                    {
                        JavaCollectionsUtil.Reverse(rows[i]);
                    }
                    for (int j = 0; j < rows[i].Count; j++)
                    {
                        table.AddCell(rows[i][j].cell);
                    }
                    if (i != rows.Count - 1)
                    {
                        table.StartNewRow();
                    }
                }
            }
            if (caption != null)
            {
                table.SetCaption(caption);
            }
            return(table);
        }
예제 #22
0
 /* (non-Javadoc)
  * @see com.itextpdf.html2pdf.attach.ITagWorker#processEnd(com.itextpdf.html2pdf.html.node.IElementNode, com.itextpdf.html2pdf.attach.ProcessorContext)
  */
 public virtual void ProcessEnd(IElementNode element, ProcessorContext context)
 {
     FlushWaitingCell();
     table = tableWrapper.ToTable(null);
     AccessiblePropHelper.TrySetLangAttribute(table, element);
 }