Esempio n. 1
0
        void _viewer_MouseDown(object sender, MouseEventArgs e)
        {
            if (command != null && e.Button == MouseButtons.Left)
            {
                if (_viewer.ViewBounds.Contains(LeadPoint.Create(e.X, e.Y)))
                {
                    double xFactor = _viewer.XScaleFactor;
                    double yFactor = _viewer.YScaleFactor;

                    int xOffset = _viewer.ViewBounds.Left;
                    int yOffset = _viewer.ViewBounds.Top;

                    LeadPoint pnt = new LeadPoint((int)((e.X - xOffset) * 1.0 / xFactor + 0.5), (int)((e.Y - yOffset) * 1.0 / yFactor + 0.5));

                    _drawing         = true;
                    _mousedown       = true;
                    _center          = pnt;
                    _curntMousePoint = _center;
                    _viewer.Invalidate();


                    if (_viewer.WorkingInteractiveMode is ImageViewerFloaterInteractiveMode)
                    {
                        _mainForm.DisableAllInteractiveModes(_viewer);
                        _form.Viewer.InteractiveModes.BeginUpdate();
                        _form.NoneInteractiveMode.IsEnabled = true;
                        _form.Viewer.InteractiveModes.EndUpdate();
                        try
                        {
                            if (_viewer.Floater != null)
                            {
                                RasterRegionXForm xForm = new RasterRegionXForm();
                                xForm.ViewPerspective = RasterViewPerspective.TopLeft;

                                /*LeadMatrix mm = _viewer.FloaterTransform.OffsetY;
                                 * Matrix m = new Matrix((float)mm.M11, (float)mm.M12, (float)mm.M21, (float)mm.M22, (float)mm.OffsetX, (float)mm.OffsetY);
                                 * Transformer t = new Transformer(m);*/
                                LeadMatrix floaterTransform = _viewer.FloaterTransform;

                                xForm.XOffset                      = (int)floaterTransform.OffsetX;
                                xForm.YOffset                      = (int)floaterTransform.OffsetY;
                                xForm.YScalarDenominator           =
                                    xForm.XScalarDenominator       =
                                        xForm.XScalarNumerator     =
                                            xForm.YScalarNumerator = 1;

                                _viewer.Image.SetRegion(xForm, _viewer.Floater.GetRegion(null), RasterRegionCombineMode.Set);

                                _viewer.Floater.Dispose();
                                _viewer.Floater = null;
                            }
                        }
                        catch (Exception ex)
                        {
                            Messager.ShowError(this, ex);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private void _thumbnailsContextMenuStrip_Opening(object sender, CancelEventArgs e)
        {
            // Get current page from the position
            if (!_documentViewer.HasDocument)
            {
                e.Cancel = true;
                return;
            }

            var thumbnails = _documentViewer.Thumbnails;

            if (thumbnails == null)
            {
                e.Cancel = true;
                return;
            }

            var pageNumber  = -1;
            var imageViewer = thumbnails.ImageViewer;
            var position    = imageViewer.PointToClient(Cursor.Position);
            var item        = imageViewer.HitTestItem(LeadPoint.Create(position.X, position.Y));
            var canRunText  = false;

            if (item != null)
            {
                pageNumber = imageViewer.Items.IndexOf(item) + 1;
                canRunText = _documentViewer.Commands.CanRun(DocumentViewerCommands.TextGet, pageNumber);
            }

            if (pageNumber != -1)
            {
                _thumbnailsGetThisPageTextToolStripMenuItem.Tag            = canRunText ? (object)pageNumber : null;
                _thumbnailsGetThisPageTextToolStripMenuItem.Enabled        = canRunText;
                _thumbnailsRotateClockwiseToolStripMenuItem.Tag            = pageNumber;
                _thumbnailsRotateClockwiseToolStripMenuItem.Enabled        = true;
                _thumbnailsRotateCounterClockwiseToolStripMenuItem.Tag     = pageNumber;
                _thumbnailsRotateCounterClockwiseToolStripMenuItem.Enabled = true;
                _thumbnailsEnableDisablePageToolStripMenuItem.Tag          = pageNumber;
                _thumbnailsEnableDisablePageToolStripMenuItem.Enabled      = true;
                _thumbnailsEnableDisablePageToolStripMenuItem.Checked      = _documentViewer.Document.Pages[pageNumber - 1].IsDeleted;
            }
            else
            {
                _thumbnailsGetThisPageTextToolStripMenuItem.Tag            = null;
                _thumbnailsGetThisPageTextToolStripMenuItem.Enabled        = false;
                _thumbnailsRotateClockwiseToolStripMenuItem.Tag            = null;
                _thumbnailsRotateClockwiseToolStripMenuItem.Enabled        = true;
                _thumbnailsRotateCounterClockwiseToolStripMenuItem.Tag     = null;
                _thumbnailsRotateCounterClockwiseToolStripMenuItem.Enabled = true;
                _thumbnailsEnableDisablePageToolStripMenuItem.Tag          = null;
                _thumbnailsEnableDisablePageToolStripMenuItem.Enabled      = false;
            }

            _thumbnailsGetAllPagesTextToolStripMenuItem.Enabled = _documentViewer.Commands.CanRun(DocumentViewerCommands.TextGet, 0);
        }
Esempio n. 3
0
 void _viewer_MouseMove(object sender, MouseEventArgs e)
 {
     if (_viewer.ViewBounds.Contains(LeadPoint.Create(e.X, e.Y)))
     {
         if (_drawing)
         {
             _currentSegment.Add(new Point(e.X, e.Y));
             _viewer.Invalidate();
         }
     }
 }
Esempio n. 4
0
        public LeadPoint PointToPixels(LeadPoint value)
        {
            if (value.IsEmpty)
            {
                return(LeadPoint.Empty);
            }

            var resolution = this.Pages.DefaultResolution;

            return(LeadPoint.Create(DocumentToPixels(resolution, value.X), DocumentToPixels(resolution, value.Y)));
        }
        public ViewContextMenu(DocumentViewer documentViewer, Action selectAllTextAction)
        {
            _commandsBinder = new CommandsBinder(documentViewer);

            _commandsBinder.Items.Add(new CommandBinderItem
            {
                CommandNames  = new string[] { DocumentViewerCommands.TextCopy, DocumentViewerCommands.AnnotationsCopy },
                ToolStripItem = this.Items.Add("Copy")
            });

            _commandsBinder.Items.Add(new CommandBinderItem
            {
                CommandName   = DocumentViewerCommands.AnnotationsPaste,
                ToolStripItem = this.Items.Add("Paste"),
                GetValue      = (() =>
                {
                    // The paste position, in viewer coordinates
                    var position = documentViewer.View.ImageViewer.PointToClient(_openingPosition);
                    return(LeadPoint.Create(position.X, position.Y));
                })
            });


            _commandsBinder.Items.Add(new CommandBinderItem
            {
                CommandName   = DocumentViewerCommands.AnnotationsDelete,
                ToolStripItem = this.Items.Add("Delete")
            });

            this.Items.Add(new ToolStripSeparator());

            _commandsBinder.Items.Add(new CommandBinderItem
            {
                CommandName   = DocumentViewerCommands.TextSelectAll,
                ToolStripItem = this.Items.Add("Select all", null, new EventHandler(delegate { selectAllTextAction(); })),
                AutoRun       = false
            });

            _commandsBinder.Items.Add(new CommandBinderItem
            {
                CommandName   = DocumentViewerCommands.AnnotationsSelectAll,
                ToolStripItem = this.Items.Add("Select all annotations")
            });

            _commandsBinder.Items.Add(new CommandBinderItem
            {
                CommandNames  = new string[] { DocumentViewerCommands.TextClearSelection, DocumentViewerCommands.AnnotationsClearSelection },
                ToolStripItem = this.Items.Add("Clear selection")
            });

            _commandsBinder.BindActions(true);
            _commandsBinder.Run();
        }
Esempio n. 6
0
        void _viewer_MouseDown(object sender, MouseEventArgs e)
        {
            if (command != null && e.Button == MouseButtons.Left)
            {
                if (_viewer.ViewBounds.Contains(LeadPoint.Create(e.X, e.Y)))
                {
                    double xFactor = _viewer.XScaleFactor;
                    double yFactor = _viewer.YScaleFactor;

                    int xOffset = _viewer.ClientRectangle.Left;
                    int yOffset = _viewer.ClientRectangle.Top;

                    LeadPoint pnt = new LeadPoint((int)((e.X - xOffset) * 1.0 / xFactor + 0.5), (int)((e.Y - yOffset) * 1.0 / yFactor + 0.5));

                    _drawing         = true;
                    _mousedown       = true;
                    _center          = pnt;
                    _curntMousePoint = _center;
                    _viewer.Invalidate();

                    if (_viewer.InteractiveModes.FindById(_form.FloaterInteractiveMode.Id).IsEnabled)
                    {
                        _form.DisableInteractiveModes(_viewer);
                        _viewer.InteractiveModes.EnableById(_form.NoneInteractiveMode.Id);
                        try
                        {
                            if (_viewer.Floater != null)
                            {
                                RasterRegionXForm xForm = new RasterRegionXForm();
                                xForm.ViewPerspective              = RasterViewPerspective.TopLeft;
                                xForm.XOffset                      = (int)_viewer.FloaterTransform.OffsetX;
                                xForm.YOffset                      = (int)_viewer.FloaterTransform.OffsetY;
                                xForm.YScalarDenominator           =
                                    xForm.XScalarDenominator       =
                                        xForm.XScalarNumerator     =
                                            xForm.YScalarNumerator = 1;

                                _viewer.Image.SetRegion(xForm, _viewer.Floater.GetRegion(null), RasterRegionCombineMode.Set);

                                _viewer.Floater.Dispose();
                                _viewer.Floater = null;
                            }
                        }
                        catch (Exception ex)
                        {
                            Messager.ShowError(this, ex);
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        private void _imageViewer_MouseClick(object sender, MouseEventArgs e)
        {
            if (_imageViewer.Image == null)
            {
                return;
            }

            // Get the mouse click in logical coordinates (page) and select the word under this point (if any)

            LeadPoint physical = LeadPoint.Create(e.X, e.Y);
            LeadPoint pixels   = _imageViewer.ConvertPoint(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, physical);

            FindWordUnderPoint(pixels);
        }
Esempio n. 8
0
        private void SetViewerZoomPercentage(double percentage)
        {
            // Normalize the percentage based on min/max value allowed
            percentage = Math.Max(_minimumViewerScalePercentage, Math.Min(_maximumViewerScalePercentage, percentage));

            if (Math.Abs(_rasterImageViewer.ScaleFactor * 100.0 - percentage) > 0.01)
            {
                // Save the current center location in the viewer, we will use it later to
                // re-center the viewer

                LeadRectD LeadPhysicalViewRectangle = _rasterImageViewer.GetItemViewBounds(_rasterImageViewer.ActiveItem, ImageViewerItemPart.Image, true);
                LeadRectD LeadLogicalViewRectangle  = _rasterImageViewer.GetItemBounds(_rasterImageViewer.ActiveItem, ImageViewerItemPart.Image);

                Rectangle PhysicalViewRectangle = new Rectangle((int)LeadPhysicalViewRectangle.Left, (int)LeadPhysicalViewRectangle.Top, (int)LeadPhysicalViewRectangle.Width, (int)LeadPhysicalViewRectangle.Height);
                Rectangle LogicalViewRectangle  = new Rectangle((int)LeadLogicalViewRectangle.Left, (int)LeadLogicalViewRectangle.Top, (int)LeadLogicalViewRectangle.Width, (int)LeadLogicalViewRectangle.Height);

                Rectangle rc     = Rectangle.Intersect(PhysicalViewRectangle, LogicalViewRectangle);
                PointF    center = new PointF(rc.Left + rc.Width / 2, rc.Top + rc.Right / 2);

                LeadMatrix  LeadM = _rasterImageViewer.ImageTransform;
                Matrix      M     = new Matrix((float)LeadM.M11, (float)LeadM.M12, (float)LeadM.M21, (float)LeadM.M22, (float)LeadM.OffsetX, (float)LeadM.OffsetY);
                Transformer trans = new Transformer(M);
                center = trans.PointToLogical(center);

                _rasterImageViewer.BeginUpdate();

                // Switch to normal size mode if we are not in it
                if (_rasterImageViewer.SizeMode != ControlSizeMode.ActualSize)
                {
                    _rasterImageViewer.Zoom(ControlSizeMode.ActualSize, 1, _rasterImageViewer.DefaultZoomOrigin);
                }

                // Zoom
                _rasterImageViewer.Zoom(ControlSizeMode.None, percentage / 100.0, _rasterImageViewer.DefaultZoomOrigin);

                // Go back to original center point
                LeadM           = _rasterImageViewer.ImageTransform;
                M               = new Matrix((float)LeadM.M11, (float)LeadM.M12, (float)LeadM.M21, (float)LeadM.M22, (float)LeadM.OffsetX, (float)LeadM.OffsetY);
                trans.Transform = M;
                center          = trans.PointToPhysical(center);

                _rasterImageViewer.CenterAtPoint(LeadPoint.Create((int)center.X, (int)center.Y));

                _rasterImageViewer.EndUpdate();

                _rasterImageViewer_TransformChanged(_rasterImageViewer, EventArgs.Empty);

                UpdateUIState();
            }
        }
Esempio n. 9
0
        void ActiveViewerForm_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (_gwireCommand != null)
                {
                    if (_gwireStarted)
                    {
                        if (_viewer.ViewBounds.Contains(LeadPoint.Create(e.Location.X, e.Location.Y)))
                        {
                            double xFactor = _viewer.XScaleFactor;
                            double yFactor = _viewer.YScaleFactor;

                            int xOffset = _viewer.ViewBounds.Left;
                            int yOffset = _viewer.ViewBounds.Top;
                            int x       = (int)((e.X - xOffset) * 1.0f / xFactor + 0.5);
                            int y       = (int)((e.Y - yOffset) * 1.0f / yFactor + 0.5);
                            if (!_gwireSeedSelected)
                            {
                                _gwireCommand.SetSeedPoint(new LeadPoint(x, y));
                                Application.DoEvents();

                                _gwireSeedSelected = true;
                                _gwireNewSeed      = false;
                                _anchorPoints.Add(new Point(x, y));
                            }
                            else
                            {
                                _gwireCommand.SetSeedPoint(new LeadPoint(x, y));
                                _gwireNewSeed = true;
                                _anchorPoints.Add(new Point(x, y));
                                Rectangle rect = CreateRectangleFromPoint(new Point(x, y));
                                if (rect.Contains(_anchorPoints[0]))
                                {
                                    FinishGWire();
                                }
                            }
                        }
                    }
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                FinishGWire();
            }
        }
Esempio n. 10
0
        private RasterImage AddTextFooter(RasterImage image, string tag, int footerMaxHeight)
        {
            LeadRect bounds = LeadRect.Create(0, 0, image.Width, image.Height);

            using (var imageTag = CreateTextFooter(LeadSize.Create(bounds.Width, footerMaxHeight), tag))
            {
                bounds.Height += imageTag.Height;

                var bpp             = 24;
                var byteOrder       = RasterByteOrder.Bgr;
                var viewPerspective = RasterViewPerspective.TopLeft;

                if (image.ViewPerspective != viewPerspective)
                {
                    image.ChangeViewPerspective(viewPerspective);
                }

                if (image.BitsPerPixel != bpp || image.Order != byteOrder)
                {
                    var colorResCommand = new ColorResolutionCommand(
                        ColorResolutionCommandMode.InPlace,
                        bpp,
                        byteOrder,
                        RasterDitheringMethod.None,
                        ColorResolutionCommandPaletteFlags.Optimized,
                        null);
                    colorResCommand.Run(image);
                }

                RasterImage imageResult = new RasterImage(RasterMemoryFlags.Conventional, bounds.Width, bounds.Height, bpp, byteOrder, viewPerspective, null, null, 0);

                {
                    var combine = new CombineFastCommand(imageResult, bounds, LeadPoint.Create(0, 0), CombineFastCommandFlags.SourceCopy);
                    combine.Run(image);
                }

                {
                    var combine = new CombineFastCommand(imageResult, LeadRect.Create(bounds.X, image.Height, bounds.Width, bounds.Height - image.Height), LeadPoint.Create(0, 0), CombineFastCommandFlags.SourceCopy);
                    combine.Run(imageTag);
                }
                return(imageResult);
            }
        }
Esempio n. 11
0
        private void _imageViewer_MouseMove(object sender, MouseEventArgs e)
        {
            string str;

            if (_imageViewer.Image != null)
            {
                // Show the mouse position in physical and logical (inches) coordinates

                LeadPoint physical = LeadPoint.Create(e.X, e.Y);
                LeadPoint pixels   = _imageViewer.ConvertPoint(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, physical);
                str = string.Format("{0},{1} px", (int)pixels.X, (int)pixels.Y);
            }
            else
            {
                str = string.Empty;
            }

            _mousePositionLabel.Text = str;
        }
Esempio n. 12
0
        void ActiveViewerForm_MouseMove(object sender, MouseEventArgs e)
        {
            if (_gwireCommand != null)
            {
                _viewer.Cursor = Cursors.Cross;
                if (_gwireStarted)
                {
                    if (_gwireSeedSelected && _viewer.ViewBounds.Contains(LeadPoint.Create(e.Location.X, e.Location.Y)))
                    {
                        double xFactor = _viewer.XScaleFactor;
                        double yFactor = _viewer.YScaleFactor;

                        int xOffset = _viewer.ViewBounds.Left;
                        int yOffset = _viewer.ViewBounds.Top;

                        LeadPoint[] GWirePath = _gwireCommand.GetMinPath(new LeadPoint((int)((e.X - xOffset) * 1.0 / xFactor + 0.5), (int)((e.Y - yOffset) * 1.0 / yFactor + 0.5)));

                        if (GWirePath != null)
                        {
                            if (_gwireNewSeed)
                            {
                                if (_gwirePath != null)
                                {
                                    _gwirePrevPath.AddRange(_gwirePath);
                                    _gwireNewSeed = false;
                                }
                            }

                            _gwirePath = new Point[GWirePath.Length];

                            for (int i = 0; i < GWirePath.Length; i++)
                            {
                                _gwirePath[i].X = GWirePath[i].X;
                                _gwirePath[i].Y = GWirePath[i].Y;
                            }

                            _viewer.Invalidate();
                        }
                    }
                }
            }
        }
Esempio n. 13
0
        private void ZoomViewer(double value)
        {
            //// zoom
            // We will do zoom/center, so save the current center in logical units
            // get what you see in physical coordinates
            LeadRect LeadPhysicalViewRectangle = _imageViewer.ViewBounds;
            //LeadRect LeadLogicalViewRectangle = _imageViewer.ImageBounds;

            Rectangle PhysicalViewRectangle = new Rectangle(LeadPhysicalViewRectangle.X, LeadPhysicalViewRectangle.Y, LeadPhysicalViewRectangle.Width, LeadPhysicalViewRectangle.Height);
            Rectangle LogicalViewRectangle  = _imageViewer.ClientRectangle;

            Rectangle rc = Rectangle.Intersect(PhysicalViewRectangle, LogicalViewRectangle);

            // get the center of what you see in physical coordinates
            PointF center = new PointF(rc.Left + rc.Width / 2, rc.Top + rc.Height / 2);

            LeadMatrix  m  = _imageViewer.GetImageTransformWithDpi(_imageViewer.UseDpi);
            Matrix      mm = new Matrix((float)m.M11, (float)m.M12, (float)m.M21, (float)m.M22, (float)m.OffsetX, (float)m.OffsetY);
            Transformer t  = new Transformer(mm);

            // get the center of what you see in logical coordinates
            center = t.PointToLogical(center);
            // zoom
            const double minimumScaleFactor = 0.05;
            const double maximumScaleFactor = 11;
            double       scaleFactor        = Math.Max(minimumScaleFactor, Math.Min(maximumScaleFactor, value));

            if (_imageViewer.ScaleFactor != scaleFactor)
            {
                _imageViewer.Zoom(ControlSizeMode.None, scaleFactor, _imageViewer.DefaultZoomOrigin);
                // bring the original center into the view center
                m  = _imageViewer.GetImageTransformWithDpi(_imageViewer.UseDpi);
                mm = new Matrix((float)m.M11, (float)m.M12, (float)m.M21, (float)m.M22, (float)m.OffsetX, (float)m.OffsetY);
                t  = new Transformer(mm);
                // get the center of what you saw before the zoom in physical coordinates
                center = t.PointToPhysical(center);
                // bring the old center into the center of the view
                _imageViewer.CenterAtPoint(LeadPoint.Create((int)center.X, (int)center.Y));
                UpdateUIState();
            }
        }
Esempio n. 14
0
        private void _imageViewer_MouseDown(object sender, MouseEventArgs e)
        {
            RasterImage image = _imageViewer.Image;

            if (image == null || rubberBandMode.IsEnabled)
            {
                // Nothing for us to do
                return;
            }

            if (_isMovingOverlayRect)
            {
                // Previously moving the rectangle, end the move operation
                EndMovingOverlayRect();
            }

            if (!_overlayRect.IsEmpty && e.Button == MouseButtons.Left)
            {
                // Check if we are on the overlay rect. Get current mouse position
                // in image coordinates. Using TopLeft since the overlay rect is in
                // TopLeft always
                LeadPoint viewerPoint = LeadPoint.Create(e.X, e.Y);
                LeadPoint imagePoint  = _imageViewer.ConvertPoint(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, viewerPoint);

                if (_overlayRect.Contains(imagePoint.X, imagePoint.Y))
                {
                    // Yes, start moving
                    _lastMovePoint       = viewerPoint;
                    _isMovingOverlayRect = true;

                    // Optional: clip the cursor to not move outside the image bounds
                    LeadRect imageRect  = LeadRect.Create(0, 0, image.ImageWidth, image.ImageHeight);
                    LeadRect viewerRect = _imageViewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, imageRect);
                    // Note, the above returns the same value as _rasterImageViewer.PhysicalViewRectangle
                    Rectangle clipRect = Rectangle.Intersect(Rectangle.FromLTRB(viewerRect.Left, viewerRect.Top, viewerRect.Right, viewerRect.Bottom), _imageViewer.ClientRectangle);
                    Cursor.Clip          = _imageViewer.RectangleToScreen(clipRect);
                    _imageViewer.Capture = true;
                }
            }
        }
Esempio n. 15
0
        private void _imageViewer_MouseMove(object sender, MouseEventArgs e)
        {
            string str = string.Empty;

            if (_imageViewer.Image != null)
            {
                // Show the mouse position in physical and logical (inches) coordinates
                if (_imageViewer.DisplayRectangle.Contains(e.X, e.Y))
                {
                    LeadPoint physical = LeadPoint.Create(e.X, e.Y);
                    LeadPoint pixels   = _imageViewer.ConvertPoint(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, physical);

                    // Convert the logical point to inches
                    PointF inches = PointF.Empty;
                    inches.X = (float)pixels.X / (float)_imageViewer.Image.XResolution;
                    inches.Y = (float)pixels.Y / (float)_imageViewer.Image.YResolution;

                    str = string.Format("{0},{1} px {2},{3} in", (int)pixels.X, (int)pixels.Y, inches.X.ToString("F02"), inches.Y.ToString("F02"));
                }
            }

            _mousePositionLabel.Text = str;
        }
Esempio n. 16
0
        void _viewer_MouseMove(object sender, MouseEventArgs e)
        {
            LeadPoint tmpPnt = _viewer.ConvertPoint(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, LeadPoint.Create(e.X, e.Y));

            if (_pressed)
            {
                switch (_button)
                {
                case downButtonPosition.END_RECT:
                case downButtonPosition.NONE:
                    _xEnd         = tmpPnt.X;
                    _yEnd         = tmpPnt.Y;
                    _numXEnd.Text = _xEnd.ToString();
                    _numYEnd.Text = _yEnd.ToString();
                    if (_cbMovable.Checked)
                    {
                        _endRect = new Rectangle(_ptEnd.X - 10, _ptEnd.Y - 10, 20, 20);
                    }
                    if (_cbMovable.Checked && _button == downButtonPosition.NONE)
                    {
                        _startRect = new Rectangle(_ptStart.X - 10, _ptStart.Y - 10, 20, 20);
                    }
                    break;

                case downButtonPosition.START_RECT:
                    _xStart         = tmpPnt.X;
                    _yStart         = tmpPnt.Y;
                    _numXStart.Text = _xStart.ToString();
                    _numYStart.Text = _yStart.ToString();
                    if (_cbMovable.Checked)
                    {
                        _startRect = new Rectangle(_ptStart.X - 10, _ptStart.Y - 10, 20, 20);
                    }
                    break;
                }
                _viewer.Invalidate();
            }
            _yCursorPosition.Text = tmpPnt.Y.ToString();
            _xCursorPosition.Text = tmpPnt.X.ToString();
        }
Esempio n. 17
0
        void _viewer_MouseUp(object sender, MouseEventArgs e)
        {
            Cursor.Clip = Rectangle.Empty;

            if (e.Button == MouseButtons.Left)
            {
                LeadPoint tmpPnt = _viewer.ConvertPoint(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, LeadPoint.Create(e.X, e.Y));
                _pressed = false;

                switch (_button)
                {
                case downButtonPosition.END_RECT:
                case downButtonPosition.NONE:
                    _xEnd         = tmpPnt.X;
                    _yEnd         = tmpPnt.Y;
                    _numXEnd.Text = _xEnd.ToString();
                    _numYEnd.Text = _yEnd.ToString();
                    break;

                case downButtonPosition.START_RECT:
                    _xStart         = tmpPnt.X;
                    _yStart         = tmpPnt.Y;
                    _numXStart.Text = _xStart.ToString();
                    _numYStart.Text = _yStart.ToString();
                    break;
                }
                if (_cbMovable.Checked)
                {
                    _startRect = new Rectangle(_ptStart.X - 10, _ptStart.Y - 10, 20, 20);
                    _endRect   = new Rectangle(_ptEnd.X - 10, _ptEnd.Y - 10, 20, 20);
                }
            }
        }
Esempio n. 18
0
        void _viewer_MouseDown(object sender, MouseEventArgs e)
        {
            Point point = _viewer.PointToScreen(new Point(0, 0));

            Cursor.Clip = new Rectangle(point.X + Math.Max(0, _viewer.ViewBounds.Left), point.Y + Math.Max(0, _viewer.ViewBounds.Top), _viewer.ViewBounds.Width, _viewer.ViewBounds.Height);
            if (e.Button == MouseButtons.Left)
            {
                LeadPoint tmpPnt = _viewer.ConvertPoint(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, LeadPoint.Create(e.X, e.Y));
                _pressed = true;

                if (_cbMovable.Checked)
                {
                    if (_startRect.Contains(tmpPnt.X, tmpPnt.Y))
                    {
                        _button = downButtonPosition.START_RECT;
                    }
                    else if (_endRect.Contains(tmpPnt.X, tmpPnt.Y))
                    {
                        _button = downButtonPosition.END_RECT;
                    }
                    else
                    {
                        _button         = downButtonPosition.NONE;
                        _xEnd           = _xStart = tmpPnt.X;
                        _yEnd           = _yStart = tmpPnt.Y;
                        _numXStart.Text = _xStart.ToString();
                        _numYStart.Text = _yStart.ToString();
                        _startRect      = new Rectangle(_ptStart.X - 10, _ptStart.Y - 10, 20, 20);
                        _endRect        = new Rectangle(_ptEnd.X - 10, _ptEnd.Y - 10, 20, 20);
                    }
                }
                else
                {
                    _xEnd           = _xStart = tmpPnt.X;
                    _yEnd           = _yStart = tmpPnt.Y;
                    _numXStart.Text = _xStart.ToString();
                    _numYStart.Text = _yStart.ToString();
                }
            }
        }
Esempio n. 19
0
        public LeadPoint PointToDocument(LeadPoint value)
        {
            var resolution = this.Pages.DefaultResolution;

            return(LeadPoint.Create(PixelsToDocument(resolution, (int)value.X), PixelsToDocument(resolution, (int)value.Y)));
        }
Esempio n. 20
0
        private void _imageViewer_MouseMove(object sender, MouseEventArgs e)
        {
            RasterImage image = _imageViewer.Image;

            if (image == null)
            {
                return;
            }

            // Here is the point in viewer (physical or client) coordinates
            // This point is the mouse position
            LeadPoint viewerPoint = LeadPoint.Create(e.X, e.Y);

            // Convert to image coordinates (top-left view perspective, since we are
            // only interested in the zoom/scroll values and not trying to get to a
            // certain pixel in the image data)
            LeadPoint imagePoint = _imageViewer.ConvertPoint(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, viewerPoint);

            ShowMousePositionAndImageColor(image, viewerPoint, imagePoint);

            if (_isMovingOverlayRect)
            {
                // We are moving the overlay rect

                // After we are done with moving the overlay rect to a new position,
                // we need to re-paint to show the effect. To optimize the code, we will
                // only repaint the combination of the old and new rects

                // Get the current (soon to be old) overlay rect in viewer coordinates
                LeadRect oldImageRect  = LeadRect.Create(_overlayRect.X, _overlayRect.Y, _overlayRect.Width, _overlayRect.Height);
                LeadRect oldViewerRect = _imageViewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, oldImageRect);

                // Get the difference
                int dx = e.X - _lastMovePoint.X;
                int dy = e.Y - _lastMovePoint.Y;

                if (dx != 0 || dy != 0)
                {
                    // Has moved

                    LeadRect newViewerRect = oldViewerRect;
                    newViewerRect.Offset(dx, dy);

                    // Now re-calculate new overlay rectangle in image coordinates
                    LeadRect newImageRect = _imageViewer.ConvertRect(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, newViewerRect);

                    // Make sure the image rectangle does not go outside the image boundaries
                    if (newImageRect.X < 0)
                    {
                        newImageRect.Offset(-newImageRect.X, 0);
                    }
                    if (newImageRect.Y < 0)
                    {
                        newImageRect.Offset(0, -newImageRect.Y);
                    }
                    if ((newImageRect.X + newImageRect.Width) > image.ImageWidth)
                    {
                        newImageRect.Offset(-(newImageRect.X + newImageRect.Width - image.ImageWidth), 0);
                    }
                    if ((newImageRect.Y + newImageRect.Height) > image.ImageHeight)
                    {
                        newImageRect.Offset(0, -(newImageRect.Y + newImageRect.Height - image.ImageHeight));
                    }

                    // Check if it has really changed
                    if (newImageRect.X != oldImageRect.X ||
                        newImageRect.Y != oldImageRect.Y ||
                        newImageRect.Width != oldImageRect.Width ||
                        newImageRect.Height != oldImageRect.Height)
                    {
                        // Yes
                        _overlayRect = new LeadRect(newImageRect.X, newImageRect.Y, newImageRect.Width, newImageRect.Height);

                        _imageViewer.Invalidate();
                    }

                    // Save the new moving position
                    _lastMovePoint = LeadPoint.Create(e.X, e.Y);
                }
            }
        }
Esempio n. 21
0
        private void _fieldResults_SelectionChanged(object sender, EventArgs e)
        {
            try
            {
                //clear annotations
                automation.SelectObjects(null);
                automation.Container.Children.Clear();

                if (_fieldResults.Rows.Count > 0 && _fieldResults.SelectedRows.Count > 0)
                {
                    if (_fieldViewer.Image != null)
                    {
                        _fieldViewer.Image.Dispose();
                    }

                    int formIndex  = _cmbSelectedForm.SelectedIndex;
                    int pageIndex  = _cmbSelectedPage.SelectedIndex;
                    int fieldIndex = _fieldResults.SelectedRows[0].Index;

                    _filledForms[_cmbSelectedForm.SelectedIndex].Image.Page = _cmbSelectedPage.SelectedIndex + 1;
                    LeadRect  tempRect = LeadRect.Empty;
                    FormField field    = _filledForms[formIndex].ProcessingPages[pageIndex][fieldIndex];

                    if (field is TableFormField)
                    {
                        TableFormField tableField        = field as TableFormField;
                        int            expectedPageIndex = -1;
                        if (tableField.ExpectedPages.Contains(pageIndex))
                        {
                            expectedPageIndex = tableField.ExpectedPages.IndexOf(pageIndex);
                        }

                        expectedPageIndex = Math.Max(expectedPageIndex, pageIndex);

                        if (tableField.PagesBounds.ContainsKey(expectedPageIndex))
                        {
                            tempRect = tableField.PagesBounds[expectedPageIndex];
                        }
                        else
                        {
                            tempRect = LeadRect.Empty;
                        }
                    }
                    else if (field is UnStructuredTextFormField)
                    {
                        tempRect = field.Bounds;
                    }
                    else if (field is OmrFormField)
                    {
                        tempRect = _filledForms[_cmbSelectedForm.SelectedIndex].Alignment[field.MasterPageNumber - 1].AlignOmrRectangle(field.Bounds);
                    }
                    else
                    {
                        tempRect = _filledForms[_cmbSelectedForm.SelectedIndex].Alignment[field.MasterPageNumber - 1 >= 0 ? field.MasterPageNumber - 1 : 0].AlignRectangle(field.Bounds);
                    }

                    Rectangle alignedRect = Leadtools.Demos.Converters.ConvertRect(_filledForms[formIndex].Image.RectangleToImage(RasterViewPerspective.TopLeft, tempRect));
                    if (!alignedRect.IsEmpty)
                    {
                        _fieldViewer.Image = _filledForms[formIndex].Image.Clone(Leadtools.Demos.Converters.ConvertRect(alignedRect));
                    }
                    else
                    {
                        _fieldViewer.Image = null;
                    }
                    AddHighlight(alignedRect);

                    LeadMatrix LeadImageMatrix = _filledFormViewer.ImageTransform;
                    //Ensure field is visible
                    Transformer transformer = new Transformer(new System.Drawing.Drawing2D.Matrix((float)LeadImageMatrix.M11,
                                                                                                  (float)LeadImageMatrix.M12,
                                                                                                  (float)LeadImageMatrix.M21,
                                                                                                  (float)LeadImageMatrix.M22,
                                                                                                  (float)LeadImageMatrix.OffsetX,
                                                                                                  (float)LeadImageMatrix.OffsetY));

                    PointF location = transformer.PointToPhysical(alignedRect.Location);
                    _filledFormViewer.CenterAtPoint(LeadPoint.Create((int)location.X, (int)location.Y));

                    UpdateControls();
                }
            }
            catch (Exception exp)
            {
                Messager.ShowError(this, exp);
            }
        }
        public override void SetImageData(AnnContainer container, LeadRectD bounds, byte[] data)
        {
            if (_image == null)
            {
                return;
            }

            using (var ms = new MemoryStream(data))
            {
                using (var codecs = new RasterCodecs())
                {
                    using (var image = codecs.Load(ms))
                    {
                        if (image.ViewPerspective != _image.ViewPerspective)
                        {
                            image.ChangeViewPerspective(_image.ViewPerspective);
                        }

                        if (image.BitsPerPixel != _image.BitsPerPixel || image.Order != _image.Order)
                        {
                            var palette      = _image.GetPalette();
                            var paletteFlags = palette != null ? ColorResolutionCommandPaletteFlags.UsePalette : ColorResolutionCommandPaletteFlags.Optimized;

                            var colorResCommand = new ColorResolutionCommand(
                                ColorResolutionCommandMode.InPlace,
                                _image.BitsPerPixel,
                                _image.Order,
                                RasterDitheringMethod.None,
                                paletteFlags,
                                palette);
                            colorResCommand.Run(image);
                        }

                        var combine = new CombineFastCommand(_image, bounds.ToLeadRect(), LeadPoint.Create(0, 0), CombineFastCommandFlags.SourceCopy);
                        combine.Run(image);
                    }
                }
            }
        }
        private void service_Move(object sender, InteractiveEventArgs e)
        {
            if (this.ImageViewer.Items.Count < 1)
            {
                return;
            }
            var item = this.ImageViewer.Items[0];

            if (item == null)
            {
                return;
            }

            e.IsHandled = true;

            this.OnWorkStarted(EventArgs.Empty);
            if (!item.HasFloater)
            {
                TryAddFloater(item);
            }
            else
            {
                LeadMatrix matrix = new LeadMatrix();

                LeadPoint positionImage = ImageViewer.ConvertPoint(ImageViewer.Items[0],
                                                                   ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, LeadPoint.Create(e.Position.X, e.Position.Y));

                matrix.OffsetX        = positionImage.X - item.Floater.Width / 2;
                matrix.OffsetY        = positionImage.Y - item.Floater.Height / 2;
                item.FloaterTransform = matrix;
            }
            this.OnWorkCompleted(EventArgs.Empty);
        }
Esempio n. 24
0
        void _viewer_PostRender(object sender, ImageViewerRenderEventArgs args)
        {
            LeadPoint firstPoint = _viewer.ConvertPoint(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, LeadPoint.Create(_xStart, _yStart));
            LeadPoint endPoint   = _viewer.ConvertPoint(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, LeadPoint.Create(_xEnd, _yEnd));

            float[]        dashValuesWhite = { 4, 4, 4, 4 };
            Pen            penBlack        = new Pen(Color.Black, 1);
            Pen            penWhite        = new Pen(Color.White, 1);
            PaintEventArgs e = args.PaintEventArgs;

            penWhite.DashPattern = dashValuesWhite;

            e.Graphics.DrawLine(penBlack, firstPoint.X, firstPoint.Y, endPoint.X, endPoint.Y);
            e.Graphics.DrawLine(penWhite, firstPoint.X, firstPoint.Y, endPoint.X, endPoint.Y);
            LeadRect startRect = _viewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, LeadRect.Create(_startRect.X, _startRect.Y, _startRect.Width, _startRect.Height));
            LeadRect endRect   = _viewer.ConvertRect(null, ImageViewerCoordinateType.Image, ImageViewerCoordinateType.Control, LeadRect.Create(_endRect.X, _endRect.Y, _endRect.Width, _endRect.Height));

            if (_cbMovable.Checked)
            {
                e.Graphics.DrawRectangle(penBlack, startRect.X, startRect.Y, startRect.Width, startRect.Height);
                e.Graphics.DrawRectangle(penWhite, startRect.X, startRect.Y, startRect.Width, startRect.Height);
                e.Graphics.DrawRectangle(penBlack, endRect.X, endRect.Y, endRect.Width, endRect.Height);
                e.Graphics.DrawRectangle(penWhite, endRect.X, endRect.Y, endRect.Width, endRect.Height);
            }
        }