コード例 #1
0
 /// <summary>
 /// Constructor for CssStyleSheet
 /// </summary>
 /// <param name="ownerNode">The node that owns this stylesheet. E.g. used for getting the BaseUri</param>
 /// <param name="href">The URL of the stylesheet</param>
 /// <param name="title">The title of the stylesheet</param>
 /// <param name="media">List of medias for the stylesheet</param>
 /// <param name="ownerRule">The rule (e.g. ImportRule) that referenced this stylesheet</param>
 /// <param name="origin">The type of stylesheet</param>
 public CssStyleSheet(XmlNode ownerNode, string href, string title, string media, 
     CssRule ownerRule, CssStyleSheetType origin)
     : base(ownerNode, href, "text/css", title, media)
 {
     Origin = origin;
     this.ownerRule = ownerRule;
 }
コード例 #2
0
ファイル: CssImportRule.cs プロジェクト: codebutler/savagesvg
 /// <summary>
 /// The constructor for CssImportRule
 /// </summary>
 /// <param name="match">The Regex match that found the charset rule</param>
 /// <param name="parent">The parent rule or parent stylesheet</param>
 /// <param name="readOnly">True if this instance is readonly</param>
 /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param>
 /// <param name="origin">The type of CssStyleSheet</param>
 internal CssImportRule(Match match, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin)
     : base(parent, readOnly, replacedStrings, origin)
 {
     media = new MediaList(match.Groups["importmedia"].Value);
     href = DeReplaceStrings(match.Groups["importhref"].Value);
     styleSheet = new CssStyleSheet(ResolveOwnerNode(), Href, null, match.Groups["importmedia"].Value, this, Origin);
 }
コード例 #3
0
ファイル: SharpCssStyle.cs プロジェクト: codebutler/savagesvg
 internal SharpCssStyle(string name, string val, string priority, CssStyleSheetType origin)
 {
     Name = name.Trim();
     Value = val.Trim();
     Priority = priority.Trim();
     Origin = origin;
 }
コード例 #4
0
 internal CssCollectedProperty(string name, int specificity, CssValue cssValue, CssStyleSheetType origin, string priority)
 {
     Name = name;
     Specificity = specificity;
     Origin = origin;
     CssValue = cssValue;
     Priority = priority;
 }
コード例 #5
0
        public CssStyleDeclaration(string css, CssRule parentRule, bool readOnly, CssStyleSheetType origin)
        {
            _origin = origin;
            _readOnly = readOnly;
            _parentRule = parentRule;

            parseString(css);
        }
コード例 #6
0
ファイル: CssRuleList.cs プロジェクト: codebutler/savagesvg
 /// <summary>
 /// Constructor for CssRuleList
 /// </summary>
 /// <param name="parent">The parent rule or parent stylesheet</param>
 /// <param name="cssText">The CSS text containing the rules that will be in this list</param>
 /// <param name="readOnly">True if this instance is readonly</param>
 /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param>
 /// <param name="origin">The type of CssStyleSheet</param>
 public CssRuleList(ref string cssText, object parent, string[] replacedStrings, bool readOnly, CssStyleSheetType origin)
 {
     Origin = origin;
     ReadOnly = readOnly;
     if(parent is CssRule || parent is CssStyleSheet)
     {
         Parent = parent;
     }
     else
     {
         throw new Exception("The CssRuleList constructor can only take a CssRule or CssStyleSheet as it's first argument " + parent.GetType());
     }
     Parse(ref cssText, parent, readOnly, replacedStrings, origin);
     //AppendRules(cssText, replacedStrings);
 }
コード例 #7
0
ファイル: CssCharsetRule.cs プロジェクト: udayanroy/SvgSharp
 internal static CssRule Parse(ref string css, object parent, bool readOnly, IList<string> replacedStrings, CssStyleSheetType origin)
 {
     Match match = regex.Match(css);
     if(match.Success)
     {
         CssCharsetRule rule = new CssCharsetRule(match, parent, readOnly, replacedStrings, origin);
         css = css.Substring(match.Length);
         return rule;
     }
     else
     {
         // didn't match => do nothing
         return null;
     }
 }
コード例 #8
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;
            }
        }
コード例 #9
0
ファイル: CssRule.cs プロジェクト: codebutler/savagesvg
 protected CssRule(object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin)
 {
     if(parent is CssRule)
     {
         _ParentRule = (CssRule)parent;
     }
     else if(parent is CssStyleSheet)
     {
         _ParentStyleSheet = (CssStyleSheet)parent;
     }
     else
     {
         throw new Exception("The CssRule constructor can only take a CssRule or CssStyleSheet as it's second argument " + parent.GetType());
     }
     Origin = origin;
     ReplacedStrings = replacedStrings;
     ReadOnly = readOnly;
 }
コード例 #10
0
ファイル: CssStyleRule.cs プロジェクト: codebutler/savagesvg
        /// <summary>
        /// The constructor for CssStyleRule
        /// </summary>
        /// <param name="match">The Regex match that found the charset rule</param>
        /// <param name="parent">The parent rule or parent stylesheet</param>
        /// <param name="readOnly">True if this instance is readonly</param>
        /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param>
        /// <param name="origin">The type of CssStyleSheet</param>
        internal CssStyleRule(Match match, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin)
            : base(parent, readOnly, replacedStrings, origin)
        {
            //SelectorText = DeReplaceStrings(match.Groups["selectors"].Value.Trim());
            //_Style = new CssStyleDeclaration(match, this, readOnly, Origin);

            Group selectorMatches = match.Groups["selector"];

            int len = selectorMatches.Captures.Count;
            ArrayList sels = new ArrayList();
            for(int i = 0; i<len; i++)
            {
                string str = DeReplaceStrings(selectorMatches.Captures[i].Value.Trim());
                if(str.Length > 0)
                {
                    sels.Add(new XPathSelector(str));
                }
            }
            XPathSelectors = (XPathSelector[])sels.ToArray(typeof(XPathSelector));
        }
コード例 #11
0
ファイル: CssStyleSheet.cs プロジェクト: codebutler/savagesvg
 /// <summary>
 /// Constructor for CssStyleSheet
 /// </summary>
 /// <param name="styleElement">The XML style element that references the stylesheet</param>
 /// <param name="origin">The type of stylesheet</param>
 internal CssStyleSheet(XmlElement styleElement, CssStyleSheetType origin)
     : base(styleElement)
 {
     Origin = origin;
 }
コード例 #12
0
ファイル: CssCharsetRule.cs プロジェクト: udayanroy/SvgSharp
 /// <summary>
 /// The constructor for CssCharSetRule
 /// </summary>
 /// <param name="match">The Regex match that found the charset rule</param>
 /// <param name="parent">The parent rule or parent stylesheet</param>
 /// <param name="readOnly">True if this instance is readonly</param>
 /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param>
 /// <param name="origin">The type of CssStyleSheet</param>
 internal CssCharsetRule(Match match, object parent, bool readOnly, 
     IList<string> replacedStrings, CssStyleSheetType origin)
     : base(parent, readOnly, replacedStrings, origin)
 {
     _Encoding = DeReplaceStrings(match.Groups["charsetencoding"].Value);
 }
コード例 #13
0
ファイル: CssStyleBlock.cs プロジェクト: udayanroy/SvgSharp
 internal CssStyleBlock(CssStyleBlock style, int specificity, CssStyleSheetType origin)
     : this(style.Name, style.Value, style.Priority, origin)
 {
     Specificity = specificity;
 }
コード例 #14
0
ファイル: CssMediaRule.cs プロジェクト: codebutler/savagesvg
 /// <summary>
 /// The constructor for CssMediaRule
 /// </summary>
 /// <param name="match">The Regex match that found the charset rule</param>
 /// <param name="parent">The parent rule or parent stylesheet</param>
 /// <param name="readOnly">True if this instance is readonly</param>
 /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param>
 /// <param name="origin">The type of CssStyleSheet</param>
 internal CssMediaRule(Match match, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin)
     : this(match.Groups["medianames"].Value, parent, readOnly, replacedStrings, origin)
 {
 }
コード例 #15
0
ファイル: CssMediaRule.cs プロジェクト: codebutler/savagesvg
 public CssMediaRule(string cssText, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin)
     : base(parent, readOnly, replacedStrings, origin)
 {
     media = new MediaList(cssText);
 }
コード例 #16
0
ファイル: CssMediaRule.cs プロジェクト: codebutler/savagesvg
        internal static CssRule Parse(ref string css, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin)
        {
            Match match = regex.Match(css);
            if(match.Success)
            {
                CssMediaRule rule = new CssMediaRule(match, parent, readOnly, replacedStrings, origin);

                css = css.Substring(match.Length);

                rule.cssRules = new CssRuleList(ref css, rule, replacedStrings, origin);

                return rule;
            }
            else
            {
                return null;
            }
        }
コード例 #17
0
ファイル: SharpCssStyle.cs プロジェクト: codebutler/savagesvg
 internal SharpCssStyle(SharpCssStyle style, int specificity, CssStyleSheetType origin)
     : this(style.Name, style.Value, style.Priority, origin)
 {
     Specificity = specificity;
 }
コード例 #18
0
ファイル: CssStyleDeclaration.cs プロジェクト: naver/protonow
        /// <summary>
        /// The constructor for CssStyleDeclaration
        /// </summary>
        /// <param name="css">The string to parse for CSS</param>
        /// <param name="parentRule">The parent rule or parent stylesheet</param>
        /// <param name="readOnly">True if this instance is readonly</param>
        /// <param name="origin">The type of CssStyleSheet</param>
        public CssStyleDeclaration(ref string css, CssRule parentRule, bool readOnly, CssStyleSheetType origin)
        {
            _origin     = origin;
            _readOnly   = readOnly;
            _parentRule = parentRule;

            css = parseString(css);
        }
コード例 #19
0
 /// <summary>
 /// The constructor used internally when collecting styles for a specified element
 /// </summary>
 internal CssStyleDeclaration()
 {
     _origin = CssStyleSheetType.Collector;
     _readOnly = true;
     _parentRule = null;
 }
コード例 #20
0
ファイル: CssStyleRule.cs プロジェクト: nagyist/savagesvg
        /// <summary>
        /// The constructor for CssStyleRule
        /// </summary>
        /// <param name="match">The Regex match that found the charset rule</param>
        /// <param name="parent">The parent rule or parent stylesheet</param>
        /// <param name="readOnly">True if this instance is readonly</param>
        /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param>
        /// <param name="origin">The type of CssStyleSheet</param>
        internal CssStyleRule(Match match, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin) : base(parent, readOnly, replacedStrings, origin)
        {
            //SelectorText = DeReplaceStrings(match.Groups["selectors"].Value.Trim());
            //_Style = new CssStyleDeclaration(match, this, readOnly, Origin);

            Group selectorMatches = match.Groups["selector"];

            int       len  = selectorMatches.Captures.Count;
            ArrayList sels = new ArrayList();

            for (int i = 0; i < len; i++)
            {
                string str = DeReplaceStrings(selectorMatches.Captures[i].Value.Trim());
                if (str.Length > 0)
                {
                    sels.Add(new XPathSelector(str));
                }
            }
            XPathSelectors = (XPathSelector[])sels.ToArray(typeof(XPathSelector));
        }
コード例 #21
0
 /// <summary>
 /// The constructor for CssUnknownRule
 /// </summary>
 internal CssUnknownRule(object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin)
     : base(parent, readOnly, replacedStrings, origin)
 {
 }
コード例 #22
0
 /// <summary>
 /// Constructor for CssStyleSheet
 /// </summary>
 /// <param name="pi">The XML processing instruction that references the stylesheet</param>
 /// <param name="origin">The type of stylesheet</param>
 internal CssStyleSheet(XmlProcessingInstruction pi, CssStyleSheetType origin)
     : base(pi)
 {
     _origin = origin;
 }
コード例 #23
0
 /// <summary>
 /// Constructor for CssStyleSheet
 /// </summary>
 /// <param name="styleElement">The XML style element that references the stylesheet</param>
 /// <param name="origin">The type of stylesheet</param>
 internal CssStyleSheet(XmlElement styleElement, CssStyleSheetType origin)
     : base(styleElement)
 {
     _origin = origin;
 }
コード例 #24
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 && match.Length > 0)
            {
                CssStyleRule rule = new CssStyleRule(match, parent, readOnly, replacedStrings, origin);

                css = css.Substring(match.Length);

                rule._Style = new CssStyleDeclaration(ref css, rule, readOnly, origin);

                return rule;
            }
            else
            {
                return null;
            }
        }
コード例 #25
0
ファイル: SharpCssStyle.cs プロジェクト: codebutler/savagesvg
 internal SharpCssStyle(string name, string val, string priority, int specificity, CssStyleSheetType origin)
     : this(name, val, priority, origin)
 {
     Specificity = specificity;
 }
コード例 #26
0
ファイル: CssStyleDeclaration.cs プロジェクト: naver/protonow
 /// <summary>
 /// The constructor used internally when collecting styles for a specified element
 /// </summary>
 internal CssStyleDeclaration()
 {
     _origin     = CssStyleSheetType.Collector;
     _readOnly   = true;
     _parentRule = null;
 }
コード例 #27
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("{"))
            {
                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("}"))
                {
                    // end of block;
                    css = css.Substring(1);
                    break;
                }
                else if(css.StartsWith("@"))
                {
                    #region 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);
                    #endregion
                }
                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("{");
                        int endBracket = css.IndexOf("}");
                        int endSemiColon = css.IndexOf(";");
                        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");
                        }
                    }

                //}
                }
            }
        }
コード例 #28
0
ファイル: CssFontFaceRule.cs プロジェクト: nagyist/savagesvg
        /// <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);
            }
        }
コード例 #29
0
ファイル: CssStyleSheet.cs プロジェクト: codebutler/savagesvg
 /// <summary>
 /// Constructor for CssStyleSheet
 /// </summary>
 /// <param name="pi">The XML processing instruction that references the stylesheet</param>
 /// <param name="origin">The type of stylesheet</param>
 internal CssStyleSheet(XmlProcessingInstruction pi, CssStyleSheetType origin)
     : base(pi)
 {
     Origin = origin;
 }
コード例 #30
0
 /// <summary>
 /// Constructor for CssRuleList
 /// </summary>
 /// <param name="parent">The parent rule or parent stylesheet</param>
 /// <param name="cssText">The CSS text containing the rules that will be in this list</param>
 /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param>
 /// <param name="origin">The type of CssStyleSheet</param>
 internal CssRuleList(ref string cssText, object parent,
     IList<string> replacedStrings, CssStyleSheetType origin)
     : this(ref cssText, parent, replacedStrings, false, origin)
 {
 }
コード例 #31
0
 /// <summary>
 /// The constructor for CssFontFaceRule
 /// </summary>
 /// <param name="match">The Regex match that found the charset rule</param>
 /// <param name="parent">The parent rule or parent stylesheet</param>
 /// <param name="readOnly">True if this instance is readonly</param>
 /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param>
 /// <param name="origin">The type of CssStyleSheet</param>
 internal CssFontFaceRule(Match match, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin)
     : base(parent, true, replacedStrings, origin)
 {
     // always read-only
 }
コード例 #32
0
        public void CollectProperty(string name, int specificity, CssValue cssValue, CssStyleSheetType origin, string priority)
        {
            CssCollectedProperty newProp = new CssCollectedProperty(name, specificity, cssValue, origin, priority);

            if (!collectedStyles.ContainsKey(name))
            {
                collectedStyles[name] = newProp;
            }
            else
            {
                CssCollectedProperty existingProp = collectedStyles[name];
                if (newProp.IsBetterThen(existingProp))
                {
                    collectedStyles[name] = newProp;
                }
            }
        }
コード例 #33
0
 /// <summary>
 /// The constructor for CssPageRule
 /// </summary>
 /// <param name="match">The Regex match that found the charset rule</param>
 /// <param name="parent">The parent rule or parent stylesheet</param>
 /// <param name="readOnly">True if this instance is readonly</param>
 /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param>
 /// <param name="origin">The type of CssStyleSheet</param>
 internal CssPageRule(Match match, object parent, bool readOnly, 
     IList<string> replacedStrings, CssStyleSheetType origin)
     : base(parent, readOnly, replacedStrings, origin)
 {
     // TODO: selectorText = DeReplaceStrings(match.Groups["pageselector"].Value.Trim());
 }
コード例 #34
0
ファイル: CssPageRule.cs プロジェクト: naver/protonow
 /// <summary>
 /// The constructor for CssPageRule
 /// </summary>
 /// <param name="match">The Regex match that found the charset rule</param>
 /// <param name="parent">The parent rule or parent stylesheet</param>
 /// <param name="readOnly">True if this instance is readonly</param>
 /// <param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method</param>
 /// <param name="origin">The type of CssStyleSheet</param>
 internal CssPageRule(Match match, object parent, bool readOnly,
                      IList <string> replacedStrings, CssStyleSheetType origin)
     : base(parent, readOnly, replacedStrings, origin)
 {
     // TODO: selectorText = DeReplaceStrings(match.Groups["pageselector"].Value.Trim());
 }