private static bool ProcessAllSpecifiedProperties(IList <String> props, IDictionary <CssBackgroundUtils.BackgroundPropertyType , String> resolvedProps, ICollection <CssBackgroundUtils.BackgroundPropertyType> usedTypes) { IList <String> boxValues = new List <String>(); bool slashEncountered = false; bool propertyProcessedCorrectly = true; foreach (String value in props) { int slashCharInd = value.IndexOf('/'); if (slashCharInd > 0 && slashCharInd < value.Length - 1 && !slashEncountered && !value.Contains("url(")) { slashEncountered = true; propertyProcessedCorrectly = ProcessValueWithSlash(value, slashCharInd, resolvedProps, usedTypes); } else { CssBackgroundUtils.BackgroundPropertyType type = CssBackgroundUtils.ResolveBackgroundPropertyType(value); if (CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_ORIGIN_OR_CLIP == type) { boxValues.Add(value); } else { propertyProcessedCorrectly = PutPropertyBasedOnType(ChangePropertyType(type, slashEncountered), value, resolvedProps , usedTypes); } } if (!propertyProcessedCorrectly) { return(false); } } return(AddBackgroundClipAndBackgroundOriginBoxValues(boxValues, resolvedProps, usedTypes)); }
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))); }
// 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 )))); }
private static BackgroundRepeat ApplyBackgroundRepeat(IList <String> backgroundRepeatArray, int iteration) { int index = GetBackgroundSidePropertyIndex(backgroundRepeatArray.Count, iteration); if (index != -1) { String[] repeatProps = iText.IO.Util.StringUtil.Split(backgroundRepeatArray[index], " "); if (repeatProps.Length == 1) { if (CommonCssConstants.REPEAT_X.Equals(repeatProps[0])) { return(new BackgroundRepeat(BackgroundRepeat.BackgroundRepeatValue.REPEAT, BackgroundRepeat.BackgroundRepeatValue .NO_REPEAT)); } else { if (CommonCssConstants.REPEAT_Y.Equals(repeatProps[0])) { return(new BackgroundRepeat(BackgroundRepeat.BackgroundRepeatValue.NO_REPEAT, BackgroundRepeat.BackgroundRepeatValue .REPEAT)); } else { BackgroundRepeat.BackgroundRepeatValue value = CssBackgroundUtils.ParseBackgroundRepeat(repeatProps[0]); return(new BackgroundRepeat(value)); } } } else { if (repeatProps.Length == 2) { return(new BackgroundRepeat(CssBackgroundUtils.ParseBackgroundRepeat(repeatProps[0]), CssBackgroundUtils.ParseBackgroundRepeat (repeatProps[1]))); } } } // Valid cases are processed by the block above, and in invalid // situations, the REPEAT property on both axes is used by default return(new BackgroundRepeat()); }
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))); } } } }
private static bool ProcessValueWithSlash(String value, int slashCharInd, IDictionary <CssBackgroundUtils.BackgroundPropertyType , String> resolvedProps, ICollection <CssBackgroundUtils.BackgroundPropertyType> usedTypes) { String value1 = value.JSubstring(0, slashCharInd); CssBackgroundUtils.BackgroundPropertyType typeBeforeSlash = ChangePropertyType(CssBackgroundUtils.ResolveBackgroundPropertyType (value1), false); if (typeBeforeSlash != CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_POSITION && typeBeforeSlash != CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_POSITION_OR_SIZE) { LOGGER.Error(MessageFormatUtil.Format(iText.StyledXmlParser.LogMessageConstant.UNKNOWN_PROPERTY, CommonCssConstants .BACKGROUND_POSITION, value1)); return(false); } String value2 = value.Substring(slashCharInd + 1); CssBackgroundUtils.BackgroundPropertyType typeAfterSlash = ChangePropertyType(CssBackgroundUtils.ResolveBackgroundPropertyType (value2), true); if (typeAfterSlash != CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_SIZE && typeAfterSlash != CssBackgroundUtils.BackgroundPropertyType .BACKGROUND_POSITION_OR_SIZE) { LOGGER.Error(MessageFormatUtil.Format(iText.StyledXmlParser.LogMessageConstant.UNKNOWN_PROPERTY, CommonCssConstants .BACKGROUND_SIZE, value2)); return(false); } return(PutPropertyBasedOnType(typeBeforeSlash, value1, resolvedProps, usedTypes) && PutPropertyBasedOnType (typeAfterSlash, value2, resolvedProps, usedTypes)); }
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); }