ExtractTransformValue() public static method

public static ExtractTransformValue ( string inputText ) : string[]
inputText string
return string[]
Exemplo n.º 1
0
    private void SetViewBox()
    {
        string attr = _attrList.GetValue("viewBox");

        if (!string.IsNullOrEmpty(attr))
        {
            string[] _temp = SVGStringExtractor.ExtractTransformValue(attr);
            if (_temp.Length == 4)
            {
                float x = float.Parse(_temp[0], CultureInfo.InvariantCulture);
                float y = float.Parse(_temp[1], CultureInfo.InvariantCulture);
                float w = float.Parse(_temp[2], CultureInfo.InvariantCulture);
                float h = float.Parse(_temp[3], CultureInfo.InvariantCulture);
                _viewport = new Rect(x, y, w, h);
            }
        }
    }
Exemplo n.º 2
0
    /***********************************************************************************/
    private void SetViewBox()
    {
        string attr = this._attrList.GetValue("viewBox");

        if (attr != "")
        {
            string[] _temp = SVGStringExtractor.ExtractTransformValue(attr);
            if (_temp.Length == 4)
            {
                float x = float.Parse(_temp[0], System.Globalization.CultureInfo.InvariantCulture);
                float y = float.Parse(_temp[1], System.Globalization.CultureInfo.InvariantCulture);
                float w = float.Parse(_temp[2], System.Globalization.CultureInfo.InvariantCulture);
                float h = float.Parse(_temp[3], System.Globalization.CultureInfo.InvariantCulture);
                this._viewport = new Rect(x, y, w, h);
            }
        }
    }
Exemplo n.º 3
0
    private static List <Vector2> ExtractPoints(string inputText)
    {
        List <Vector2> _return = new List <Vector2>();

        string[] _lstStr = SVGStringExtractor.ExtractTransformValue(inputText);

        int len = _lstStr.Length;

        for (int i = 0; i < len - 1; i++)
        {
            string    value1   = _lstStr[i];
            string    value2   = _lstStr[i + 1];
            SVGLength _length1 = new SVGLength(value1);
            SVGLength _length2 = new SVGLength(value2);
            Vector2   _point   = new Vector2(_length1.value, _length2.value);
            _return.Add(_point);
            i++;
        }
        return(_return);
    }
Exemplo n.º 4
0
        public SVGTransform(string strKey, string strValue)
        {
            string[] valuesStr = SVGStringExtractor.ExtractTransformValue(strValue);
            int      len       = valuesStr.Length;

            float[] values = new float[len];

            for (int i = 0; i < len; i++)
            {
                try
                {
                    values.SetValue(float.Parse(valuesStr [i], System.Globalization.CultureInfo.InvariantCulture), i);
                } catch (System.Exception e)
                {
                    UnityEngine.Debug.Log("SVGTransform: e: " + e);
                }
            }

            switch (strKey)
            {
            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 = SVGTransformMode.Unknown;
                break;
            }
        }
Exemplo n.º 5
0
        public static SVGMatrix GetRootViewBoxTransform(AttributeList attributeList, ref Rect viewport)
        {
            SVGMatrix matrix = SVGMatrix.identity;

            string attrXString      = attributeList.GetValue("x");
            string attrYString      = attributeList.GetValue("y");
            string attrWidthString  = attributeList.GetValue("width");
            string attrHeightString = attributeList.GetValue("height");

            SVGLength attrX = new SVGLength(SVGLengthType.PX, 0f), attrY = new SVGLength(SVGLengthType.PX, 0f),
                      attrWidth = new SVGLength(SVGLengthType.PX, 1f), attrHeight = new SVGLength(SVGLengthType.PX, 1f);

            if (!string.IsNullOrEmpty(attrXString))
            {
                attrX = new SVGLength(attrXString);
            }
            if (!string.IsNullOrEmpty(attrYString))
            {
                attrY = new SVGLength(attrYString);
            }
            if (!string.IsNullOrEmpty(attrWidthString))
            {
                attrWidth = new SVGLength(attrWidthString);
            }
            if (!string.IsNullOrEmpty(attrHeightString))
            {
                attrHeight = new SVGLength(attrHeightString);
            }

            string viewBox = attributeList.GetValue("viewBox");

            if (!string.IsNullOrEmpty(viewBox))
            {
                string[] _temp = SVGStringExtractor.ExtractTransformValue(viewBox);
                if (_temp.Length > 0)
                {
                    if (string.IsNullOrEmpty(attrXString))
                    {
                        attrX = new SVGLength(_temp [0]);
                    }
                }
                if (_temp.Length > 1)
                {
                    if (string.IsNullOrEmpty(attrYString))
                    {
                        attrY = new SVGLength(_temp [1]);
                    }
                }
                if (_temp.Length > 2)
                {
                    if (string.IsNullOrEmpty(attrWidthString))
                    {
                        attrWidth = new SVGLength(_temp [2]);
                    }
                }
                if (_temp.Length > 3)
                {
                    if (string.IsNullOrEmpty(attrHeightString))
                    {
                        attrHeight = new SVGLength(_temp [3]);
                    }
                }

                viewport = new Rect(attrX.value, attrY.value, attrWidth.value, attrHeight.value);

                if (string.IsNullOrEmpty(attrXString))
                {
                    viewport.x = attrX.value;
                }

                if (string.IsNullOrEmpty(attrYString))
                {
                    viewport.y = attrY.value;
                }

                if (string.IsNullOrEmpty(attrWidthString))
                {
                    viewport.width = attrWidth.value;
                }

                if (string.IsNullOrEmpty(attrHeightString))
                {
                    viewport.height = attrHeight.value;
                }
            }
            else
            {
                viewport = new Rect(attrX.value, attrY.value, attrWidth.value, attrHeight.value);
            }

            return(matrix);
        }
Exemplo n.º 6
0
        public static SVGMatrix GetViewBoxTransform(AttributeList attributeList, ref Rect viewport, bool negotiate = false)
        {
            SVGMatrix matrix = SVGMatrix.identity;

            float x = 0.0f;
            float y = 0.0f;
            float w = 0.0f;
            float h = 0.0f;

            string preserveAspectRatio = attributeList.GetValue("preserveAspectRatio");
            string viewBox             = attributeList.GetValue("viewBox");

            if (!string.IsNullOrEmpty(viewBox))
            {
                string[] viewBoxValues = SVGStringExtractor.ExtractTransformValue(viewBox);
                if (viewBoxValues.Length == 4)
                {
                    Rect contentRect = new Rect(
                        new SVGLength(viewBoxValues[0]).value,
                        new SVGLength(viewBoxValues[1]).value,
                        new SVGLength(viewBoxValues[2]).value,
                        new SVGLength(viewBoxValues[3]).value
                        );

                    SVGViewport.Align       align       = SVGViewport.Align.xMidYMid;
                    SVGViewport.MeetOrSlice meetOrSlice = SVGViewport.MeetOrSlice.Meet;

                    if (!string.IsNullOrEmpty(preserveAspectRatio))
                    {
                        string[] aspectRatioValues = SVGStringExtractor.ExtractStringArray(preserveAspectRatio);
                        align       = SVGViewport.GetAlignFromStrings(aspectRatioValues);
                        meetOrSlice = SVGViewport.GetMeetOrSliceFromStrings(aspectRatioValues);
                    }

                    Rect oldViewport = viewport;
                    viewport = SVGViewport.GetViewport(viewport, contentRect, align, meetOrSlice);

                    float sizeX = 0f, sizeY = 0f;
                    if (oldViewport.size.x != 0f)
                    {
                        sizeX = viewport.size.x / oldViewport.size.x;
                    }
                    if (oldViewport.size.y != 0f)
                    {
                        sizeY = viewport.size.y / oldViewport.size.y;
                    }

                    matrix.Scale(sizeX, sizeY);
                    matrix = matrix.Translate(viewport.x - oldViewport.x, viewport.y - oldViewport.y);
                }
            }
            else
            {
                if (negotiate)
                {
                    string attrXString      = attributeList.GetValue("x");
                    string attrYString      = attributeList.GetValue("y");
                    string attrWidthString  = attributeList.GetValue("width");
                    string attrHeightString = attributeList.GetValue("height");

                    SVGLength attrX = new SVGLength(SVGLengthType.PX, 0f), attrY = new SVGLength(SVGLengthType.PX, 0f),
                              attrWidth = new SVGLength(SVGLengthType.PX, 1f), attrHeight = new SVGLength(SVGLengthType.PX, 1f);

                    if (!string.IsNullOrEmpty(attrXString))
                    {
                        attrX = new SVGLength(attrXString);
                    }
                    if (!string.IsNullOrEmpty(attrYString))
                    {
                        attrY = new SVGLength(attrYString);
                    }
                    if (!string.IsNullOrEmpty(attrWidthString))
                    {
                        attrWidth = new SVGLength(attrWidthString);
                    }
                    if (!string.IsNullOrEmpty(attrHeightString))
                    {
                        attrHeight = new SVGLength(attrHeightString);
                    }


                    x = attrX.value;
                    y = attrY.value;
                    w = attrWidth.value;
                    h = attrHeight.value;

                    float x_ratio = 1f;
                    if (w != 0f)
                    {
                        x_ratio = attrWidth.value / w;
                    }

                    float y_ratio = 1f;
                    if (h != 0f)
                    {
                        y_ratio = attrHeight.value / h;
                    }

                    matrix   = matrix.Scale(x_ratio, y_ratio);
                    matrix   = matrix.Translate(x, y);
                    viewport = new Rect(x, y, w, h);

                    //                Debug.Log(string.Format("x: {0}, y: {1}, width: {2}, height: {3}, attrWidth: {4}, attrHeight: {5}", x, y, w, h, attrWidth, attrHeight));
                }
                //                Debug.Log(string.Format("x: {0}, y: {1}, width: {2}, height: {3}, attrWidth: {4}, attrHeight: {5}", x, y, w, h, attrWidth, attrHeight));
            }

            return(matrix);
        }