예제 #1
0
        void _rasterImageList_PostRender(object sender, Leadtools.Controls.ImageViewerRenderEventArgs e)
        {
            for (int i = 0; i < _rasterImageList.Items.Count; i++)
            {
                ImageViewerItem item = _rasterImageList.Items[i];

                LeadRectD itemLeadRect  = _rasterImageList.GetItemBounds(item, ImageViewerItemPart.Item);
                Rectangle itemRect      = new Rectangle((int)itemLeadRect.X, (int)itemLeadRect.Y, (int)itemLeadRect.Width, (int)itemLeadRect.Height);
                LeadSize  itemImageSize = _rasterImageList.GetItemImageSize(item, false);

                LeadRect imageRect = new LeadRect(
                    itemRect.Left + (itemRect.Width - itemImageSize.Width) / 2,
                    itemRect.Top + (itemRect.Height - itemImageSize.Height) / 2,
                    itemImageSize.Width,
                    itemImageSize.Height);

                itemLeadRect = ImageViewer.GetDestinationRectangle(item.Image.ImageWidth, item.Image.ImageHeight, imageRect, ControlSizeMode.None, ControlAlignment.Near, ControlAlignment.Near).ToLeadRectD();

                var destRect = LeadRectD.Create(itemLeadRect.X, itemLeadRect.Y, itemLeadRect.Width * 720.0 / 96.0, itemLeadRect.Height * 720.0 / 96.0);

                destRect.X = 0.0;
                destRect.Y = 0.0;

                //Get the graphic object from the item's image to draw (burn) annotations on it.
                Leadtools.Drawing.RasterImageGdiPlusGraphicsContainer GdiPlusGraphicsContainer = new RasterImageGdiPlusGraphicsContainer(item.Image);
                Graphics g = GdiPlusGraphicsContainer.Graphics;

                // Use anti-aliasing
                g.SmoothingMode = SmoothingMode.AntiAlias;

                // Now draw the annotation s on this rectangle
                if (_automationManager != null && _automation.Containers.Count > 0 && _automation.Containers.Count > i)
                {
                    AnnContainer container = _automation.Containers[i];

                    //Clear the old painting
                    g.Clear(Color.White);

                    //Burn the current annotations to the image list item
                    if (container != null)
                    {
                        AnnWinFormsRenderingEngine engine = new AnnWinFormsRenderingEngine();
                        engine.Resources = _automationManager.Resources;

                        // Save its visible state and set it to true (it is false if viewer is in single mode)
                        bool containerIsVisible = container.IsVisible;
                        container.IsVisible = true;

                        engine.Attach(container, g);
                        engine.BurnToRectWithDpi(destRect, 96, 96, 96, 96);
                        engine.Detach();

                        if (container.IsVisible != containerIsVisible)
                        {
                            container.IsVisible = containerIsVisible;
                        }
                    }
                }
            }
        }
예제 #2
0
        private LeadRectD BoundsToAnnotations(AnnObject annObject, RectangleF rect)
        {
            // Convert a rectangle from logical (top-left) to annotation object coordinates
            LeadRectD rc = LeadRectD.Create(rect.Left + System.Convert.ToDouble(rect.Width < 0) * rect.Width, rect.Top + System.Convert.ToDouble(rect.Height < 0) * rect.Height, Math.Abs(rect.Width), Math.Abs(rect.Height));

            rc = _filledFormViewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, rc);
            rc = automation.Container.Mapper.RectToContainerCoordinates(rc);
            return(rc);
        }
        protected override LeadRectD GetBoundingRectangle()
        {
            LeadRectD rc = base.GetBoundingRectangle();

            double radius = _intersectionPointRadius.Value;

            if (!(double.IsInfinity(radius) || (double.IsInfinity(radius))))
            {
                if (!_intersectionPoint.IsEmpty && _intersectionInsideContainer)
                {
                    LeadRectD intersectionBounds = LeadRectD.Create(_intersectionPoint.X - radius, _intersectionPoint.Y - radius, radius * 2, radius * 2);
                    rc = LeadRectD.UnionRects(rc, intersectionBounds);
                }
            }

            return(rc);
        }
        private void RenderContainer(PaintEventArgs e, AnnWinFormsRenderingEngine engine, AnnContainer container)
        {
            // Attach to the current container and graphics.
            Graphics  graphics      = e.Graphics;
            Rectangle clipRectangle = e.ClipRectangle;

            try
            {
                engine.Attach(container, graphics);

                // Render the annotatirons
                LeadRectD rc = LeadRectD.Create(clipRectangle.X, clipRectangle.Y, clipRectangle.Width, clipRectangle.Height);
                rc = container.Mapper.RectToContainerCoordinates(rc);
                engine.Render(rc, true);
            }
            finally
            {
                engine.Detach();
            }
        }
예제 #5
0
        private static void RenderContainer(PaintEventArgs e, AnnWinFormsRenderingEngine engine, AnnContainer container, bool runMode)
        {
            // Attach to the current container and graphics.
            var context       = e.Graphics;
            var clipRectangle = e.ClipRectangle;

            engine.Attach(container, context);

            try
            {
                // Render the annotatirons
                var rc = LeadRectD.Create(clipRectangle.X, clipRectangle.Y, clipRectangle.Width, clipRectangle.Height);
                rc = container.Mapper.RectToContainerCoordinates(rc);
                engine.Render(rc, runMode);
            }
            finally
            {
                engine.Detach();
            }
        }
예제 #6
0
        private static void RenderContainer(ImageViewerRenderEventArgs e, AnnRenderingEngine renderingEngine, AnnContainer container, bool runMode)
        {
            // Attach to the current container and graphics
            var context       = e.PaintEventArgs.Graphics;
            var clipRectangle = e.PaintEventArgs.ClipRectangle;

            // Render the annotations
            renderingEngine.Attach(container, (Graphics)context);

            try
            {
                // Convert the clip rectangle to annotation coordinates
                var annClipRect = LeadRectD.Create(clipRectangle.X, clipRectangle.Y, clipRectangle.Width, clipRectangle.Height);
                annClipRect = container.Mapper.RectToContainerCoordinates(annClipRect);

                renderingEngine.Render(annClipRect, runMode);
            }
            finally
            {
                renderingEngine.Detach();
            }
        }
예제 #7
0
        private void _imageViewer_PostRender(object sender, ImageViewerRenderEventArgs e)
        {
            // Do we have a rendering engine?
            var renderingEngine = this.RenderingEngine as Leadtools.Annotations.Rendering.AnnWinFormsRenderingEngine;

            if (renderingEngine == null)
            {
                return;
            }

            bool runMode = false;

            if (_automationObject != null && _automationObject.Manager != null)
            {
                runMode = (_automationObject.Manager.UserMode == AnnUserMode.Run);
            }

            var context = e.PaintEventArgs.Graphics;

            var saveSmoothingMode = context.SmoothingMode;

            try
            {
                // Set the anti alias mode
                if (this.AutomationAntiAlias)
                {
                    if (context.SmoothingMode != SmoothingMode.AntiAlias)
                    {
                        context.SmoothingMode = SmoothingMode.AntiAlias;
                    }
                }
                else
                {
                    if (context.SmoothingMode != SmoothingMode.Default)
                    {
                        context.SmoothingMode = SmoothingMode.Default;
                    }
                }

                // Do we have multiple containers?
                if (_getContainersCallback != null)
                {
                    // Yes, get the container for this item
                    var containers = _getContainersCallback();
                    var clipRect   = LeadRectD.Create(
                        e.PaintEventArgs.ClipRectangle.X,
                        e.PaintEventArgs.ClipRectangle.Y,
                        e.PaintEventArgs.ClipRectangle.Width,
                        e.PaintEventArgs.ClipRectangle.Height);

                    if (containers != null)
                    {
                        switch (this.MultiContainerMode)
                        {
                        case AutomationControlMultiContainerMode.MultiPage:
                            // Each container belong to an item
                            for (var index = 0; index < containers.Count; index++)
                            {
                                if (index < _imageViewer.Items.Count)
                                {
                                    var itemBounds = _imageViewer.GetItemBounds(_imageViewer.Items[index], ImageViewerItemPart.Item);
                                    if (!itemBounds.IsEmpty)
                                    {
                                        var container       = containers[index];
                                        var item            = _imageViewer.Items[index];
                                        var containerBounds = _automationObject.GetContainerInvalidRect(container, true);
                                        var intersects      = !containerBounds.IsEmpty && containerBounds.IntersectsWith(clipRect);

                                        if (intersects || !_imageViewer.GetItemViewBounds(item, ImageViewerItemPart.Item, true).IsEmpty)
                                        {
                                            RenderContainer(e, renderingEngine, container, runMode);
                                        }
                                    }
                                }
                            }
                            break;

                        case AutomationControlMultiContainerMode.SinglePage:
                        default:
                            // All containers belong to the active item
                            ImageViewerItem activeItem = _imageViewer.ActiveItem;

                            if (activeItem != null &&
                                !_imageViewer.GetItemViewBounds(activeItem, ImageViewerItemPart.Item, true).IsEmpty)
                            {
                                for (var index = 0; index < containers.Count; index++)
                                {
                                    var itemBounds = _imageViewer.GetItemBounds(activeItem, ImageViewerItemPart.Item);
                                    if (!itemBounds.IsEmpty)
                                    {
                                        var container       = containers[index];
                                        var containerBounds = _automationObject.GetContainerInvalidRect(container, true);
                                        var intersects      = !containerBounds.IsEmpty && containerBounds.IntersectsWith(clipRect);

                                        if (intersects)
                                        {
                                            RenderContainer(e, renderingEngine, container, runMode);
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
                else
                {
                    // Using single-containers, just render the one the user set
                    var container = this._container;
                    if (container != null)
                    {
                        RenderContainer(e, renderingEngine, container, runMode);
                    }
                }
            }
            finally
            {
                if (context.SmoothingMode != saveSmoothingMode)
                {
                    context.SmoothingMode = saveSmoothingMode;
                }
            }
        }
예제 #8
0
        private void DrawImage(PaintEventArgs e, Rectangle clipRect)
        {
            if (_documents.Count == 0)
            {
                return;
            }

            if (_documents[_currentPageIndex].Document == null || !this.CanUpdate)
            {
                return;
            }

            var graphics = e.Graphics;

            var options = new SvgRenderOptions();

            options.Transform          = _transform;
            options.Bounds             = _documents[_currentPageIndex].Document.Bounds.Bounds;
            options.UseBackgroundColor = true;
            options.ClipBounds         = LeadRectD.Create(clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height);
            options.BackgroundColor    = RasterColor.FromKnownColor(RasterKnownColor.White);

            try
            {
                using (var engine = RenderingEngineFactory.Create(graphics))
                    _documents[_currentPageIndex].Document.Render(engine, options);
            }
            catch
            {
                Console.WriteLine();
            }

            DrawBounds(graphics, Pens.Black, null, null, null, null, options.Bounds, options.Transform);

            if (_documents[_currentPageIndex].DocumentText != null && _documents[_currentPageIndex].ShowText)
            {
                LeadRectD docBounds = _documents[_currentPageIndex].Document.Bounds.Bounds;

                // Could be rotated, so
                LeadPointD topLeft     = docBounds.TopLeft;
                LeadPointD bottomRight = docBounds.BottomRight;

                LeadPointD[] corners = new LeadPointD[4];
                corners[0].X = topLeft.X;
                corners[0].Y = topLeft.Y;
                corners[1].X = bottomRight.X;
                corners[1].Y = topLeft.Y;
                corners[2].X = bottomRight.X;
                corners[2].Y = bottomRight.Y;
                corners[3].X = topLeft.X;
                corners[3].Y = bottomRight.Y;

                options.Transform.TransformPoints(corners);

                GraphicsPath path = new GraphicsPath();
                PointF[]     pts  = new PointF[4];
                for (int i = 0; i < corners.Length; i++)
                {
                    pts[i].X = (float)corners[i].X;
                    pts[i].Y = (float)corners[i].Y;
                }
                path.AddPolygon(pts);
                graphics.SetClip(path, System.Drawing.Drawing2D.CombineMode.Intersect);

                using (var brush = new SolidBrush(Color.FromArgb(64, Color.Black)))
                {
                    foreach (var character in _documents[_currentPageIndex].DocumentText.Characters)
                    {
                        var bounds = character.Bounds;
                        var text   = new string(new char[] { character.Code });

                        DrawBounds(graphics, Pens.Yellow, brush, Brushes.Yellow, Font, text, character.Bounds, options.Transform);
                    }
                }
            }

            base.OnPaint(e);
        }