The CSSFontFaceRule interface represents a @font-face rule in a CSS style sheet. The @font-face rule is used to hold a set of font descriptions.
Inheritance: CssRule, ICssFontFaceRule
Ejemplo n.º 1
0
        /// <summary>
        /// Parses a string containging CSS and creates a CssFontFaceRule instance if found as the first content
        /// </summary>
        internal static CssFontFaceRule Parse(ref string css, object parent, bool readOnly,
                                              IList <string> replacedStrings, CssStyleSheetType origin)
        {
            Match match = _reRule.Match(css);

            if (match.Success)
            {
                CssFontFaceRule rule = new CssFontFaceRule(parent, readOnly, replacedStrings, origin);
                css = css.Substring(match.Length);

                if (string.IsNullOrWhiteSpace(css))
                {
                    rule._style = CssStyleDeclaration.EmptyCssStyle;
                }
                else
                {
                    rule._style = new CssStyleDeclaration(ref css, rule, true, origin);
                }

                return(rule);
            }

            // didn't match => do nothing
            return(null);
        }
Ejemplo n.º 2
0
        private CssRule TryParse(ref string css, object parent, bool readOnly,
                                 IList <string> replacedStrings, CssStyleSheetType origin)
        {
            CssRule rule;

            // creates and parses a CssMediaRule or return null
            rule = CssMediaRule.Parse(ref css, parent, readOnly, replacedStrings, origin);
            if (rule != null)
            {
                return(rule);
            }

            // create ImportRule
            rule = CssImportRule.Parse(ref css, parent, readOnly, replacedStrings, origin);
            if (rule != null)
            {
                return(rule);
            }

            // create CharSetRule
            rule = CssCharsetRule.Parse(ref css, parent, readOnly, replacedStrings, origin);
            if (rule != null)
            {
                return(rule);
            }

            rule = CssFontFaceRule.Parse(ref css, parent, readOnly, replacedStrings, origin);
            if (rule != null)
            {
                _hasFontRule = true;
                return(rule);
            }

            rule = CssPageRule.Parse(ref css, parent, readOnly, replacedStrings, origin);
            if (rule != null)
            {
                return(rule);
            }

            rule = CssUnknownRule.Parse(ref css, parent, readOnly, replacedStrings, origin);
            if (rule != null)
            {
                return(rule);
            }

            return(rule);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Parses a string containging CSS and creates a CssFontFaceRule instance if found as the first content
        /// </summary>
        internal static CssRule Parse(ref string css, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin)
        {
            Match match = regex.Match(css);
            if(match.Success)
            {
                CssFontFaceRule rule = new CssFontFaceRule(match, parent, readOnly, replacedStrings, origin);
                css = css.Substring(match.Length);

                rule.style = new CssStyleDeclaration(ref css, rule, true, origin);

                return rule;
            }
            else
            {
                // didn't match => do nothing
                return null;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Parses a string containging CSS and creates a CssFontFaceRule instance if found as the first content
        /// </summary>
        internal static CssRule Parse(ref string css, object parent, bool readOnly,
                                      IList <string> replacedStrings, CssStyleSheetType origin)
        {
            Match match = regex.Match(css);

            if (match.Success)
            {
                CssFontFaceRule rule = new CssFontFaceRule(match, parent, readOnly, replacedStrings, origin);
                css = css.Substring(match.Length);

                rule._style = new CssStyleDeclaration(ref css, rule, true, origin);

                return(rule);
            }

            // didn't match => do nothing
            return(null);
        }
Ejemplo n.º 5
0
        /* can take two kind of structures:
         * rule{}
         * rule{}
         * or:
         * {
         *	rule{}
         *	rule{}
         * }
         * */
        private void Parse(ref string css, object parent, bool readOnly, IList <string> replacedStrings, CssStyleSheetType origin)
        {
            bool withBrackets = false;

            css = css.Trim();
            if (css.StartsWith("{", StringComparison.OrdinalIgnoreCase))
            {
                withBrackets = true;
                css          = css.Substring(1);
            }

            while (true)
            {
                css = css.Trim();
                if (css.Length == 0)
                {
                    if (withBrackets)
                    {
                        throw new DomException(DomExceptionType.SyntaxErr, "Style block missing ending bracket");
                    }
                    break;
                }
                else if (css.StartsWith("}", StringComparison.OrdinalIgnoreCase))
                {
                    // end of block;
                    css = css.Substring(1);
                    break;
                }
                else if (css.StartsWith("@", StringComparison.OrdinalIgnoreCase))
                {
                    // Parse at-rules
                    // @-rule
                    CssRule rule;

                    // creates and parses a CssMediaRule or return null
                    rule = CssMediaRule.Parse(ref css, parent, readOnly, replacedStrings, origin);
                    if (rule == null)
                    {
                        // create ImportRule
                        rule = CssImportRule.Parse(ref css, parent, readOnly, replacedStrings, origin);

                        if (rule == null)
                        {
                            // create CharSetRule
                            rule = CssCharsetRule.Parse(ref css, parent, readOnly, replacedStrings, origin);

                            if (rule == null)
                            {
                                rule = CssFontFaceRule.Parse(ref css, parent, readOnly, replacedStrings, origin);

                                if (rule == null)
                                {
                                    rule = CssPageRule.Parse(ref css, parent, readOnly, replacedStrings, origin);

                                    if (rule == null)
                                    {
                                        rule = CssUnknownRule.Parse(ref css, parent, readOnly, replacedStrings, origin);
                                    }
                                }
                            }
                        }
                    }
                    InsertRule(rule);
                }
                else
                {
                    // must be a selector or error
                    CssRule rule = CssStyleRule.Parse(ref css, parent, readOnly, replacedStrings, origin);
                    if (rule != null)
                    {
                        InsertRule(rule);
                    }
                    else
                    {
                        // this is an unknown rule format, possibly a new kind of selector. Try to find the end of it to skip it

                        int startBracket = css.IndexOf("{", StringComparison.OrdinalIgnoreCase);
                        int endBracket   = css.IndexOf("}", StringComparison.OrdinalIgnoreCase);
                        int endSemiColon = css.IndexOf(";", StringComparison.OrdinalIgnoreCase);
                        int endRule;

                        if (endSemiColon > 0 && endSemiColon < startBracket)
                        {
                            endRule = endSemiColon;
                        }
                        else
                        {
                            endRule = endBracket;
                        }


                        if (endRule > -1)
                        {
                            css = css.Substring(endRule + 1);
                        }
                        else
                        {
                            throw new DomException(DomExceptionType.SyntaxErr, "Can not parse the CSS file");
                        }
                    }
                }
            }
        }