Exemplo n.º 1
0
 private bool IsPropertyValueCorrespondsPropertyType(String value)
 {
     CssBackgroundUtils.BackgroundPropertyType propertyType = CssBackgroundUtils.ResolveBackgroundPropertyType(
         value);
     if (propertyType == CssBackgroundUtils.BackgroundPropertyType.UNDEFINED)
     {
         return(false);
     }
     if (CssBackgroundUtils.GetBackgroundPropertyNameFromType(propertyType).Equals(backgroundProperty))
     {
         return(true);
     }
     if (propertyType == CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_POSITION && (CommonCssConstants.BACKGROUND_POSITION_X
                                                                                           .Equals(backgroundProperty) || CommonCssConstants.BACKGROUND_POSITION_Y.Equals(backgroundProperty)))
     {
         return(true);
     }
     if (propertyType == CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_ORIGIN_OR_CLIP && (CommonCssConstants
                                                                                                 .BACKGROUND_CLIP.Equals(backgroundProperty) || CommonCssConstants.BACKGROUND_ORIGIN.Equals(backgroundProperty
                                                                                                                                                                                            )))
     {
         return(true);
     }
     return(propertyType == CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_POSITION_OR_SIZE && (CommonCssConstants
                                                                                                      .BACKGROUND_POSITION_X.Equals(backgroundProperty) || CommonCssConstants.BACKGROUND_POSITION_Y.Equals(backgroundProperty
                                                                                                                                                                                                           ) || CommonCssConstants.BACKGROUND_SIZE.Equals(backgroundProperty)));
 }
Exemplo n.º 2
0
        // With CSS3, you can apply multiple backgrounds to elements. These are layered atop one another
        // with the first background you provide on top and the last background listed in the back. Only
        // the last background can include a background color.

        /* (non-Javadoc)
         * @see com.itextpdf.styledxmlparser.css.resolve.shorthand.IShorthandResolver#resolveShorthand(java.lang.String)
         */
        public virtual IList <CssDeclaration> ResolveShorthand(String shorthandExpression)
        {
            if (CssUtils.IsInitialOrInheritOrUnset(shorthandExpression))
            {
                return(JavaUtil.ArraysAsList(new CssDeclaration(CommonCssConstants.BACKGROUND_COLOR, shorthandExpression),
                                             new CssDeclaration(CommonCssConstants.BACKGROUND_IMAGE, shorthandExpression), new CssDeclaration(CommonCssConstants
                                                                                                                                              .BACKGROUND_POSITION, shorthandExpression), new CssDeclaration(CommonCssConstants.BACKGROUND_SIZE, shorthandExpression
                                                                                                                                                                                                             ), new CssDeclaration(CommonCssConstants.BACKGROUND_REPEAT, shorthandExpression), new CssDeclaration(CommonCssConstants
                                                                                                                                                                                                                                                                                                                  .BACKGROUND_ORIGIN, shorthandExpression), new CssDeclaration(CommonCssConstants.BACKGROUND_CLIP, shorthandExpression
                                                                                                                                                                                                                                                                                                                                                                               ), new CssDeclaration(CommonCssConstants.BACKGROUND_ATTACHMENT, shorthandExpression)));
            }
            if (String.IsNullOrEmpty(shorthandExpression.Trim()))
            {
                LOGGER.Error(MessageFormatUtil.Format(iText.StyledXmlParser.LogMessageConstant.SHORTHAND_PROPERTY_CANNOT_BE_EMPTY
                                                      , CommonCssConstants.BACKGROUND));
                return(new List <CssDeclaration>());
            }
            IList <IList <String> > propsList = CssUtils.ExtractShorthandProperties(shorthandExpression);
            IDictionary <CssBackgroundUtils.BackgroundPropertyType, String> resolvedProps = new Dictionary <CssBackgroundUtils.BackgroundPropertyType
                                                                                                            , String>();

            FillMapWithPropertiesTypes(resolvedProps);
            foreach (IList <String> props in propsList)
            {
                if (!ProcessProperties(props, resolvedProps))
                {
                    return(new List <CssDeclaration>());
                }
            }
            if (resolvedProps.Get(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_COLOR) == null)
            {
                resolvedProps.Put(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_COLOR, CommonCssConstants.TRANSPARENT
                                  );
            }
            if (!CheckProperties(resolvedProps))
            {
                return(new List <CssDeclaration>());
            }
            return(JavaUtil.ArraysAsList(new CssDeclaration(CssBackgroundUtils.GetBackgroundPropertyNameFromType(CssBackgroundUtils.BackgroundPropertyType
                                                                                                                 .BACKGROUND_COLOR), resolvedProps.Get(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_COLOR)), new
                                         CssDeclaration(CssBackgroundUtils.GetBackgroundPropertyNameFromType(CssBackgroundUtils.BackgroundPropertyType
                                                                                                             .BACKGROUND_IMAGE), resolvedProps.Get(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_IMAGE)), new
                                         CssDeclaration(CssBackgroundUtils.GetBackgroundPropertyNameFromType(CssBackgroundUtils.BackgroundPropertyType
                                                                                                             .BACKGROUND_POSITION), resolvedProps.Get(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_POSITION
                                                                                                                                                      )), new CssDeclaration(CssBackgroundUtils.GetBackgroundPropertyNameFromType(CssBackgroundUtils.BackgroundPropertyType
                                                                                                                                                                                                                                  .BACKGROUND_SIZE), resolvedProps.Get(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_SIZE)), new
                                         CssDeclaration(CssBackgroundUtils.GetBackgroundPropertyNameFromType(CssBackgroundUtils.BackgroundPropertyType
                                                                                                             .BACKGROUND_REPEAT), resolvedProps.Get(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_REPEAT)),
                                         new CssDeclaration(CssBackgroundUtils.GetBackgroundPropertyNameFromType(CssBackgroundUtils.BackgroundPropertyType
                                                                                                                 .BACKGROUND_ORIGIN), resolvedProps.Get(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_ORIGIN)),
                                         new CssDeclaration(CssBackgroundUtils.GetBackgroundPropertyNameFromType(CssBackgroundUtils.BackgroundPropertyType
                                                                                                                 .BACKGROUND_CLIP), resolvedProps.Get(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_CLIP)), new
                                         CssDeclaration(CssBackgroundUtils.GetBackgroundPropertyNameFromType(CssBackgroundUtils.BackgroundPropertyType
                                                                                                             .BACKGROUND_ATTACHMENT), resolvedProps.Get(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_ATTACHMENT
                                                                                                                                                        ))));
        }
Exemplo n.º 3
0
 private static void FillNotProcessedProperties(IDictionary <CssBackgroundUtils.BackgroundPropertyType, String
                                                             > resolvedProps, ICollection <CssBackgroundUtils.BackgroundPropertyType> usedTypes)
 {
     foreach (CssBackgroundUtils.BackgroundPropertyType type in new List <CssBackgroundUtils.BackgroundPropertyType
                                                                          >(resolvedProps.Keys))
     {
         if (!usedTypes.Contains(type) && type != CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_COLOR)
         {
             if (resolvedProps.Get(type) == null)
             {
                 resolvedProps.Put(type, CssDefaults.GetDefaultValue(CssBackgroundUtils.GetBackgroundPropertyNameFromType(type
                                                                                                                          )));
             }
             else
             {
                 resolvedProps.Put(type, resolvedProps.Get(type) + "," + CssDefaults.GetDefaultValue(CssBackgroundUtils.GetBackgroundPropertyNameFromType
                                                                                                         (type)));
             }
         }
     }
 }
Exemplo n.º 4
0
 private static bool CheckProperties(IDictionary <CssBackgroundUtils.BackgroundPropertyType, String> resolvedProps
                                     )
 {
     foreach (KeyValuePair <CssBackgroundUtils.BackgroundPropertyType, String> property in resolvedProps)
     {
         if (!CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CssBackgroundUtils.GetBackgroundPropertyNameFromType
                                                                                     (property.Key), property.Value)))
         {
             LOGGER.Error(MessageFormatUtil.Format(iText.StyledXmlParser.LogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION
                                                   , property.Value));
             return(false);
         }
         IShorthandResolver resolver = ShorthandResolverFactory.GetShorthandResolver(CssBackgroundUtils.GetBackgroundPropertyNameFromType
                                                                                         (property.Key));
         if (resolver != null && resolver.ResolveShorthand(property.Value).IsEmpty())
         {
             return(false);
         }
     }
     return(true);
 }