private static void ExportTextShape(RadDiagramTextShape shape, Rect enclosingBounds, RadFixedPage page) { var bounds = new Rect(shape.Bounds.X - enclosingBounds.X, shape.Bounds.Y - enclosingBounds.Y, shape.Bounds.Width, shape.Bounds.Height); var transformGroup = new TransformGroup(); transformGroup.Children.Add(new RotateTransform() { Angle = shape.RotationAngle, CenterX = bounds.Width / 2, CenterY = bounds.Height / 2 }); transformGroup.Children.Add(new TranslateTransform() { X = bounds.X, Y = bounds.Y }); var position = new MatrixPosition(transformGroup.Value); FixedContentEditor containerEditor = CreateEditor(new EditorInfo(page, position, shape, bounds, shape.BorderBrush, shape.RotationAngle), true); containerEditor.DrawRectangle(new Rect(new Point(), bounds.ToSize())); if (shape.Content != null) { var center = bounds.Center(); ExportContent(shape, bounds, shape.RotationAngle, page, (s) => { return new Point(bounds.Center().X - s.Width / 2, center.Y - s.Height / 2); }); } }
public static RadFixedPage ExportDiagram(RadDiagram diagram, Rect pageSize) { RadFixedPage page = new RadFixedPage(); page.Size = pageSize.ToSize(); var orderedContainers = diagram.Items.Select(i => diagram.ContainerGenerator.ContainerFromItem(i)).OrderBy(c => c.ZIndex); foreach (var container in orderedContainers) { if (container.Visibility != Visibility.Visible) continue; var shape = container as RadDiagramShape; if (shape != null) { ExportShape(shape, pageSize, page); continue; } var textShape = container as RadDiagramTextShape; if (textShape != null) { ExportTextShape(textShape, pageSize, page); continue; } var containerShape = container as RadDiagramContainerShape; if (containerShape != null) { ExportContainerShape(containerShape, pageSize, page); continue; } var connection = container as RadDiagramConnection; if (connection != null) { ExportConnection(connection, pageSize, page); continue; } } return page; }
private static void ExportContent(ContentControl control, Rect bounds, double angle, RadFixedPage page, Func<Size, Point> positionFunc, string contentString = null) { string text = contentString ?? control.Content.ToString(); if (string.IsNullOrWhiteSpace(text)) return; FixedContentEditor textEditor = new FixedContentEditor(page); var block = new Block(); // Set the text and graphic properties. block.TextProperties.FontSize = control.FontSize; block.TextProperties.RenderingMode = RenderingMode.Fill; block.TextProperties.TrySetFont(control.FontFamily, control.FontStyle, control.FontWeight); block.GraphicProperties.FillColor = ColorHelper.GetColor(control.Foreground, control.Opacity, bounds); block.GraphicProperties.StrokeColor = block.GraphicProperties.FillColor; // Measure the text. block.InsertText(text); var boundsSize = bounds.ToSize(); var availableSize = new Size(boundsSize.Width - control.Padding.Left - control.Padding.Right, boundsSize.Width - control.Padding.Top - control.Padding.Bottom); var textSize = block.Measure(availableSize); var position = positionFunc(textSize); var textGroup = new TransformGroup(); textGroup.Children.Add(new RotateTransform() { Angle = angle, CenterX = textSize.Width / 2, CenterY = textSize.Height / 2 }); textGroup.Children.Add(new TranslateTransform() { X = position.X, Y = position.Y }); textEditor.Position = new MatrixPosition(textGroup.Value); textEditor.DrawBlock(block, availableSize); }
private static void ExportContainerShape(RadDiagramContainerShape container, Rect enclosingBounds, RadFixedPage page) { var bounds = new Rect(container.Bounds.X - enclosingBounds.X, container.Bounds.Y - enclosingBounds.Y, container.Bounds.Width, container.Bounds.Height); var transformGroup = new TransformGroup(); transformGroup.Children.Add(new RotateTransform() { Angle = container.RotationAngle, CenterX = bounds.Width / 2, CenterY = bounds.Height / 2 }); transformGroup.Children.Add(new TranslateTransform() { X = bounds.X, Y = bounds.Y }); var position = new MatrixPosition(transformGroup.Value); FixedContentEditor containerEditor = CreateEditor(new EditorInfo(page, position, container, bounds, container.BorderBrush, container.RotationAngle), true); containerEditor.DrawRectangle(new Rect(new Point(), bounds.ToSize())); containerEditor.GraphicProperties.StrokeThickness = 0.5; var headerHeight = container.ContentBounds.Y - container.Bounds.Y - DiagramConstants.ContainerMargin; containerEditor.DrawRectangle(new Rect(new Point(0, headerHeight), new Size(bounds.Width, 0.5))); if (container.IsCollapsible) { var buttonTop = headerHeight / 2 - 2.5; var buttonLeft = bounds.Width - 20; if (container.IsCollapsed) { containerEditor.DrawLine(new Point(buttonLeft, buttonTop), new Point(buttonLeft + 4, buttonTop + 4)); containerEditor.DrawLine(new Point(buttonLeft + 4, buttonTop + 4), new Point(buttonLeft + 8, buttonTop)); if (container.CollapsedContent != null) { var contentHeight = container.ActualHeight - headerHeight; ExportContent(container, bounds, container.RotationAngle, page, (s) => { return new Point(bounds.Center().X - s.Width / 2, bounds.Bottom - contentHeight / 2 - s.Height / 2); }, container.CollapsedContent.ToString()); } } else { containerEditor.DrawLine(new Point(buttonLeft, buttonTop + 4), new Point(buttonLeft + 4, buttonTop)); containerEditor.DrawLine(new Point(buttonLeft + 4, buttonTop), new Point(buttonLeft + 8, buttonTop + 4)); } } if (container.Content != null) { ExportContent(container, bounds, container.RotationAngle, page, (s) => { return new Point(bounds.Center().X - s.Width / 2, bounds.Top + headerHeight / 2 - s.Height / 2); }); } }
protected override Size MeasureOverride(Size availableSize) { if (Children == null || Children.Count < 1) { return new Size (0, 0); } var resultingRect = new Rect (); object accumulatedState = null; try { var count = Children.Count; for (var iter = 0; iter < count; ++iter) { var child = Children[iter]; child.Measure (availableSize); var desiredSize = child.DesiredSize; var args = new LayoutItemEventArgs { LayoutItemState = LayoutItemState.IsMeasuring, UiElement = child, AccumulateState = accumulatedState, State = GetUIElementState (child), AvailableSize = availableSize, DesiredSize = desiredSize, Count = count, Index = iter, Transform = child.RenderTransform, }; OnItemLayout (args); accumulatedState = args.AccumulateState; var childRect = (args.Transform ?? s_identityTransform).TransformBounds (new Rect (0, 0, desiredSize.Width, desiredSize.Height)); resultingRect.Union (childRect); } return availableSize.Merge (resultingRect.ToSize ()); } finally { Common.Dispose (accumulatedState); } }
internal WriteableBitmap CreateImage(Rect bounds) { return BitmapUtils.CreateWriteableBitmap(this.itemHost as UIElement, bounds, bounds.ToSize(), null, new Thickness()); }