Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/SharpVectorModel/BasicTypes/SvgFitToViewBox.cs @ 12762

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

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

File size: 2.1 KB
Line 
1using System;
2using System.Xml;
3
4using SharpVectors.Dom.Css;
5
6namespace SharpVectors.Dom.Svg
7{
8  public class SvgFitToViewBox
9  {
10        private ISvgAnimatedRect viewBox;
11        private ISvgAnimatedPreserveAspectRatio preserveAspectRatio;
12
13        #region Protected Fields
14
15        protected SvgElement ownerElement;
16
17        #endregion
18
19    public SvgFitToViewBox(SvgElement ownerElement)
20    {
21      this.ownerElement = ownerElement;
22      this.ownerElement.attributeChangeHandler += new NodeChangeHandler(AttributeChange);
23    }
24
25    #region Update handling
26
27    private void AttributeChange(Object src, XmlNodeChangedEventArgs args)
28    {
29      XmlAttribute attribute = src as XmlAttribute;
30
31      if(attribute.NamespaceURI.Length == 0)
32      {
33        switch(attribute.LocalName)
34        {
35          case "viewBox":
36            viewBox = null;
37            break;
38          case "preserveAspectRatio":
39            preserveAspectRatio = null;
40            break;
41        }
42      }
43    }
44
45    #endregion
46
47    public ISvgAnimatedRect ViewBox
48    {
49      get
50      {
51        if (viewBox == null)
52        {
53          string attr = ownerElement.GetAttribute("viewBox").Trim();
54          if (String.IsNullOrEmpty(attr))
55          {
56            double x      = 0;
57            double y      = 0;
58            double width  = 0;
59            double height = 0;
60            if (ownerElement is SvgSvgElement)
61            {
62              SvgSvgElement svgSvgElm = ownerElement as SvgSvgElement;
63
64              x      = svgSvgElm.X.AnimVal.Value;
65              y      = svgSvgElm.Y.AnimVal.Value;
66              width  = svgSvgElm.Width.AnimVal.Value;
67              height = svgSvgElm.Height.AnimVal.Value;
68            }
69            viewBox = new SvgAnimatedRect(new SvgRect(x, y, width, height));
70          }
71          else
72          {
73            viewBox = new SvgAnimatedRect(attr);
74          }
75        }
76
77        return viewBox;
78      }
79    }
80
81    public ISvgAnimatedPreserveAspectRatio PreserveAspectRatio
82    {
83      get
84      {
85        if (preserveAspectRatio == null)
86        {
87          preserveAspectRatio = new SvgAnimatedPreserveAspectRatio(
88                        ownerElement.GetAttribute("preserveAspectRatio"), ownerElement);
89        }
90        return preserveAspectRatio;
91      }
92    } 
93  }
94}
Note: See TracBrowser for help on using the repository browser.