// ................................................................. // // Processing CSS Attributes // // ................................................................. internal static void GetElementPropertiesFromCssAttributes(XElement htmlElement, string elementName, IDictionary<string, string> localProperties, HtmlToXamlContext context) { string styleFromStylesheet = context.Stylesheet.GetStyle(elementName, context.SourceContext); string styleInline = HtmlToXamlConverter.GetAttribute(htmlElement, "style"); // Combine styles from stylesheet and from inline attribute. // The order is important - the latter styles will override the former. string style = styleFromStylesheet != null ? styleFromStylesheet : null; if (styleInline != null) { style = style == null ? styleInline : (style + ";" + styleInline); } // Apply local style to current formatting properties if (style != null) { string[] styleValues = style.Split(';'); for (int i = 0; i < styleValues.Length; i++) { string[] styleNameValue; styleNameValue = styleValues[i].Split(':'); if (styleNameValue.Length == 2) { string styleName = styleNameValue[0].Trim().ToLower(); string styleValue = HtmlToXamlConverter.UnQuote(styleNameValue[1].Trim()).ToLower(); int nextIndex = 0; switch (styleName) { case "font": ParseCssFont(styleValue, localProperties); break; case "font-family": ParseCssFontFamily(styleValue, ref nextIndex, localProperties); break; case "font-size": ParseCssSize(styleValue, ref nextIndex, localProperties, "font-size", /*mustBeNonNegative:*/true); break; case "font-style": ParseCssFontStyle(styleValue, ref nextIndex, localProperties); break; case "font-weight": ParseCssFontWeight(styleValue, ref nextIndex, localProperties); break; case "font-variant": ParseCssFontVariant(styleValue, ref nextIndex, localProperties); break; case "line-height": ParseCssSize(styleValue, ref nextIndex, localProperties, "line-height", /*mustBeNonNegative:*/true); break; case "word-spacing": // Implement word-spacing conversion break; case "letter-spacing": // Implement letter-spacing conversion break; case "color": ParseCssColor(styleValue, ref nextIndex, localProperties, "color"); break; case "text-decoration": ParseCssTextDecoration(styleValue, ref nextIndex, localProperties); break; case "text-transform": ParseCssTextTransform(styleValue, ref nextIndex, localProperties); break; case "background-color": ParseCssColor(styleValue, ref nextIndex, localProperties, "background-color"); break; case "background": // TODO: need to parse composite background property ParseCssBackground(styleValue, ref nextIndex, localProperties); break; case "text-align": ParseCssTextAlign(styleValue, ref nextIndex, localProperties); break; case "vertical-align": ParseCssVerticalAlign(styleValue, ref nextIndex, localProperties); break; case "text-indent": ParseCssSize(styleValue, ref nextIndex, localProperties, "text-indent", /*mustBeNonNegative:*/false); break; case "width": case "height": ParseCssSize(styleValue, ref nextIndex, localProperties, styleName, /*mustBeNonNegative:*/true); break; case "margin": // top/right/bottom/left ParseCssRectangleProperty(styleValue, ref nextIndex, localProperties, styleName); break; case "margin-top": case "margin-right": case "margin-bottom": case "margin-left": ParseCssSize(styleValue, ref nextIndex, localProperties, styleName, /*mustBeNonNegative:*/true); break; case "padding": ParseCssRectangleProperty(styleValue, ref nextIndex, localProperties, styleName); break; case "padding-top": case "padding-right": case "padding-bottom": case "padding-left": ParseCssSize(styleValue, ref nextIndex, localProperties, styleName, /*mustBeNonNegative:*/true); break; case "border": ParseCssBorder(styleValue, ref nextIndex, localProperties); break; case "border-style": case "border-width": case "border-color": ParseCssRectangleProperty(styleValue, ref nextIndex, localProperties, styleName); break; case "border-top": case "border-right": case "border-left": case "border-bottom": // Parse css border style break; // NOTE: css names for elementary border styles have side indications in the middle (top/bottom/left/right) // In our internal notation we intentionally put them at the end - to unify processing in ParseCssRectangleProperty method case "border-top-style": case "border-right-style": case "border-left-style": case "border-bottom-style": case "border-top-color": case "border-right-color": case "border-left-color": case "border-bottom-color": case "border-top-width": case "border-right-width": case "border-left-width": case "border-bottom-width": // Parse css border style break; case "display": // Implement display style conversion break; case "float": ParseCssFloat(styleValue, ref nextIndex, localProperties); break; case "clear": ParseCssClear(styleValue, ref nextIndex, localProperties); break; case "border-collapse": if ("collapse".Equals(styleValue)) { localProperties.Add("border-collapse", "collapse"); } break; default: break; } } } } }
private bool MatchSelectorLevel(string selectorLevel, XmlElement xmlElement) { if (selectorLevel.Length == 0) { return(false); } int num = selectorLevel.IndexOf('.'); int num2 = selectorLevel.IndexOf('#'); string text = null; string text2 = null; string text3 = null; if (num >= 0) { if (num > 0) { text3 = selectorLevel.Substring(0, num); } text = selectorLevel.Substring(num + 1); } else { if (num2 >= 0) { if (num2 > 0) { text3 = selectorLevel.Substring(0, num2); } text2 = selectorLevel.Substring(num2 + 1); } else { text3 = selectorLevel; } } return((text3 == null || !(text3 != xmlElement.LocalName)) && (text2 == null || !(HtmlToXamlConverter.GetAttribute(xmlElement, "id") != text2)) && (text == null || !(HtmlToXamlConverter.GetAttribute(xmlElement, "class") != text))); }
private static bool MatchSelectorLevel ( string selectorLevel, XmlElement xmlElement) { if (selectorLevel.Length == 0) { return(false); } int indexOfDot = selectorLevel.IndexOf('.'); int indexOfPound = selectorLevel.IndexOf('#'); string selectorClass = null; string selectorId = null; string selectorTag = null; if (indexOfDot >= 0) { if (indexOfDot > 0) { selectorTag = selectorLevel.Substring ( 0, indexOfDot); } selectorClass = selectorLevel.Substring(indexOfDot + 1); } else if (indexOfPound >= 0) { if (indexOfPound > 0) { selectorTag = selectorLevel.Substring ( 0, indexOfPound); } selectorId = selectorLevel.Substring(indexOfPound + 1); } else { selectorTag = selectorLevel; } if (selectorTag != null && selectorTag != xmlElement.LocalName) { return(false); } if (selectorId != null && HtmlToXamlConverter.GetAttribute ( xmlElement, "id") != selectorId) { return(false); } return(selectorClass == null || HtmlToXamlConverter.GetAttribute ( xmlElement, "class") == selectorClass); }
internal static void GetElementPropertiesFromCssAttributes(XmlElement htmlElement, string elementName, CssStylesheet stylesheet, Hashtable localProperties, List <XmlElement> sourceContext) { string style = stylesheet.GetStyle(elementName, sourceContext); string attribute = HtmlToXamlConverter.GetAttribute(htmlElement, "style"); string text = (style != null) ? style : null; if (attribute != null) { text = ((text == null) ? attribute : (text + ";" + attribute)); } if (text != null) { string[] array = text.Split(new char[] { ';' }); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(new char[] { ':' }); if (array2.Length == 2) { string text2 = array2[0].Trim().ToLower(); string text3 = array2[1].Trim(); string styleValue = text3.ToLower(); int num = 0; string key; switch (key = text2) { case "font": HtmlCssParser.ParseCssFont(text3, localProperties); break; case "font-family": HtmlCssParser.ParseCssFontFamily(text3, ref num, localProperties); break; case "font-size": HtmlCssParser.ParseCssSize(styleValue, ref num, localProperties, "font-size", true); break; case "font-style": HtmlCssParser.ParseCssFontStyle(styleValue, ref num, localProperties); break; case "font-weight": HtmlCssParser.ParseCssFontWeight(styleValue, ref num, localProperties); break; case "font-variant": HtmlCssParser.ParseCssFontVariant(styleValue, ref num, localProperties); break; case "line-height": HtmlCssParser.ParseCssSize(styleValue, ref num, localProperties, "line-height", true); break; case "color": HtmlCssParser.ParseCssColor(styleValue, ref num, localProperties, "color"); break; case "text-decoration": HtmlCssParser.ParseCssTextDecoration(styleValue, ref num, localProperties); break; case "text-transform": HtmlCssParser.ParseCssTextTransform(styleValue, ref num, localProperties); break; case "background-color": HtmlCssParser.ParseCssColor(styleValue, ref num, localProperties, "background-color"); break; case "background": HtmlCssParser.ParseCssColor(styleValue, ref num, localProperties, "background-color"); break; case "text-align": HtmlCssParser.ParseCssTextAlign(styleValue, ref num, localProperties); break; case "vertical-align": HtmlCssParser.ParseCssVerticalAlign(styleValue, ref num, localProperties); break; case "text-indent": HtmlCssParser.ParseCssSize(styleValue, ref num, localProperties, "text-indent", false); break; case "width": case "height": HtmlCssParser.ParseCssSize(styleValue, ref num, localProperties, text2, true); break; case "margin": HtmlCssParser.ParseCssRectangleProperty(styleValue, ref num, localProperties, text2); break; case "margin-top": case "margin-right": case "margin-bottom": case "margin-left": HtmlCssParser.ParseCssSize(styleValue, ref num, localProperties, text2, true); break; case "padding": HtmlCssParser.ParseCssRectangleProperty(styleValue, ref num, localProperties, text2); break; case "padding-top": case "padding-right": case "padding-bottom": case "padding-left": HtmlCssParser.ParseCssSize(styleValue, ref num, localProperties, text2, true); break; case "border": HtmlCssParser.ParseCssBorder(styleValue, ref num, localProperties); break; case "border-style": case "border-width": case "border-color": HtmlCssParser.ParseCssRectangleProperty(styleValue, ref num, localProperties, text2); break; case "border-top": case "border-right": case "border-left": case "border-bottom": HtmlCssParser.ParseCssRectangleSideProperty(styleValue, ref num, localProperties, text2); break; case "float": HtmlCssParser.ParseCssFloat(styleValue, ref num, localProperties); break; case "clear": HtmlCssParser.ParseCssClear(styleValue, ref num, localProperties); break; } } } } }
internal static void GetElementPropertiesFromCssAttributes(XmlElement htmlElement, string elementName, CssStylesheet stylesheet, Hashtable localProperties, List <XmlElement> sourceContext) { var styleFromStylesheet = stylesheet.GetStyle(elementName, sourceContext); var styleInline = HtmlToXamlConverter.GetAttribute(htmlElement, "style"); var style = styleFromStylesheet; if (styleInline != null) { style = style == null ? styleInline : style + ";" + styleInline; } if (style == null) { return; } var styleValues = style.Split(';'); foreach (var t in styleValues) { var styleNameValue = t.Split(':'); if (styleNameValue.Length != 2) { continue; } var styleName = styleNameValue[0].Trim().ToLower(CultureInfo.GetCultureInfo("en-US")); var styleValue = HtmlToXamlConverter.UnQuote(styleNameValue[1].Trim()).ToLower(CultureInfo.GetCultureInfo("en-US")); var nextIndex = 0; switch (styleName) { case "font": ParseCssFont(styleValue, localProperties); break; case "font-family": ParseCssFontFamily(styleValue, ref nextIndex, localProperties); break; case "font-size": ParseCssSize(styleValue, ref nextIndex, localProperties, "font-size", true); break; case "font-style": ParseCssFontStyle(styleValue, ref nextIndex, localProperties); break; case "font-weight": ParseCssFontWeight(styleValue, ref nextIndex, localProperties); break; case "font-variant": ParseCssFontVariant(styleValue, ref nextIndex, localProperties); break; case "line-height": ParseCssSize(styleValue, ref nextIndex, localProperties, "line-height", true); break; case "word-spacing": break; case "letter-spacing": break; case "color": ParseCssColor(styleValue, ref nextIndex, localProperties, "color"); break; case "text-decoration": ParseCssTextDecoration(styleValue, ref nextIndex, localProperties); break; case "text-transform": ParseCssTextTransform(styleValue, ref nextIndex, localProperties); break; case "background-color": ParseCssColor(styleValue, ref nextIndex, localProperties, "background-color"); break; case "background": //ParseCssBackground(styleValue, ref nextIndex, localProperties); break; case "text-align": ParseCssTextAlign(styleValue, ref nextIndex, localProperties); break; case "vertical-align": ParseCssVerticalAlign(styleValue, ref nextIndex, localProperties); break; case "text-indent": ParseCssSize(styleValue, ref nextIndex, localProperties, "text-indent", false); break; case "width": case "height": ParseCssSize(styleValue, ref nextIndex, localProperties, styleName, true); break; case "margin": ParseCssRectangleProperty(styleValue, ref nextIndex, localProperties, styleName); break; case "margin-top": case "margin-right": case "margin-bottom": case "margin-left": ParseCssSize(styleValue, ref nextIndex, localProperties, styleName, true); break; case "padding": ParseCssRectangleProperty(styleValue, ref nextIndex, localProperties, styleName); break; case "padding-top": case "padding-right": case "padding-bottom": case "padding-left": ParseCssSize(styleValue, ref nextIndex, localProperties, styleName, true); break; case "border": ParseCssBorder(styleValue, ref nextIndex, localProperties); break; case "border-style": case "border-width": case "border-color": ParseCssRectangleProperty(styleValue, ref nextIndex, localProperties, styleName); break; case "border-top": case "border-right": case "border-left": case "border-bottom": break; case "border-top-style": case "border-right-style": case "border-left-style": case "border-bottom-style": case "border-top-color": case "border-right-color": case "border-left-color": case "border-bottom-color": case "border-top-width": case "border-right-width": case "border-left-width": case "border-bottom-width": break; case "display": break; case "float": ParseCssFloat(styleValue, ref nextIndex, localProperties); break; case "clear": ParseCssClear(styleValue, ref nextIndex, localProperties); break; } } }