PageRule.cs 1.57 KB
Newer Older
Matt Schneeberger's avatar
Matt Schneeberger committed
1
2
using Svg.ExCSS.Model;
using Svg.ExCSS.Model.Extensions;
Eric Domke's avatar
Eric Domke committed
3
4

// ReSharper disable once CheckNamespace
Matt Schneeberger's avatar
Matt Schneeberger committed
5
namespace Svg.ExCSS
Eric Domke's avatar
Eric Domke committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{
    public class PageRule : RuleSet, ISupportsSelector, ISupportsDeclarations
    {
        private readonly StyleDeclaration _declarations;
        private BaseSelector _selector;
        private string _selectorText;

        public PageRule() 
        {
            _declarations = new StyleDeclaration();
            RuleType = RuleType.Page;
        }

        internal PageRule AppendRule(Property rule)
        {
            _declarations.Properties.Add(rule);
            return this;
        }

        public BaseSelector Selector
        {
            get { return _selector; }
            set
            {
                _selector = value;
                _selectorText = value.ToString();
            }
        }

        public StyleDeclaration Declarations
        {
            get { return _declarations; }
        }

        public override string ToString()
        {
            return ToString(false);
        }

        public override string ToString(bool friendlyFormat, int indentation = 0)
        {
            var pseudo = string.IsNullOrEmpty(_selectorText)
                             ? ""
                             : ":" + _selectorText;

            var declarations = _declarations.ToString(friendlyFormat, indentation);//.TrimFirstLine();

            return ("@page " + pseudo + "{").NewLineIndent(friendlyFormat, indentation) +
                declarations +
                "}".NewLineIndent(friendlyFormat, indentation);
        }
    }
}