/// <summary>Registers a property based on its type.</summary> /// <param name="type">the property type</param> /// <param name="value">the property value</param> /// <param name="resolvedProps">the resolved properties</param> /// <param name="usedTypes">already used types</param> /// <returns>false if the property is invalid. True in all other cases</returns> private static bool PutPropertyBasedOnType(CssBackgroundUtils.BackgroundPropertyType type, String value, IDictionary <CssBackgroundUtils.BackgroundPropertyType, String> resolvedProps, ICollection <CssBackgroundUtils.BackgroundPropertyType > usedTypes) { if (type == CssBackgroundUtils.BackgroundPropertyType.UNDEFINED) { LOGGER.Error(MessageFormatUtil.Format(iText.StyledXmlParser.LogMessageConstant.WAS_NOT_ABLE_TO_DEFINE_BACKGROUND_CSS_SHORTHAND_PROPERTIES , value)); return(false); } if (resolvedProps.Get(type) == null) { resolvedProps.Put(type, value); } else { if (usedTypes.Contains(type)) { resolvedProps.Put(type, resolvedProps.Get(type) + " " + value); } else { resolvedProps.Put(type, resolvedProps.Get(type) + "," + value); } } usedTypes.Add(type); return(true); }
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 AddBackgroundClipAndBackgroundOriginBoxValues(IList <String> boxValues, IDictionary <CssBackgroundUtils.BackgroundPropertyType , String> resolvedProps, ICollection <CssBackgroundUtils.BackgroundPropertyType> usedTypes) { if (boxValues.Count == 1) { return(PutPropertyBasedOnType(CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_CLIP, boxValues[0], resolvedProps , usedTypes)); } else { if (boxValues.Count >= 2) { for (int i = 0; i < 2; i++) { CssBackgroundUtils.BackgroundPropertyType type = i == 0 ? CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_ORIGIN : CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_CLIP; if (!PutPropertyBasedOnType(type, boxValues[i], resolvedProps, usedTypes)) { return(false); } } } } return(true); }
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))); }
/// <summary>Gets background property name corresponding to its type.</summary> /// <param name="propertyType">background property type</param> /// <returns>background property name</returns> public static String GetBackgroundPropertyNameFromType(CssBackgroundUtils.BackgroundPropertyType propertyType ) { switch (propertyType) { case CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_COLOR: { return(CommonCssConstants.BACKGROUND_COLOR); } case CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_IMAGE: { return(CommonCssConstants.BACKGROUND_IMAGE); } case CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_POSITION: { return(CommonCssConstants.BACKGROUND_POSITION); } case CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_POSITION_X: { return(CommonCssConstants.BACKGROUND_POSITION_X); } case CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_POSITION_Y: { return(CommonCssConstants.BACKGROUND_POSITION_Y); } case CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_SIZE: { return(CommonCssConstants.BACKGROUND_SIZE); } case CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_REPEAT: { return(CommonCssConstants.BACKGROUND_REPEAT); } case CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_ORIGIN: { return(CommonCssConstants.BACKGROUND_ORIGIN); } case CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_CLIP: { return(CommonCssConstants.BACKGROUND_CLIP); } case CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_ATTACHMENT: { return(CommonCssConstants.BACKGROUND_ATTACHMENT); } default: { return(CommonCssConstants.UNDEFINED_NAME); } } }
private static CssBackgroundUtils.BackgroundPropertyType ChangePropertyType(CssBackgroundUtils.BackgroundPropertyType propertyType, bool slashEncountered) { if (propertyType == CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_POSITION_X || propertyType == CssBackgroundUtils.BackgroundPropertyType .BACKGROUND_POSITION_Y) { propertyType = CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_POSITION; } if (propertyType == CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_POSITION_OR_SIZE) { return(slashEncountered ? CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_SIZE : CssBackgroundUtils.BackgroundPropertyType .BACKGROUND_POSITION); } if (propertyType == CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_SIZE && !slashEncountered) { return(CssBackgroundUtils.BackgroundPropertyType.UNDEFINED); } if (propertyType == CssBackgroundUtils.BackgroundPropertyType.BACKGROUND_POSITION && slashEncountered) { return(CssBackgroundUtils.BackgroundPropertyType.UNDEFINED); } return(propertyType); }