Esempio n. 1
0
    public SVGMatrix ViewBoxTransform()
    {
        if (this._cachedViewBoxTransform == null)
        {
            SVGMatrix matrix = new SVGMatrix();

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

            float attrWidth  = this._width.value;
            float attrHeight = this._height.value;

            if (_attrList.GetValue("viewBox") != "")
            {
                Rect r = this._viewport;
                x += -r.x;
                y += -r.y;
                w  = r.width;
                h  = r.height;
            }
            else
            {
                w = attrWidth;
                h = attrHeight;
            }

            float x_ratio = attrWidth / w;
            float y_ratio = attrHeight / h;

            matrix = matrix.ScaleNonUniform(x_ratio, y_ratio);
            matrix = matrix.Translate(x, y);
            _cachedViewBoxTransform = matrix;
        }
        return(this._cachedViewBoxTransform);
    }
Esempio n. 2
0
        protected override void PrepareForRendering(SVGLayer[] layers, SVGAsset svgAsset, bool force)
        {
            SVGMatrix T = SVGMatrix.identity.Translate(-position);
            SVGMatrix R = SVGMatrix.identity.Rotate(rotation);
            SVGMatrix S = SVGMatrix.identity.Scale(scale);

            SVGMatrix tempMatrix = SVGMatrix.identity;

            if (preprocess)
            {
                tempMatrix = tempMatrix.Translate(Vector2.one * 0.5f).Scale(0.25f, 0.25f);
            }

            switch (transformOrder)
            {
            case TransformOrder.TRS:
                tempMatrix *= S * R * T;
                break;

            case TransformOrder.TSR:
                tempMatrix *= R * S * T;
                break;

            case TransformOrder.RTS:
                tempMatrix *= S * T * R;
                break;

            case TransformOrder.RST:
                tempMatrix *= T * S * R;
                break;

            case TransformOrder.STR:
                tempMatrix *= S * T * S;
                break;

            case TransformOrder.SRT:
                tempMatrix *= T * R * S;
                break;
            }

            if (layers == null)
            {
                return;
            }
            int totalLayers = layers.Length;

            if (!useSelection)
            {
                for (int i = 0; i < totalLayers; i++)
                {
                    if (layers[i].shapes == null)
                    {
                        continue;
                    }
                    int shapesLength = layers[i].shapes.Length;
                    for (int j = 0; j < shapesLength; j++)
                    {
                        int vertexCount = layers[i].shapes[j].vertexCount;
                        for (int k = 0; k < vertexCount; k++)
                        {
                            layers[i].shapes[j].fill.fillType  = FILL_TYPE.TEXTURE;
                            layers[i].shapes[j].fill.transform = tempMatrix;
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < totalLayers; i++)
                {
                    if (layers[i].shapes == null)
                    {
                        continue;
                    }
                    if (!layerSelection.Contains(i))
                    {
                        continue;
                    }

                    int shapesLength = layers[i].shapes.Length;
                    for (int j = 0; j < shapesLength; j++)
                    {
                        int vertexCount = layers[i].shapes[j].vertexCount;
                        for (int k = 0; k < vertexCount; k++)
                        {
                            layers[i].shapes[j].fill.fillType  = FILL_TYPE.TEXTURE;
                            layers[i].shapes[j].fill.transform = tempMatrix;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
    public SVGMatrix ViewBoxTransform()
    {
        if(this._cachedViewBoxTransform == null) {

          SVGMatrix matrix = new SVGMatrix();

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

          float attrWidth = this._width.value;
          float attrHeight = this._height.value;

          if(_attrList.GetValue("viewBox") != "") {
        Rect r = this._viewport;
        x += -r.x;
        y += -r.y;
        w = r.width;
        h = r.height;
          } else {
        w = attrWidth;
        h = attrHeight;
          }

          float x_ratio = attrWidth / w;
          float y_ratio = attrHeight / h;

          matrix = matrix.ScaleNonUniform(x_ratio, y_ratio);
          matrix = matrix.Translate(x, y);
          _cachedViewBoxTransform = matrix;
        }
        return this._cachedViewBoxTransform;
    }