Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/SharpVectorCss/Css/CssPageRule.cs @ 13791

Last change on this file since 13791 was 12762, checked in by aballeit, 9 years ago

#2283 GUI updates, Tree-chart, MCTS Version 2 (prune leaves)

File size: 3.4 KB
Line 
1// <developer>niklas@protocol7.com</developer>
2// <completed>80</completed>
3
4using System;
5using System.Collections.Generic;
6using System.Text.RegularExpressions;
7
8namespace SharpVectors.Dom.Css
9{
10  /// <summary>
11  /// 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.
12  /// </summary>
13    public sealed class CssPageRule : CssRule, ICssPageRule
14  {
15    #region Static members
16    private static Regex regex = new Regex(@"^@font-face");
17
18        internal static CssRule Parse(ref string css, object parent, bool readOnly,
19            IList<string> replacedStrings, CssStyleSheetType origin)
20    {
21      Match match = regex.Match(css);
22      if(match.Success)
23      {
24        CssPageRule rule = new CssPageRule(match, parent, readOnly, replacedStrings, origin);
25        css = css.Substring(match.Length);
26
27        rule.style = new CssStyleDeclaration(ref css, rule, true, origin);
28
29        return rule;
30      }
31      else
32      {
33        // didn't match => do nothing
34        return null;
35      }
36    }
37    #endregion
38
39    #region Constructors
40
41    /// <summary>
42    /// The constructor for CssPageRule
43    /// </summary>
44    /// <param name="match">The Regex match that found the charset rule</param>
45    /// <param name="parent">The parent rule or parent stylesheet</param>
46    /// <param name="readOnly">True if this instance is readonly</param>
47    /// <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>
48    /// <param name="origin">The type of CssStyleSheet</param>
49        internal CssPageRule(Match match, object parent, bool readOnly,
50            IList<string> replacedStrings, CssStyleSheetType origin)
51            : base(parent, readOnly, replacedStrings, origin)
52    {
53      // TODO: selectorText = DeReplaceStrings(match.Groups["pageselector"].Value.Trim());
54    }
55
56    #endregion
57
58    #region Implementation of ICssPageRule
59
60    private string selectorText;
61    /// <summary>
62    /// The parsable textual representation of the page selector for the rule.
63    /// </summary>
64    /// <exception cref="DomException">SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable.</exception>
65    /// <exception cref="DomException">NO_MODIFICATION_ALLOWED_ERR: Raised if this rule is readonly.</exception>
66    public string SelectorText
67    {
68      get
69      {
70        return selectorText;
71      }
72      set
73      {
74        /*    SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable.*/
75        if (readOnly)
76                    throw new DomException(DomExceptionType.NoModificationAllowedErr);
77
78        selectorText = value;
79      }
80    }
81
82    private CssStyleDeclaration style;
83    /// <summary>
84    /// The declaration-block of this rule.
85    /// </summary>
86    public ICssStyleDeclaration Style
87    {
88      get
89      {
90        return style;
91      }
92    }
93
94    #endregion
95
96    #region Implementation of ICssRule
97    /// <summary>
98    /// The type of the rule. The expectation is that binding-specific casting methods can be used to cast down from an instance of the CSSRule interface to the specific derived interface implied by the type.
99    /// </summary>
100    public override CssRuleType Type
101    {
102      get
103      {
104        return CssRuleType.PageRule;
105      }
106    }
107    #endregion
108  }
109}
Note: See TracBrowser for help on using the repository browser.