Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new
        /// <see cref="ColTagWorker"/>
        /// instance.
        /// </summary>
        /// <param name="element">the element</param>
        /// <param name="context">the context</param>
        public ColTagWorker(IElementNode element, ProcessorContext context)
        {
            int?span = CssDimensionParsingUtils.ParseInteger(element.GetAttribute(AttributeConstants.SPAN));

            col = new ColWrapper(span != null ? (int)span : 1);
            col.SetLang(element.GetAttribute(AttributeConstants.LANG));
        }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
0
        /// <summary>Resolves a normalized form name.</summary>
        /// <param name="name">the proposed name</param>
        /// <returns>the resolved name</returns>
        private String ResolveNormalizedFormName(String name)
        {
            int separatorIndex = name.LastIndexOf(NAME_COUNT_SEPARATOR);
            int?nameIndex      = null;

            if (separatorIndex != -1 && separatorIndex < name.Length)
            {
                String numberString = name.Substring(separatorIndex + 1);
                nameIndex = CssDimensionParsingUtils.ParseInteger(numberString);
                //Treat number as index only in case it is positive
                if (nameIndex != null && nameIndex > 0)
                {
                    name = name.JSubstring(0, separatorIndex);
                }
            }
            int?savedIndex  = names.Get(name);
            int indexToSave = savedIndex != null ? savedIndex.Value + 1 : 0;

            if (nameIndex != null && indexToSave < nameIndex.Value)
            {
                indexToSave = nameIndex.Value;
            }
            names.Put(name, indexToSave);
            return(indexToSave == 0 ? name : name + NAME_COUNT_SEPARATOR + indexToSave.ToString());
        }
        /// <summary>Applies column styles.</summary>
        /// <param name="node">the node</param>
        /// <param name="rowColHelper">the helper class to keep track of the position inside the table</param>
        private void ApplyColStyles(INode node, RowColHelper rowColHelper)
        {
            int          col;
            IElementNode element;

            foreach (INode child in node.ChildNodes())
            {
                if (child is IElementNode)
                {
                    element = (IElementNode)child;
                    if (TagConstants.TR.Equals(element.Name()))
                    {
                        ApplyColStyles(element, rowColHelper);
                        rowColHelper.NewRow();
                    }
                    else
                    {
                        if (TagConstants.TH.Equals(element.Name()) || TagConstants.TD.Equals(element.Name()))
                        {
                            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;
                            col     = rowColHelper.MoveToNextEmptyCol();
                            if (GetColWrapper(col) != null)
                            {
                                ColWrapper colWrapper = GetColWrapper(col);
                                if (colWrapper.GetCellCssProps() != null)
                                {
                                    element.AddAdditionalHtmlStyles(colWrapper.GetCellCssProps());
                                }
                                String elemLang = element.GetAttribute(AttributeConstants.LANG);
                                String trLang   = null;
                                if (node is IElementNode)
                                {
                                    trLang = ((IElementNode)node).GetAttribute(AttributeConstants.LANG);
                                }
                                if (trLang == null && colWrapper.GetLang() != null && elemLang == null)
                                {
                                    element.GetAttributes().SetAttribute(AttributeConstants.LANG, colWrapper.GetLang());
                                }
                            }
                            rowColHelper.UpdateCurrentPosition((int)colspan, (int)rowspan);
                        }
                        else
                        {
                            ApplyColStyles(child, rowColHelper);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
 }
        /// <summary>
        /// Creates a new
        /// <see cref="TextAreaTagWorker"/>
        /// instance.
        /// </summary>
        /// <param name="element">the element</param>
        /// <param name="context">the context</param>
        public TextAreaTagWorker(IElementNode element, ProcessorContext context)
        {
            String name = element.GetAttribute(AttributeConstants.ID);

            if (name == null)
            {
                name = DEFAULT_TEXTAREA_NAME;
            }
            name     = context.GetFormFieldNameResolver().ResolveFormName(name);
            textArea = new TextArea(name);
            int?rows = CssDimensionParsingUtils.ParseInteger(element.GetAttribute(AttributeConstants.ROWS));
            int?cols = CssDimensionParsingUtils.ParseInteger(element.GetAttribute(AttributeConstants.COLS));

            textArea.SetProperty(Html2PdfProperty.FORM_FIELD_ROWS, rows);
            textArea.SetProperty(Html2PdfProperty.FORM_FIELD_COLS, cols);
            textArea.SetProperty(Html2PdfProperty.FORM_FIELD_FLATTEN, !context.IsCreateAcroForm());
            textArea.SetProperty(Html2PdfProperty.FORM_ACCESSIBILITY_LANGUAGE, element.GetAttribute(AttributeConstants
                                                                                                    .LANG));
            String placeholder = element.GetAttribute(AttributeConstants.PLACEHOLDER);

            if (null != placeholder)
            {
                Paragraph paragraph;
                if (String.IsNullOrEmpty(placeholder))
                {
                    paragraph = new Paragraph();
                }
                else
                {
                    if (String.IsNullOrEmpty(placeholder.Trim()))
                    {
                        paragraph = new Paragraph("\u00A0");
                    }
                    else
                    {
                        paragraph = new Paragraph(placeholder);
                    }
                }
                textArea.SetPlaceholder(paragraph.SetMargin(0));
            }
            display = element.GetStyles() != null?element.GetStyles().Get(CssConstants.DISPLAY) : null;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a new
        /// <see cref="SelectTagWorker"/>
        /// instance.
        /// </summary>
        /// <param name="element">the element</param>
        /// <param name="context">the context</param>
        public SelectTagWorker(IElementNode element, ProcessorContext context)
        {
            String name = context.GetFormFieldNameResolver().ResolveFormName(element.GetAttribute(AttributeConstants.NAME
                                                                                                  ));
            bool multipleAttr = element.GetAttribute(AttributeConstants.MULTIPLE) != null;
            int? sizeAttr     = CssDimensionParsingUtils.ParseInteger(element.GetAttribute(AttributeConstants.SIZE));
            int  size         = GetSelectSize(sizeAttr, multipleAttr);

            if (size > 1 || multipleAttr)
            {
                selectElement = new ListBoxField(name, size, multipleAttr);
            }
            else
            {
                selectElement = new ComboBoxField(name);
            }
            String lang = element.GetAttribute(AttributeConstants.LANG);

            selectElement.SetProperty(Html2PdfProperty.FORM_ACCESSIBILITY_LANGUAGE, lang);
            selectElement.SetProperty(Html2PdfProperty.FORM_FIELD_FLATTEN, !context.IsCreateAcroForm());
            display = element.GetStyles() != null?element.GetStyles().Get(CssConstants.DISPLAY) : null;
        }
 private static void ProcessIncrement(String counterIncrement, CssContext context)
 {
     if (counterIncrement != null)
     {
         CssCounterManager counterManager = context.GetCounterManager();
         String[]          @params        = iText.IO.Util.StringUtil.Split(counterIncrement, " ");
         for (int i = 0; i < @params.Length; i++)
         {
             String counterName = @params[i];
             int?   possibleIncrementValue;
             if (i + 1 < @params.Length && (possibleIncrementValue = CssDimensionParsingUtils.ParseInteger(@params[i +
                                                                                                                   1])) != null)
             {
                 counterManager.IncrementCounter(counterName, (int)possibleIncrementValue);
                 i++;
             }
             else
             {
                 counterManager.IncrementCounter(counterName);
             }
         }
     }
 }
 /// <summary>Applies orphans and widows properties to an element.</summary>
 /// <param name="cssProps">the CSS properties</param>
 /// <param name="element">to which the property will be applied.</param>
 public static void ApplyOrphansAndWidows(IDictionary <String, String> cssProps, IPropertyContainer element)
 {
     if (cssProps != null)
     {
         if (cssProps.ContainsKey(CssConstants.WIDOWS))
         {
             int?minWidows = CssDimensionParsingUtils.ParseInteger(cssProps.Get(CssConstants.WIDOWS));
             if (minWidows != null && minWidows > 0)
             {
                 element.SetProperty(Property.WIDOWS_CONTROL, new ParagraphWidowsControl(minWidows.Value, MAX_LINES_TO_MOVE
                                                                                         , OVERFLOW_PARAGRAPH_ON_VIOLATION));
             }
         }
         if (cssProps.ContainsKey(CssConstants.ORPHANS))
         {
             int?minOrphans = CssDimensionParsingUtils.ParseInteger(cssProps.Get(CssConstants.ORPHANS));
             if (minOrphans != null && minOrphans > 0)
             {
                 element.SetProperty(Property.ORPHANS_CONTROL, new ParagraphOrphansControl(minOrphans.Value));
             }
         }
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a new
        /// <see cref="InputTagWorker"/>
        /// instance.
        /// </summary>
        /// <param name="element">the element</param>
        /// <param name="context">the context</param>
        public InputTagWorker(IElementNode element, ProcessorContext context)
        {
            String lang      = element.GetAttribute(AttributeConstants.LANG);
            String inputType = element.GetAttribute(AttributeConstants.TYPE);

            if (!AttributeConstants.INPUT_TYPE_VALUES.Contains(inputType))
            {
                if (null != inputType && 0 != inputType.Length)
                {
                    ILog logger = LogManager.GetLogger(typeof(iText.Html2pdf.Attach.Impl.Tags.InputTagWorker));
                    logger.Warn(MessageFormatUtil.Format(iText.Html2pdf.LogMessageConstant.INPUT_TYPE_IS_INVALID, inputType));
                }
                inputType = AttributeConstants.TEXT;
            }
            String value = element.GetAttribute(AttributeConstants.VALUE);
            String name  = context.GetFormFieldNameResolver().ResolveFormName(element.GetAttribute(AttributeConstants.NAME
                                                                                                   ));

            // Default input type is text
            if (inputType == null || AttributeConstants.TEXT.Equals(inputType) || AttributeConstants.EMAIL.Equals(inputType
                                                                                                                  ) || AttributeConstants.PASSWORD.Equals(inputType) || AttributeConstants.NUMBER.Equals(inputType))
            {
                int?size = CssDimensionParsingUtils.ParseInteger(element.GetAttribute(AttributeConstants.SIZE));
                formElement = new InputField(name);
                value       = PreprocessInputValue(value, inputType);
                // process placeholder instead
                String placeholder = element.GetAttribute(AttributeConstants.PLACEHOLDER);
                if (null != placeholder)
                {
                    Paragraph paragraph;
                    if (String.IsNullOrEmpty(placeholder))
                    {
                        paragraph = new Paragraph();
                    }
                    else
                    {
                        if (String.IsNullOrEmpty(placeholder.Trim()))
                        {
                            paragraph = new Paragraph("\u00A0");
                        }
                        else
                        {
                            paragraph = new Paragraph(placeholder);
                        }
                    }
                    ((InputField)formElement).SetPlaceholder(paragraph.SetMargin(0));
                }
                formElement.SetProperty(Html2PdfProperty.FORM_FIELD_VALUE, value);
                formElement.SetProperty(Html2PdfProperty.FORM_FIELD_SIZE, size);
                if (AttributeConstants.PASSWORD.Equals(inputType))
                {
                    formElement.SetProperty(Html2PdfProperty.FORM_FIELD_PASSWORD_FLAG, true);
                }
            }
            else
            {
                if (AttributeConstants.SUBMIT.Equals(inputType) || AttributeConstants.BUTTON.Equals(inputType))
                {
                    formElement = new InputButton(name);
                    formElement.SetProperty(Html2PdfProperty.FORM_FIELD_VALUE, value);
                }
                else
                {
                    if (AttributeConstants.CHECKBOX.Equals(inputType))
                    {
                        formElement = new CheckBox(name);
                        String @checked = element.GetAttribute(AttributeConstants.CHECKED);
                        if (null != @checked)
                        {
                            formElement.SetProperty(Html2PdfProperty.FORM_FIELD_CHECKED, @checked);
                        }
                    }
                    else
                    {
                        // has attribute == is checked
                        if (AttributeConstants.RADIO.Equals(inputType))
                        {
                            formElement = new Radio(name);
                            String radioGroupName = element.GetAttribute(AttributeConstants.NAME);
                            formElement.SetProperty(Html2PdfProperty.FORM_FIELD_VALUE, radioGroupName);
                            String @checked = element.GetAttribute(AttributeConstants.CHECKED);
                            if (null != @checked)
                            {
                                context.GetRadioCheckResolver().CheckField(radioGroupName, (Radio)formElement);
                                formElement.SetProperty(Html2PdfProperty.FORM_FIELD_CHECKED, @checked);
                            }
                        }
                        else
                        {
                            // has attribute == is checked
                            ILog logger = LogManager.GetLogger(typeof(iText.Html2pdf.Attach.Impl.Tags.InputTagWorker));
                            logger.Error(MessageFormatUtil.Format(iText.Html2pdf.LogMessageConstant.INPUT_TYPE_IS_NOT_SUPPORTED, inputType
                                                                  ));
                        }
                    }
                }
            }
            if (formElement != null)
            {
                formElement.SetProperty(Html2PdfProperty.FORM_FIELD_FLATTEN, !context.IsCreateAcroForm());
                formElement.SetProperty(Html2PdfProperty.FORM_ACCESSIBILITY_LANGUAGE, lang);
            }
            display = element.GetStyles() != null?element.GetStyles().Get(CssConstants.DISPLAY) : null;
        }