Inheritance: CssPrimitiveValue
Esempio n. 1
0
        /// <summary>
        /// Constructs a new Rect
        /// </summary>
        /// <param name="s">The string to parse that contains the Rect structure</param>
        /// <param name="readOnly">Specifies if the Rect should be read-only</param>
        public CssRect(string rectString, bool readOnly)
        {
            this.readOnly = readOnly;

            if (rectString == null)
            {
                rectString = String.Empty;
            }

            // remove leading and trailing whitespace
            // NOTE: Need to check if .NET whitespace = SVG (XML) whitespace
            rectString = rectString.Trim();

            if (rectString.Length > 0)
            {
                string[] parts = rectString.Split(' ');
                if (parts.Length != 4)
                {
                    parts = delim.Split(rectString);
                }
                if (parts.Length == 4)
                {
                    _top    = new CssPrimitiveLengthValue(parts[0], readOnly);
                    _right  = new CssPrimitiveLengthValue(parts[1], readOnly);
                    _bottom = new CssPrimitiveLengthValue(parts[2], readOnly);
                    _left   = new CssPrimitiveLengthValue(parts[3], readOnly);
                }
                else
                {
                    throw new DomException(DomExceptionType.SyntaxErr);
                }
            }
        }
 public void TestMmValue()
 {
     length = new CssPrimitiveLengthValue("10mm", false);
             Assert.AreEqual(10, length.GetFloatValue(CssPrimitiveType.Mm));
             Assert.AreEqual(1, length.GetFloatValue(CssPrimitiveType.Cm));
             Assert.AreEqual(1/2.54D, length.GetFloatValue(CssPrimitiveType.In));
             Assert.AreEqual(1/2.54D * 6, length.GetFloatValue(CssPrimitiveType.Pc));
             Assert.AreEqual(1/2.54D * 72, length.GetFloatValue(CssPrimitiveType.Pt));
 }
 public void TestInValue()
 {
     length = new CssPrimitiveLengthValue("10in", false);
             Assert.AreEqual(10, length.GetFloatValue(CssPrimitiveType.In));
             Assert.AreEqual(10*2.54D, length.GetFloatValue(CssPrimitiveType.Cm));
             Assert.AreEqual(100*2.54D, length.GetFloatValue(CssPrimitiveType.Mm));
             Assert.AreEqual(60, length.GetFloatValue(CssPrimitiveType.Pc));
             Assert.AreEqual(720, length.GetFloatValue(CssPrimitiveType.Pt));
 }
Esempio n. 4
0
        /// <summary>
        /// Constructs a new Rect
        /// </summary>
        /// <param name="s">The string to parse that contains the Rect structure</param>
        /// <param name="readOnly">Specifies if the Rect should be read-only</param>
        public Rect(string s, bool readOnly)
        {
            this.readOnly = readOnly;

            string[] parts = s.Split(new char[] { ' ' });
            if (parts.Length == 4)
            {
                _top    = new CssPrimitiveLengthValue(parts[0], readOnly);
                _right  = new CssPrimitiveLengthValue(parts[1], readOnly);
                _bottom = new CssPrimitiveLengthValue(parts[2], readOnly);
                _left   = new CssPrimitiveLengthValue(parts[3], readOnly);
            }
            else
            {
                throw new DomException(DomExceptionType.SyntaxErr);
            }
        }
 public void TestPcValue()
 {
     length = new CssPrimitiveLengthValue("10pc", false);
             Assert.AreEqual(10, length.GetFloatValue(CssPrimitiveType.Pc), "To pc");
             Assert.AreEqual(10/6D*2.54D, length.GetFloatValue(CssPrimitiveType.Cm), "To cm");
             Assert.AreEqual(100/6D*2.54D, length.GetFloatValue(CssPrimitiveType.Mm), "To mm");
             Assert.AreEqual(10/6D, length.GetFloatValue(CssPrimitiveType.In), "To in");
             Assert.AreEqual(120, length.GetFloatValue(CssPrimitiveType.Pt), "To pt");
 }
 public void TestExValue()
 {
     length = new CssPrimitiveLengthValue("10ex", false);
             Assert.AreEqual(10, length.GetFloatValue(CssPrimitiveType.Exs), "To ex");
 }
 public void TestUnitLessValue()
 {
     length = new CssPrimitiveLengthValue("10", false);
             Assert.AreEqual(10, length.GetFloatValue(CssPrimitiveType.Number));
 }
    public void TestPxValue()
    {
        length = new CssPrimitiveLengthValue("12px", false);
                Assert.AreEqual(12, length.GetFloatValue(CssPrimitiveType.Px));
                try
                {
                    length.GetCounterValue();
          Assert.Fail("length.GetCounterValue()");
                }
                catch{}

                try
                {
                    length.GetFloatValue(CssPrimitiveType.Ems);
                    Assert.Fail("length.GetFloatValue(CssPrimitiveType.Ems)");
                }
                catch(DomException e)
                {
                    Assert.AreEqual(DomExceptionType.InvalidAccessErr, e.Code);
                }
    }
 public void TestPercentageValue()
 {
     length = new CssPrimitiveLengthValue("10%", false);
             Assert.AreEqual(10, length.GetFloatValue(CssPrimitiveType.Percentage), "To %");
 }