예제 #1
0
        private static void DrawHeaderAndFooterToPage(RadFixedPage page, int pageNumber, int numberOfPages)
        {
            FixedContentEditor pageEditor = new FixedContentEditor(page);

            Block       header      = new Block();
            ImageSource imageSource = ImportImage(InputLogoFile);
            Size        imageSize   = new Size(168, 50);

            header.InsertImage(imageSource, imageSize);
            header.Measure();

            double headerOffsetX = (page.Size.Width / 2) - (header.DesiredSize.Width / 2);
            double headerOffsetY = 50;

            pageEditor.Position.Translate(headerOffsetX, headerOffsetY);
            pageEditor.DrawBlock(header);

            Block footer = new Block();

            footer.InsertText(String.Format("Page {0} of {1}", pageNumber, numberOfPages));
            footer.Measure();

            double footerOffsetX = (page.Size.Width / 2) - (footer.DesiredSize.Width / 2);
            double fotterOffsetY = page.Size.Height - 50 - footer.DesiredSize.Height;

            pageEditor.Position.Translate(footerOffsetX, fotterOffsetY);
            pageEditor.DrawBlock(footer);
        }
        private void AddPageWithImage(string description, ImageSource imageSource)
        {
            RadFixedPage page = this.document.Pages.AddPage();

            page.Size = PageSize;
            FixedContentEditor editor = new FixedContentEditor(page);

            editor.GraphicProperties.StrokeThickness = 0;
            editor.GraphicProperties.IsStroked       = false;
            editor.GraphicProperties.FillColor       = new RgbColor(200, 200, 200);
            editor.DrawRectangle(new Rect(0, 0, PageSize.Width, PageSize.Height));
            editor.Position.Translate(Margins.Left, Margins.Top);

            Block block = new Block();

            block.HorizontalAlignment     = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            block.TextProperties.FontSize = 22;
            block.InsertText(description);
            Size blockSize = block.Measure(RemainingPageSize);

            editor.DrawBlock(block, RemainingPageSize);

            editor.Position.Translate(Margins.Left, blockSize.Height + Margins.Top + 20);

            Block imageBlock = new Block();

            imageBlock.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            imageBlock.InsertImage(imageSource);
            editor.DrawBlock(imageBlock, RemainingPageSize);
        }
예제 #3
0
 private void AddContentElement(ContentElementBase contentElement)
 {
     #region radpdfprocessing-model-radfixedpage_1
     RadFixedPage page = new RadFixedPage();
     page.Content.Add(contentElement);
     #endregion
 }
예제 #4
0
 private void CreateLinkToAction(Action action, RadFixedPage page)
 {
     #region radpdfprocessing-model-annotations-and-destinations_1
     Link linkWithAction = new Link(action);
     page.Annotations.Add(linkWithAction);
     #endregion
 }
예제 #5
0
        private void OnRowEditEndedExecuted(object obj)
        {
            GridViewRowEditEndedEventArgs e = obj as GridViewRowEditEndedEventArgs;

            BookmarkViewModel bookmarkViewModel = e.NewData as BookmarkViewModel;

            if (e.EditAction == GridViewEditAction.Cancel)
            {
                return;
            }
            else if (e.EditOperationType == GridViewEditOperationType.Insert)
            {
                RadFixedPage page = this.document.Pages[bookmarkViewModel.PageNumber - 1];
                bookmarkViewModel.UpdateBookmarkItem(page);

                this.document.Bookmarks.Add(bookmarkViewModel.BookmarkItem);
            }
            else if (e.EditOperationType == GridViewEditOperationType.Edit)
            {
                RadFixedPage page = this.document.Pages[bookmarkViewModel.PageNumber - 1];

                BookmarkViewModel viewModel = e.EditedItem as BookmarkViewModel;
                viewModel.UpdateBookmarkItem(page);
            }
        }
예제 #6
0
        internal void UpdateBookmarkItem(RadFixedPage page)
        {
            if (this.BookmarkItem == null)
            {
                this.BookmarkItem = new BookmarkItem(this.Title, new Location());
            }

            BookmarkItem currentBookmark = this.BookmarkItem;

            byte red   = Convert.ToByte(this.TextColorR);
            byte green = Convert.ToByte(this.TextColorG);
            byte blue  = Convert.ToByte(this.TextColorB);

            currentBookmark.TextColor  = new RgbColor(red, green, blue);
            currentBookmark.Title      = this.Title;
            currentBookmark.IsExpanded = this.IsExpanded;
            currentBookmark.TextStyle  = this.TextStyle;

            Location destination = (Location)currentBookmark.Destination;

            destination.Top  = this.Top;
            destination.Left = this.Left;
            destination.Zoom = this.Zoom;
            destination.Page = page;
        }
예제 #7
0
        private void CreatePageWithImage(RadFixedDocument document, string imageExtension, EncodedImageData imageData)
        {
            RadFixedPage page = document.Pages.AddPage();

            page.Size = PageSize;
            FixedContentEditor editor = new FixedContentEditor(page);

            editor.Position.Translate(Margins.Left, Margins.Top);

            Block block = new Block();

            block.HorizontalAlignment     = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            block.TextProperties.FontSize = 22;
            block.InsertText(string.Format("This is {0} image in {1} color space encoded with {2} filter.", imageExtension, imageData.ColorSpace, imageData.Filters.FirstOrDefault() ?? "None"));
            Size blockSize = block.Measure(RemainingPageSize);

            editor.DrawBlock(block, RemainingPageSize);

            editor.Position.Translate(Margins.Left, blockSize.Height + Margins.Top + 50);

            Block imageBlock = new Block();

            imageBlock.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            imageBlock.InsertImage(new ImageSource(imageData), new Size(imageData.Width, imageData.Height));
            editor.DrawBlock(imageBlock, RemainingPageSize);
        }
        public RadFixedDocument CreateDocument()
        {
            RadFixedDocument document = new RadFixedDocument();
            RadFixedPage     page     = document.Pages.AddPage();

            page.Size   = new Size(600, 800);
            this.editor = new FixedContentEditor(page);
            this.editor.Position.Translate(40, 50);

            using (Stream stream = this.resourceService.GetResourceStream("banner.jpg"))
            {
                this.editor.DrawImage(stream, new Size(530, 80));
            }

            this.editor.Position.Translate(ExampleDocumentSizes.DefaultLeftIndent, 160);
            double maxWidth = page.Size.Width - ExampleDocumentSizes.DefaultLeftIndent * 2;

            this.DrawDescription(maxWidth);

            using (this.editor.SaveProperties())
            {
                using (this.editor.SavePosition())
                {
                    this.DrawFunnelFigure();
                }
            }

            return(document);
        }
예제 #9
0
        private void SubmitChangesAndRemoveTextBox(object sender)
        {
            TextBox textBox = (TextBox)sender;

            textBox.LostFocus -= this.TextBox_LostFocus;
            textBox.KeyDown   -= this.TextBox_KeyDown;

            this.canvas.Children.Remove(textBox);

            string text = textBox.Text;

            RadFixedPage page = this.context.Page;

            FixedContentEditor editor = new FixedContentEditor(page);

            editor.Position.Translate(this.mouseLocation.X, this.mouseLocation.Y);
            editor.DrawText(text);

            RadPdfViewer viewer = this.context.Presenter.Owner as RadPdfViewer;

            if (viewer != null)
            {
                viewer.InvalidatePageUI(page);
            }

            this.hasActiveTextBox = false;
        }
예제 #10
0
 private void AddAnnotation(Annotation annotation)
 {
     #region radpdfprocessing-model-radfixedpage_2
     RadFixedPage page = new RadFixedPage();
     page.Annotations.Add(annotation);
     #endregion
 }
예제 #11
0
 private void CreateAndAddPagesToFixedDocument(RadFixedDocument document)
 {
     #region radpdfprocessing-model-radfixeddocument_2
     RadFixedPage page = new RadFixedPage();
     document.Pages.Add(page);
     #endregion
 }
예제 #12
0
        private void AddPageWithImage()
        {
            RadFixedPage page = this.document.Pages.AddPage();

            page.Size = PageSize;
            FixedContentEditor editor = new FixedContentEditor(page);

            editor.GraphicProperties.StrokeThickness = 0;
            editor.GraphicProperties.IsStroked       = false;
            editor.GraphicProperties.FillColor       = new RgbColor(200, 200, 200);
            editor.DrawRectangle(new Rect(0, 0, PageSize.Width, PageSize.Height));
            Margins margins = new Margins();

            editor.Position.Translate(margins.Left, margins.Top);

            Block block = new Block();

            block.HorizontalAlignment     = HorizontalAlignment.Center;
            block.TextProperties.FontSize = 22;
            block.InsertText("Image converted from PNG to JPG");
            block.InsertLineBreak();
            block.InsertText(string.Format("when ImageQuality set to {0}", this.imageQuality));
            Size blockSize = block.Measure(RemainingPageSize);

            editor.DrawBlock(block, RemainingPageSize);

            editor.Position.Translate(margins.Left, blockSize.Height + margins.Top + 20);

            Block imageBlock = new Block();

            imageBlock.HorizontalAlignment = HorizontalAlignment.Center;
            imageBlock.InsertImage(this.imageSource);
            editor.DrawBlock(imageBlock, RemainingPageSize);
        }
예제 #13
0
 private void CreateRadFixedPage()
 {
     #region radpdfprocessing-model-radfixedpage_0
     RadFixedDocument document = new RadFixedDocument();
     RadFixedPage     page     = new RadFixedPage();
     document.Pages.Add(page);
     #endregion
 }
예제 #14
0
 private void ModifyProperties()
 {
     #region radpdfprocessing-model-radfixedpage_3
     RadFixedPage page = new RadFixedPage();
     page.Rotation = Rotation.Rotate270;
     page.Size     = new Size(792, 1128);
     #endregion
 }
예제 #15
0
 public SinglePageInfo(double topOffsetInPresenter, double bottomPositionInView, bool intersectsHorizontally, bool intersectsVertically, RadFixedPage page, Rect positionInView, GeneralTransform transformations)
     : base(page, positionInView, transformations)
 {
     this.topOffsetInPresenter = topOffsetInPresenter;
     this.bottomPositionInView = bottomPositionInView;
     this.intersectsWithViewportVertically = intersectsVertically;
     this.intersectsWithViewportHorizontally = intersectsHorizontally;
 }
예제 #16
0
        private RadFixedPage CreatePage(System.Windows.Controls.Border element)
        {
            RadFixedPage page = new RadFixedPage();
            page.Size = new Size(1000, 1000);
            FixedContentEditor editor = new FixedContentEditor(page, Telerik.Windows.Documents.Fixed.Model.Data.MatrixPosition.Default);

            ExportHelper.ExportToPdf(element, editor);

            return page;
        }
예제 #17
0
        private RadFixedDocument CreateDocument(RadPivotGrid element)
        {
            RadFixedDocument document = new RadFixedDocument();

            RadFixedPage page = this.CreatePage(element);

            document.Pages.Add(page);

            return(document);
        }
예제 #18
0
        public static RadFixedDocument CreateDocument(FrameworkElement element)
        {
            RadFixedDocument document = new RadFixedDocument();

            RadFixedPage page = CreatePage(element);

            document.Pages.Add(page);

            return(document);
        }
예제 #19
0
        static void Main()
        {
            RadFixedDocument document = Program.ImportDocument("BlueTemplate.pdf");
            RadFixedPage     page     = document.Pages.First();

            Program.DeleteTextFragment(page, "This is the blue template!");
            Program.AddWatermarkText(page, "Watermark text!", 100);

            Program.ExportAndViewPdf(document, "testWatermarks.pdf");
        }
        private RadFixedDocument CreateDocument(System.Windows.Controls.Border element)
        {
            RadFixedDocument document = new RadFixedDocument();

            RadFixedPage page = this.CreatePage(element);

            document.Pages.Add(page);

            return(document);
        }
예제 #21
0
        public static void DrawHeaderAndFooterToDocument()
        {
            int numberOfPages = document.Pages.Count;

            for (int pageIndex = 0; pageIndex < numberOfPages; pageIndex++)
            {
                int          pageNumber  = pageIndex + 1;
                RadFixedPage currentPage = document.Pages[pageIndex];
                DrawHeaderAndFooterToPage(currentPage, pageNumber, numberOfPages);
            }
        }
        private RadFixedPage CreatePage(System.Windows.Controls.Border element)
        {
            RadFixedPage page = new RadFixedPage();

            page.Size = new Size(1000, 1000);
            FixedContentEditor editor = new FixedContentEditor(page, Telerik.Windows.Documents.Fixed.Model.Data.MatrixPosition.Default);

            ExportHelper.ExportToPdf(element, editor);

            return(page);
        }
예제 #23
0
 public EditorInfo(RadFixedPage page, IPosition position, RadDiagramItem element, Rect bounds, Brush stroke, double angle)
 {
     this.Page = page;
     this.Position = position;
     this.Background = element.Background;
     this.StrokeThickness = element.StrokeThickness;
     this.StrokeDashArray = element.StrokeDashArray;
     this.Opacity = element.Opacity;
     this.Stroke = stroke;
     this.Bounds = bounds;
     this.Angle = angle;
 }
예제 #24
0
 public EditorInfo(RadFixedPage page, IPosition position, RadDiagramItem element, Rect bounds, Brush stroke, double angle)
 {
     this.Page            = page;
     this.Position        = position;
     this.Background      = element.Background;
     this.StrokeThickness = element.StrokeThickness;
     this.StrokeDashArray = element.StrokeDashArray;
     this.Opacity         = element.Opacity;
     this.Stroke          = stroke;
     this.Bounds          = bounds;
     this.Angle           = angle;
 }
예제 #25
0
        private void CreateLinearGradient(RadFixedPage container)
        {
            #region radpdfprocessing-concepts-colors-and-color-spaces_1
            FixedContentEditor containerEditor = new FixedContentEditor(container);

            LinearGradient linearGradient = new LinearGradient(new Point(0, 0), new Point(30, 30));
            linearGradient.GradientStops.Add(new GradientStop(new RgbColor(0, 207, 0), 0));
            linearGradient.GradientStops.Add(new GradientStop(new RgbColor(0, 102, 204), 0));

            containerEditor.GraphicProperties.FillColor = linearGradient;
            containerEditor.DrawRectangle(new Rect(10, 10, 48, 29));
            #endregion
        }
예제 #26
0
        private void CreateLocation(RadFixedPage secondPage, RadFixedPage firstPage)
        {
            #region radpdfprocessing-model-annotations-and-destinations_2
            Location location = new Location();
            location.Left = 225;
            location.Top  = 500;
            location.Zoom = 4;
            location.Page = secondPage;

            var link = firstPage.Annotations.AddLink(location);
            link.Rect = new Rect(10, 10, 50, 50);
            #endregion
        }
예제 #27
0
        private static RadFixedPage GenerateBackgroundImageContent(string watermarkImage)
        {
            using (Stream imageStream = File.OpenRead(watermarkImage))
            {
                ImageSource  image = new ImageSource(imageStream);
                RadFixedPage backgroundContentOwner = new RadFixedPage();
                backgroundContentOwner.Size = new Size(image.Width, image.Height);
                FixedContentEditor imagePageEditor = new FixedContentEditor(backgroundContentOwner);
                imagePageEditor.DrawImage(image);

                return(backgroundContentOwner);
            }
        }
예제 #28
0
        public bool GetLocationFromViewPoint(Point viewPoint, Size viewport, out RadFixedPage page, out Point location)
        {
            location = new Point();
            page     = null;
            if (this.ContentSize.Width == 0 || this.ContentSize.Height == 0 || this.pageLayoutInfos == null || this.pageLayoutInfos.Count == 0)
            {
                return(false);
            }

            SinglePageInfo pageInfo = this.visiblePage;

            if (pageInfo == null || !pageInfo.FixedPage.HasContent)
            {
                return(false);
            }

            page = pageInfo.FixedPage;

            double verticalScrollOffset = this.Presenter.Owner.VerticalScrollOffset;

            if (pageInfo.IntersectsWithViewportVertically)
            {
                if (verticalScrollOffset < pageInfo.PositionInView.Y)
                {
                    viewPoint.Y += pageInfo.PositionInView.Y - verticalScrollOffset;
                }
                else if (verticalScrollOffset + viewport.Height > pageInfo.BottomPositionInView)
                {
                    viewPoint.Y -= verticalScrollOffset + viewport.Height - pageInfo.BottomPositionInView;
                }
            }
            else
            {
                if (verticalScrollOffset + pageInfo.VerticalOffset > pageInfo.PositionInView.Y)
                {
                    viewPoint.Y -= verticalScrollOffset + pageInfo.VerticalOffset - pageInfo.PositionInView.Y;
                }
                else if (verticalScrollOffset + pageInfo.VerticalOffset < pageInfo.PositionInView.Y)
                {
                    viewPoint.Y += pageInfo.PositionInView.Y - (verticalScrollOffset + pageInfo.VerticalOffset);
                }
            }

            location = new Point(viewPoint.X - pageInfo.PositionInView.X, viewPoint.Y - pageInfo.PositionInView.Y);
            if (pageInfo.InverseTransformations != null)
            {
                location = pageInfo.InverseTransformations.Transform(location);
            }

            return(true);
        }
예제 #29
0
        public static RadFixedPage CreatePage(FrameworkElement element)
        {
            //RadFixedPage page = new RadFixedPage { Size = new Size(1000, 1000) };

            RadFixedPage page = new RadFixedPage()
            {
                Size = new Size(element.ActualWidth, element.ActualHeight)
            };
            FixedContentEditor editor = new FixedContentEditor(page, MatrixPosition.Default);

            ExportHelper.ExportToPdf(element, editor);

            return(page);
        }
예제 #30
0
        private static void DeleteTextFragment(RadFixedPage page, string text)
        {
            ContentElementBase fragment = page.Content.FirstOrDefault((element) =>
            {
                TextFragment textElement = element as TextFragment;

                return(textElement != null && textElement.Text == text);
            });

            if (fragment != null)
            {
                page.Content.Remove(fragment);
            }
        }
        public bool GetLocationFromViewPoint(Point viewPoint, Size viewport, out RadFixedPage page, out Point location)
        {
            location = new Point();
            page = null;
            if (this.ContentSize.Width == 0 || this.ContentSize.Height == 0 || this.pageLayoutInfos == null || this.pageLayoutInfos.Count == 0)
            {
                return false;
            }

            SinglePageInfo pageInfo = this.visiblePage;
            if (pageInfo == null || !pageInfo.FixedPage.HasContent == null)
            {
                return false;
            }

            page = pageInfo.FixedPage;

            double verticalScrollOffset = this.Presenter.Owner.VerticalScrollOffset;

            if (pageInfo.IntersectsWithViewportVertically)
            {
                if (verticalScrollOffset < pageInfo.PositionInView.Y)
                {
                    viewPoint.Y += pageInfo.PositionInView.Y - verticalScrollOffset;
                }
                else if (verticalScrollOffset + viewport.Height > pageInfo.BottomPositionInView)
                {
                    viewPoint.Y -= verticalScrollOffset + viewport.Height - pageInfo.BottomPositionInView;
                }
            }
            else
            {
                if (verticalScrollOffset + pageInfo.VerticalOffset > pageInfo.PositionInView.Y)
                {
                    viewPoint.Y -= verticalScrollOffset + pageInfo.VerticalOffset - pageInfo.PositionInView.Y;
                }
                else if (verticalScrollOffset + pageInfo.VerticalOffset < pageInfo.PositionInView.Y)
                {
                    viewPoint.Y += pageInfo.PositionInView.Y - (verticalScrollOffset + pageInfo.VerticalOffset);
                }
            }

            location = new Point(viewPoint.X - pageInfo.PositionInView.X, viewPoint.Y - pageInfo.PositionInView.Y);
            if (pageInfo.InverseTransformations != null)
            {
                location = pageInfo.InverseTransformations.Transform(location);
            }

            return true;
        }
예제 #32
0
        private void UsingFixedContentEditor()
        {
            #region radpdfprocessing-editing-table_9
            Table table = GenerateSampleTable();

            RadFixedDocument   document = new RadFixedDocument();
            RadFixedPage       page     = document.Pages.AddPage();
            FixedContentEditor editor   = new FixedContentEditor(page, new SimplePosition());

            editor.Position.Translate(10, 100);
            editor.Position.Rotate(-45);
            editor.DrawTable(table);
            #endregion
        }
예제 #33
0
        private static void ExportShape(RadDiagramShape 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 pathGeometry   = shape.Geometry as PathGeometry;
            var transformGroup = new TransformGroup();

#if WPF
            if (pathGeometry == null)
            {
                var streamGeometry = shape.Geometry as StreamGeometry;
                if (streamGeometry != null)
                {
                    pathGeometry = streamGeometry.AsPathGeometry();
                }
            }
#endif

            var geometrySize = shape.Geometry.Bounds.ToSize();
            if (IsValidSize(geometrySize) && (geometrySize.Width != bounds.Width || geometrySize.Width != bounds.Width))
            {
                transformGroup.Children.Add(new ScaleTransform()
                {
                    ScaleX = bounds.Width / geometrySize.Width, ScaleY = bounds.Height / geometrySize.Height
                });
            }
            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);

            EditorInfo         info         = new EditorInfo(page, position, shape, bounds, shape.BorderBrush, shape.RotationAngle);
            FixedContentEditor editor       = CreateEditor(info, false);
            FixedContentEditor filledEditor = CreateEditor(info, true);

            ExportGeometry(editor, filledEditor, pathGeometry);

            if (shape.Content != null)
            {
                var center = bounds.Center();
                ExportContent(shape, bounds, shape.RotationAngle, page, (s) => { return(new Point(center.X - s.Width / 2, center.Y - s.Height / 2)); });
            }
        }
예제 #34
0
        private void CreateTiling(RadFixedPage container)
        {
            #region radpdfprocessing-concepts-colors-and-color-spaces_2
            FixedContentEditor containerEditor = new FixedContentEditor(container);

            Tiling             tiling       = new Tiling(new Rect(0, 0, 10, 10));
            FixedContentEditor tilingEditor = new FixedContentEditor(tiling);
            tilingEditor.GraphicProperties.IsStroked = false;
            tilingEditor.GraphicProperties.FillColor = new RgbColor(128, 28, 43);
            tilingEditor.DrawRectangle(new Rect(2, 2, 5, 7));

            containerEditor.GraphicProperties.FillColor = tiling;
            containerEditor.DrawCircle(new Point(30, 30), 20);
            #endregion
        }
예제 #35
0
        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); });
            }
        }
예제 #36
0
        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;
        }
예제 #37
0
        private static void ExportConnection(RadDiagramConnection connection, Rect enclosingBounds, RadFixedPage page)
        {
            var bounds = new Rect(connection.Bounds.X - enclosingBounds.X, connection.Bounds.Y - enclosingBounds.Y, connection.Bounds.Width, connection.Bounds.Height);

            var pathGeometry = connection.Geometry as PathGeometry;
            var pathBounds = connection.ConnectionType == ConnectionType.Bezier ? pathGeometry.Bounds : new Rect();

            var transformGroup = new TransformGroup();
            transformGroup.Children.Add(new TranslateTransform() { X = bounds.X - pathBounds.X, Y = bounds.Y - pathBounds.Y });
            var position = new MatrixPosition(transformGroup.Value);

            EditorInfo info = new EditorInfo(page, position, connection, bounds, connection.Stroke, 0);
            FixedContentEditor editor = CreateEditor(info, false);
            FixedContentEditor filledEditor = CreateEditor(info, true);

            ExportGeometry(editor, filledEditor, pathGeometry, true);

            if (connection.Content != null)
            {
                var center = bounds.Center();
                ExportContent(connection, bounds, 0, page, (s) => { return new Point(bounds.Center().X - s.Width / 2, center.Y - s.Height / 2); });
            }
        }
 public override bool GetLocationFromViewPoint(Point positionInView, out RadFixedPage page, out Point location)
 {
     return this.pagesLayoutManager.GetLocationFromViewPoint(positionInView, this.ViewportSize, out page, out location);
 }  
예제 #39
0
        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); });
            }
        }
예제 #40
0
        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);
        }
예제 #41
0
        private static void ExportShape(RadDiagramShape 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 pathGeometry = shape.Geometry as PathGeometry;
            var transformGroup = new TransformGroup();
#if WPF
            if (pathGeometry == null)
            {
                var streamGeometry = shape.Geometry as StreamGeometry;
                if (streamGeometry != null)
                    pathGeometry = streamGeometry.AsPathGeometry();
            }
#endif

            var geometrySize = shape.Geometry.Bounds.ToSize();
            if (IsValidSize(geometrySize) && (geometrySize.Width != bounds.Width || geometrySize.Width != bounds.Width))
                transformGroup.Children.Add(new ScaleTransform() { ScaleX = bounds.Width / geometrySize.Width, ScaleY = bounds.Height / geometrySize.Height });
            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);

            EditorInfo info = new EditorInfo(page, position, shape, bounds, shape.BorderBrush, shape.RotationAngle);
            FixedContentEditor editor = CreateEditor(info, false);
            FixedContentEditor filledEditor = CreateEditor(info, true);

            ExportGeometry(editor, filledEditor, pathGeometry);

            if (shape.Content != null)
            {
                var center = bounds.Center();
                ExportContent(shape, bounds, shape.RotationAngle, page, (s) => { return new Point(center.X - s.Width / 2, center.Y - s.Height / 2); });
            }
        }