Inheritance: SharpVectors.Dom.Svg.SvgPaint
Esempio n. 1
0
        public void TestColorFill()
        {
            elm.SetAttribute("fill", "red");
            GdiSvgPaint paint = new GdiSvgPaint(elm, "fill");

            Brush brush = paint.GetBrush(getGp());

            Assert.AreEqual(typeof(SolidBrush), brush.GetType());
            Assert.IsTrue(isSameColor(Color.Red, ((SolidBrush)brush).Color));
        }
Esempio n. 2
0
        public void TestCurrentColor()
        {
            elm.SetAttribute("stroke", "currentColor");
            elm.SetAttribute("color", "red");
            GdiSvgPaint paint = new GdiSvgPaint(elm, "stroke");

            Pen pen = paint.GetPen(getGp());

            Assert.IsTrue(isSameColor(Color.Red, pen.Color));
        }
Esempio n. 3
0
        public void TestColorStroke()
        {
            elm.SetAttribute("stroke", "green");
            elm.SetAttribute("stroke-width", "23px");
            GdiSvgPaint paint = new GdiSvgPaint(elm, "stroke");

            Pen pen = paint.GetPen(getGp());

            Assert.IsTrue(isSameColor(Color.Green, pen.Color));
            Assert.AreEqual(23, pen.Width);
        }
Esempio n. 4
0
        public Pen GetPen(GraphicsPath gp)
        {
            float strokeWidth = getStrokeWidth();
            if(strokeWidth == 0) return null;

            GdiSvgPaint stroke;
            if(PaintType == SvgPaintType.None)
            {
                return null;
            }
            else if(PaintType == SvgPaintType.CurrentColor)
            {
                stroke = new GdiSvgPaint(_element, "color");
            }
            else
            {
                stroke = this;
            }

            Pen pen = new Pen(stroke.GetBrush(gp, "stroke"), strokeWidth);

            pen.StartCap = pen.EndCap = getLineCap();
            pen.LineJoin = getLineJoin();
            pen.MiterLimit = getMiterLimit();

            float[] fDashArray = getDashArray(strokeWidth);
            if(fDashArray != null)
            {
                // Do not draw if dash array had a zero value in it

                for(int i=0;i<fDashArray.Length;i++)
                {
                    if(fDashArray[i] == 0)
                        return null;
                }

                pen.DashPattern = fDashArray;
            }

            pen.DashOffset = getDashOffset(strokeWidth);

            return pen;
        }
Esempio n. 5
0
        public void TestDashPattern()
        {
            elm.SetAttribute("stroke", "white");
            elm.SetAttribute("stroke-width", "2px");
            elm.SetAttribute("stroke-dasharray", "5,3,2");
            //elm.SetAttribute("stroke-dashoffset", "0.5");
            GdiSvgPaint paint = new GdiSvgPaint(elm, "stroke");
            Pen pen = paint.GetPen(getGp());
            float[] correct = new float[]{2.5F, 1.5F, 1F, 2.5F, 1.5F, 1F};
            float[] actual = pen.DashPattern;

            Assert.AreEqual(6, actual.Length);
            Assert.AreEqual(2.5F, actual[0]);
            Assert.AreEqual(1.5F, actual[1]);
            Assert.AreEqual(1F, actual[2]);

            Assert.AreEqual(2.5F, actual[3]);
            Assert.AreEqual(1.5F, actual[4]);
            Assert.AreEqual(1F, actual[5]);
        }
Esempio n. 6
0
 public void TestOpacityStrokeOpacityAndOpacity()
 {
     elm.SetAttribute("stroke", "white");
     elm.SetAttribute("opacity", "0.1");
     elm.SetAttribute("stroke-opacity", "0.5");
     GdiSvgPaint paint = new GdiSvgPaint(elm, "stroke");
     Pen pen = paint.GetPen(getGp());
     Assert.AreEqual(Convert.ToInt32(255*0.1*0.5), pen.Color.A);
 }
Esempio n. 7
0
        public void TestOpacityStroke()
        {
            elm.SetAttribute("stroke", "white");
            elm.SetAttribute("opacity", "0.5");
            GdiSvgPaint paint = new GdiSvgPaint(elm, "stroke");

            Pen pen = paint.GetPen(getGp());
            Assert.AreEqual(128, pen.Color.A);
        }
Esempio n. 8
0
 public void TestOpacityFill()
 {
     elm.SetAttribute("opacity", "0.5");
     GdiSvgPaint paint = new GdiSvgPaint(elm, "fill");
     Brush brush = paint.GetBrush(getGp());
     Assert.AreEqual(128, ((SolidBrush)brush).Color.A);
 }
Esempio n. 9
0
        public void TestNonExistingGradientRgbColor()
        {
            elm.SetAttribute("stroke", "url(#myGradient) blue");
            GdiSvgPaint paint = new GdiSvgPaint(elm, "stroke");

            Assert.AreEqual(SvgPaintType.UriRgbColor, paint.PaintType);

            Pen pen = paint.GetPen(getGp());
            Assert.IsTrue(isSameColor(Color.Blue, pen.Color));
        }
Esempio n. 10
0
        public override void Render(ISvgRenderer renderer)
        {
            GdiRenderer     gdiRenderer = renderer as GdiRenderer;
            GraphicsWrapper graphics    = gdiRenderer.GraphicsWrapper;

            if (!(element is SvgClipPathElement) && !(element.ParentNode is SvgClipPathElement))
            {
                SvgStyleableElement styleElm = element as SvgStyleableElement;
                if (styleElm != null)
                {
                    string sVisibility = styleElm.GetPropertyValue("visibility");
                    string sDisplay    = styleElm.GetPropertyValue("display");

                    if (element is ISharpGDIPath && sVisibility != "hidden" && sDisplay != "none")
                    {
                        GraphicsPath gp = ((ISharpGDIPath)element).GetGraphicsPath();

                        if (gp != null)
                        {
                            Clip(graphics);

                            GdiSvgPaint fillPaint = new GdiSvgPaint(styleElm, "fill");
                            Brush       brush     = fillPaint.GetBrush(gp);

                            GdiSvgPaint strokePaint = new GdiSvgPaint(styleElm, "stroke");
                            Pen         pen         = strokePaint.GetPen(gp);

                            if (brush != null)
                            {
                                if (brush is PathGradientBrush)
                                {
                                    GradientPaintServer gps = fillPaint.PaintServer as GradientPaintServer;
                                    //GraphicsContainer container = graphics.BeginContainer();

                                    graphics.SetClip(gps.GetRadialGradientRegion(gp.GetBounds()), CombineMode.Exclude);

                                    SolidBrush tempBrush = new SolidBrush(((PathGradientBrush)brush).InterpolationColors.Colors[0]);
                                    graphics.FillPath(this, tempBrush, gp);
                                    tempBrush.Dispose();
                                    graphics.ResetClip();

                                    //graphics.EndContainer(container);
                                }

                                graphics.FillPath(this, brush, gp);
                                brush.Dispose();
                            }

                            if (pen != null)
                            {
                                if (pen.Brush is PathGradientBrush)
                                {
                                    GradientPaintServer      gps       = strokePaint.PaintServer as GradientPaintServer;
                                    GraphicsContainerWrapper container = graphics.BeginContainer();

                                    graphics.SetClip(gps.GetRadialGradientRegion(gp.GetBounds()), CombineMode.Exclude);

                                    SolidBrush tempBrush = new SolidBrush(((PathGradientBrush)pen.Brush).InterpolationColors.Colors[0]);
                                    Pen        tempPen   = new Pen(tempBrush, pen.Width);
                                    graphics.DrawPath(this, tempPen, gp);
                                    tempPen.Dispose();
                                    tempBrush.Dispose();

                                    graphics.EndContainer(container);
                                }

                                graphics.DrawPath(this, pen, gp);
                                pen.Dispose();
                            }
                        }
                    }
                    PaintMarkers(gdiRenderer, styleElm, graphics);
                }
            }
        }
Esempio n. 11
0
        private Brush GetBrush(GraphicsPath gp, string propPrefix)
        {
            SvgPaint fill;
            if(PaintType == SvgPaintType.None)
            {
                return null;
            }
            else if(PaintType == SvgPaintType.CurrentColor)
            {
                fill = new GdiSvgPaint(_element, "color");
            }
            else
            {
                fill = this;
            }

            if(fill.PaintType == SvgPaintType.Uri ||
                fill.PaintType == SvgPaintType.UriCurrentColor ||
                fill.PaintType == SvgPaintType.UriNone ||
                fill.PaintType == SvgPaintType.UriRgbColor ||
                fill.PaintType == SvgPaintType.UriRgbColorIccColor)
            {
                ps = getPaintServer(fill.Uri);
                if(ps != null)
                {
                    Brush br = ps.GetBrush(gp.GetBounds());
              if (br is LinearGradientBrush)
              {
            LinearGradientBrush lgb = (LinearGradientBrush)br;
            int opacityl = getOpacity(propPrefix);
            for (int i = 0; i < lgb.InterpolationColors.Colors.Length; i++)
            {
              lgb.InterpolationColors.Colors[i] = Color.FromArgb(opacityl, lgb.InterpolationColors.Colors[i]);
            }
            for (int i = 0; i < lgb.LinearColors.Length; i++)
            {
              lgb.LinearColors[i] = Color.FromArgb(opacityl, lgb.LinearColors[i]);
            }
              } else if (br is PathGradientBrush)
              {
            PathGradientBrush pgb = (PathGradientBrush)br;
            int opacityl = getOpacity(propPrefix);
            for (int i = 0; i < pgb.InterpolationColors.Colors.Length; i++)
            {
              pgb.InterpolationColors.Colors[i] = Color.FromArgb(opacityl, pgb.InterpolationColors.Colors[i]);
            }
            for (int i = 0; i < pgb.SurroundColors.Length; i++)
            {
              pgb.SurroundColors[i] = Color.FromArgb(opacityl, pgb.SurroundColors[i]);
            }
              }
              return br;
                }
                else
                {
                    if(PaintType == SvgPaintType.UriNone ||
                        PaintType == SvgPaintType.Uri)
                    {
                        return null;
                    }
                    else if(PaintType == SvgPaintType.UriCurrentColor)
                    {
                        fill = new GdiSvgPaint(_element, "color");
                    }
                    else
                    {
                        fill = this;
                    }
                }
            }

            SolidBrush brush = new SolidBrush( ((RgbColor)fill.RgbColor).GdiColor );
            int opacity = getOpacity(propPrefix);
            brush.Color = Color.FromArgb(opacity, brush.Color);
            return brush;
        }
        public override void Render(ISvgRenderer renderer)
        {
            GdiRenderer gdiRenderer = renderer as GdiRenderer;
            GraphicsWrapper graphics = gdiRenderer.GraphicsWrapper;

            if ( !(element is SvgClipPathElement) && !(element.ParentNode is SvgClipPathElement) )
            {
                SvgStyleableElement styleElm = element as SvgStyleableElement;
                if ( styleElm != null )
                {
                    string sVisibility = styleElm.GetPropertyValue("visibility");
                    string sDisplay = styleElm.GetPropertyValue("display");

                    if (element is ISharpGDIPath && sVisibility != "hidden" && sDisplay != "none")
                    {
                        GraphicsPath gp = ((ISharpGDIPath)element).GetGraphicsPath();

                        if ( gp != null )
                        {
                            Clip(graphics);

                            GdiSvgPaint fillPaint = new GdiSvgPaint(styleElm, "fill");
                            Brush brush = fillPaint.GetBrush(gp);

                            GdiSvgPaint strokePaint = new GdiSvgPaint(styleElm, "stroke");
                            Pen pen = strokePaint.GetPen(gp);

                            if ( brush != null )
                            {
                                if ( brush is PathGradientBrush )
                                {
                                    GradientPaintServer gps = fillPaint.PaintServer as GradientPaintServer;
                                    //GraphicsContainer container = graphics.BeginContainer();

                                    graphics.SetClip(gps.GetRadialGradientRegion(gp.GetBounds()), CombineMode.Exclude);

                                    SolidBrush tempBrush = new SolidBrush(((PathGradientBrush)brush).InterpolationColors.Colors[0]);
                                    graphics.FillPath(this, tempBrush,gp);
                                    tempBrush.Dispose();
                                    graphics.ResetClip();

                                    //graphics.EndContainer(container);
                                }

                                graphics.FillPath(this, brush, gp);
                                brush.Dispose();
                            }

                            if ( pen != null )
                            {
                                if ( pen.Brush is PathGradientBrush )
                                {
                                    GradientPaintServer gps = strokePaint.PaintServer as GradientPaintServer;
                                    GraphicsContainerWrapper container = graphics.BeginContainer();

                                    graphics.SetClip(gps.GetRadialGradientRegion(gp.GetBounds()), CombineMode.Exclude);

                                    SolidBrush tempBrush = new SolidBrush(((PathGradientBrush)pen.Brush).InterpolationColors.Colors[0]);
                                    Pen tempPen = new Pen(tempBrush, pen.Width);
                                    graphics.DrawPath(this, tempPen,gp);
                                    tempPen.Dispose();
                                    tempBrush.Dispose();

                                    graphics.EndContainer(container);
                                }

                                graphics.DrawPath(this, pen, gp);
                                pen.Dispose();
                            }
                        }
                    }
                    PaintMarkers(gdiRenderer, styleElm, graphics);
                }
            }
        }
 private Pen GetPen(GraphicsPath gp)
 {
     GdiSvgPaint paint = new GdiSvgPaint(element as SvgStyleableElement, "stroke");
     return paint.GetPen(gp);
 }
 private Brush GetBrush(GraphicsPath gp)
 {
     GdiSvgPaint paint = new GdiSvgPaint(element as SvgStyleableElement, "fill");
     return paint.GetBrush(gp);
 }
Esempio n. 15
0
        private Pen GetPen(GraphicsPath gp)
        {
            GdiSvgPaint paint = new GdiSvgPaint(element as SvgStyleableElement, "stroke");

            return(paint.GetPen(gp));
        }
Esempio n. 16
0
        private Brush GetBrush(GraphicsPath gp)
        {
            GdiSvgPaint paint = new GdiSvgPaint(element as SvgStyleableElement, "fill");

            return(paint.GetBrush(gp));
        }
Esempio n. 17
0
        public void TestNonExistingGradient()
        {
            elm.SetAttribute("fill", "url(#myGradient)");
            GdiSvgPaint paint = new GdiSvgPaint(elm, "fill");

            Assert.AreEqual(SvgPaintType.Uri, paint.PaintType);

            Brush brush = paint.GetBrush(getGp());
            Assert.IsNull(brush);
        }
Esempio n. 18
0
        public void TestNonExistingGradientCurrentColor()
        {
            elm.SetAttribute("color", "red");
            elm.SetAttribute("fill", "url(#myGradient) currentColor");
            GdiSvgPaint paint = new GdiSvgPaint(elm, "fill");

            Assert.AreEqual(SvgPaintType.UriCurrentColor, paint.PaintType);

            Brush brush = paint.GetBrush(getGp());
            Assert.IsTrue(isSameColor(Color.Red, ((SolidBrush)brush).Color));
        }
Esempio n. 19
0
        public void TestNone()
        {
            elm.SetAttribute("stroke", "none");
            GdiSvgPaint paint = new GdiSvgPaint(elm, "stroke");
            Pen pen = paint.GetPen(getGp());

            Assert.IsNull(pen);
        }
        private Brush GetBrush(GraphicsPath gp, string propPrefix)
        {
            SvgPaint fill;

            if (PaintType == SvgPaintType.None)
            {
                return(null);
            }
            else if (PaintType == SvgPaintType.CurrentColor)
            {
                fill = new GdiSvgPaint(_element, "color");
            }
            else
            {
                fill = this;
            }

            if (fill.PaintType == SvgPaintType.Uri ||
                fill.PaintType == SvgPaintType.UriCurrentColor ||
                fill.PaintType == SvgPaintType.UriNone ||
                fill.PaintType == SvgPaintType.UriRgbColor ||
                fill.PaintType == SvgPaintType.UriRgbColorIccColor)
            {
                ps = getPaintServer(fill.Uri);
                if (ps != null)
                {
                    Brush br = ps.GetBrush(gp.GetBounds());
                    if (br is LinearGradientBrush)
                    {
                        LinearGradientBrush lgb = (LinearGradientBrush)br;
                        int opacityl            = getOpacity(propPrefix);
                        for (int i = 0; i < lgb.InterpolationColors.Colors.Length; i++)
                        {
                            lgb.InterpolationColors.Colors[i] = Color.FromArgb(opacityl, lgb.InterpolationColors.Colors[i]);
                        }
                        for (int i = 0; i < lgb.LinearColors.Length; i++)
                        {
                            lgb.LinearColors[i] = Color.FromArgb(opacityl, lgb.LinearColors[i]);
                        }
                    }
                    else if (br is PathGradientBrush)
                    {
                        PathGradientBrush pgb = (PathGradientBrush)br;
                        int opacityl          = getOpacity(propPrefix);
                        for (int i = 0; i < pgb.InterpolationColors.Colors.Length; i++)
                        {
                            pgb.InterpolationColors.Colors[i] = Color.FromArgb(opacityl, pgb.InterpolationColors.Colors[i]);
                        }
                        for (int i = 0; i < pgb.SurroundColors.Length; i++)
                        {
                            pgb.SurroundColors[i] = Color.FromArgb(opacityl, pgb.SurroundColors[i]);
                        }
                    }
                    return(br);
                }
                else
                {
                    if (PaintType == SvgPaintType.UriNone ||
                        PaintType == SvgPaintType.Uri)
                    {
                        return(null);
                    }
                    else if (PaintType == SvgPaintType.UriCurrentColor)
                    {
                        fill = new GdiSvgPaint(_element, "color");
                    }
                    else
                    {
                        fill = this;
                    }
                }
            }

            SolidBrush brush   = new SolidBrush(((RgbColor)fill.RgbColor).GdiColor);
            int        opacity = getOpacity(propPrefix);

            brush.Color = Color.FromArgb(opacity, brush.Color);
            return(brush);
        }