Exemple #1
0
        /// <summary>
        /// Parse a complex font property value that contains multiple css properties into specific css properties.
        /// </summary>
        /// <param name="propValue">the value of the property to parse to specific values</param>
        /// <param name="properties">the properties collection to add the specific properties to</param>
        private static void ParseFontProperty(string propValue, Dictionary <string, string> properties)
        {
            int    mustBePos;
            string mustBe = RegexParserUtils.Search(RegexParserUtils.CssFontSizeAndLineHeight, propValue, out mustBePos);

            if (!string.IsNullOrEmpty(mustBe))
            {
                mustBe = mustBe.Trim();
                //Check for style||variant||weight on the left
                string leftSide    = propValue.Substring(0, mustBePos);
                string fontStyle   = RegexParserUtils.Search(RegexParserUtils.CssFontStyle, leftSide);
                string fontVariant = RegexParserUtils.Search(RegexParserUtils.CssFontVariant, leftSide);
                string fontWeight  = RegexParserUtils.Search(RegexParserUtils.CssFontWeight, leftSide);

                //Check for family on the right
                string rightSide  = propValue.Substring(mustBePos + mustBe.Length);
                string fontFamily = rightSide.Trim();
                //Parser.Search(Parser.CssFontFamily, rightSide); //TODO: Would this be right?

                //Check for font-size and line-height
                string fontSize   = mustBe;
                string lineHeight = string.Empty;

                if (mustBe.Contains("/") && mustBe.Length > mustBe.IndexOf("/", StringComparison.Ordinal) + 1)
                {
                    int slashPos = mustBe.IndexOf("/", StringComparison.Ordinal);
                    fontSize   = mustBe.Substring(0, slashPos);
                    lineHeight = mustBe.Substring(slashPos + 1);
                }

                if (!string.IsNullOrEmpty(fontFamily))
                {
                    properties["font-family"] = ParseFontFamilyProperty(fontFamily);
                }
                if (!string.IsNullOrEmpty(fontStyle))
                {
                    properties["font-style"] = fontStyle;
                }
                if (!string.IsNullOrEmpty(fontVariant))
                {
                    properties["font-variant"] = fontVariant;
                }
                if (!string.IsNullOrEmpty(fontWeight))
                {
                    properties["font-weight"] = fontWeight;
                }
                if (!string.IsNullOrEmpty(fontSize))
                {
                    properties["font-size"] = fontSize;
                }
                if (!string.IsNullOrEmpty(lineHeight))
                {
                    properties["line-height"] = lineHeight;
                }
            }
            else
            {
                // Check for: caption | icon | menu | message-box | small-caption | status-bar
                //TODO: Interpret font values of: caption | icon | menu | message-box | small-caption | status-bar
            }
        }