Пример #1
0
 /// <summary>Resolves the property type.</summary>
 /// <param name="value">the value</param>
 /// <returns>the property type value</returns>
 private int ResolvePropertyType(String value)
 {
     if (value.Contains("url(") || CssGradientUtil.IsCssLinearGradientValue(value) || CommonCssConstants.NONE.Equals
             (value))
     {
         return(BACKGROUND_IMAGE_TYPE);
     }
     else
     {
         if (CommonCssConstants.BACKGROUND_REPEAT_VALUES.Contains(value))
         {
             return(BACKGROUND_REPEAT_TYPE);
         }
         else
         {
             if (CommonCssConstants.BACKGROUND_ATTACHMENT_VALUES.Contains(value))
             {
                 return(BACKGROUND_ATTACHMENT_TYPE);
             }
             else
             {
                 if (CommonCssConstants.BACKGROUND_POSITION_VALUES.Contains(value))
                 {
                     return(BACKGROUND_POSITION_TYPE);
                 }
                 else
                 {
                     if (CssUtils.IsNumericValue(value) || CssUtils.IsMetricValue(value) || CssUtils.IsRelativeValue(value))
                     {
                         return(BACKGROUND_POSITION_OR_SIZE_TYPE);
                     }
                     else
                     {
                         if (CommonCssConstants.BACKGROUND_SIZE_VALUES.Contains(value))
                         {
                             return(BACKGROUND_POSITION_OR_SIZE_TYPE);
                         }
                         else
                         {
                             if (CssUtils.IsColorProperty(value))
                             {
                                 return(BACKGROUND_COLOR_TYPE);
                             }
                             else
                             {
                                 if (CommonCssConstants.BACKGROUND_ORIGIN_OR_CLIP_VALUES.Contains(value))
                                 {
                                     return(BACKGROUND_ORIGIN_OR_CLIP_TYPE);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return(UNDEFINED_TYPE);
 }
Пример #2
0
        /* (non-Javadoc)
         * @see com.itextpdf.styledxmlparser.css.resolve.shorthand.IShorthandResolver#resolveShorthand(java.lang.String)
         */
        public virtual IList <CssDeclaration> ResolveShorthand(String shorthandExpression)
        {
            String widthPropName = MessageFormatUtil.Format(_0_WIDTH, GetPrefix());
            String stylePropName = MessageFormatUtil.Format(_0_STYLE, GetPrefix());
            String colorPropName = MessageFormatUtil.Format(_0_COLOR, GetPrefix());

            if (CommonCssConstants.INITIAL.Equals(shorthandExpression) || CommonCssConstants.INHERIT.Equals(shorthandExpression
                                                                                                            ))
            {
                return(JavaUtil.ArraysAsList(new CssDeclaration(widthPropName, shorthandExpression), new CssDeclaration(stylePropName
                                                                                                                        , shorthandExpression), new CssDeclaration(colorPropName, shorthandExpression)));
            }
            String[] props            = iText.IO.Util.StringUtil.Split(shorthandExpression, "\\s+");
            String   borderColorValue = null;
            String   borderStyleValue = null;
            String   borderWidthValue = null;

            foreach (String value in props)
            {
                if (CommonCssConstants.INITIAL.Equals(value) || CommonCssConstants.INHERIT.Equals(value))
                {
                    ILog logger = LogManager.GetLogger(typeof(AbstractBorderShorthandResolver));
                    logger.Warn(MessageFormatUtil.Format(iText.StyledXmlParser.LogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION
                                                         , shorthandExpression));
                    return(JavaCollectionsUtil.EmptyList <CssDeclaration>());
                }
                if (CommonCssConstants.BORDER_WIDTH_VALUES.Contains(value) || CssUtils.IsNumericValue(value) || CssUtils.IsMetricValue
                        (value) || CssUtils.IsRelativeValue(value))
                {
                    borderWidthValue = value;
                }
                else
                {
                    if (CommonCssConstants.BORDER_STYLE_VALUES.Contains(value) || value.Equals(CommonCssConstants.AUTO))
                    {
                        // AUTO property value is needed for outline property only
                        borderStyleValue = value;
                    }
                    else
                    {
                        if (CssUtils.IsColorProperty(value))
                        {
                            borderColorValue = value;
                        }
                    }
                }
            }
            IList <CssDeclaration> resolvedDecl = new List <CssDeclaration>();

            resolvedDecl.Add(new CssDeclaration(widthPropName, borderWidthValue == null ? CommonCssConstants.INITIAL :
                                                borderWidthValue));
            resolvedDecl.Add(new CssDeclaration(stylePropName, borderStyleValue == null ? CommonCssConstants.INITIAL :
                                                borderStyleValue));
            resolvedDecl.Add(new CssDeclaration(colorPropName, borderColorValue == null ? CommonCssConstants.INITIAL :
                                                borderColorValue));
            return(resolvedDecl);
        }