Exemple #1
0
        /// <summary>
        /// Apply percent unit conversion to the given value
        /// </summary>
        private bool ApplyPercent(ref double dblVal, string unit, PercentBaseSelector percentBaseSelector)
        {
            if (unit != "%")
            {
                return(false);
            }

            dblVal /= 100.0;
            var viewBox = cssStyleCascade.GetCurrentViewBox().ViewBox;

            switch (percentBaseSelector)
            {
            case PercentBaseSelector.ViewBoxWidth:
                dblVal = viewBox.Width * dblVal;
                break;

            case PercentBaseSelector.ViewBoxHeight:
                dblVal = viewBox.Height * dblVal;
                break;

            case PercentBaseSelector.ViewBoxDiagonal:
                dblVal = Math.Sqrt(viewBox.Width * viewBox.Width + viewBox.Height * viewBox.Height) * dblVal;
                break;
            }

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Get a list of length or percent
        /// </summary>
        public List <double> GetLengthPercentList(string strVal, PercentBaseSelector percentBaseSelector)
        {
            strVal = strVal.Trim();
            var splits = listDelimiter.Split(strVal);
            var dbls   = new List <double>();

            for (int i = 0; i < splits.Length; i += 2)
            {
                var dbl = GetLengthPercent(splits[i], percentBaseSelector);
                dbls.Add(dbl);
            }

            return(dbls);
        }
Exemple #3
0
        /// <summary>
        /// Get a LengthPercentAuto
        /// </summary>
        public DoubleLengthPercentAuto GetLengthPercentAuto(string strVal, PercentBaseSelector percentBaseSelector)
        {
            DoubleLengthPercentAuto retVal = new DoubleLengthPercentAuto();

            if (strVal == null || strVal == "auto")
            {
                retVal.IsAuto = true;
            }
            else
            {
                retVal.Value = GetLengthPercent(strVal, percentBaseSelector);
            }

            return(retVal);
        }
Exemple #4
0
        public double GetLengthPercent(string strVal, PercentBaseSelector percentBaseSelector)
        {
            var(dblVal, unit) = SplitNumberUnit(strVal);

            if (ApplyLength(ref dblVal, unit))
            {
                return(dblVal);
            }

            if (ApplyPercent(ref dblVal, unit, percentBaseSelector))
            {
                return(dblVal);
            }

            throw new ArgumentException("unknown unit");
        }
Exemple #5
0
        /// <summary>
        /// Get a LengthPercentAuto attribute
        /// </summary>
        public static DoubleLengthPercentAuto GetLengthPercentAuto(this DoubleParser doubleParser, XElement element, string attrName, PercentBaseSelector percentBaseSelector)
        {
            XAttribute xAttr = element.Attribute(attrName);

            return(doubleParser.GetLengthPercentAuto(xAttr?.Value, percentBaseSelector));
        }
Exemple #6
0
        /// <summary>
        /// Get a LengthPercent
        /// </summary>
        public static double GetLengthPercent(this DoubleParser doubleParser, XElement element, string attrName, double defaultValue, PercentBaseSelector percentBaseSelector)
        {
            double     retVal = defaultValue;
            XAttribute xAttr  = element.Attribute(attrName);

            if (xAttr != null)
            {
                retVal = doubleParser.GetLengthPercent(xAttr.Value, percentBaseSelector);
            }

            return(retVal);
        }
 /// <summary>
 /// Get a double attribute, if it doesn't exist it defaults to 0
 /// </summary>
 private double GetLengthPercentAttr(XElement path, string attrName, PercentBaseSelector percentBaseSelector)
 {
     return(doubleParser.GetLengthPercent(path, attrName, 0.0, percentBaseSelector));
 }