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)); }
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); }
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]); }
public void TestNone() { elm.SetAttribute("stroke", "none"); GdiSvgPaint paint = new GdiSvgPaint(elm, "stroke"); Pen pen = paint.GetPen(getGp()); Assert.IsNull(pen); }
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); }
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); }
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)); }
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 Pen GetPen(GraphicsPath gp) { GdiSvgPaint paint = new GdiSvgPaint(element as SvgStyleableElement, "stroke"); return(paint.GetPen(gp)); }
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); } } }