/// <summary> /// Render this marker using the slope of the given line segment /// </summary> /// <param name="pRenderer"></param> /// <param name="pOwner"></param> /// <param name="pMarkerPoint1"></param> /// <param name="pMarkerPoint2"></param> public void RenderMarker(SvgRenderer pRenderer, SvgPath pOwner, PointF pRefPoint, PointF pMarkerPoint1, PointF pMarkerPoint2) { float xDiff = pMarkerPoint2.X - pMarkerPoint1.X; float yDiff = pMarkerPoint2.Y - pMarkerPoint1.Y; float fAngle1 = (float)(Math.Atan2(yDiff, xDiff) * 180.0 / Math.PI); RenderPart2(fAngle1, pRenderer, pOwner, pRefPoint); }
public void TestAddingPath() { var doc = new SvgDocument(); var elements = doc.ParseFragment(TestingSources.SvgFragmentGroup); var epath = (SvgPath)elements[0].Children[0]; var path = new SvgPath(); doc.Children.Add(path); path.PathData.Add(epath.Path); SaveText(doc.ToString(), "PathDataAddPath.svg"); }
/// <summary> /// Create a pen that can be used to render this marker /// </summary> /// <param name="pStroke"></param> /// <returns></returns> private Pen CreatePen(SvgPath pPath) { Brush pBrush = pPath.Stroke.GetBrush(this, Opacity); switch (MarkerUnits) { case SvgMarkerUnits.strokeWidth: return(new Pen(pBrush, StrokeWidth * pPath.StrokeWidth)); case SvgMarkerUnits.userSpaceOnUse: return(new Pen(pBrush, StrokeWidth)); } return(new Pen(pBrush, StrokeWidth)); }
/// <summary> /// Create a pen that can be used to render this marker /// </summary> /// <param name="pStroke"></param> /// <returns></returns> private Pen CreatePen(SvgPath pPath, SvgRenderer renderer) { Brush pBrush = pPath.Stroke.GetBrush(this, renderer, Opacity); switch (MarkerUnits) { case SvgMarkerUnits.strokeWidth: return(new Pen(pBrush, StrokeWidth.ToDeviceValue(renderer, UnitRenderingType.Other, this) * pPath.StrokeWidth.ToDeviceValue(renderer, UnitRenderingType.Other, this))); case SvgMarkerUnits.userSpaceOnUse: return(new Pen(pBrush, StrokeWidth.ToDeviceValue(renderer, UnitRenderingType.Other, this))); } return(new Pen(pBrush, StrokeWidth.ToDeviceValue(renderer, UnitRenderingType.Other, this))); }
/// <summary> /// Common code for rendering a marker once the orientation angle has been calculated /// </summary> /// <param name="fAngle"></param> /// <param name="pRenderer"></param> /// <param name="pOwner"></param> /// <param name="pMarkerPoint"></param> private void RenderPart2(float fAngle, SvgRenderer pRenderer, SvgPath pOwner, PointF pMarkerPoint) { Pen pRenderPen = CreatePen(pOwner, pRenderer); GraphicsPath markerPath = GetClone(pOwner); Matrix transMatrix = new Matrix(); transMatrix.Translate(pMarkerPoint.X, pMarkerPoint.Y); if (Orient.IsAuto) { transMatrix.Rotate(fAngle); } else { transMatrix.Rotate(Orient.Angle); } switch (MarkerUnits) { case SvgMarkerUnits.strokeWidth: transMatrix.Translate(AdjustForViewBoxWidth(-RefX.ToDeviceValue(pRenderer, UnitRenderingType.Horizontal, this) * pOwner.StrokeWidth.ToDeviceValue(pRenderer, UnitRenderingType.Other, this)), AdjustForViewBoxHeight(-RefY.ToDeviceValue(pRenderer, UnitRenderingType.Vertical, this) * pOwner.StrokeWidth.ToDeviceValue(pRenderer, UnitRenderingType.Other, this))); break; case SvgMarkerUnits.userSpaceOnUse: transMatrix.Translate(-RefX.ToDeviceValue(pRenderer, UnitRenderingType.Horizontal, this), -RefY.ToDeviceValue(pRenderer, UnitRenderingType.Vertical, this)); break; } markerPath.Transform(transMatrix); pRenderer.DrawPath(pRenderPen, markerPath); SvgPaintServer pFill = Fill; SvgFillRule pFillRule = FillRule; // TODO: What do we use the fill rule for? float fOpacity = FillOpacity; if (pFill != null) { Brush pBrush = pFill.GetBrush(this, pRenderer, fOpacity); pRenderer.FillPath(pBrush, markerPath); pBrush.Dispose(); } pRenderPen.Dispose(); markerPath.Dispose(); transMatrix.Dispose(); }
/// <summary> /// Get a clone of the current path, scaled for the stroke with /// </summary> /// <returns></returns> private GraphicsPath GetClone(SvgPath pPath) { GraphicsPath pRet = Path(null).Clone() as GraphicsPath; switch (MarkerUnits) { case SvgMarkerUnits.strokeWidth: Matrix transMatrix = new Matrix(); transMatrix.Scale(AdjustForViewBoxWidth(pPath.StrokeWidth), AdjustForViewBoxHeight(pPath.StrokeWidth)); pRet.Transform(transMatrix); break; case SvgMarkerUnits.userSpaceOnUse: break; } return(pRet); }