Inheritance: ISvgNumber
コード例 #1
0
        private double getViewportProp(string propertyName, string inValue, double calcParentVP,
                                       double defaultValue, SvgLengthDirection dir)
        {
            double ret;

            inValue = inValue.Trim();

            if (inValue.Length > 0)
            {
                if (inValue.EndsWith("%", StringComparison.OrdinalIgnoreCase))
                {
                    double perc = SvgNumber.ParseNumber(inValue.Substring(0, inValue.Length - 1)) / 100;
                    ret = calcParentVP * perc;
                }
                else
                {
                    ret = new SvgLength(this, propertyName, dir, inValue, string.Empty).Value;
                }
            }
            else
            {
                ret = defaultValue;
            }

            return(ret);
        }
コード例 #2
0
ファイル: SvgLength.cs プロジェクト: naver/protonow
        /// <summary>
        /// Creates a SvgLength value
        /// </summary>
        /// <param name="baseVal">String to be parsed into a length</param>
        /// <param name="ownerElement">The associated element</param>
        /// <param name="direction">Direction of the length, used for percentages</param>
        public SvgLength(string propertyName, string baseVal, SvgElement ownerElement, SvgLengthDirection direction)
        {
            this.ownerElement = ownerElement;
            this.direction    = direction;

            baseVal = SvgNumber.ScientificToDec(baseVal);

            this.cssLength = new CssAbsPrimitiveLengthValue(new CssPrimitiveLengthValue(baseVal, false), propertyName, ownerElement);
        }
コード例 #3
0
ファイル: SvgLength.cs プロジェクト: nagyist/savagesvg
 public SvgLength(SvgElement ownerElement, string propertyName, SvgLengthDirection direction, string baseVal, string defaultValue) :
     this(ownerElement, propertyName, SvgLengthSource.String, direction, defaultValue)
 {
     if (baseVal == null || baseVal.Length == 0)
     {
         baseVal = defaultValue;
     }
     baseVal   = SvgNumber.ScientificToDec(baseVal);
     cssLength = new CssAbsPrimitiveLengthValue(new CssPrimitiveLengthValue(baseVal, false), propertyName, ownerElement);
 }
コード例 #4
0
ファイル: SvgNumber.cs プロジェクト: zellus/SharpVectors
        public static double[] ParseDoubles(string str)
        {
            List <double> valueList = new List <double>();

            foreach (Match m in DoubleRegex.Matches(str))
            {
                if (!string.IsNullOrEmpty(m.Value))
                {
                    valueList.Add(SvgNumber.ParseDouble(m.Value));
                }
            }
            return(valueList.ToArray());
        }
コード例 #5
0
        /// <summary>
        /// Creates a SvgAngle value
        /// </summary>
        /// <param name="s">The string to parse for the angle value</param>
        /// <param name="defaultValue">The default value for the angle.</param>
        /// <param name="readOnly">Specifies if the value should be read-only</param>
        public SvgAngle(string baseVal, string defaultValue, bool readOnly)
        {
            baseVal = baseVal.Trim();
            if (baseVal.Length == 0)
            {
                baseVal = defaultValue;
            }

            baseVal = SvgNumber.ScientificToDec(baseVal);

            _cssAngle = new CssPrimitiveAngleValue(baseVal, readOnly);
            _readOnly = readOnly;
        }
コード例 #6
0
 public static string ScientificToDec(string sc)
 {
     if (sc.IndexOfAny(new char[] { 'e', 'E' }) > -1)
     {
         sc = sc.Trim();
         // remove the unit
         Match match = reUnit.Match(sc);
         return(SvgNumber.ParseToFloat(sc.Substring(0, sc.Length - match.Length)).ToString(Format) + match.Value);
     }
     else
     {
         return(sc);
     }
 }
コード例 #7
0
ファイル: SvgLength.cs プロジェクト: zellus/SharpVectors
        public SvgLength(string propertyName, string baseVal, string defaultValue,
                         SvgElement ownerElement, SvgLengthDirection direction)
        {
            _ownerElement = ownerElement;
            _direction    = direction;

            if (baseVal == null || baseVal.Length == 0)
            {
                baseVal = defaultValue;
            }

            baseVal = SvgNumber.ScientificToDec(baseVal);

            _cssLength = new CssAbsPrimitiveLengthValue(new CssPrimitiveLengthValue(baseVal, false),
                                                        propertyName, ownerElement);
        }
コード例 #8
0
ファイル: SvgLength.cs プロジェクト: zellus/SharpVectors
        public SvgLength(string propertyName, SvgStyleableElement ownerElement, SvgLengthDirection direction, string defaultValue)
        {
            _ownerElement = ownerElement;
            _direction    = direction;

            string baseVal = ownerElement.GetPropertyValue(propertyName);

            if (string.IsNullOrWhiteSpace(baseVal))
            {
                baseVal = defaultValue;
            }

            baseVal = SvgNumber.ScientificToDec(baseVal);

            _cssLength = new CssAbsPrimitiveLengthValue(new CssPrimitiveLengthValue(baseVal, false), propertyName, ownerElement);
        }
コード例 #9
0
ファイル: SvgLength.cs プロジェクト: naver/protonow
        public SvgLength(string propertyName, SvgStyleableElement ownerElement, SvgLengthDirection direction, string defaultValue)
        {
            this.ownerElement = ownerElement;
            this.direction    = direction;

            string baseVal = ownerElement.GetPropertyValue(propertyName);

            if (baseVal == null || baseVal == "")
            {
                baseVal = defaultValue;
            }

            baseVal = SvgNumber.ScientificToDec(baseVal);

            this.cssLength = new CssAbsPrimitiveLengthValue(new CssPrimitiveLengthValue(baseVal, false), propertyName, ownerElement);
        }
コード例 #10
0
ファイル: SvgRect.cs プロジェクト: nagyist/savagesvg
        public SvgRect(string str)
        {
            string replacedStr = Regex.Replace(str, @"(\s|,)+", ",");

            string[] tokens = replacedStr.Split(new char[] { ',' });
            if (tokens.Length == 4)
            {
                this.x      = SvgNumber.ParseToFloat(tokens[0]);
                this.y      = SvgNumber.ParseToFloat(tokens[1]);
                this.width  = SvgNumber.ParseToFloat(tokens[2]);
                this.height = SvgNumber.ParseToFloat(tokens[3]);
            }
            else
            {
                throw new SvgException(SvgExceptionType.SvgInvalidValueErr, "Invalid SvgRect value: " + str);
            }
        }
コード例 #11
0
        public static string ScientificToDec(string sc)
        {
            if (sc.ToUpper().Contains("E"))
            {
                sc = sc.Trim();
                // remove the unit
                Match match = reUnit.Match(sc);

                // Fix for scientific conversion
                // Idea is to convert the the decimal to "Number" format and remove the grouping and set proper decimal digits.
                return(SvgNumber.ParseNumber(sc.Substring(0, sc.Length - match.Length)).ToString("N", Format) + match.Value);

                //return SvgNumber.ParseNumber(sc.Substring(0, sc.Length - match.Length)).ToString(Format) + match.Value;
            }
            else
            {
                return(sc);
            }
        }
コード例 #12
0
        private static double[] ParseCoords(string segment)
        {
            double[] coords = new double[0];

            segment = segment.Substring(1);
            segment = segment.Trim();
            segment = segment.Trim(new char[] { ',' });

            if (segment.Length > 0)
            {
                string[] sCoords = RegexCoordSplit.Split(segment);

                coords = new double[sCoords.Length];
                for (int i = 0; i < sCoords.Length; i++)
                {
                    coords[i] = SvgNumber.ParseNumber(sCoords[i]);
                }
            }
            return(coords);
        }
コード例 #13
0
        private float[] getCoords(String segment)
        {
            float[] coords = new float[0];

            segment = segment.Substring(1);
            segment = segment.Trim();
            segment = segment.Trim(new char[] { ',' });

            if (segment.Length > 0)
            {
                string[] sCoords = coordSplit.Split(segment);

                coords = new float[sCoords.Length];
                for (int i = 0; i < sCoords.Length; i++)
                {
                    coords[i] = SvgNumber.ParseToFloat(sCoords[i]);
                }
            }
            return(coords);
        }
コード例 #14
0
        public bool Parse(ISvgPathSegList pathList, string pathSegs)
        {
            if (pathList == null || string.IsNullOrWhiteSpace(pathSegs))
            {
                return(false);
            }

            _isClosed      = false;
            _mayHaveCurves = false;

            int closedPath = 0;

            ISvgPathSeg seg;

            string[] paths = RegexPathCmd.Split(pathSegs);

            SvgPointF startPoint = new SvgPointF(0, 0);

            foreach (string path in paths)
            {
                string segment = path.Trim();
                if (segment.Length == 0)
                {
                    continue;
                }
//                    char cmd = segment.ToCharArray(0, 1)[0];
//                    double[] coords = ParseCoords(segment);
                char     cmd    = segment[0];
                double[] coords = SvgNumber.ParseDoubles(segment.Substring(1));

                int length = coords.Length;
                switch (cmd)
                {
                // Parse: moveto
                case 'M':
                    for (int i = 0; i < length; i += 2)
                    {
                        if (i == 0)
                        {
                            seg = new SvgPathSegMovetoAbs(coords[i], coords[i + 1]);

                            startPoint = new SvgPointF(coords[i], coords[i + 1]);
                            SvgPointF endPoint = new SvgPointF(coords[i], coords[i + 1]);
                            seg.Limits = new SvgPointF[] { startPoint, endPoint };
                            startPoint = endPoint;
                        }
                        else
                        {
                            seg = new SvgPathSegLinetoAbs(coords[i], coords[i + 1]);

                            SvgPointF endPoint = new SvgPointF(coords[i], coords[i + 1]);
                            seg.Limits = new SvgPointF[] { startPoint, endPoint };
                            startPoint = endPoint;
                        }
                        pathList.AppendItem(seg);
                    }
                    break;

                case 'm':
                    for (int i = 0; i < length; i += 2)
                    {
                        if (i == 0)
                        {
                            seg = new SvgPathSegMovetoRel(coords[i], coords[i + 1]);

                            SvgPointF endPoint = new SvgPointF(coords[i] + startPoint.X, coords[i + 1] + startPoint.Y);
                            seg.Limits = new SvgPointF[] { startPoint, endPoint };
                            startPoint = endPoint;
                        }
                        else
                        {
                            seg = new SvgPathSegLinetoRel(coords[i], coords[i + 1]);

                            SvgPointF endPoint = new SvgPointF(coords[i] + startPoint.X, coords[i + 1] + startPoint.Y);
                            seg.Limits = new SvgPointF[] { startPoint, endPoint };
                            startPoint = endPoint;
                        }
                        pathList.AppendItem(seg);
                    }
                    break;
                // End of: moveto

                // Parse: lineto
                case 'L':
                    for (int i = 0; i < length; i += 2)
                    {
                        seg = new SvgPathSegLinetoAbs(coords[i], coords[i + 1]);
                        pathList.AppendItem(seg);

                        SvgPointF endPoint = new SvgPointF(coords[i], coords[i + 1]);
                        seg.Limits = new SvgPointF[] { startPoint, endPoint };
                        startPoint = endPoint;
                    }
                    break;

                case 'l':
                    for (int i = 0; i < length; i += 2)
                    {
                        seg = new SvgPathSegLinetoRel(coords[i], coords[i + 1]);
                        pathList.AppendItem(seg);

                        SvgPointF endPoint = new SvgPointF(coords[i] + startPoint.X, coords[i + 1] + startPoint.Y);
                        seg.Limits = new SvgPointF[] { startPoint, endPoint };
                        startPoint = endPoint;
                    }
                    break;

                case 'H':
                    for (int i = 0; i < length; i++)
                    {
                        seg = new SvgPathSegLinetoHorizontalAbs(coords[i]);
                        pathList.AppendItem(seg);

                        SvgPointF endPoint = new SvgPointF(coords[i], startPoint.Y);
                        seg.Limits = new SvgPointF[] { startPoint, endPoint };
                        startPoint = endPoint;
                    }
                    break;

                case 'h':
                    for (int i = 0; i < length; i++)
                    {
                        seg = new SvgPathSegLinetoHorizontalRel(coords[i]);
                        pathList.AppendItem(seg);

                        SvgPointF endPoint = new SvgPointF(coords[i] + startPoint.X, startPoint.Y);
                        seg.Limits = new SvgPointF[] { startPoint, endPoint };
                        startPoint = endPoint;
                    }
                    break;

                case 'V':
                    for (int i = 0; i < length; i++)
                    {
                        seg = new SvgPathSegLinetoVerticalAbs(coords[i]);
                        pathList.AppendItem(seg);

                        SvgPointF endPoint = new SvgPointF(startPoint.X, coords[i]);
                        seg.Limits = new SvgPointF[] { startPoint, endPoint };
                        startPoint = endPoint;
                    }
                    break;

                case 'v':
                    for (int i = 0; i < length; i++)
                    {
                        seg = new SvgPathSegLinetoVerticalRel(coords[i]);
                        pathList.AppendItem(seg);

                        SvgPointF endPoint = new SvgPointF(startPoint.X, coords[i] + startPoint.Y);
                        seg.Limits = new SvgPointF[] { startPoint, endPoint };
                        startPoint = endPoint;
                    }
                    break;
                // End of: lineto

                // Parse: beziers
                case 'C':
                    for (int i = 0; i < length; i += 6)
                    {
                        seg = new SvgPathSegCurvetoCubicAbs(
                            coords[i + 4],
                            coords[i + 5],
                            coords[i],
                            coords[i + 1],
                            coords[i + 2],
                            coords[i + 3]);
                        pathList.AppendItem(seg);

                        _mayHaveCurves = true;

                        SvgPointF endPoint = new SvgPointF(coords[i + 4], coords[i + 5]);
                        seg.Limits = new SvgPointF[] { startPoint, endPoint };
                        startPoint = endPoint;
                    }
                    break;

                case 'c':
                    for (int i = 0; i < length; i += 6)
                    {
                        if ((i + 5) >= length)
                        {
                            break;
                        }
                        seg = new SvgPathSegCurvetoCubicRel(
                            coords[i + 4],
                            coords[i + 5],
                            coords[i],
                            coords[i + 1],
                            coords[i + 2],
                            coords[i + 3]);

                        pathList.AppendItem(seg);

                        _mayHaveCurves = true;

                        SvgPointF endPoint = new SvgPointF(coords[i + 4] + startPoint.X, coords[i + 5] + startPoint.Y);
                        seg.Limits = new SvgPointF[] { startPoint, endPoint };
                        startPoint = endPoint;
                    }
                    break;

                case 'S':
                    for (int i = 0; i < length; i += 4)
                    {
                        seg = new SvgPathSegCurvetoCubicSmoothAbs(
                            coords[i + 2],
                            coords[i + 3],
                            coords[i],
                            coords[i + 1]);
                        pathList.AppendItem(seg);

                        _mayHaveCurves = true;

                        SvgPointF endPoint = new SvgPointF(coords[i + 2], coords[i + 3]);
                        seg.Limits = new SvgPointF[] { startPoint, endPoint };
                        startPoint = endPoint;
                    }
                    break;

                case 's':
                    for (int i = 0; i < length; i += 4)
                    {
                        seg = new SvgPathSegCurvetoCubicSmoothRel(
                            coords[i + 2],
                            coords[i + 3],
                            coords[i],
                            coords[i + 1]);
                        pathList.AppendItem(seg);

                        _mayHaveCurves = true;

                        SvgPointF endPoint = new SvgPointF(coords[i + 2] + startPoint.X, coords[i + 3] + startPoint.Y);
                        seg.Limits = new SvgPointF[] { startPoint, endPoint };
                        startPoint = endPoint;
                    }
                    break;

                case 'Q':
                    for (int i = 0; i < length; i += 4)
                    {
                        seg = new SvgPathSegCurvetoQuadraticAbs(
                            coords[i + 2],
                            coords[i + 3],
                            coords[i],
                            coords[i + 1]);
                        pathList.AppendItem(seg);

                        _mayHaveCurves = true;

                        SvgPointF endPoint = new SvgPointF(coords[i + 2], coords[i + 3]);
                        seg.Limits = new SvgPointF[] { startPoint, endPoint };
                        startPoint = endPoint;
                    }
                    break;

                case 'q':
                    for (int i = 0; i < length; i += 4)
                    {
                        seg = new SvgPathSegCurvetoQuadraticRel(
                            coords[i + 2],
                            coords[i + 3],
                            coords[i],
                            coords[i + 1]);
                        pathList.AppendItem(seg);

                        _mayHaveCurves = true;

                        SvgPointF endPoint = new SvgPointF(coords[i + 2] + startPoint.X, coords[i + 3] + startPoint.Y);
                        seg.Limits = new SvgPointF[] { startPoint, endPoint };
                        startPoint = endPoint;
                    }
                    break;

                case 'T':
                    for (int i = 0; i < length; i += 2)
                    {
                        seg = new SvgPathSegCurvetoQuadraticSmoothAbs(
                            coords[i], coords[i + 1]);
                        pathList.AppendItem(seg);

                        _mayHaveCurves = true;

                        SvgPointF endPoint = new SvgPointF(coords[i], coords[i + 1]);
                        seg.Limits = new SvgPointF[] { startPoint, endPoint };
                        startPoint = endPoint;
                    }
                    break;

                case 't':
                    for (int i = 0; i < length; i += 2)
                    {
                        seg = new SvgPathSegCurvetoQuadraticSmoothRel(
                            coords[i], coords[i + 1]);
                        pathList.AppendItem(seg);

                        _mayHaveCurves = true;

                        SvgPointF endPoint = new SvgPointF(coords[i] + startPoint.X, coords[i + 1] + startPoint.Y);
                        seg.Limits = new SvgPointF[] { startPoint, endPoint };
                        startPoint = endPoint;
                    }
                    break;
                // End of: bezier

                // Parse: arcs
                case 'A':
                case 'a':
                    for (int i = 0; i < length; i += 7)
                    {
                        if (cmd == 'A')
                        {
                            seg = new SvgPathSegArcAbs(
                                coords[i + 5],
                                coords[i + 6],
                                coords[i],
                                coords[i + 1],
                                coords[i + 2],
                                (!coords[i + 3].Equals(0)),
                                (!coords[i + 4].Equals(0)));

                            SvgPointF endPoint = new SvgPointF(coords[i + 5], coords[i + 6]);
                            seg.Limits = new SvgPointF[] { startPoint, endPoint };
                            startPoint = endPoint;
                        }
                        else
                        {
                            seg = new SvgPathSegArcRel(
                                coords[i + 5],
                                coords[i + 6],
                                coords[i],
                                coords[i + 1],
                                coords[i + 2],
                                (!coords[i + 3].Equals(0)),
                                (!coords[i + 4].Equals(0)));

                            SvgPointF endPoint = new SvgPointF(coords[i + 5] + startPoint.X, coords[i + 6] + startPoint.Y);
                            seg.Limits = new SvgPointF[] { startPoint, endPoint };
                            startPoint = endPoint;
                        }
                        pathList.AppendItem(seg);

                        _mayHaveCurves = true;
                    }
                    break;
                // End of: arcs

                // Parse: close
                case 'z':
                case 'Z':
                    closedPath++;
                    seg = new SvgPathSegClosePath();
                    pathList.AppendItem(seg);

                    if (pathList.Count >= 2)
                    {
                        SvgPointF endPoint = pathList[0].Limits[0];
                        seg.Limits = new SvgPointF[] { endPoint, startPoint };
                        startPoint = endPoint;
                    }
                    else
                    {
                        seg.Limits = new SvgPointF[] { startPoint, startPoint };
                        startPoint = new SvgPointF(0, 0);
                    }
                    break;
                // End of: close

                // Unknown path command
                default:
                    throw new ApplicationException(string.Format("Unknown path command - ({0})", cmd));
                }
            }

            _isClosed = (closedPath == 1);

            return(true);
        }
コード例 #15
0
 public SvgAnimatedNumber(string str)
 {
     _baseVal = SvgNumber.ParseNumber(str);
     _animVal = _baseVal;
 }
コード例 #16
0
ファイル: SvgTransform.cs プロジェクト: nagyist/savagesvg
        public SvgTransform(string str)
        {
            int    start      = str.IndexOf("(");
            string type       = str.Substring(0, start);
            string valuesList = (str.Substring(start + 1, str.Length - start - 2)).Trim();           //JR added trim
            Regex  re         = new Regex("[\\s\\,]+");

            valuesList = re.Replace(valuesList, ",");
            string[] valuesStr = valuesList.Split(new char[] { ',' });
            int      len       = valuesStr.GetLength(0);

            float[] values = new float[len];

            for (int i = 0; i < len; i++)
            {
                values.SetValue(SvgNumber.ParseToFloat(valuesStr[i]), i);
            }

            switch (type)
            {
            case "translate":
                switch (len)
                {
                case 1:
                    SetTranslate(values[0], 0);
                    break;

                case 2:
                    SetTranslate(values[0], values[1]);
                    break;

                default:
                    throw new ApplicationException("Wrong number of arguments in translate transform");
                }
                break;

            case "rotate":
                switch (len)
                {
                case 1:
                    SetRotate(values[0]);
                    break;

                case 3:
                    SetRotate(values[0], values[1], values[2]);
                    break;

                default:
                    throw new ApplicationException("Wrong number of arguments in rotate transform");
                }
                break;

            case "scale":
                switch (len)
                {
                case 1:
                    SetScale(values[0], values[0]);
                    break;

                case 2:
                    SetScale(values[0], values[1]);
                    break;

                default:
                    throw new ApplicationException("Wrong number of arguments in scale transform");
                }
                break;

            case "skewX":
                if (len != 1)
                {
                    throw new ApplicationException("Wrong number of arguments in skewX transform");
                }
                SetSkewX(values[0]);
                break;

            case "skewY":
                if (len != 1)
                {
                    throw new ApplicationException("Wrong number of arguments in skewY transform");
                }
                SetSkewY(values[0]);
                break;

            case "matrix":
                if (len != 6)
                {
                    throw new ApplicationException("Wrong number of arguments in matrix transform");
                }
                SetMatrix(
                    new SvgMatrix(
                        values[0],
                        values[1],
                        values[2],
                        values[3],
                        values[4],
                        values[5]
                        ));
                break;

            default:
                this.type = (short)SvgTransformType.Unknown;
                break;
            }
        }
コード例 #17
0
 public SvgNumber(string str)
 {
     _value = SvgNumber.ParseToFloat(str);
 }
コード例 #18
0
        public double[] FitToViewBox(SvgRect viewBox, SvgRect rectToFit)
        {
            var localName = _ownerElement.LocalName;

            if (string.Equals(localName, "svg", StringComparison.Ordinal)) // (_ownerElement is SvgSvgElement)
            {
                ISvgMatrix mat = ((SvgSvgElement)_ownerElement).ViewBoxTransform;
                return(new double[] { mat.E, mat.F, mat.A, mat.D });
            }
            if (string.Equals(localName, "pattern", StringComparison.Ordinal)) // (_ownerElement is SvgPatternElement)
            {
                ISvgMatrix mat = ((SvgPatternElement)_ownerElement).ViewBoxTransform;
                return(new double[] { mat.E, mat.F, mat.A, mat.D });
            }

            double translateX = 0;
            double translateY = 0;
            double scaleX     = 1;
            double scaleY     = 1;

            if (!viewBox.IsEmpty && !rectToFit.IsEmpty)
            {
                // calculate scale values for non-uniform scaling
                scaleX = rectToFit.Width / viewBox.Width;
                scaleY = rectToFit.Height / viewBox.Height;

                if (_alignment != SvgPreserveAspectRatioType.None)
                {
                    // uniform scaling
                    if (_meetOrSlice == SvgMeetOrSlice.Meet)
                    {
                        scaleX = Math.Min(scaleX, scaleY);
                    }
                    else
                    {
                        scaleX = Math.Max(scaleX, scaleY);
                    }

                    scaleY = scaleX;

                    if (_alignment == SvgPreserveAspectRatioType.XMidYMax ||
                        _alignment == SvgPreserveAspectRatioType.XMidYMid ||
                        _alignment == SvgPreserveAspectRatioType.XMidYMin)
                    {
                        // align to the Middle X
                        translateX = (rectToFit.X + rectToFit.Width / 2) - scaleX * (viewBox.X + viewBox.Width / 2);
                    }
                    else if (_alignment == SvgPreserveAspectRatioType.XMaxYMax ||
                             _alignment == SvgPreserveAspectRatioType.XMaxYMid ||
                             _alignment == SvgPreserveAspectRatioType.XMaxYMin)
                    {
                        // align to the right X
                        translateX = (rectToFit.Width - viewBox.Width * scaleX);
                    }

                    if (_alignment == SvgPreserveAspectRatioType.XMaxYMid ||
                        _alignment == SvgPreserveAspectRatioType.XMidYMid ||
                        _alignment == SvgPreserveAspectRatioType.XMinYMid)
                    {
                        // align to the Middle Y
                        translateY = (rectToFit.Y + rectToFit.Height / 2) - scaleY * (viewBox.Y + viewBox.Height / 2);
                    }
                    else if (_alignment == SvgPreserveAspectRatioType.XMaxYMax ||
                             _alignment == SvgPreserveAspectRatioType.XMidYMax ||
                             _alignment == SvgPreserveAspectRatioType.XMinYMax)
                    {
                        // align to the bottom Y
                        translateY = (rectToFit.Height - viewBox.Height * scaleY);
                    }
                }
                else
                {
                    translateX = -viewBox.X * scaleX;
                    translateY = -viewBox.Y * scaleY;
                }
            }

            if (!SvgNumber.IsValid(translateX))
            {
                translateX = 0;
            }
            if (!SvgNumber.IsValid(translateY))
            {
                translateY = 0;
            }
            if (!SvgNumber.IsValid(scaleX))
            {
                scaleX = 1;
            }
            if (!SvgNumber.IsValid(scaleY))
            {
                scaleY = 1;
            }

            return(new double[] { translateX, translateY, scaleX, scaleY });
        }
コード例 #19
0
        public SvgTransform(string str)
        {
            int    start      = str.IndexOf("(", StringComparison.OrdinalIgnoreCase);
            string type       = str.Substring(0, start);
            string valuesList = (str.Substring(start + 1, str.Length - start - 2)).Trim();           //JR added trim
            Regex  re         = new Regex("[\\s\\,]+");

            valuesList = re.Replace(valuesList, ",");

            string[] valuesStr = valuesList.Split(new char[] { ',' });
            int      len       = valuesStr.GetLength(0);

            double[] values = new double[len];

            try
            {
                for (int i = 0; i < len; i++)
                {
                    values[i] = SvgNumber.Parse(valuesStr[i]);
                }
            }
            catch
            {
                values = SvgNumber.ParseDoubles(str);
                len    = values.Length;
            }

            _values = values;

            switch (type.Trim())
            {
            case "translate":
                switch (len)
                {
                case 1:
                    SetTranslate(values[0], 0);
                    break;

                case 2:
                    SetTranslate(values[0], values[1]);
                    break;

                default:
                    throw new ApplicationException("Wrong number of arguments in translate transform");
                }
                break;

            case "rotate":
                switch (len)
                {
                case 1:
                    SetRotate(values[0]);
                    break;

                case 3:
                    SetRotate(values[0], values[1], values[2]);
                    break;

                default:
                    throw new ApplicationException("Wrong number of arguments in rotate transform");
                }
                break;

            case "scale":
                switch (len)
                {
                case 1:
                    SetScale(values[0], values[0]);
                    break;

                case 2:
                    SetScale(values[0], values[1]);
                    break;

                default:
                    throw new ApplicationException("Wrong number of arguments in scale transform");
                }
                break;

            case "skewX":
                if (len != 1)
                {
                    throw new ApplicationException("Wrong number of arguments in skewX transform");
                }
                SetSkewX(values[0]);
                break;

            case "skewY":
                if (len != 1)
                {
                    throw new ApplicationException("Wrong number of arguments in skewY transform");
                }
                SetSkewY(values[0]);
                break;

            case "matrix":
                if (len != 6)
                {
                    throw new ApplicationException("Wrong number of arguments in matrix transform");
                }
                SetMatrix(new SvgMatrix(values[0], values[1], values[2], values[3], values[4], values[5]));
                break;

            default:
                _type = SvgTransformType.Unknown;
                break;
            }
        }
コード例 #20
0
 public SvgNumber(string str)
 {
     _value = SvgNumber.ParseNumber(str);
 }
コード例 #21
0
 public SvgAnimatedNumber(string str)
 {
     baseVal = SvgNumber.ParseToFloat(str);
     animVal = baseVal;
 }
コード例 #22
0
 public SvgAnimatedInteger(string str)
 {
     _baseVal = Convert.ToInt64(SvgNumber.ParseNumber(str));
     _animVal = _baseVal;
 }
コード例 #23
0
        public void FromString(string listString)
        {
            // remove existing list items
            Clear();

            if (string.IsNullOrWhiteSpace(listString))
            {
                return;
            }
            int len = listString.Length; // temp

            int  p = 0;                  // pos
            char c;                      // temp
            int  sNum      = -1;         // start of the number
            int  eNum      = -1;         // end of the number
            bool seenComma = false;      // to handle 123,,123
            int  tempSNum  = -1;         // start of the number (held in temp until two numbers are found)
            int  tempENum  = -1;         // end of the number (held in temp until two numbers are found)

            // This used to be a regex-- it is *much* faster this way
            while (p < len)
            {
                // Get the char in a temp
                c = listString[p];

                // TODO: worry about NEL?
                if ((c == '\t') || (c == '\r') || (c == '\n') || (c == 0x20) || (c == ','))
                {
                    // Special handling for two commas
                    if (c == ',')
                    {
                        if (seenComma && sNum < 0)
                        {
                            throw new SvgException(SvgExceptionType.SvgInvalidValueErr);
                        }
                        seenComma = true;
                    }

                    // Are we in a number?
                    if (sNum >= 0)
                    {
                        // The end of the number is the previous char
                        eNum = p - 1;

                        // Is this the x or y?
                        if (tempSNum == -1)
                        {
                            // must be the x, hang onto it for a second
                            tempSNum = sNum;
                            tempENum = eNum;
                        }
                        else
                        {
                            // must be the y, use temp as x and append the item
                            AppendItem(new SvgPoint(SvgNumber.ParseNumber(listString.Substring(tempSNum, (tempENum - tempSNum) + 1)),
                                                    SvgNumber.ParseNumber(listString.Substring(sNum, (eNum - sNum) + 1))));
                            tempSNum = -1;
                            tempENum = -1;
                        }

                        // Reset
                        sNum      = -1;
                        eNum      = -1;
                        seenComma = false;
                    }
                }
                else if (sNum == -1)
                {
                    sNum = p;
                }
                // OPTIMIZE: Right here we could check for [Ee] to save some time in IndexOfAny later

                // Move to next char
                p++;
            }

            // We need to handle the end of the buffer as a delimiter
            if (sNum >= 0)
            {
                if (tempSNum == -1)
                {
                    throw new SvgException(SvgExceptionType.SvgInvalidValueErr);
                }

                // The end of the number is the previous char
                eNum = p - 1;
                // must be the y, use temp as x and append the item
                AppendItem(new SvgPoint(SvgNumber.ParseNumber(listString.Substring(tempSNum, (tempENum - tempSNum) + 1)),
                                        SvgNumber.ParseNumber(listString.Substring(sNum, (eNum - sNum) + 1))));
            }
            else if (tempSNum != -1)
            {
                throw new SvgException(SvgExceptionType.SvgInvalidValueErr);
            }
        }
コード例 #24
0
        protected virtual void GetGraphicsPath(ref PointF ctp)
        {
            gp = new GraphicsPath();

            if (this is SvgTextPositioningElement)
            {
                SvgTextPositioningElement tpElm = (SvgTextPositioningElement)this;
                ctp = this.GetCurrentTextPosition(tpElm, ctp);
            }
            string sBaselineShift = GetPropertyValue("baseline-shift").Trim();
            double shiftBy        = 0;

            if (sBaselineShift.Length > 0)
            {
                SvgTextElement textElement = this as SvgTextElement;
                if (textElement == null)
                {
                    textElement = (SvgTextElement)this.SelectSingleNode("ancestor::svg:text", this.OwnerDocument.NamespaceManager);
                }

                float textFontSize = textElement._getComputedFontSize();
                if (sBaselineShift.EndsWith("%"))
                {
                    shiftBy = SvgNumber.ParseToFloat(sBaselineShift.Substring(0, sBaselineShift.Length - 1)) / 100 * textFontSize;
                }
                else if (sBaselineShift == "sub")
                {
                    shiftBy = -0.6F * textFontSize;
                }
                else if (sBaselineShift == "super")
                {
                    shiftBy = 0.6F * textFontSize;
                }
                else if (sBaselineShift == "baseline")
                {
                    shiftBy = 0;
                }
                else
                {
                    shiftBy = SvgNumber.ParseToFloat(sBaselineShift);
                }
            }


            foreach (XmlNode child in this.ChildNodes)
            {
                gp.StartFigure();
                if (child.NodeType == XmlNodeType.Text)
                {
                    ctp.Y -= (float)shiftBy;
                    this.AddGraphicsPath(ref ctp, GetText(child));
                    ctp.Y += (float)shiftBy;
                }
                else if (child is SvgTRefElement)
                {
                    SvgTRefElement trChild = (SvgTRefElement)child;
                    trChild.GetGraphicsPath(ref ctp);
                }
                else if (child is SvgTextContentElement)
                {
                    SvgTextContentElement tcChild = (SvgTextContentElement)child;
                    tcChild.GetGraphicsPath(ref ctp);
                }
            }
        }