private DrawingGroup GetDrawingLayer(DrawingGroup drawingGroup) { DrawingGroup groupDrawing = null; // Enumerate the drawings in the DrawingCollection. foreach (Drawing drawing in drawingGroup.Children) { var itemKey = SvgLink.GetKey(drawing); if (!string.IsNullOrWhiteSpace(itemKey) && itemKey.Equals(SvgObject.DrawLayer, StringComparison.OrdinalIgnoreCase)) { return((DrawingGroup)drawing); } // If the drawing is a DrawingGroup, call the function recursively. if (TryCast.Cast(drawing, out groupDrawing)) { SvgObjectType objectType = SvgObject.GetType(groupDrawing); if (objectType != SvgObjectType.Text) { var nextGroup = GetDrawingLayer(groupDrawing); if (nextGroup != groupDrawing) { itemKey = SvgLink.GetKey(nextGroup); if (!string.IsNullOrWhiteSpace(itemKey) && itemKey.Equals(SvgObject.DrawLayer, StringComparison.OrdinalIgnoreCase)) { return(nextGroup); } } } } } return(drawingGroup); }
public override void Initialize(DrawingGroup linkGroup, WpfDrawingContext context) { if (linkGroup != null) { SvgLink.SetKey(linkGroup, SvgObject.LinksLayer); } }
private void RenderHeader() { var accessibility = new SvgText( _svgRoot, _classDiagram.Accessibility, (_diagramSize.Width - _classDiagram.Accessibility.GetWidth(11, Fonts.FontItalic)) / 2, ACCESSIBILITY_LABEL_Y); accessibility.FontSize = 11; SvgElement name; if (_classDiagram.IsProjectStranger) { name = new SvgText( _svgRoot, _classDiagram.Name, (_diagramSize.Width - _classDiagram.Name.GetWidth(14, Fonts.FontLight)) / 2, CLASSLABEL_Y); ((SvgText)name).FontSize = 14; } else { name = new SvgLink( _svgRoot, _classDiagram.Name, string.Format("{{{{type-link:{0}}}}}", _classDiagram.TypeIdentifier), (_diagramSize.Width - _classDiagram.Name.GetWidth(14, Fonts.FontLight)) / 2, CLASSLABEL_Y); ((SvgLink)name).Text.FontSize = 14; } var path = new SvgPath( _svgRoot, string.Format("M0.5,{0}L{1},{0}", (CLASSLABEL_Y + 10).ToString("0.00", CultureInfo.InvariantCulture), _diagramSize.Width.ToString("0.00", CultureInfo.InvariantCulture))); path.StrokeWidth = 1; path.Stroke = "#979797"; _svgGraphic.Add(accessibility); _svgGraphic.Add(name); _svgGraphic.Add(path); }
private void DrawConnection(SequenceDiagramConnection connection) { var callerNodeMiddlePoint = connection.CallerId == Guid.Empty ? 0 : _nodeMiddlePoints[connection.CallerId]; var calledNodeMiddlePoint = _nodeMiddlePoints[connection.CalledId]; var textWidth = connection.Text.GetWidth(12, Fonts.FontLight); var link = new SvgLink(_svgRoot, connection.Text, string.Format("{{{{method-link:{0}}}}}", connection.CalledMethodIdentifier), callerNodeMiddlePoint + 10, _diagramSize.Height + 10); link.Text.FontSize = 12; _svgGraphic.Add(link); if ((textWidth + callerNodeMiddlePoint + 10) > _diagramSize.Width) { _diagramSize.Width = textWidth + callerNodeMiddlePoint + 20; } DrawConnectionLine(connection, callerNodeMiddlePoint, calledNodeMiddlePoint); DrawConnectionArrow(calledNodeMiddlePoint); }
private void RenderRowSection(List <ClassDiagramRow> classDiagramRows, string memberType, int rowCountOffset, int sectionOffset) { for (int i = 0; i < classDiagramRows.Count; i++) { var image = new SvgImage( _svgRoot, 15, FIRSTROW_OFFSET_Y + ((i + rowCountOffset) * 25) + (sectionOffset * 10) - 12, 16, 16, string.Format("data:image/png;base64,{0}", Icons.GetBase64Icon(classDiagramRows[i].Type, classDiagramRows[i].Accessibility))); SvgElement text; if (_classDiagram.IsProjectStranger) { text = new SvgText( _svgRoot, classDiagramRows[i].Text, 40, FIRSTROW_OFFSET_Y + ((i + rowCountOffset) * 25) + (sectionOffset * 10)); ((SvgText)text).FontSize = 14; } else { text = new SvgLink( _svgRoot, classDiagramRows[i].Text, string.Format("{{{{{0}-link:{1}}}}}", memberType, classDiagramRows[i].Identifier), 40, FIRSTROW_OFFSET_Y + ((i + rowCountOffset) * 25) + (sectionOffset * 10)); ((SvgLink)text).Text.FontSize = 14; } _svgGraphic.Add(image); _svgGraphic.Add(text); } if (classDiagramRows.Count > 0 && FollowingSectionsNotEmpty(memberType)) { RenderLine(FIRSTROW_OFFSET_Y + ((classDiagramRows.Count + rowCountOffset) * 25) + (sectionOffset * 10) - 10); } }
private void AddExtraLinkInformation(DrawingGroup group, SvgElement element) { string linkColor = element.GetAttribute("color"); if (!String.IsNullOrEmpty(linkColor)) { SvgLink.SetColor(group, linkColor); } string linkPartsId = element.GetAttribute("partsid"); if (!String.IsNullOrEmpty(linkPartsId)) { SvgLink.SetPartsId(group, linkPartsId); } string linkType = element.GetAttribute("type"); if (!String.IsNullOrEmpty(linkType)) { SvgLink.SetPartsId(group, linkType); } string linkNumber = element.GetAttribute("num"); if (!String.IsNullOrEmpty(linkNumber)) { SvgLink.SetPartsId(group, linkNumber); } string linkPin = element.GetAttribute("pin"); if (!String.IsNullOrEmpty(linkPin)) { SvgLink.SetPartsId(group, linkPin); } string linkLineId = element.GetAttribute("lineid"); if (!String.IsNullOrEmpty(linkLineId)) { SvgLink.SetPartsId(group, linkLineId); } }
// Данный метод основывается на деталях реализации SharpVectors конвертора // Предполагается, что реальные размеры DrawingGroup хранятся в ClipGeometry // группы, помеченной ключом SvgObject.DrawLayer static Rect?GetDrawingRectRecursive(DrawingGroup group) { var key = SvgLink.GetKey(group); if (key == SvgObject.DrawLayer) { var geometry = group.ClipGeometry as RectangleGeometry; if (geometry != null) { return(geometry.Bounds); } } foreach (var childGroup in group.Children.OfType <DrawingGroup>()) { var res = GetDrawingRectRecursive(childGroup); if (res != null) { return(res); } } return(null); }
private void DrawNode(SequenceDiagramNode node) { var textWidth = node.Text.GetWidth(12, Fonts.FontLight); var textPosition = new Point(_diagramSize.Width, 10); var textSize = new Size(textWidth + 20, 35); _diagramSize = new Size(_diagramSize.Width + textWidth + 40, _diagramSize.Height); var rectangle = new SvgRectangle(_svgRoot, textPosition.X, textPosition.Y, textSize.Width, textSize.Height); rectangle.StrokeWidth = 1; rectangle.Stroke = "#979797"; rectangle.Fill = "#FFFFFF"; var link = new SvgLink(_svgRoot, node.Text, string.Format("{{{{type-link:{0}}}}}", node.TypeIdentifier), textPosition.X + 15, textPosition.Y + 22); link.Text.FontSize = 12; _svgGraphic.Add(rectangle); _svgGraphic.Add(link); _nodeMiddlePoints.Add(node.ID, textSize.Width / 2 + textPosition.X); }
private double RenderHeader(ClassDiagram classDiagram, double position) { var accessibility = new SvgText(_svgRoot, classDiagram.Accessibility, (_diagramWidth - classDiagram.Accessibility.GetWidth(11, Fonts.FontItalic)) / 2, position); accessibility.FontSize = 11; var name = new SvgLink(_svgRoot, classDiagram.Name, string.Format("{{{{type-link:{0}}}}}", classDiagram.TypeIdentifier), (_diagramWidth - classDiagram.Name.GetWidth(14, Fonts.FontLight)) / 2, position += 20); name.Text.FontSize = 14; position += 15; var path = new SvgPath(_svgRoot, string.Format("M0.5,{0}L{1},{0}", position.ToString("0.00", CultureInfo.InvariantCulture), _diagramWidth.ToString("0.00", CultureInfo.InvariantCulture))); path.StrokeWidth = 1; path.Stroke = "#979797"; _svgRoot.AppendChild(accessibility.XmlElement); _svgRoot.AppendChild(name.XmlElement); _svgRoot.AppendChild(path.XmlElement); return(position + 25); }
private double RenderRowSection(List <ClassDiagramRow> classDiagramRows, string memberType, double position, bool renderLine) { var actualPosition = position; foreach (var row in classDiagramRows) { var image = new SvgImage(_svgRoot, 15, actualPosition - 12, 16, 16, string.Format("data:image/png;base64,{0}", Icons.GetBase64Icon(row.Type, row.Accessibility))); var text = new SvgLink(_svgRoot, row.Text, string.Format("{{{{{0}-link:{1}}}}}", memberType, row.Identifier), 40, actualPosition); text.Text.FontSize = 14; _svgRoot.AppendChild(image.XmlElement); _svgRoot.AppendChild(text.XmlElement); actualPosition += 25; } if (classDiagramRows.Count > 0 && renderLine) { actualPosition -= 10; actualPosition = RenderLine(actualPosition); } return(actualPosition); }
public override void Visit(DrawingGroup group, SvgAElement element, WpfDrawingContext context, float opacity) { _isAggregated = false; if (group == null || element == null || context == null) { return; } AddExtraLinkInformation(group, element); //string linkId = element.GetAttribute("id"); string linkId = GetElementName(element); if (String.IsNullOrEmpty(linkId)) { return; } SvgLink.SetKey(group, linkId); if (_dicLinks.ContainsKey(linkId)) { _isAggregated = _dicLinks[linkId]; return; } string linkAction = element.GetAttribute("onclick"); if (String.IsNullOrEmpty(linkAction)) { linkAction = element.GetAttribute("onmouseover"); if (!String.IsNullOrEmpty(linkAction) && linkAction.StartsWith("parent.svgMouseOverName", StringComparison.OrdinalIgnoreCase)) { SvgLink.SetAction(group, SvgLinkAction.LinkTooltip); } else { SvgLink.SetAction(group, SvgLinkAction.LinkNone); } } else { if (linkAction.StartsWith("parent.svgClick", StringComparison.OrdinalIgnoreCase)) { SvgLink.SetAction(group, SvgLinkAction.LinkPage); } else if (linkAction.StartsWith("parent.svgOpenHtml", StringComparison.OrdinalIgnoreCase)) { SvgLink.SetAction(group, SvgLinkAction.LinkHtml); } else { SvgLink.SetAction(group, SvgLinkAction.LinkNone); } } if (!String.IsNullOrEmpty(linkAction)) { if (linkAction.IndexOf("'Top'") > 0) { SvgLink.SetLocation(group, "Top"); } else if (linkAction.IndexOf("'Bottom'") > 0) { SvgLink.SetLocation(group, "Bottom"); } else { SvgLink.SetLocation(group, "Top"); } } this.AggregateChildren(element, context, opacity); if (_isAggregated) { Geometry drawGeometry = null; if (_aggregatedGeom.Count == 1) { drawGeometry = _aggregatedGeom[0]; } else { GeometryGroup geomGroup = new GeometryGroup(); geomGroup.FillRule = FillRule.Nonzero; for (int i = 0; i < _aggregatedGeom.Count; i++) { geomGroup.Children.Add(_aggregatedGeom[i]); } drawGeometry = geomGroup; } WpfSvgPaint fillPaint = new WpfSvgPaint(context, _aggregatedFill, "fill"); Brush brush = fillPaint.GetBrush(false); brush.SetValue(FrameworkElement.NameProperty, linkId + "_Brush"); GeometryDrawing drawing = new GeometryDrawing(brush, null, drawGeometry); group.Children.Add(drawing); } _dicLinks.Add(linkId, _isAggregated); }
public override void BeforeRender(WpfDrawingRenderer renderer) { base.BeforeRender(renderer); WpfDrawingContext context = renderer.Context; if (context.Count == 0) { _drawGroup = new DrawingGroup(); context.Push(_drawGroup); context.Root = _drawGroup; } else if (context.Count == 1) { DrawingGroup currentGroup = context.Peek(); if (currentGroup == null) { throw new InvalidOperationException("An existing group is expected."); } if (currentGroup == context.Root) { if (context.IsFragment) { // Do not add extra layer to fragments... _drawGroup = currentGroup; } else { _drawGroup = new DrawingGroup(); SvgObject.SetName(_drawGroup, SvgObject.DrawLayer); if (context.IncludeRuntime) { SvgLink.SetKey(_drawGroup, SvgObject.DrawLayer); } currentGroup.Children.Add(_drawGroup); context.Push(_drawGroup); } } else { _drawGroup = new DrawingGroup(); currentGroup.Children.Add(_drawGroup); context.Push(_drawGroup); } } else { _drawGroup = new DrawingGroup(); DrawingGroup currentGroup = context.Peek(); if (currentGroup == null) { throw new InvalidOperationException("An existing group is expected."); } currentGroup.Children.Add(_drawGroup); context.Push(_drawGroup); } SvgSvgElement svgElm = (SvgSvgElement)_svgElement; double x = Math.Round(svgElm.X.AnimVal.Value, 4); double y = Math.Round(svgElm.Y.AnimVal.Value, 4); double width = Math.Round(svgElm.Width.AnimVal.Value, 4); double height = Math.Round(svgElm.Height.AnimVal.Value, 4); if (width < 0 || height < 0) { // For invalid dimension, prevent the drawing of the children... _isRecursive = true; return; } Rect elmRect = new Rect(x, y, width, height); XmlNode parentNode = _svgElement.ParentNode; ISvgFitToViewBox fitToView = svgElm as ISvgFitToViewBox; ISvgAnimatedPreserveAspectRatio preserveAspectRatio = null; if (fitToView != null && fitToView.PreserveAspectRatio != null) { preserveAspectRatio = fitToView.PreserveAspectRatio; ISvgAnimatedRect animRect = fitToView.ViewBox; if (animRect != null) { ISvgRect viewRect = animRect.AnimVal; if (viewRect != null) { Rect wpfViewRect = WpfConvert.ToRect(viewRect); if (!wpfViewRect.IsEmpty && wpfViewRect.Width > 0 && wpfViewRect.Height > 0) { elmRect = wpfViewRect; } } } } Transform transform = null; var aspectRatio = (preserveAspectRatio != null) ? preserveAspectRatio.AnimVal : null; if (parentNode.NodeType != XmlNodeType.Document || (aspectRatio != null && aspectRatio.Align == SvgPreserveAspectRatioType.None)) { FitToViewbox(context, elmRect); transform = this.Transform; if (transform != null) { _drawGroup.Transform = transform; } } if (!elmRect.IsEmpty && !elmRect.Width.Equals(0) && !elmRect.Height.Equals(0)) { // Elements such as "pattern" are also rendered by this renderer, so we make sure we are // dealing with the root SVG element... if (parentNode != null && parentNode.NodeType == XmlNodeType.Document) { _drawGroup.ClipGeometry = new RectangleGeometry(elmRect); } else { if (transform != null) { // We have already applied the transform, which will translate to the start point... if (transform is TranslateTransform) { //_drawGroup.ClipGeometry = new RectangleGeometry( // new Rect(0, 0, elmRect.Width, elmRect.Height)); } else { _drawGroup.ClipGeometry = new RectangleGeometry(elmRect); } } else { _drawGroup.ClipGeometry = new RectangleGeometry(elmRect); } } } }
public override void BeforeRender(WpfDrawingRenderer renderer) { base.BeforeRender(renderer); _idElement = string.Empty; WpfDrawingContext context = renderer.Context; DrawingGroup currentGroup = context.Peek(); if (currentGroup == null) { throw new InvalidOperationException("An existing group is expected."); } if (currentGroup == context.Root) { if (context.IsFragment) { // Do not add extra layer to fragments... _drawGroup = currentGroup; } else { _drawGroup = new DrawingGroup(); SvgObject.SetName(_drawGroup, SvgObject.DrawLayer); if (context.IncludeRuntime) { SvgLink.SetKey(_drawGroup, SvgObject.DrawLayer); } currentGroup.Children.Add(_drawGroup); context.Push(_drawGroup); } } else { _drawGroup = new DrawingGroup(); currentGroup.Children.Add(_drawGroup); context.Push(_drawGroup); } SvgPatternElement svgElm = (SvgPatternElement)_svgElement; _idElement = svgElm.Id; if (!string.IsNullOrWhiteSpace(_idElement)) { context.AddUrl(_idElement); } double x = Math.Round(svgElm.X.AnimVal.Value, 4); double y = Math.Round(svgElm.Y.AnimVal.Value, 4); double width = Math.Round(svgElm.Width.AnimVal.Value, 4); double height = Math.Round(svgElm.Height.AnimVal.Value, 4); if (width < 0 || height < 0) { // For invalid dimension, prevent the drawing of the children... _isRecursive = true; return; } Rect elmRect = new Rect(x, y, width, height); // XmlNode parentNode = _svgElement.ParentNode; ISvgFitToViewBox fitToView = svgElm as ISvgFitToViewBox; ISvgAnimatedPreserveAspectRatio preserveAspectRatio = null; if (fitToView != null && fitToView.PreserveAspectRatio != null) { preserveAspectRatio = fitToView.PreserveAspectRatio; ISvgAnimatedRect animRect = fitToView.ViewBox; if (animRect != null) { ISvgRect viewRect = animRect.AnimVal; if (viewRect != null) { Rect wpfViewRect = WpfConvert.ToRect(viewRect); if (!wpfViewRect.IsEmpty && wpfViewRect.Width > 0 && wpfViewRect.Height > 0) { elmRect = wpfViewRect; } } } } Transform transform = null; var aspectRatio = (preserveAspectRatio != null) ? preserveAspectRatio.AnimVal : null; if (aspectRatio != null /* && aspectRatio.Align == SvgPreserveAspectRatioType.None*/) { FitToViewbox(context, elmRect); transform = this.Transform; if (transform != null) { _drawGroup.Transform = transform; } } }
public override void BeforeRender(WpfDrawingRenderer renderer) { base.BeforeRender(renderer); WpfDrawingContext context = renderer.Context; _drawGroup = new DrawingGroup(); if (context.Count == 0) { context.Push(_drawGroup); context.Root = _drawGroup; } else if (context.Count == 1) { DrawingGroup currentGroup = context.Peek(); if (currentGroup == null) { throw new InvalidOperationException("An existing group is expected."); } if (currentGroup == context.Root && !context.IsFragment) { _drawGroup.SetValue(FrameworkElement.NameProperty, SvgObject.DrawLayer); if (context.IncludeRuntime) { SvgLink.SetKey(_drawGroup, SvgObject.DrawLayer); } } currentGroup.Children.Add(_drawGroup); context.Push(_drawGroup); } else { DrawingGroup currentGroup = context.Peek(); if (currentGroup == null) { throw new InvalidOperationException("An existing group is expected."); } currentGroup.Children.Add(_drawGroup); context.Push(_drawGroup); } SvgSvgElement svgElm = (SvgSvgElement)_svgElement; double x = Math.Round(svgElm.X.AnimVal.Value, 4); double y = Math.Round(svgElm.Y.AnimVal.Value, 4); double width = Math.Round(svgElm.Width.AnimVal.Value, 4); double height = Math.Round(svgElm.Height.AnimVal.Value, 4); Rect elmRect = new Rect(x, y, width, height); //if (element.ParentNode is SvgElement) //{ // // TODO: should it be moved with x and y? //} XmlNode parentNode = _svgElement.ParentNode; //if (parentNode.NodeType == XmlNodeType.Document) { ISvgFitToViewBox fitToView = svgElm as ISvgFitToViewBox; if (fitToView != null) { ISvgAnimatedRect animRect = fitToView.ViewBox; if (animRect != null) { ISvgRect viewRect = animRect.AnimVal; if (viewRect != null) { Rect wpfViewRect = WpfConvert.ToRect(viewRect); if (!wpfViewRect.IsEmpty && wpfViewRect.Width > 0 && wpfViewRect.Height > 0) { elmRect = wpfViewRect; } } } } } Transform transform = null; if (parentNode.NodeType != XmlNodeType.Document) { FitToViewbox(context, elmRect); transform = this.Transform; if (transform != null) { _drawGroup.Transform = transform; } } //if (height > 0 && width > 0) //{ // ClipGeometry = new RectangleGeometry(elmRect); //} //Geometry clipGeom = this.ClipGeometry; //if (clipGeom != null) //{ // _drawGroup.ClipGeometry = clipGeom; //} if (((float)elmRect.Width != 0 && (float)elmRect.Height != 0)) { // Elements such as "pattern" are also rendered by this renderer, so we make sure we are // dealing with the root SVG element... if (parentNode != null && parentNode.NodeType == XmlNodeType.Document) { _drawGroup.ClipGeometry = new RectangleGeometry(elmRect); } else { if (transform != null) { // We have already applied the transform, which will translate to the start point... if (transform is TranslateTransform) { _drawGroup.ClipGeometry = new RectangleGeometry( new Rect(0, 0, elmRect.Width, elmRect.Height)); } else { _drawGroup.ClipGeometry = new RectangleGeometry(elmRect); } } else { _drawGroup.ClipGeometry = new RectangleGeometry(elmRect); } } //DrawingGroup animationGroup = context.Links; //if (animationGroup != null) //{ // animationGroup.ClipGeometry = clipGeom; //} } }