/// <summary>Applies opacity to an element.</summary>
 /// <param name="cssProps">the CSS properties</param>
 /// <param name="context">the processor context</param>
 /// <param name="container">the container element</param>
 public static void ApplyOpacity(IDictionary<String, String> cssProps, ProcessorContext context, IPropertyContainer
      container) {
     float? opacity = CssDimensionParsingUtils.ParseFloat(cssProps.Get(CssConstants.OPACITY));
     if (opacity != null) {
         container.SetProperty(Property.OPACITY, opacity);
     }
 }
            /* (non-Javadoc)
             * @see com.itextpdf.html2pdf.css.resolve.HtmlStylesToCssConverter.IAttributeConverter#convert(com.itextpdf.styledxmlparser.html.node.IElementNode, java.lang.String)
             */
            public virtual IList <CssDeclaration> Convert(IElementNode element, String value)
            {
                float?cellPadding = CssDimensionParsingUtils.ParseFloat(value);

                if (cellPadding != null)
                {
                    if (TagConstants.TABLE.Equals(element.Name()))
                    {
                        IDictionary <String, String> styles = new Dictionary <String, String>();
                        styles.Put(CssConstants.PADDING, value + "px");
                        ApplyPaddingsToTableCells(element, styles);
                    }
                }
                return(JavaCollectionsUtil.EmptyList <CssDeclaration>());
            }
Ejemplo n.º 3
0
 private static void SetLineHeight(IPropertyContainer elementToSet, String lineHeight, float em, float rem)
 {
     if (lineHeight != null && !CssConstants.NORMAL.Equals(lineHeight) && !CssConstants.AUTO.Equals(lineHeight)
         )
     {
         if (CssTypesValidationUtils.IsNumericValue(lineHeight))
         {
             float?number = CssDimensionParsingUtils.ParseFloat(lineHeight);
             if (number != null)
             {
                 elementToSet.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateMultipliedValue((float)number));
             }
             else
             {
                 elementToSet.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateNormalValue());
             }
         }
         else
         {
             UnitValue lineHeightValue = CssDimensionParsingUtils.ParseLengthValueToPt(lineHeight, em, rem);
             if (lineHeightValue != null && lineHeightValue.IsPointValue())
             {
                 elementToSet.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateFixedValue(lineHeightValue.GetValue()));
             }
             else
             {
                 if (lineHeightValue != null)
                 {
                     elementToSet.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateMultipliedValue(lineHeightValue.GetValue()
                                                                                                     / 100f));
                 }
                 else
                 {
                     elementToSet.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateNormalValue());
                 }
             }
         }
     }
     else
     {
         elementToSet.SetProperty(Property.LINE_HEIGHT, LineHeight.CreateNormalValue());
     }
 }
Ejemplo n.º 4
0
 private static void SetLineHeightByLeading(IPropertyContainer element, String lineHeight, float em, float
                                            rem)
 {
     // specification does not give auto as a possible lineHeight value
     // nevertheless some browsers compute it as normal so we apply the same behaviour.
     // What's more, it's basically the same thing as if lineHeight is not set in the first place
     if (lineHeight != null && !CssConstants.NORMAL.Equals(lineHeight) && !CssConstants.AUTO.Equals(lineHeight)
         )
     {
         if (CssTypesValidationUtils.IsNumericValue(lineHeight))
         {
             float?mult = CssDimensionParsingUtils.ParseFloat(lineHeight);
             if (mult != null)
             {
                 element.SetProperty(Property.LEADING, new Leading(Leading.MULTIPLIED, (float)mult));
             }
         }
         else
         {
             UnitValue lineHeightValue = CssDimensionParsingUtils.ParseLengthValueToPt(lineHeight, em, rem);
             if (lineHeightValue != null && lineHeightValue.IsPointValue())
             {
                 element.SetProperty(Property.LEADING, new Leading(Leading.FIXED, lineHeightValue.GetValue()));
             }
             else
             {
                 if (lineHeightValue != null)
                 {
                     element.SetProperty(Property.LEADING, new Leading(Leading.MULTIPLIED, lineHeightValue.GetValue() / 100));
                 }
             }
         }
     }
     else
     {
         element.SetProperty(Property.LEADING, new Leading(Leading.MULTIPLIED, DEFAULT_LINE_HEIGHT));
     }
 }
            /* (non-Javadoc)
             * @see com.itextpdf.html2pdf.css.resolve.HtmlStylesToCssConverter.IAttributeConverter#convert(com.itextpdf.styledxmlparser.html.node.IElementNode, java.lang.String)
             */
            public virtual IList <CssDeclaration> Convert(IElementNode element, String value)
            {
                float?width = CssDimensionParsingUtils.ParseFloat(value);

                if (width != null)
                {
                    if (TagConstants.TABLE.Equals(element.Name()) && width != 0)
                    {
                        IList <CssDeclaration>       declarations = new BorderShorthandResolver().ResolveShorthand("1px solid");
                        IDictionary <String, String> styles       = new Dictionary <String, String>(declarations.Count);
                        foreach (CssDeclaration declaration in declarations)
                        {
                            styles.Put(declaration.GetProperty(), declaration.GetExpression());
                        }
                        ApplyBordersToTableCells(element, styles);
                    }
                    if (width >= 0)
                    {
                        return(JavaUtil.ArraysAsList(new CssDeclaration(CssConstants.BORDER, value + "px solid")));
                    }
                }
                return(JavaCollectionsUtil.EmptyList <CssDeclaration>());
            }