Пример #1
0
        /// <summary>
        /// Parse a complex font family css property to check if it contains multiple fonts and if the font exists.<br/>
        /// returns the font family name to use or 'inherit' if failed.
        /// </summary>
        /// <param name="propValue">the value of the property to parse</param>
        /// <returns>parsed font-family value</returns>
        private static string ParseFontFamilyProperty(string propValue)
        {
            int start = 0;

            while (start > -1 && start < propValue.Length)
            {
                while (char.IsWhiteSpace(propValue[start]) || propValue[start] == ',' || propValue[start] == '\'' || propValue[start] == '"')
                {
                    start++;
                }
                var end = propValue.IndexOf(',', start);
                if (end < 0)
                {
                    end = propValue.Length;
                }
                var adjEnd = end - 1;
                while (char.IsWhiteSpace(propValue[adjEnd]) || propValue[adjEnd] == '\'' || propValue[adjEnd] == '"')
                {
                    adjEnd--;
                }

                var font = propValue.Substring(start, adjEnd - start + 1);

                if (font.Equals("monospace", StringComparison.InvariantCultureIgnoreCase))
                {
                    font = "Courier New";
                }

                if (CssUtils.IsFontExists(font))
                {
                    return(font);
                }

                start = end;
            }

            return(CssConstants.Inherit);
        }