The CSSPageRule interface represents a @page rule within a CSS style sheet. The @page rule is used to specify the dimensions, orientation, margins, etc. of a page box for paged media.
Inheritance: CssRule, ICssPageRule
示例#1
0
        internal static CssRule Parse(ref string css, object parent, bool readOnly,
                                      IList <string> replacedStrings, CssStyleSheetType origin)
        {
            Match match = regex.Match(css);

            if (match.Success)
            {
                CssPageRule rule = new CssPageRule(match, 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);
        }
示例#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);
        }
示例#3
0
        internal static CssRule Parse(ref string css, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin)
        {
            Match match = regex.Match(css);

            if (match.Success)
            {
                CssPageRule rule = new CssPageRule(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);
            }
        }
示例#4
0
        internal static CssRule Parse(ref string css, object parent, bool readOnly, 
            IList<string> replacedStrings, CssStyleSheetType origin)
        {
            Match match = regex.Match(css);
            if(match.Success)
            {
                CssPageRule rule = new CssPageRule(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;
            }
        }
示例#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");
                        }
                    }
                }
            }
        }