SharpVectors.Dom.Svg.SvgPaint.SetPaint C# (CSharp) Method

SetPaint() public method

public SetPaint ( SvgPaintType paintType, string uri, string rgbColor, string iccColor ) : void
paintType SvgPaintType
uri string
rgbColor string
iccColor string
return void
        public void SetPaint(SvgPaintType paintType, string uri, string rgbColor, string iccColor )
        {
            _paintType = paintType;

            // check URI
            switch(_paintType)
            {
                case SvgPaintType.Uri:
                case SvgPaintType.UriCurrentColor:
                case SvgPaintType.UriNone:
                case SvgPaintType.UriRgbColor:
                case SvgPaintType.UriRgbColorIccColor:
                    if(uri == null)
                    {
                        throw new SvgException(SvgExceptionType.SvgInvalidValueErr, "Missing URI");
                    }
                    else
                    {
                        _uri = uri;

                    }
                    break;
                default:
                    if(uri != null)
                    {
                        throw new SvgException(SvgExceptionType.SvgInvalidValueErr, "URI must be null");
                    }
                    break;
            }

            // check RGB and ICC color
            switch(_paintType)
            {
                case SvgPaintType.CurrentColor:
                case SvgPaintType.UriCurrentColor:
                    base._parseColor("currentColor");
                    break;
                case SvgPaintType.RgbColor:
                case SvgPaintType.UriRgbColor:
                    if(rgbColor != null && rgbColor.Length > 0)
                    {
                        base.SetRgbColor(rgbColor);
                    }
                    else
                    {
                        throw new SvgException(SvgExceptionType.SvgInvalidValueErr, "Missing RGB color");
                    }
                    break;
                case SvgPaintType.RgbColorIccColor:
                case SvgPaintType.UriRgbColorIccColor:
                    if(rgbColor != null && rgbColor.Length > 0 &&
                        iccColor != null && iccColor.Length > 0)
                    {
                        base.SetRgbColorIccColor(rgbColor, iccColor);
                    }
                    else
                    {
                        throw new SvgException(SvgExceptionType.SvgInvalidValueErr, "Missing RGB or ICC color");
                    }
                    break;
                default:
                    if(rgbColor != null)
                    {
                        throw new SvgException(SvgExceptionType.SvgInvalidValueErr, "rgbColor must be null");
                    }
                    break;
            }
        }

Usage Example

Exemplo n.º 1
0
        public void TestSetPaint()
        {
            SvgPaint paint = new SvgPaint("none");

            paint.SetPaint(SvgPaintType.Uri, "someuri", null, null);
            Assert.AreEqual("someuri", paint.Uri);
            Assert.AreEqual("url(someuri)", paint.CssText);
            Assert.AreEqual(SvgPaintType.Uri, paint.PaintType);

            paint.SetPaint(SvgPaintType.UriCurrentColor, "someuri", null, null);
            Assert.AreEqual("someuri", paint.Uri);
            Assert.AreEqual("url(someuri) currentColor", paint.CssText);
            Assert.AreEqual(SvgPaintType.UriCurrentColor, paint.PaintType);

            paint.SetPaint(SvgPaintType.UriNone, "someuri", null, null);
            Assert.AreEqual("someuri", paint.Uri);
            Assert.AreEqual("url(someuri) none", paint.CssText);
            Assert.AreEqual(SvgPaintType.UriNone, paint.PaintType);

            paint.SetPaint(SvgPaintType.None, null, null, null);
            Assert.AreEqual("none", paint.CssText);
            Assert.AreEqual(SvgPaintType.None, paint.PaintType);

            paint.SetPaint(SvgPaintType.CurrentColor, null, null, null);
            Assert.AreEqual("currentColor", paint.CssText);
            Assert.AreEqual(SvgPaintType.CurrentColor, paint.PaintType);

            paint.SetPaint(SvgPaintType.UriRgbColor, "someuri", "#ff00ff", null);
            Assert.AreEqual("url(someuri) rgb(255,0,255)", paint.CssText);
            Assert.AreEqual(SvgPaintType.UriRgbColor, paint.PaintType);
        }