ConvertToSpecifiedUnits() public method

Preserve the same underlying stored value, but reset the stored unit identifier to the given unitType. Object attributes unitType, valueAsSpecified and valueAsString might be modified as a result of this method. For example, if the original value were "0.5cm" and the method was invoked to convert to millimeters, then the unitType would be changed to MM, valueAsSpecified would be changed to the numeric value 5 and valueAsString would be changed to "5mm".
public ConvertToSpecifiedUnits ( SvgLengthType unitType ) : void
unitType SvgLengthType The unitType to switch to (e.g., MM).
return void
Esempio n. 1
0
        public void TestSettingValues()
        {
            length = new SvgLength(elm, "test", SvgLengthDirection.Horizontal, "10px");
            Assert.AreEqual(10, length.Value);
            Assert.AreEqual(SvgLengthType.Px, length.UnitType);
            Assert.AreEqual(10, length.ValueInSpecifiedUnits);
            Assert.AreEqual("10px", length.ValueAsString);

            length.ValueAsString = "10cm";
            Assert.AreEqual(10, length.ValueInSpecifiedUnits);
            length.Value = 200;
            double valueInCm = 200 / 96D * 2.54D;
            Assert.AreEqual(200, length.Value);
            Assert.AreEqual(valueInCm, length.ValueInSpecifiedUnits);
            Assert.AreEqual(valueInCm.ToString(SvgNumber.Format)+"cm", length.ValueAsString);

            // change px value
            length.ValueAsString = "2px";
            Assert.AreEqual(2, length.Value);
            Assert.AreEqual(2, length.ValueInSpecifiedUnits);
            Assert.AreEqual("2px", length.ValueAsString);

            // set to a CM value
            length.NewValueSpecifiedUnits(SvgLengthType.Cm, 23);
            Assert.AreEqual(23, length.ValueInSpecifiedUnits);
            Assert.AreEqual(23 / 2.54D * 96, length.Value);
            Assert.AreEqual("23cm", length.ValueAsString);
            Assert.AreEqual(SvgLengthType.Cm, length.UnitType);

            length.ConvertToSpecifiedUnits(SvgLengthType.Mm);
            Assert.AreEqual(230, length.ValueInSpecifiedUnits);
            Assert.AreEqual("230mm", length.ValueAsString);
            Assert.AreEqual(SvgLengthType.Mm, length.UnitType);
        }