public static bool TryGetBrush(SvgStyleableElement element, string property, Rect bounds, Matrix transform, out Brush brush) { SvgPaint paint = new SvgPaint(element.GetComputedStyle("").GetPropertyValue(property)); SvgPaint svgBrush; if (paint.PaintType == SvgPaintType.None) { brush = null; return(false); } else if (paint.PaintType == SvgPaintType.CurrentColor) { svgBrush = new SvgPaint(element.GetComputedStyle("").GetPropertyValue("color")); } else { svgBrush = paint; } SvgPaintType paintType = svgBrush.PaintType; if (paintType == SvgPaintType.Uri || paintType == SvgPaintType.UriCurrentColor || paintType == SvgPaintType.UriNone || paintType == SvgPaintType.UriRgbColor || paintType == SvgPaintType.UriRgbColorIccColor) { SvgStyleableElement fillNode = null; string absoluteUri = element.ResolveUri(svgBrush.Uri); if (element.Imported && element.ImportDocument != null && element.ImportNode != null) { // We need to determine whether the provided URI refers to element in the // original document or in the current document... SvgStyleableElement styleElm = element.ImportNode as SvgStyleableElement; if (styleElm != null) { string propertyValue = styleElm.GetComputedStyle("").GetPropertyValue(property); if (!String.IsNullOrEmpty(propertyValue)) { SvgPaint importFill = new SvgPaint(styleElm.GetComputedStyle("").GetPropertyValue(property)); if (String.Equals(svgBrush.Uri, importFill.Uri, StringComparison.OrdinalIgnoreCase)) { fillNode = element.ImportDocument.GetNodeByUri(absoluteUri) as SvgStyleableElement; } } } } else { fillNode = element.OwnerDocument.GetNodeByUri(absoluteUri) as SvgStyleableElement; } if (fillNode != null) { switch (fillNode) { case SvgLinearGradientElement linearGradient: brush = ConstructBrush(linearGradient, bounds, transform); return(true); case SvgRadialGradientElement radialGradient: brush = ConstructBrush(radialGradient, bounds, transform); return(true); case SvgPatternElement pattern: brush = ConstructBrush(pattern, bounds, transform); return(true); } } } if (svgBrush == null || svgBrush.RgbColor == null || !TryConvertColor(svgBrush.RgbColor, out Color solidColor)) { brush = null; return(false); } brush = new SolidColorBrush(solidColor); brush.Opacity = GetOpacity(element, property); if (brush.CanFreeze) { brush.Freeze(); } return(true); }
private void AggregateChildren(SvgAElement aElement, WpfDrawingContext context, float opacity) { _isAggregated = false; if (aElement == null || aElement.ChildNodes == null) { return; } string aggregatedFill = aElement.GetAttribute("fill"); bool isFillFound = !string.IsNullOrWhiteSpace(aggregatedFill); SvgStyleableElement paintElement = null; if (isFillFound) { paintElement = aElement; } XmlNode targetNode = aElement; // Check if the children of the link are wrapped in a Group Element... if (aElement.ChildNodes.Count == 1) { var groupElement = aElement.ChildNodes[0] as SvgGElement; if (groupElement != null) { targetNode = groupElement; } } WpfDrawingSettings settings = context.Settings; GeometryCollection geomColl = new GeometryCollection(); foreach (XmlNode node in targetNode.ChildNodes) { if (node.NodeType != XmlNodeType.Element) { continue; } // Handle a case where the clip element has "use" element as a child... if (string.Equals(node.LocalName, "use")) { SvgUseElement useElement = (SvgUseElement)node; XmlElement refEl = useElement.ReferencedElement; if (refEl != null) { XmlElement refElParent = (XmlElement)refEl.ParentNode; useElement.OwnerDocument.Static = true; useElement.CopyToReferencedElement(refEl); refElParent.RemoveChild(refEl); useElement.AppendChild(refEl); foreach (XmlNode useChild in useElement.ChildNodes) { if (useChild.NodeType != XmlNodeType.Element) { continue; } var element = useChild as SvgStyleableElement; if (element != null && element.RenderingHint == SvgRenderingHint.Shape) { Geometry childPath = CreateGeometry(element, settings.OptimizePath); if (childPath != null) { if (isFillFound) { string elementFill = element.GetAttribute("fill"); if (!string.IsNullOrWhiteSpace(elementFill) && !string.Equals(elementFill, aggregatedFill, StringComparison.OrdinalIgnoreCase)) { return; } } else { aggregatedFill = element.GetAttribute("fill"); isFillFound = !string.IsNullOrWhiteSpace(aggregatedFill); if (isFillFound) { paintElement = element; } } geomColl.Add(childPath); } } } useElement.RemoveChild(refEl); useElement.RestoreReferencedElement(refEl); refElParent.AppendChild(refEl); useElement.OwnerDocument.Static = false; } } //else if (string.Equals(node.LocalName, "g")) //{ //} else { var element = node as SvgStyleableElement; if (element != null && element.RenderingHint == SvgRenderingHint.Shape) { Geometry childPath = CreateGeometry(element, settings.OptimizePath); if (childPath != null) { if (isFillFound) { string elementFill = element.GetAttribute("fill"); if (!string.IsNullOrWhiteSpace(elementFill) && !string.Equals(elementFill, aggregatedFill, StringComparison.OrdinalIgnoreCase)) { return; } } else { aggregatedFill = element.GetAttribute("fill"); isFillFound = !string.IsNullOrWhiteSpace(aggregatedFill); if (isFillFound) { paintElement = element; } } geomColl.Add(childPath); } } } } if (geomColl.Count == 0 || paintElement == null) { return; } _aggregatedFill = paintElement; _aggregatedGeom = geomColl; _isAggregated = true; }
public void RenderMarker2(WpfDrawingRenderer renderer, WpfDrawingContext gr, SvgMarkerPosition markerPos, SvgStyleableElement refElement) { ISharpMarkerHost markerHostElm = (ISharpMarkerHost)refElement; SvgMarkerElement markerElm = (SvgMarkerElement)_svgElement; SvgPointF[] vertexPositions = markerHostElm.MarkerPositions; int start; int len; // Choose which part of the position array to use switch (markerPos) { case SvgMarkerPosition.Start: start = 0; len = 1; break; case SvgMarkerPosition.Mid: start = 1; len = vertexPositions.Length - 2; break; default: // == MarkerPosition.End start = vertexPositions.Length - 1; len = 1; break; } for (int i = start; i < start + len; i++) { SvgPointF point = vertexPositions[i]; //GdiGraphicsContainer gc = gr.BeginContainer(); this.BeforeRender(renderer); //Matrix matrix = Matrix.Identity; Matrix matrix = GetTransformMatrix(_svgElement); if (markerElm.OrientType.AnimVal.Equals((ushort)SvgMarkerOrient.Angle)) { matrix.Rotate(markerElm.OrientAngle.AnimVal.Value); } else { double angle = 0; switch (markerPos) { case SvgMarkerPosition.Start: angle = markerHostElm.GetStartAngle(i + 1); break; case SvgMarkerPosition.Mid: //angle = (markerHostElm.GetEndAngle(i) + markerHostElm.GetStartAngle(i + 1)) / 2; angle = SvgNumber.CalcAngleBisection(markerHostElm.GetEndAngle(i), markerHostElm.GetStartAngle(i + 1)); break; default: angle = markerHostElm.GetEndAngle(i); break; } matrix.Rotate(angle); } if (markerElm.MarkerUnits.AnimVal.Equals((ushort)SvgMarkerUnit.StrokeWidth)) { SvgLength strokeWidthLength = new SvgLength(refElement, "stroke-width", SvgLengthSource.Css, SvgLengthDirection.Viewport, "1"); double strokeWidth = strokeWidthLength.Value; matrix.Scale(strokeWidth, strokeWidth); } SvgPreserveAspectRatio spar = (SvgPreserveAspectRatio)markerElm.PreserveAspectRatio.AnimVal; double[] translateAndScale = spar.FitToViewBox((SvgRect)markerElm.ViewBox.AnimVal, new SvgRect(0, 0, markerElm.MarkerWidth.AnimVal.Value, markerElm.MarkerHeight.AnimVal.Value)); matrix.Translate(-markerElm.RefX.AnimVal.Value * translateAndScale[2], -markerElm.RefY.AnimVal.Value * translateAndScale[3]); matrix.Scale(translateAndScale[2], translateAndScale[3]); matrix.Translate(point.X, point.Y); _matrix = matrix; this.Render(renderer); //Clip(gr); renderer.RenderChildren(markerElm); //gr.EndContainer(gc); this.AfterRender(renderer); } }
protected static void RenderMarkers(WpfDrawingRenderer renderer, SvgStyleableElement styleElm, WpfDrawingContext gr) { // OPTIMIZE if (styleElm is ISharpMarkerHost) { string markerStartUrl = ExtractMarkerUrl(styleElm.GetPropertyValue("marker-start", "marker")); string markerMiddleUrl = ExtractMarkerUrl(styleElm.GetPropertyValue("marker-mid", "marker")); string markerEndUrl = ExtractMarkerUrl(styleElm.GetPropertyValue("marker-end", "marker")); string markerAll = ExtractMarkerUrl(styleElm.GetPropertyValue("marker", "marker")); // The SVG specification defines three properties to reference markers: marker-start, // marker -mid, marker-end. It also provides a shorthand property, marker. Using the marker // property from a style sheet is equivalent to using all three (start, mid, end). // However, shorthand properties cannot be used as presentation attributes. if (!string.IsNullOrWhiteSpace(markerAll) && !IsPresentationMarker(styleElm)) { if (string.IsNullOrWhiteSpace(markerStartUrl)) { markerStartUrl = markerAll; } if (string.IsNullOrWhiteSpace(markerMiddleUrl)) { markerMiddleUrl = markerAll; } if (string.IsNullOrWhiteSpace(markerEndUrl)) { markerEndUrl = markerAll; } } if (markerStartUrl.Length > 0) { WpfMarkerRendering markerRenderer = CreateByUri(styleElm.OwnerDocument, styleElm.BaseURI, markerStartUrl) as WpfMarkerRendering; if (markerRenderer != null) { markerRenderer.RenderMarker(renderer, gr, SvgMarkerPosition.Start, styleElm); } } if (markerMiddleUrl.Length > 0) { // TODO markerMiddleUrl != markerStartUrl WpfMarkerRendering markerRenderer = CreateByUri(styleElm.OwnerDocument, styleElm.BaseURI, markerMiddleUrl) as WpfMarkerRendering; if (markerRenderer != null) { markerRenderer.RenderMarker(renderer, gr, SvgMarkerPosition.Mid, styleElm); } } if (markerEndUrl.Length > 0) { // TODO: markerEndUrl != markerMiddleUrl WpfMarkerRendering markerRenderer = CreateByUri(styleElm.OwnerDocument, styleElm.BaseURI, markerEndUrl) as WpfMarkerRendering; if (markerRenderer != null) { markerRenderer.RenderMarker(renderer, gr, SvgMarkerPosition.End, styleElm); } } } }
public void PaintMarker(GdiRenderer renderer, GraphicsWrapper gr, SvgMarkerPosition markerPos, SvgStyleableElement refElement) { ISharpMarkerHost markerHostElm = (ISharpMarkerHost)refElement; SvgMarkerElement markerElm = (SvgMarkerElement)element; PointF[] vertexPositions = markerHostElm.MarkerPositions; int start; int len; // Choose which part of the position array to use switch (markerPos) { case SvgMarkerPosition.Start: start = 0; len = 1; break; case SvgMarkerPosition.Mid: start = 1; len = vertexPositions.Length - 2; break; default: // == MarkerPosition.End start = vertexPositions.Length - 1; len = 1; break; } for (int i = start; i < start + len; i++) { PointF point = vertexPositions[i]; GraphicsContainerWrapper gc = gr.BeginContainer(); gr.TranslateTransform(point.X, point.Y); if (markerElm.OrientType.AnimVal.Equals(SvgMarkerOrient.Angle)) { gr.RotateTransform((float)markerElm.OrientAngle.AnimVal.Value); } else { float angle; switch (markerPos) { case SvgMarkerPosition.Start: angle = markerHostElm.GetStartAngle(i + 1); break; case SvgMarkerPosition.Mid: //angle = (markerHostElm.GetEndAngle(i) + markerHostElm.GetStartAngle(i + 1)) / 2; angle = SvgNumber.CalcAngleBisection(markerHostElm.GetEndAngle(i), markerHostElm.GetStartAngle(i + 1)); break; default: angle = markerHostElm.GetEndAngle(i); break; } gr.RotateTransform(angle); } if (markerElm.MarkerUnits.AnimVal.Equals(SvgMarkerUnit.StrokeWidth)) { SvgLength strokeWidthLength = new SvgLength(refElement, "stroke-width", SvgLengthSource.Css, SvgLengthDirection.Viewport, "1"); float strokeWidth = (float)strokeWidthLength.Value; gr.ScaleTransform(strokeWidth, strokeWidth); } SvgPreserveAspectRatio spar = (SvgPreserveAspectRatio)markerElm.PreserveAspectRatio.AnimVal; float[] translateAndScale = spar.FitToViewBox( (SvgRect)markerElm.ViewBox.AnimVal, new SvgRect( 0, 0, (float)markerElm.MarkerWidth.AnimVal.Value, (float)markerElm.MarkerHeight.AnimVal.Value) ); gr.TranslateTransform( -(float)markerElm.RefX.AnimVal.Value * translateAndScale[2], -(float)markerElm.RefY.AnimVal.Value * translateAndScale[3] ); gr.ScaleTransform(translateAndScale[2], translateAndScale[3]); Clip(gr); markerElm.RenderChildren(renderer); gr.EndContainer(gc); } }
public override void BeforeRender(WpfDrawingRenderer renderer) { base.BeforeRender(renderer); if (renderer == null) { return; } _isLineSegment = false; _setBrushOpacity = true; WpfDrawingContext context = renderer.Context; //SetQuality(context); //SetTransform(context); //SetMask(context); // _drawGroup = new DrawingGroup(); SvgStyleableElement styleElm = (SvgStyleableElement)_svgElement; float opacityValue = -1; bool isStyleOpacity = false; string opacity = styleElm.GetAttribute("opacity"); if (string.IsNullOrWhiteSpace(opacity)) { opacity = styleElm.GetPropertyValue("opacity"); if (!string.IsNullOrWhiteSpace(opacity)) { isStyleOpacity = true; } } if (!string.IsNullOrWhiteSpace(opacity)) { opacityValue = (float)SvgNumber.ParseNumber(opacity); opacityValue = Math.Min(opacityValue, 1); opacityValue = Math.Max(opacityValue, 0); if (isStyleOpacity && (opacityValue >= 0 && opacityValue < 1)) { _setBrushOpacity = false; if (styleElm.HasAttribute("fill-opacity") || (styleElm.HasAttribute("style") && styleElm.GetAttribute("style").Contains("fill-opacity"))) { _setBrushOpacity = true; } } } //string eVisibility = _svgElement.GetAttribute("visibility"); //string eDisplay = _svgElement.GetAttribute("display"); //if (string.Equals(eVisibility, "hidden") || string.Equals(eDisplay, "none")) //{ // opacityValue = 0; //} //else //{ // string sVisibility = styleElm.GetPropertyValue("visibility"); // string sDisplay = styleElm.GetPropertyValue("display"); // if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none")) // { // opacityValue = 0; // } //} string sVisibility = styleElm.GetPropertyValue("visibility"); if (string.IsNullOrWhiteSpace(sVisibility)) { sVisibility = _svgElement.GetAttribute("visibility"); } string sDisplay = styleElm.GetPropertyValue("display"); if (string.IsNullOrWhiteSpace(sDisplay)) { sDisplay = _svgElement.GetAttribute("display"); } if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none")) { opacityValue = 0; } Transform pathTransform = this.Transform; if (pathTransform != null && !pathTransform.Value.IsIdentity) { if (_drawGroup == null) { _drawGroup = new DrawingGroup(); } _drawGroup.Transform = pathTransform; } else { pathTransform = null; // render any identity transform useless... } Geometry pathClip = this.ClipGeometry; if (pathClip != null && !pathClip.IsEmpty()) { if (_drawGroup == null) { _drawGroup = new DrawingGroup(); } _drawGroup.ClipGeometry = pathClip; } else { pathClip = null; // render any empty geometry useless... } Brush pathMask = this.Masking; if (pathMask != null) { if (_drawGroup == null) { _drawGroup = new DrawingGroup(); } _drawGroup.OpacityMask = pathMask; } if (pathTransform != null || pathClip != null || pathMask != null || (opacityValue >= 0 && opacityValue < 1)) { if (_drawGroup == null) { _drawGroup = new DrawingGroup(); } if ((opacityValue >= 0 && opacityValue < 1)) { _drawGroup.Opacity = opacityValue; } DrawingGroup curGroup = _context.Peek(); Debug.Assert(curGroup != null); if (curGroup != null) { curGroup.Children.Add(_drawGroup); context.Push(_drawGroup); } } else { _drawGroup = null; } if (_drawGroup != null) { string elementClass = this.GetElementClass(); if (!string.IsNullOrWhiteSpace(elementClass) && context.IncludeRuntime) { SvgObject.SetClass(_drawGroup, elementClass); } string elementId = this.GetElementName(); if (!string.IsNullOrWhiteSpace(elementId) && !context.IsRegisteredId(elementId)) { SvgObject.SetName(_drawGroup, elementId); context.RegisterId(elementId); if (context.IncludeRuntime) { SvgObject.SetId(_drawGroup, elementId); } } } }
public void RenderMarker(WpfDrawingRenderer renderer, WpfDrawingContext gr, SvgMarkerPosition markerPos, SvgStyleableElement refElement) { _hostElement = refElement; if (_hostElement != null) { var paintContext = gr.GetPaintContext(_hostElement.UniqueId); if (paintContext != null) { PathGeometry pathGeometry = paintContext.Tag as PathGeometry; if (pathGeometry != null) { _pathFigures = pathGeometry.Figures; } } } ISharpMarkerHost markerHostElm = (ISharpMarkerHost)refElement; SvgPointF[] vertexPositions = markerHostElm.MarkerPositions; if (vertexPositions == null) { return; } bool mayHaveCurves = markerHostElm.MayHaveCurves; int start = 0; int len = 0; // Choose which part of the position array to use switch (markerPos) { case SvgMarkerPosition.Start: start = 0; len = 1; break; case SvgMarkerPosition.Mid: start = 1; len = vertexPositions.Length - 2; break; default: // == MarkerPosition.End start = vertexPositions.Length - 1; len = 1; break; } int end = start + len; TransformGroup transform = new TransformGroup(); for (int i = start; i < end; i++) { SvgPointF point = vertexPositions[i]; //GdiGraphicsContainer gc = gr.BeginContainer(); this.BeforeRender(renderer); //Matrix matrix = Matrix.Identity; Matrix matrix = GetTransformMatrix(_svgElement, transform); ISvgAnimatedEnumeration orientType = _markerElement.OrientType; if (orientType.AnimVal.Equals((ushort)SvgMarkerOrient.Angle)) { double scaleValue = _markerElement.OrientAngle.AnimVal.Value; if (!scaleValue.Equals(0)) { matrix.Rotate(scaleValue); transform.Children.Add(new RotateTransform(scaleValue)); } } else { bool isAutoReverse = orientType.AnimVal.Equals((ushort)SvgMarkerOrient.AutoStartReverse); double angle = 0; switch (markerPos) { case SvgMarkerPosition.Start: angle = markerHostElm.GetStartAngle(i); //angle = markerHostElm.GetStartAngle(i + 1); if (vertexPositions.Length >= 2) { SvgPointF pMarkerPoint1 = vertexPositions[start]; SvgPointF pMarkerPoint2 = vertexPositions[end]; float xDiff = pMarkerPoint2.X - pMarkerPoint1.X; float yDiff = pMarkerPoint2.Y - pMarkerPoint1.Y; double angleMarker = (float)(Math.Atan2(yDiff, xDiff) * 180.0 / Math.PI); if (!angleMarker.Equals(angle)) { angle = angleMarker; } } if (mayHaveCurves) { angle = this.GetAngleAt(start, angle, markerPos, markerHostElm); } // A value of 'auto-start-reverse' means the same as 'auto' except that for a // marker placed by 'marker-start', the orientation is 180° different from // the orientation as determined by 'auto'. if (isAutoReverse) { angle += 180; } break; case SvgMarkerPosition.Mid: //angle = (markerHostElm.GetEndAngle(i) + markerHostElm.GetStartAngle(i + 1)) / 2; angle = SvgNumber.CalcAngleBisection(markerHostElm.GetEndAngle(i), markerHostElm.GetStartAngle(i + 1)); if (mayHaveCurves) { angle = this.GetAngleAt(i, angle, markerPos, markerHostElm); } break; default: angle = markerHostElm.GetEndAngle(i - 1); //double angle2 = markerHostElm.GetEndAngle(i); if (vertexPositions.Length >= 2) { SvgPointF pMarkerPoint1 = vertexPositions[start - 1]; SvgPointF pMarkerPoint2 = vertexPositions[start]; float xDiff = pMarkerPoint2.X - pMarkerPoint1.X; float yDiff = pMarkerPoint2.Y - pMarkerPoint1.Y; double angleMarker = (float)(Math.Atan2(yDiff, xDiff) * 180.0 / Math.PI); if (!angleMarker.Equals(angle)) { angle = angleMarker; } } if (mayHaveCurves) { angle = this.GetAngleAt(start - 1, angle, markerPos, markerHostElm); } break; } matrix.Rotate(angle); transform.Children.Add(new RotateTransform(angle)); } // 'viewBox' and 'preserveAspectRatio' attributes // viewBox -> viewport(0, 0, markerWidth, markerHeight) SvgPreserveAspectRatio spar = (SvgPreserveAspectRatio)_markerElement.PreserveAspectRatio.AnimVal; double[] translateAndScale = spar.FitToViewBox((SvgRect)_markerElement.ViewBox.AnimVal, new SvgRect(0, 0, _markerElement.MarkerWidth.AnimVal.Value, _markerElement.MarkerHeight.AnimVal.Value)); // Warning at this time, refX and refY are relative to the painted element's coordinate system. // We need to move the reference point to the marker's coordinate system double refX = _markerElement.RefX.AnimVal.Value; double refY = _markerElement.RefY.AnimVal.Value; if (!(refX.Equals(0) && refY.Equals(0))) { var ptRef = matrix.Transform(new Point(refX, refY)); refX = ptRef.X; refY = ptRef.Y; matrix.Translate(-refX, -refY); transform.Children.Add(new TranslateTransform(-refX, -refY)); } //matrix.Translate(-markerElm.RefX.AnimVal.Value * translateAndScale[2], // -markerElm.RefY.AnimVal.Value * translateAndScale[3]); //transform.Children.Add(new TranslateTransform(-markerElm.RefX.AnimVal.Value * translateAndScale[2], // -markerElm.RefY.AnimVal.Value * translateAndScale[3])); // compute an additional transform for 'strokeWidth' coordinate system ISvgAnimatedEnumeration markerUnits = _markerElement.MarkerUnits; if (markerUnits.AnimVal.Equals((ushort)SvgMarkerUnit.StrokeWidth)) { SvgLength strokeWidthLength = new SvgLength(refElement, "stroke-width", SvgLengthSource.Css, SvgLengthDirection.Viewport, "1"); double strokeWidth = strokeWidthLength.Value; if (!strokeWidth.Equals(1)) { matrix.Scale(strokeWidth, strokeWidth); transform.Children.Add(new ScaleTransform(strokeWidth, strokeWidth)); } } if (!(translateAndScale[2].Equals(1) && translateAndScale[3].Equals(1))) { matrix.Scale(translateAndScale[2], translateAndScale[3]); transform.Children.Add(new ScaleTransform(translateAndScale[2], translateAndScale[3])); } matrix.Translate(point.X, point.Y); transform.Children.Add(new TranslateTransform(point.X, point.Y)); _matrix = matrix; this.Transform = transform; this.Render(renderer); //Clip(gr); renderer.RenderChildren(_markerElement); //gr.EndContainer(gc); this.AfterRender(renderer); } }
public void SingleClassDontTrim() { SvgStyleableElement elm = Util.GetXmlElement("<title class=' foo ' />", "", "title") as SvgStyleableElement; Assert.AreEqual(" foo ", elm.ClassName.AnimVal); }
public void MultipleClasses() { SvgStyleableElement elm = Util.GetXmlElement("<title class='foo bar run' />", "", "title") as SvgStyleableElement; Assert.AreEqual("foo bar run", elm.ClassName.AnimVal); }
public void PaintMarker(GdiGraphicsRenderer renderer, GdiGraphics gr, SvgMarkerPosition markerPos, SvgStyleableElement refElement) { ISharpMarkerHost markerHostElm = (ISharpMarkerHost)refElement; SvgMarkerElement markerElm = (SvgMarkerElement)_svgElement; SvgPointF[] vertexPositions = markerHostElm.MarkerPositions; if (vertexPositions == null) { return; } var comparer = StringComparison.OrdinalIgnoreCase; bool mayHaveCurves = markerHostElm.MayHaveCurves; int start; int len; // Choose which part of the position array to use switch (markerPos) { case SvgMarkerPosition.Start: start = 0; len = 1; break; case SvgMarkerPosition.Mid: start = 1; len = vertexPositions.Length - 2; break; default: // == MarkerPosition.End start = vertexPositions.Length - 1; len = 1; break; } int end = start + len; for (int i = start; i < end; i++) { SvgPointF point = vertexPositions[i]; GdiGraphicsContainer gc = gr.BeginContainer(); gr.TranslateTransform(point.X, point.Y); if (markerElm.OrientType.AnimVal.Equals((ushort)SvgMarkerOrient.Angle)) { double scaleValue = markerElm.OrientAngle.AnimVal.Value; if (!scaleValue.Equals(0)) { gr.RotateTransform((float)scaleValue); } } else { double angle; switch (markerPos) { case SvgMarkerPosition.Start: angle = markerHostElm.GetStartAngle(i); //angle = markerHostElm.GetStartAngle(i + 1); if (vertexPositions.Length >= 2) { SvgPointF pMarkerPoint1 = vertexPositions[start]; SvgPointF pMarkerPoint2 = vertexPositions[end]; float xDiff = pMarkerPoint2.X - pMarkerPoint1.X; float yDiff = pMarkerPoint2.Y - pMarkerPoint1.Y; double angleMarker = (float)(Math.Atan2(yDiff, xDiff) * 180.0 / Math.PI); if (!angleMarker.Equals(angle)) { angle = angleMarker; } } break; case SvgMarkerPosition.Mid: //angle = (markerHostElm.GetEndAngle(i) + markerHostElm.GetStartAngle(i + 1)) / 2; angle = SvgNumber.CalcAngleBisection(markerHostElm.GetEndAngle(i), markerHostElm.GetStartAngle(i + 1)); break; default: angle = markerHostElm.GetEndAngle(i - 1); //double angle2 = markerHostElm.GetEndAngle(i); if (vertexPositions.Length >= 2) { SvgPointF pMarkerPoint1 = vertexPositions[start - 1]; SvgPointF pMarkerPoint2 = vertexPositions[start]; float xDiff = pMarkerPoint2.X - pMarkerPoint1.X; float yDiff = pMarkerPoint2.Y - pMarkerPoint1.Y; double angleMarker = (float)(Math.Atan2(yDiff, xDiff) * 180.0 / Math.PI); if (!angleMarker.Equals(angle)) { angle = angleMarker; } } //if (mayHaveCurves) //{ // angle = this.GetAngleAt(start - 1, angle, markerPos, markerHostElm); //} break; } gr.RotateTransform((float)angle); } // 'viewBox' and 'preserveAspectRatio' attributes // viewBox -> viewport(0, 0, markerWidth, markerHeight) var spar = (SvgPreserveAspectRatio)markerElm.PreserveAspectRatio.AnimVal; double[] translateAndScale = spar.FitToViewBox((SvgRect)markerElm.ViewBox.AnimVal, new SvgRect(0, 0, markerElm.MarkerWidth.AnimVal.Value, markerElm.MarkerHeight.AnimVal.Value)); //// Warning at this time, refX and refY are relative to the painted element's coordinate system. //// We need to move the reference point to the marker's coordinate system //float refX = (float)markerElm.RefX.AnimVal.Value; //float refY = (float)markerElm.RefY.AnimVal.Value; ////if (!(refX.Equals(0) && refY.Equals(0))) ////{ //// var points = new PointF[] { new PointF(refX, refY) }; //// gr.Transform.TransformPoints(points); //// refX = points[0].X; //// refY = points[0].Y; //// gr.TranslateTransform(-refX, -refY); ////} //if (markerElm.MarkerUnits.AnimVal.Equals((ushort)SvgMarkerUnit.StrokeWidth)) //{ // SvgLength strokeWidthLength = new SvgLength(refElement, // "stroke-width", SvgLengthSource.Css, SvgLengthDirection.Viewport, "1"); // float strokeWidth = (float)strokeWidthLength.Value; // gr.ScaleTransform(strokeWidth, strokeWidth); //} //gr.TranslateTransform(-(float)(markerElm.RefX.AnimVal.Value * translateAndScale[2]), // -(float)(markerElm.RefY.AnimVal.Value * translateAndScale[3])); //gr.ScaleTransform((float)translateAndScale[2], (float)translateAndScale[3]); // compute an additional transform for 'strokeWidth' coordinate system ISvgAnimatedEnumeration markerUnits = markerElm.MarkerUnits; if (markerUnits.AnimVal.Equals((ushort)SvgMarkerUnit.StrokeWidth)) { SvgLength strokeWidthLength = new SvgLength(refElement, "stroke-width", SvgLengthSource.Css, SvgLengthDirection.Viewport, "1"); double strokeWidth = strokeWidthLength.Value; if (!strokeWidth.Equals(1)) { gr.ScaleTransform((float)strokeWidth, (float)strokeWidth); } } gr.TranslateTransform(-(float)(markerElm.RefX.AnimVal.Value * translateAndScale[2]), -(float)(markerElm.RefY.AnimVal.Value * translateAndScale[3])); if (!(translateAndScale[2].Equals(1) && translateAndScale[3].Equals(1))) { gr.ScaleTransform((float)translateAndScale[2], (float)translateAndScale[3]); } // gr.TranslateTransform(point.X, point.Y); RectangleF rectClip = RectangleF.Empty; if (markerUnits.AnimVal.Equals((ushort)SvgMarkerUnit.StrokeWidth)) { string overflowAttr = markerElm.GetAttribute("overflow"); if (string.IsNullOrWhiteSpace(overflowAttr) || overflowAttr.Equals("scroll", comparer) || overflowAttr.Equals("hidden", comparer)) { var markerClip = RectangleF.Empty; SvgRect clipRect = (SvgRect)markerElm.ViewBox.AnimVal; if (clipRect != null && !clipRect.IsEmpty) { rectClip = new RectangleF((float)clipRect.X, (float)clipRect.Y, (float)clipRect.Width, (float)clipRect.Height); } else if (markerElm.IsSizeDefined) { rectClip = new RectangleF(0, 0, (float)markerElm.MarkerWidth.AnimVal.Value, (float)markerElm.MarkerHeight.AnimVal.Value); } } } if (rectClip.IsEmpty) { SetClip(gr); } else { gr.SetClip(rectClip); } renderer.RenderChildren(markerElm); gr.EndContainer(gc); } }
public void EmptyClass() { SvgStyleableElement elm = Util.GetXmlElement("<title class='' />", "", "title") as SvgStyleableElement; Assert.AreEqual("", elm.ClassName.AnimVal); }
private void RenderElement(ISvgElement svgElement) { bool isNotRenderable = !svgElement.IsRenderable || string.Equals(svgElement.LocalName, "a"); if (isNotRenderable) { return; } SvgElement currentElement = (SvgElement)svgElement; GdiRenderingBase renderingNode = GdiRendering.Create(currentElement); if (renderingNode == null) { return; } if (!renderingNode.NeedRender(_renderer)) { renderingNode.Dispose(); renderingNode = null; return; } bool shouldRender = true; SvgStyleableElement stylable = svgElement as SvgStyleableElement; if (stylable != null) { string sVisibility = stylable.GetPropertyValue("visibility"); string sDisplay = stylable.GetPropertyValue("display"); if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none")) { shouldRender = false; } } if (shouldRender) { //_rendererMap[svgElement] = renderingNode; // _rendererMap.Push(renderingNode); if (_rendererMap.ContainsKey(currentElement.UniqueId)) { // Might be circular rendering... // System.Diagnostics.Debug.WriteLine("Circular Object: " + currentElement.LocalName); return; } _rendererMap[currentElement.UniqueId] = renderingNode; renderingNode.BeforeRender(_renderer); renderingNode.Render(_renderer); if (!renderingNode.IsRecursive && svgElement.HasChildNodes) { RenderChildren(svgElement); } //renderingNode = _rendererMap[svgElement]; renderingNode = _rendererMap[currentElement.UniqueId]; // renderingNode = _rendererMap.Pop(); Debug.Assert(renderingNode.Element == svgElement); renderingNode.AfterRender(_renderer); _rendererMap.Remove(currentElement.UniqueId); //_rendererMap.Remove(svgElement); } renderingNode.Dispose(); renderingNode = null; }
public override void Render(GdiGraphicsRenderer renderer) { _graphics = renderer.GraphicsWrapper; SvgRenderingHint hint = element.RenderingHint; if (hint == SvgRenderingHint.Clipping) { return; } if (element.ParentNode is SvgClipPathElement) { return; } SvgTextElement textElement = element as SvgTextElement; if (textElement == null) { return; } string sVisibility = textElement.GetPropertyValue("visibility"); string sDisplay = textElement.GetPropertyValue("display"); if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none")) { return; } Clip(_graphics); PointF ctp = new PointF(0, 0); // current text position ctp = GetCurrentTextPosition(textElement, ctp); string sBaselineShift = textElement.GetPropertyValue("baseline-shift").Trim(); double shiftBy = 0; if (sBaselineShift.Length > 0) { float textFontSize = GetComputedFontSize(textElement); if (sBaselineShift.EndsWith("%")) { shiftBy = SvgNumber.ParseNumber(sBaselineShift.Substring(0, sBaselineShift.Length - 1)) / 100 * textFontSize; } else if (sBaselineShift == "sub") { shiftBy = -0.6F * textFontSize; } else if (sBaselineShift == "super") { shiftBy = 0.6F * textFontSize; } else if (sBaselineShift == "baseline") { shiftBy = 0; } else { shiftBy = SvgNumber.ParseNumber(sBaselineShift); } } XmlNodeType nodeType = XmlNodeType.None; foreach (XmlNode child in element.ChildNodes) { SvgStyleableElement stylable = child as SvgStyleableElement; if (stylable != null) { sVisibility = stylable.GetPropertyValue("visibility"); sDisplay = stylable.GetPropertyValue("display"); if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none")) { continue; } } nodeType = child.NodeType; if (nodeType == XmlNodeType.Text) { ctp.Y -= (float)shiftBy; AddGraphicsPath(textElement, ref ctp, GetText(textElement, child)); ctp.Y += (float)shiftBy; } else if (nodeType == XmlNodeType.Element) { string nodeName = child.Name; if (string.Equals(nodeName, "tref")) { AddTRefElementPath((SvgTRefElement)child, ref ctp); } else if (string.Equals(nodeName, "tspan")) { AddTSpanElementPath((SvgTSpanElement)child, ref ctp); } } } PaintMarkers(renderer, textElement, _graphics); _graphics = null; }
public void RenderMarkerEx0(WpfDrawingRenderer renderer, WpfDrawingContext gr, SvgMarkerPosition markerPos, SvgStyleableElement refElement) { //ISharpMarkerHost markerHostElm = (ISharpMarkerHost)refElement; //SvgMarkerElement markerElm = (SvgMarkerElement)element; //SvgPointF[] vertexPositions = markerHostElm.MarkerPositions; //int start; //int len; //// Choose which part of the position array to use //switch (markerPos) //{ // case SvgMarkerPosition.Start: // start = 0; // len = 1; // break; // case SvgMarkerPosition.Mid: // start = 1; // len = vertexPositions.Length - 2; // break; // default: // // == MarkerPosition.End // start = vertexPositions.Length - 1; // len = 1; // break; //} //for (int i = start; i < start + len; i++) //{ // SvgPointF point = vertexPositions[i]; // GdiGraphicsContainer gc = gr.BeginContainer(); // gr.TranslateTransform(point.X, point.Y); // if (markerElm.OrientType.AnimVal.Equals((ushort)SvgMarkerOrient.Angle)) // { // gr.RotateTransform((float)markerElm.OrientAngle.AnimVal.Value); // } // else // { // float angle; // switch (markerPos) // { // case SvgMarkerPosition.Start: // angle = markerHostElm.GetStartAngle(i + 1); // break; // case SvgMarkerPosition.Mid: // //angle = (markerHostElm.GetEndAngle(i) + markerHostElm.GetStartAngle(i + 1)) / 2; // angle = SvgNumber.CalcAngleBisection(markerHostElm.GetEndAngle(i), markerHostElm.GetStartAngle(i + 1)); // break; // default: // angle = markerHostElm.GetEndAngle(i); // break; // } // gr.RotateTransform(angle); // } // if (markerElm.MarkerUnits.AnimVal.Equals((ushort)SvgMarkerUnit.StrokeWidth)) // { // SvgLength strokeWidthLength = new SvgLength(refElement, // "stroke-width", SvgLengthSource.Css, SvgLengthDirection.Viewport, "1"); // float strokeWidth = (float)strokeWidthLength.Value; // gr.ScaleTransform(strokeWidth, strokeWidth); // } // SvgPreserveAspectRatio spar = // (SvgPreserveAspectRatio)markerElm.PreserveAspectRatio.AnimVal; // float[] translateAndScale = spar.FitToViewBox((SvgRect)markerElm.ViewBox.AnimVal, // new SvgRect(0, 0, markerElm.MarkerWidth.AnimVal.Value, // markerElm.MarkerHeight.AnimVal.Value)); // gr.TranslateTransform(-(float)markerElm.RefX.AnimVal.Value * translateAndScale[2], // -(float)markerElm.RefY.AnimVal.Value * translateAndScale[3]); // gr.ScaleTransform(translateAndScale[2], translateAndScale[3]); // Clip(gr); // renderer.RenderChildren(markerElm); // gr.EndContainer(gc); //} }
public WpfSvgColor(SvgStyleableElement elm, string propertyName) : base(elm.GetComputedStyle("").GetPropertyValue(propertyName)) { _element = elm; _propertyName = propertyName; }
public void PresAttNonExisting() { SvgStyleableElement elm = Util.GetXmlElement("<title />", "", "title") as SvgStyleableElement; Assert.IsNull(elm.GetPresentationAttribute("dummy")); }
public override void Render(WpfDrawingRenderer renderer) { WpfDrawingContext context = renderer.Context; SvgRenderingHint hint = _svgElement.RenderingHint; if (hint != SvgRenderingHint.Shape || hint == SvgRenderingHint.Clipping) { return; } // We do not directly render the contents of the clip-path, unless specifically requested... if (String.Equals(_svgElement.ParentNode.LocalName, "clipPath") && !context.RenderingClipRegion) { return; } SvgStyleableElement styleElm = (SvgStyleableElement)_svgElement; string sVisibility = styleElm.GetPropertyValue("visibility"); string sDisplay = styleElm.GetPropertyValue("display"); if (String.Equals(sVisibility, "hidden") || String.Equals(sDisplay, "none")) { return; } DrawingGroup drawGroup = context.Peek(); Debug.Assert(drawGroup != null); Geometry geometry = CreateGeometry(_svgElement, context.OptimizePath); if (geometry != null && !geometry.IsEmpty()) { SetClip(context); WpfSvgPaint fillPaint = new WpfSvgPaint(context, styleElm, "fill"); string fileValue = styleElm.GetAttribute("fill"); Brush brush = fillPaint.GetBrush(geometry); WpfSvgPaint strokePaint = new WpfSvgPaint(context, styleElm, "stroke"); Pen pen = strokePaint.GetPen(); if (brush != null || pen != null) { Transform transform = this.Transform; if (transform != null && !transform.Value.IsIdentity) { geometry.Transform = transform; if (brush != null) { Transform brushTransform = brush.Transform; if (brushTransform == null || brushTransform == Transform.Identity) { brush.Transform = transform; } else { TransformGroup groupTransform = new TransformGroup(); groupTransform.Children.Add(brushTransform); groupTransform.Children.Add(transform); brush.Transform = groupTransform; } } } else { transform = null; // render any identity transform useless... } GeometryDrawing drawing = new GeometryDrawing(brush, pen, geometry); string elementId = this.GetElementName(); if (!String.IsNullOrEmpty(elementId) && !context.IsRegisteredId(elementId)) { drawing.SetValue(FrameworkElement.NameProperty, elementId); context.RegisterId(elementId); if (context.IncludeRuntime) { SvgObject.SetId(drawing, elementId); } } Brush maskBrush = this.Masking; Geometry clipGeom = this.ClipGeometry; if (clipGeom != null || maskBrush != null) { //Geometry clipped = Geometry.Combine(geometry, clipGeom, // GeometryCombineMode.Exclude, null); //if (clipped != null && !clipped.IsEmpty()) //{ // geometry = clipped; //} DrawingGroup clipMaskGroup = new DrawingGroup(); Rect geometryBounds = geometry.Bounds; if (clipGeom != null) { clipMaskGroup.ClipGeometry = clipGeom; SvgUnitType clipUnits = this.ClipUnits; if (clipUnits == SvgUnitType.ObjectBoundingBox) { Rect drawingBounds = geometryBounds; if (transform != null) { drawingBounds = transform.TransformBounds(drawingBounds); } TransformGroup transformGroup = new TransformGroup(); // Scale the clip region (at (0, 0)) and translate to the top-left corner of the target. transformGroup.Children.Add( new ScaleTransform(drawingBounds.Width, drawingBounds.Height)); transformGroup.Children.Add( new TranslateTransform(drawingBounds.X, drawingBounds.Y)); clipGeom.Transform = transformGroup; } else { if (transform != null) { clipGeom.Transform = transform; } } } if (maskBrush != null) { SvgUnitType maskUnits = this.MaskUnits; if (maskUnits == SvgUnitType.ObjectBoundingBox) { Rect drawingBounds = geometryBounds; if (transform != null) { drawingBounds = transform.TransformBounds(drawingBounds); } TransformGroup transformGroup = new TransformGroup(); // Scale the clip region (at (0, 0)) and translate to the top-left corner of the target. transformGroup.Children.Add( new ScaleTransform(drawingBounds.Width, drawingBounds.Height)); transformGroup.Children.Add( new TranslateTransform(drawingBounds.X, drawingBounds.Y)); DrawingGroup maskGroup = ((DrawingBrush)maskBrush).Drawing as DrawingGroup; if (maskGroup != null) { DrawingCollection maskDrawings = maskGroup.Children; for (int i = 0; i < maskDrawings.Count; i++) { Drawing maskDrawing = maskDrawings[i]; GeometryDrawing maskGeomDraw = maskDrawing as GeometryDrawing; if (maskGeomDraw != null) { if (maskGeomDraw.Brush != null) { ConvertColors(maskGeomDraw.Brush); } if (maskGeomDraw.Pen != null) { ConvertColors(maskGeomDraw.Pen.Brush); } } } } //if (transformGroup != null) //{ // drawingBounds = transformGroup.TransformBounds(drawingBounds); //} //maskBrush.Viewbox = drawingBounds; //maskBrush.ViewboxUnits = BrushMappingMode.Absolute; //maskBrush.Stretch = Stretch.Uniform; //maskBrush.Viewport = drawingBounds; //maskBrush.ViewportUnits = BrushMappingMode.Absolute; maskBrush.Transform = transformGroup; } else { if (transform != null) { maskBrush.Transform = transform; } } clipMaskGroup.OpacityMask = maskBrush; } clipMaskGroup.Children.Add(drawing); drawGroup.Children.Add(clipMaskGroup); } else { drawGroup.Children.Add(drawing); } } } RenderMarkers(renderer, styleElm, context); }
public void PresAttExisting() { SvgStyleableElement elm = Util.GetXmlElement("<title fill='black' />", "", "title") as SvgStyleableElement; Assert.AreEqual(CssValue.GetCssValue("black", false).CssText, elm.GetPresentationAttribute("fill").CssText); }
private void RenderPath(WpfDrawingRenderer renderer) { WpfDrawingContext context = renderer.Context; SvgRenderingHint hint = _svgElement.RenderingHint; if (hint != SvgRenderingHint.Shape || hint == SvgRenderingHint.Clipping) { return; } var parentNode = _svgElement.ParentNode; // We do not directly render the contents of the clip-path, unless specifically requested... if (string.Equals(parentNode.LocalName, "clipPath") && !context.RenderingClipRegion) { return; } SvgStyleableElement styleElm = (SvgStyleableElement)_svgElement; //string sVisibility = styleElm.GetPropertyValue("visibility"); //string sDisplay = styleElm.GetPropertyValue("display"); //if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none")) //{ // return; //} DrawingGroup drawGroup = context.Peek(); Debug.Assert(drawGroup != null); Geometry geometry = CreateGeometry(_svgElement, context.OptimizePath); string elementId = this.GetElementName(); string elementClass = this.GetElementClass(); GeometryDrawing drawing = null; if (geometry == null || geometry.IsEmpty()) { return; } var bounds = geometry.Bounds; if (string.Equals(_svgElement.LocalName, "line", StringComparison.Ordinal)) { _isLineSegment = true; } else if (string.Equals(_svgElement.LocalName, "rect", StringComparison.Ordinal)) { _isLineSegment = bounds.Width.Equals(0) || bounds.Height.Equals(0); } else if (string.Equals(_svgElement.LocalName, "path", StringComparison.Ordinal)) { _isLineSegment = bounds.Width.Equals(0) || bounds.Height.Equals(0); } context.UpdateBounds(geometry.Bounds); // SetClip(context); WpfSvgPaint fillPaint = new WpfSvgPaint(context, styleElm, "fill"); // string fileValue = styleElm.GetAttribute("fill"); Brush brush = fillPaint.GetBrush(geometry, _setBrushOpacity); if (brush == null) { WpfSvgPaint fallbackPaint = fillPaint.WpfFallback; if (fallbackPaint != null) { brush = fallbackPaint.GetBrush(geometry, _setBrushOpacity); } } bool isFillTransmable = fillPaint.IsFillTransformable; WpfSvgPaint strokePaint = new WpfSvgPaint(context, styleElm, "stroke"); Pen pen = strokePaint.GetPen(geometry, _setBrushOpacity); // By the SVG Specifications: // Keyword 'objectBoundingBox' should not be used when the geometry of the applicable // element has no width or no height, such as the case of a horizontal or vertical line, // even when the line has actual thickness when viewed due to having a non-zero stroke // width since stroke width is ignored for bounding box calculations. When the geometry // of the applicable element has no width or height and 'objectBoundingBox' is specified, // then the given effect (e.g., a gradient) will be ignored. if (pen != null && _isLineSegment && strokePaint.FillType == WpfFillType.Gradient) { WpfGradientFill gradientFill = (WpfGradientFill)strokePaint.PaintServer; if (gradientFill.IsUserSpace == false) { bool invalidGrad = false; if (string.Equals(_svgElement.LocalName, "line", StringComparison.Ordinal)) { LineGeometry lineGeometry = geometry as LineGeometry; if (lineGeometry != null) { invalidGrad = SvgObject.IsEqual(lineGeometry.EndPoint.X, lineGeometry.StartPoint.X) || SvgObject.IsEqual(lineGeometry.EndPoint.Y, lineGeometry.StartPoint.Y); } } else { invalidGrad = true; } if (invalidGrad) { // Brush is not likely inherited, we need to support fallback too WpfSvgPaint fallbackPaint = strokePaint.WpfFallback; if (fallbackPaint != null) { pen.Brush = fallbackPaint.GetBrush(geometry, _setBrushOpacity); } else { var scopePaint = strokePaint.GetScopeStroke(); if (scopePaint != null) { if (scopePaint != strokePaint) { pen.Brush = scopePaint.GetBrush(geometry, _setBrushOpacity); } else { pen.Brush = null; } } else { pen.Brush = null; } } } } } if (_paintContext != null) { _paintContext.Fill = fillPaint; _paintContext.Stroke = strokePaint; _paintContext.Tag = geometry; } if (brush != null || pen != null) { Transform transform = this.Transform; if (transform != null && !transform.Value.IsIdentity) { geometry.Transform = transform; if (brush != null && isFillTransmable) { Transform brushTransform = brush.Transform; if (brushTransform == null || brushTransform == Transform.Identity) { brush.Transform = transform; } else { TransformGroup groupTransform = new TransformGroup(); groupTransform.Children.Add(brushTransform); groupTransform.Children.Add(transform); brush.Transform = groupTransform; } } if (pen != null && pen.Brush != null) { Transform brushTransform = pen.Brush.Transform; if (brushTransform == null || brushTransform == Transform.Identity) { pen.Brush.Transform = transform; } else { TransformGroup groupTransform = new TransformGroup(); groupTransform.Children.Add(brushTransform); groupTransform.Children.Add(transform); pen.Brush.Transform = groupTransform; } } } else { transform = null; // render any identity transform useless... } drawing = new GeometryDrawing(brush, pen, geometry); if (!string.IsNullOrWhiteSpace(elementId) && !context.IsRegisteredId(elementId)) { SvgObject.SetName(drawing, elementId); context.RegisterId(elementId); if (context.IncludeRuntime) { SvgObject.SetId(drawing, elementId); } } if (!string.IsNullOrWhiteSpace(elementClass) && context.IncludeRuntime) { SvgObject.SetClass(drawing, elementClass); } Brush maskBrush = this.Masking; Geometry clipGeom = this.ClipGeometry; if (clipGeom != null || maskBrush != null) { //Geometry clipped = Geometry.Combine(geometry, clipGeom, // GeometryCombineMode.Exclude, null); //if (clipped != null && !clipped.IsEmpty()) //{ // geometry = clipped; //} DrawingGroup clipMaskGroup = new DrawingGroup(); Rect geometryBounds = geometry.Bounds; if (clipGeom != null) { clipMaskGroup.ClipGeometry = clipGeom; SvgUnitType clipUnits = this.ClipUnits; if (clipUnits == SvgUnitType.ObjectBoundingBox) { Rect drawingBounds = geometryBounds; if (transform != null) { drawingBounds = transform.TransformBounds(drawingBounds); } TransformGroup transformGroup = new TransformGroup(); // Scale the clip region (at (0, 0)) and translate to the top-left corner of the target. transformGroup.Children.Add(new ScaleTransform(drawingBounds.Width, drawingBounds.Height)); transformGroup.Children.Add(new TranslateTransform(drawingBounds.X, drawingBounds.Y)); clipGeom.Transform = transformGroup; } else { if (transform != null) { clipGeom.Transform = transform; } } } if (maskBrush != null) { DrawingBrush drawingBrush = (DrawingBrush)maskBrush; SvgUnitType maskUnits = this.MaskUnits; SvgUnitType maskContentUnits = this.MaskContentUnits; if (maskUnits == SvgUnitType.ObjectBoundingBox) { Rect drawingBounds = geometryBounds; if (transform != null) { drawingBounds = transform.TransformBounds(drawingBounds); } DrawingGroup maskGroup = drawingBrush.Drawing as DrawingGroup; if (maskGroup != null) { DrawingCollection maskDrawings = maskGroup.Children; for (int i = 0; i < maskDrawings.Count; i++) { Drawing maskDrawing = maskDrawings[i]; GeometryDrawing maskGeomDraw = maskDrawing as GeometryDrawing; if (maskGeomDraw != null) { if (maskGeomDraw.Brush != null) { ConvertColors(maskGeomDraw.Brush); } if (maskGeomDraw.Pen != null) { ConvertColors(maskGeomDraw.Pen.Brush); } } } } if (maskContentUnits == SvgUnitType.ObjectBoundingBox) { TransformGroup transformGroup = new TransformGroup(); // Scale the clip region (at (0, 0)) and translate to the top-left corner of the target. var scaleTransform = new ScaleTransform(drawingBounds.Width, drawingBounds.Height); transformGroup.Children.Add(scaleTransform); var translateTransform = new TranslateTransform(drawingBounds.X, drawingBounds.Y); transformGroup.Children.Add(translateTransform); Matrix scaleMatrix = new Matrix(); Matrix translateMatrix = new Matrix(); scaleMatrix.Scale(drawingBounds.Width, drawingBounds.Height); translateMatrix.Translate(drawingBounds.X, drawingBounds.Y); Matrix matrix = Matrix.Multiply(scaleMatrix, translateMatrix); //maskBrush.Transform = transformGroup; maskBrush.Transform = new MatrixTransform(matrix); } else { drawingBrush.Viewbox = drawingBounds; drawingBrush.ViewboxUnits = BrushMappingMode.Absolute; drawingBrush.Stretch = Stretch.Uniform; drawingBrush.Viewport = drawingBounds; drawingBrush.ViewportUnits = BrushMappingMode.Absolute; } } else { if (transform != null) { maskBrush.Transform = transform; } } clipMaskGroup.OpacityMask = maskBrush; } clipMaskGroup.Children.Add(drawing); drawGroup.Children.Add(clipMaskGroup); } else { drawGroup.Children.Add(drawing); } } // If this is not the child of a "marker", then try rendering a marker... if (!string.Equals(parentNode.LocalName, "marker")) { RenderMarkers(renderer, styleElm, context); } // Register this drawing with the Drawing-Document... if (drawing != null) { this.Rendered(drawing); } }
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); } } }
public GdiSvgPaint(SvgStyleableElement elm, string propName) : base(elm.GetComputedStyle("").GetPropertyValue(propName)) { _element = elm; }
public override void Render(GdiGraphicsRenderer renderer) { _graphics = renderer.GdiGraphics; //SvgRenderingHint hint = _svgElement.RenderingHint; //if (hint == SvgRenderingHint.Clipping) //{ // return; //} //if (_svgElement.ParentNode is SvgClipPathElement) //{ // return; //} SvgTextElement textElement = _svgElement as SvgTextElement; if (textElement == null) { return; } string sVisibility = textElement.GetPropertyValue("visibility"); string sDisplay = textElement.GetPropertyValue("display"); if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none")) { return; } if (_textMode != GdiTextMode.Outlining) { SetClip(_graphics); } PointF ctp = new PointF(0, 0); // current text position ctp = GetCurrentTextPosition(textElement, ctp); string sBaselineShift = textElement.GetPropertyValue("baseline-shift").Trim(); double shiftBy = 0; if (sBaselineShift.Length > 0) { float textFontSize = GetComputedFontSize(textElement); if (sBaselineShift.EndsWith("%", StringComparison.OrdinalIgnoreCase)) { shiftBy = SvgNumber.ParseNumber(sBaselineShift.Substring(0, sBaselineShift.Length - 1)) / 100 * textFontSize; } else if (sBaselineShift == "sub") { shiftBy = -0.6F * textFontSize; } else if (sBaselineShift == "super") { shiftBy = 0.6F * textFontSize; } else if (sBaselineShift == "baseline") { shiftBy = 0; } else { shiftBy = SvgNumber.ParseNumber(sBaselineShift); } } // For for fonts loading in the background... var svgDoc = _svgElement.OwnerDocument; if (svgDoc.IsFontsLoaded == false) { //TODO: Use of SpinUntil is known to CPU heavy, but will work for now... SpinWait.SpinUntil(() => svgDoc.IsFontsLoaded == true); } XmlNodeType nodeType = XmlNodeType.None; foreach (XmlNode child in _svgElement.ChildNodes) { SvgStyleableElement stylable = child as SvgStyleableElement; if (stylable != null) { sVisibility = stylable.GetPropertyValue("visibility"); sDisplay = stylable.GetPropertyValue("display"); if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none")) { continue; } } nodeType = child.NodeType; if (nodeType == XmlNodeType.Text) { ctp.Y -= (float)shiftBy; AddGraphicsPath(textElement, ref ctp, GetText(textElement, child)); ctp.Y += (float)shiftBy; } else if (nodeType == XmlNodeType.Element) { string nodeName = child.Name; if (string.Equals(nodeName, "tref")) { AddTRefElementPath((SvgTRefElement)child, ref ctp); } else if (string.Equals(nodeName, "tspan")) { AddTSpanElementPath((SvgTSpanElement)child, ref ctp); } } } PaintMarkers(renderer, textElement, _graphics); _graphics = null; }
private GeometryCollection CreateClippingRegion(SvgClipPathElement clipPath, WpfDrawingContext context) { GeometryCollection geomColl = new GeometryCollection(); foreach (XmlNode node in clipPath.ChildNodes) { if (node.NodeType != XmlNodeType.Element) { continue; } // Handle a case where the clip element has "use" element as a child... if (string.Equals(node.LocalName, "use")) { SvgUseElement useElement = (SvgUseElement)node; XmlElement refEl = useElement.ReferencedElement; if (refEl != null) { XmlElement refElParent = (XmlElement)refEl.ParentNode; useElement.OwnerDocument.Static = true; useElement.CopyToReferencedElement(refEl); refElParent.RemoveChild(refEl); useElement.AppendChild(refEl); foreach (XmlNode useChild in useElement.ChildNodes) { if (useChild.NodeType != XmlNodeType.Element) { continue; } SvgStyleableElement element = useChild as SvgStyleableElement; if (element != null && element.RenderingHint == SvgRenderingHint.Shape) { Geometry childPath = CreateGeometry(element, context.OptimizePath); if (childPath != null) { geomColl.Add(childPath); } } } useElement.RemoveChild(refEl); useElement.RestoreReferencedElement(refEl); refElParent.AppendChild(refEl); useElement.OwnerDocument.Static = false; } } else { SvgStyleableElement element = node as SvgStyleableElement; if (element != null) { if (element.RenderingHint == SvgRenderingHint.Shape) { Geometry childPath = CreateGeometry(element, context.OptimizePath); if (childPath != null) { geomColl.Add(childPath); } } else if (element.RenderingHint == SvgRenderingHint.Text) { GeometryCollection textGeomColl = GetTextClippingRegion(element, context); if (textGeomColl != null) { for (int i = 0; i < textGeomColl.Count; i++) { geomColl.Add(textGeomColl[i]); } } } } } } return(geomColl); }
public override void Render(GdiGraphicsRenderer renderer) { var graphics = renderer.GdiGraphics; SvgRenderingHint hint = _svgElement.RenderingHint; if (hint != SvgRenderingHint.Shape || hint == SvgRenderingHint.Clipping) { return; } if (_svgElement.ParentNode is SvgClipPathElement) { return; } SvgStyleableElement styleElm = (SvgStyleableElement)_svgElement; string sVisibility = styleElm.GetPropertyValue("visibility"); string sDisplay = styleElm.GetPropertyValue("display"); if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none")) { return; } GraphicsPath gp = CreatePath(_svgElement); if (gp == null) { return; } 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) { var gps = fillPaint.PaintFill as GdiRadialGradientFill; graphics.SetClip(gps.GetRadialRegion(gp.GetBounds()), CombineMode.Exclude); SolidBrush tempBrush = new SolidBrush(((PathGradientBrush)brush).InterpolationColors.Colors[0]); graphics.FillPath(this, tempBrush, gp); tempBrush.Dispose(); graphics.ResetClip(); } graphics.FillPath(this, brush, gp); brush.Dispose(); brush = null; } if (pen != null) { if (pen.Brush is PathGradientBrush) { var gps = strokePaint.PaintFill as GdiRadialGradientFill; GdiGraphicsContainer container = graphics.BeginContainer(); graphics.SetClip(gps.GetRadialRegion(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(); pen = null; } gp.Dispose(); gp = null; PaintMarkers(renderer, styleElm, graphics); }
private void setNodeFillColor(ISvgElement targetNode, Color fillColor, string property) { string szRGB = null, szOpacity = null, szNodeopacity = null; if (targetNode.RenderingHint == SvgRenderingHint.Text || targetNode.RenderingHint == SvgRenderingHint.Shape) { szRGB = (targetNode as SvgElement).GetComputedStyle("").GetPropertyValue(property); //Special handling: if fill color is white and it is inner node, don't change it. //add id for svgs in Social/Gesture/Style BG. need to check svg if load new svg folder. if (string.IsNullOrEmpty(szRGB) || (szRGB == "rgb(255,255,255)" && !string.IsNullOrEmpty((targetNode as SvgElement).Id))) { return; } //Get RGB Color SvgPaint paint = new SvgPaint(szRGB); if (paint.RgbColor == null) { return; } } //Set RGB Color CssCollectedStyleDeclaration All = (targetNode as SvgElement).GetComputedStyle("") as CssCollectedStyleDeclaration; CssStyleSheetType origin = All.GetPropertyOrigin(property); switch (origin) { //For those default fill color is black,and has no this attribute.Add and set it. case CssStyleSheetType.Unknown: case CssStyleSheetType.NonCssPresentationalHints: { string value = string.Format("rgb({0},{1},{2})", fillColor.R, fillColor.G, fillColor.B); targetNode.SetAttribute(property, value); break; } case CssStyleSheetType.Inline: { string value = string.Format("rgb({0},{1},{2})", fillColor.R, fillColor.G, fillColor.B); SvgStyleableElement styleNode = targetNode as SvgStyleableElement; styleNode.Style.SetProperty(property, value, string.Empty); targetNode.SetAttribute("style", styleNode.Style.CssText); break; } case CssStyleSheetType.Author: { break; } } //Set Alpha value szOpacity = (targetNode as SvgElement).GetComputedStyle("").GetPropertyValue(property + @"-opacity"); szNodeopacity = (targetNode as SvgElement).GetComputedStyle("").GetPropertyValue("opacity"); if (szNodeopacity == null && szOpacity == null) { if (fillColor.A == 255) { return; } string value = string.Format("{0}", Convert.ToDouble((double)fillColor.A / (double)255)); targetNode.SetAttribute(property + @"-opacity", value); } else { string Oproperty = null; if (szNodeopacity != null && szNodeopacity.Length > 0) { Oproperty = "opacity"; } else { Oproperty = property + @"-opacity"; } origin = All.GetPropertyOrigin(Oproperty); switch (origin) { case CssStyleSheetType.NonCssPresentationalHints: { string value = string.Format("{0}", Convert.ToDouble((double)fillColor.A / (double)255)); targetNode.SetAttribute(Oproperty, value); break; } case CssStyleSheetType.Unknown: { string value = string.Format("{0}", Convert.ToDouble((double)fillColor.A / (double)255)); targetNode.SetAttribute(Oproperty, value); break; } case CssStyleSheetType.Inline: { string value = string.Format("{0}", Convert.ToDouble((double)fillColor.A / (double)255)); SvgStyleableElement styleNode = targetNode as SvgStyleableElement; styleNode.Style.SetProperty(Oproperty, value, string.Empty); targetNode.SetAttribute("style", styleNode.Style.CssText); break; } case CssStyleSheetType.Author: { break; } } } }
private Style CreateStyle(Path shape, SvgStyleableElement element) { if (element == null) { return(null); } Style style = new Style(); style.BasedOn = this.renderer.ItemStyle; style.Setters.Add(new Setter(UIElement.SnapsToDevicePixelsProperty, true)); Rect shapeBounds = Rect.Empty; Matrix shapeTransform = Matrix.Identity; if (shape.Data != null) { if (shape.Data.Transform?.Value.IsIdentity == true) { shapeBounds = shape.Data.Bounds; } else { var transform = shape.Data.Transform; shape.Data.Transform = null; shapeBounds = shape.Data.Bounds; shape.Data.Transform = transform; shapeTransform = transform.Value; } } // Stroke Brush stroke; if (TryGetBrush(element, "stroke", shapeBounds, shapeTransform, out stroke)) { style.Setters.Add(new Setter(Shape.StrokeProperty, stroke)); } double strokeWidth; if (TryGetStrokeWidth(element, out strokeWidth)) { style.Setters.Add(new Setter(Shape.StrokeThicknessProperty, strokeWidth)); } double miterLimit; if (TryGetMiterLimit(element, strokeWidth, out miterLimit)) { style.Setters.Add(new Setter(Shape.StrokeMiterLimitProperty, miterLimit)); } PenLineJoin lineJoin; if (TryGetLineJoin(element, out lineJoin)) { style.Setters.Add(new Setter(Shape.StrokeLineJoinProperty, lineJoin)); } PenLineCap lineCap; if (TryGetLineCap(element, out lineCap)) { style.Setters.Add(new Setter(Shape.StrokeStartLineCapProperty, lineCap)); style.Setters.Add(new Setter(Shape.StrokeEndLineCapProperty, lineCap)); } DoubleCollection dashArray; if (TryGetDashArray(element, strokeWidth, out dashArray)) { style.Setters.Add(new Setter(Shape.StrokeDashArrayProperty, dashArray)); } double dashOffset; if (TryGetDashOffset(element, out dashOffset)) { style.Setters.Add(new Setter(Shape.StrokeDashOffsetProperty, dashOffset)); } // Fill Brush fill; if (TryGetBrush(element, "fill", shapeBounds, shapeTransform, out fill)) { style.Setters.Add(new Setter(Shape.FillProperty, fill)); } return(style); }
private GraphicsPath CreateClippingRegion(SvgClipPathElement clipPath) { GraphicsPath path = new GraphicsPath(); foreach (XmlNode node in clipPath.ChildNodes) { if (node.NodeType != XmlNodeType.Element) { continue; } // Handle a case where the clip element has "use" element as a child... if (String.Equals(node.LocalName, "use")) { SvgUseElement useElement = (SvgUseElement)node; XmlElement refEl = useElement.ReferencedElement; if (refEl != null) { XmlElement refElParent = (XmlElement)refEl.ParentNode; useElement.OwnerDocument.Static = true; useElement.CopyToReferencedElement(refEl); refElParent.RemoveChild(refEl); useElement.AppendChild(refEl); foreach (XmlNode useChild in useElement.ChildNodes) { if (useChild.NodeType != XmlNodeType.Element) { continue; } SvgStyleableElement element = useChild as SvgStyleableElement; if (element != null && element.RenderingHint == SvgRenderingHint.Shape) { GraphicsPath childPath = CreatePath(element); if (childPath != null) { string clipRule = element.GetPropertyValue("clip-rule"); path.FillMode = (clipRule == "evenodd") ? FillMode.Alternate : FillMode.Winding; path.AddPath(childPath, true); } } } useElement.RemoveChild(refEl); useElement.RestoreReferencedElement(refEl); refElParent.AppendChild(refEl); useElement.OwnerDocument.Static = false; } } else { SvgStyleableElement element = node as SvgStyleableElement; if (element != null && element.RenderingHint == SvgRenderingHint.Shape) { GraphicsPath childPath = CreatePath(element); if (childPath != null) { string clipRule = element.GetPropertyValue("clip-rule"); path.FillMode = (clipRule == "evenodd") ? FillMode.Alternate : FillMode.Winding; path.AddPath(childPath, true); } } } } return(path); }
public void RenderMarker0(WpfDrawingRenderer renderer, WpfDrawingContext gr, SvgMarkerPosition markerPos, SvgStyleableElement refElement) { //PathGeometry g; //g.GetPointAtFractionLength( ISharpMarkerHost markerHostElm = (ISharpMarkerHost)refElement; SvgMarkerElement markerElm = (SvgMarkerElement)_svgElement; SvgPointF[] vertexPositions = markerHostElm.MarkerPositions; int start; int len; // Choose which part of the position array to use switch (markerPos) { case SvgMarkerPosition.Start: start = 0; len = 1; break; case SvgMarkerPosition.Mid: start = 1; len = vertexPositions.Length - 2; break; default: // == MarkerPosition.End start = vertexPositions.Length - 1; len = 1; break; } for (int i = start; i < start + len; i++) { SvgPointF point = vertexPositions[i]; Matrix m = GetTransformMatrix(_svgElement); //GraphicsContainer gc = gr.BeginContainer(); this.BeforeRender(renderer); //gr.TranslateTransform(point.X, point.Y); //PAUL: //m.Translate(point.X, point.Y); if (markerElm.OrientType.AnimVal.Equals((ushort)SvgMarkerOrient.Angle)) { m.Rotate(markerElm.OrientAngle.AnimVal.Value); //gr.RotateTransform((double)markerElm.OrientAngle.AnimVal.Value); } else { double angle; switch (markerPos) { case SvgMarkerPosition.Start: angle = markerHostElm.GetStartAngle(i + 1); break; case SvgMarkerPosition.Mid: //angle = (markerHostElm.GetEndAngle(i) + markerHostElm.GetStartAngle(i + 1)) / 2; angle = SvgNumber.CalcAngleBisection(markerHostElm.GetEndAngle(i), markerHostElm.GetStartAngle(i + 1)); break; default: angle = markerHostElm.GetEndAngle(i); break; } //gr.RotateTransform(angle); m.Rotate(angle); } if (markerElm.MarkerUnits.AnimVal.Equals((ushort)SvgMarkerUnit.StrokeWidth)) { string propValue = refElement.GetPropertyValue("stroke-width"); if (propValue.Length == 0) { propValue = "1"; } SvgLength strokeWidthLength = new SvgLength("stroke-width", propValue, refElement, SvgLengthDirection.Viewport); double strokeWidth = strokeWidthLength.Value; //gr.ScaleTransform(strokeWidth, strokeWidth); m.Scale(strokeWidth, strokeWidth); } SvgPreserveAspectRatio spar = (SvgPreserveAspectRatio)markerElm.PreserveAspectRatio.AnimVal; double[] translateAndScale = spar.FitToViewBox( (SvgRect)markerElm.ViewBox.AnimVal, new SvgRect(0, 0, markerElm.MarkerWidth.AnimVal.Value, markerElm.MarkerHeight.AnimVal.Value)); //PAUL: //m.Translate(-(double)markerElm.RefX.AnimVal.Value * translateAndScale[2], -(double)markerElm.RefY.AnimVal.Value * translateAndScale[3]); //PAUL: m.Scale(translateAndScale[2], translateAndScale[3]); m.Translate(point.X, point.Y); //Matrix oldTransform = TransformMatrix; //TransformMatrix = m; //try //{ //newTransform.Append(m); //TransformGroup tg = new TransformGroup(); //renderer.Canvas.re //gr.TranslateTransform( // -(double)markerElm.RefX.AnimVal.Value * translateAndScale[2], // -(double)markerElm.RefY.AnimVal.Value * translateAndScale[3] // ); //gr.ScaleTransform(translateAndScale[2], translateAndScale[3]); renderer.RenderChildren(markerElm); // markerElm.RenderChildren(renderer); //} //finally //{ // TransformMatrix = oldTransform; //} // //gr.EndContainer(gc); _matrix = m; this.Render(renderer); //gr.EndContainer(gc); this.AfterRender(renderer); } }