Пример #1
0
        public virtual void ParseDoubleNegativeTextTest()
        {
            double?expectedString = null;
            double?actualString   = CssUtils.ParseDouble("text");

            NUnit.Framework.Assert.AreEqual(expectedString, actualString);
        }
Пример #2
0
        public virtual void ParseDoubleManyCharsAfterDotNegativeTest()
        {
            double?expectedString = -5.123456789;
            double?actualString   = CssUtils.ParseDouble("-5.123456789");

            NUnit.Framework.Assert.AreEqual(expectedString, actualString);
        }
Пример #3
0
        public virtual void ParseDoubleNullValueTest()
        {
            double?expectedString = null;
            double?actualString   = CssUtils.ParseDouble(null);

            NUnit.Framework.Assert.AreEqual(expectedString, actualString);
        }
Пример #4
0
        public virtual void ParseDoubleIntegerValueTest()
        {
            double?expectedString = 5.0;
            double?actualString   = CssUtils.ParseDouble("5");

            NUnit.Framework.Assert.AreEqual(expectedString, actualString);
        }
Пример #5
0
        /// <summary>Evaluates the stop color offset value</summary>
        /// <returns>the stop color offset value in [0, 1] range</returns>
        public virtual double GetOffset()
        {
            double?offset          = null;
            String offsetAttribute = GetAttribute(SvgConstants.Attributes.OFFSET);

            if (CssUtils.IsPercentageValue(offsetAttribute))
            {
                offset = (double)CssUtils.ParseRelativeValue(offsetAttribute, 1);
            }
            else
            {
                if (CssUtils.IsNumericValue(offsetAttribute))
                {
                    offset = CssUtils.ParseDouble(offsetAttribute);
                }
            }
            double result = offset != null ? offset.Value : 0d;

            return(result > 1d ? 1d : result > 0d ? result : 0d);
        }
Пример #6
0
        private double GetCoordinateForObjectBoundingBox(String attributeName, double defaultValue)
        {
            String attributeValue = GetAttribute(attributeName);
            double absoluteValue  = defaultValue;

            if (CssUtils.IsPercentageValue(attributeValue))
            {
                absoluteValue = CssUtils.ParseRelativeValue(attributeValue, 1);
            }
            else
            {
                if (CssUtils.IsNumericValue(attributeValue) || CssUtils.IsMetricValue(attributeValue) || CssUtils.IsRelativeValue
                        (attributeValue))
                {
                    // if there is incorrect value metric, then we do not need to parse the value
                    int unitsPosition = CssUtils.DeterminePositionBetweenValueAndUnit(attributeValue);
                    if (unitsPosition > 0)
                    {
                        // We want to ignore the unit type. From the svg specification:
                        // "the normal of the linear gradient is perpendicular to the gradient vector in
                        // object bounding box space (i.e., the abstract coordinate system where (0,0)
                        // is at the top/left of the object bounding box and (1,1) is at the bottom/right
                        // of the object bounding box)".
                        // Different browsers treats this differently. We chose the "Google Chrome" approach
                        // which treats the "abstract coordinate system" in the coordinate metric measure,
                        // i.e. for value '0.5cm' the top/left of the object bounding box would be (1cm, 1cm),
                        // for value '0.5em' the top/left of the object bounding box would be (1em, 1em) and etc.
                        // no null pointer should be thrown as determine
                        absoluteValue = CssUtils.ParseDouble(attributeValue.JSubstring(0, unitsPosition)).Value;
                    }
                }
            }
            // need to multiply by 0.75 as further the (top, right) coordinates of the object bbox
            // would be transformed into (0.75, 0.75) point instead of (1, 1). The reason described
            // as a comment inside the method constructing the gradient transformation
            return(absoluteValue * 0.75);
        }
 protected internal virtual Point CreatePoint(String coordX, String coordY)
 {
     return(new Point((double)CssUtils.ParseDouble(coordX), (double)CssUtils.ParseDouble(coordY)));
 }
Пример #8
0
 private double GetCoordinate(int index)
 {
     // casting to double fot porting compatibility
     return((double)CssUtils.ParseDouble(coordinates[index]));
 }