Пример #1
0
        PDFObject HitTestPDFImageObject(LeadPoint pt)
        {
            PDFObject retObject = new PDFObject();

            PDFDocumentPage page = _document.Pages[_currentPageNumber - 1];

            if (page.Objects != null && page.Objects.Count > 0)
            {
                foreach (PDFObject obj in page.Objects)
                {
                    if (obj.ObjectType == PDFObjectType.Image)
                    {
                        PDFRect  tempPDFRect = page.ConvertRect(PDFCoordinateType.Pdf, PDFCoordinateType.Pixel, obj.Bounds);
                        LeadRect objectRect  = ToLeadRect(tempPDFRect);
                        if (objectRect.Contains(pt))
                        {
                            // Point in rect then user pressed over image object, so return it.
                            retObject = obj;
                            break;
                        }
                    }
                }
            }

            return(retObject);
        }
Пример #2
0
        void _viewer_MouseDown(object sender, MouseEventArgs e)
        {
            LeadPoint pixels      = _form.PhysicalToLogical(new LeadPoint(e.X, e.Y));
            LeadRect  imageBounds = new LeadRect(0, 0, _viewer.Image.ImageWidth, _viewer.Image.ImageHeight);

            if (imageBounds.Contains(pixels))
            {
                if (e.Button == MouseButtons.Left)
                {
                    double xFactor = 1;
                    double yFactor = 1;

                    int xOffset = 0;
                    int yOffset = 0;

                    Point pnt = new Point((int)Math.Ceiling(((pixels.X - xOffset) * 1.0 / xFactor + 0.5)), (int)Math.Ceiling(((pixels.Y - yOffset) * 1.0 / yFactor + 0.5)));

                    _movingPntIdx = -1;

                    if (!_drawing)
                    {
                        Rectangle[] hyberAreas = new Rectangle[_polyPoints.Count];
                        for (int idx = 0; idx < hyberAreas.Length; idx++)
                        {
                            hyberAreas[idx] = CreateRectFromPoint(_polyPoints[idx], 15);
                            if (hyberAreas[idx].Contains(pnt))
                            {
                                _movingPntIdx = idx;
                                break;
                            }
                        }
                    }

                    if (_movingPntIdx == -1)
                    {
                        if (_polyPoints.Count < 4)
                        {
                            if (pnt.Equals(_lastPoint))
                            {
                                return;
                            }
                            _firstPointSelected = true;
                            _polyPoints.Add(pnt);
                            _currentMousePoint = pnt;
                            UpdateDialogPoints(_polyPoints.Count - 1, pnt);
                            _lastPoint = pnt;
                        }

                        if (_polyPoints.Count == 4)
                        {
                            _drawing = false;
                            _viewer.Invalidate();
                            _btnApply.Enabled = true;
                        }
                    }
                }
            }
        }
Пример #3
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;
                }
            }
        }
Пример #4
0
        void _viewer_MouseUp(object sender, MouseEventArgs e)
        {
            LeadPoint pixels      = _form.PhysicalToLogical(new LeadPoint(e.X, e.Y));
            LeadRect  imageBounds = new LeadRect(0, 0, _viewer.Image.ImageWidth, _viewer.Image.ImageHeight);

            if (imageBounds.Contains(pixels))
            {
                if (e.Button == MouseButtons.Left)
                {
                    _movingPntIdx = -1;
                }
            }
        }
Пример #5
0
        void _viewer_MouseMove(object sender, MouseEventArgs e)
        {
            double xFactor = 1;
            double yFactor = 1;

            int       xOffset = 0;
            int       yOffset = 0;
            LeadPoint pixels  = _form.PhysicalToLogical(new LeadPoint(e.X, e.Y));

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

            _txtCursorX.Text = pnt.X.ToString();
            _txtCursorY.Text = pnt.Y.ToString();

            LeadRect imageBounds = new LeadRect(0, 0, _viewer.Image.ImageWidth, _viewer.Image.ImageHeight);

            if (imageBounds.Contains(pixels))
            {
                //_viewer.Cursor = Cursors.Cross;

                if (_firstPointSelected)
                {
                    _currentMousePoint = pnt;
                }

                if (_movingPntIdx != -1)
                {
                    if (pnt.X < 0)
                    {
                        pnt.X = 0;
                    }
                    if (pnt.X > _viewer.Image.ImageWidth - 1)
                    {
                        pnt.X = _viewer.Image.ImageWidth - 1;
                    }
                    if (pnt.Y < 0)
                    {
                        pnt.Y = 0;
                    }
                    if (pnt.Y > _viewer.Image.ImageHeight - 1)
                    {
                        pnt.Y = _viewer.Image.ImageHeight - 1;
                    }

                    _polyPoints.RemoveAt(_movingPntIdx);
                    _polyPoints.Insert(_movingPntIdx, pnt);
                    UpdateDialogPoints(_movingPntIdx, pnt);
                }
                _viewer.Invalidate();
            }
        }
        private void ApplyEncryptDecrypt(ScrambleCommandFlags flags, LeadRectD bounds, int key)
        {
            LeadRect boundsInImage = _image.RectangleToImage(RasterViewPerspective.TopLeft, bounds.ToLeadRect());
            LeadRect imageRect     = LeadRect.Create(0, 0, _image.ImageWidth, _image.ImageHeight);

            flags |= ScrambleCommandFlags.Intersect;

            ScrambleCommand scrambleCommand = new ScrambleCommand(boundsInImage, key, flags);

            if (imageRect.Contains(boundsInImage))
            {
                scrambleCommand.Run(_image);
            }
        }
Пример #7
0
        private void ApplyEncryptDecrypt(ScrambleCommandFlags flags, LeadRectD bounds, int key)
        {
            LeadRect rect = bounds.ToLeadRect();

            LeadRect imageRect = LeadRect.Create(0, 0, _image.ImageWidth, _image.ImageHeight);

            flags |= ScrambleCommandFlags.Intersect;

            ScrambleCommand scrambleCommand = new ScrambleCommand(rect, key, flags);

            if (imageRect.Contains(rect))
            {
                scrambleCommand.Run(_image);
            }
        }
Пример #8
0
        void _viewer_MouseUp(object sender, MouseEventArgs e)
        {
            LeadPoint pixels      = _form.PhysicalToLogical(new LeadPoint(e.X, e.Y));
            LeadRect  imageBounds = new LeadRect(0, 0, _viewer.Image.ImageWidth, _viewer.Image.ImageHeight);

            if (imageBounds.Contains(pixels))
            {
                if (e.Button == MouseButtons.Left)
                {
                    _movingPntIdx = -1;
                }
            }

            if (_unWarpPoints.Count >= 4)
            {
                double xFactor = 1;
                double yFactor = 1;
                int    xOffset = 0;
                int    yOffset = 0;

                LeadPoint[] inUpperPoints = new LeadPoint[4];
                inUpperPoints[0] = new LeadPoint((int)Math.Ceiling(((_unWarpPoints[0].X - xOffset) * 1.0 / xFactor + 0.5)), (int)Math.Ceiling(((_unWarpPoints[0].Y - yOffset) * 1.0 / yFactor + 0.5)));
                inUpperPoints[1] = new LeadPoint((int)Math.Ceiling(((_unWarpPoints[4].X - xOffset) * 1.0 / xFactor + 0.5)), (int)Math.Ceiling(((_unWarpPoints[4].Y - yOffset) * 1.0 / yFactor + 0.5)));
                inUpperPoints[2] = new LeadPoint((int)Math.Ceiling(((_unWarpPoints[5].X - xOffset) * 1.0 / xFactor + 0.5)), (int)Math.Ceiling(((_unWarpPoints[5].Y - yOffset) * 1.0 / yFactor + 0.5)));
                inUpperPoints[3] = new LeadPoint((int)Math.Ceiling(((_unWarpPoints[1].X - xOffset) * 1.0 / xFactor + 0.5)), (int)Math.Ceiling(((_unWarpPoints[1].Y - yOffset) * 1.0 / yFactor + 0.5)));
                BezierPathCommand cmd = new BezierPathCommand(inUpperPoints);
                cmd.Run(_viewer.Image);
                _upperCurvePath = cmd.PathPoints;

                LeadPoint[] inLowerPoints = new LeadPoint[4];
                inLowerPoints[0] = new LeadPoint((int)Math.Ceiling(((_unWarpPoints[3].X - xOffset) * 1.0 / xFactor + 0.5)), (int)Math.Ceiling(((_unWarpPoints[3].Y - yOffset) * 1.0 / yFactor + 0.5)));
                inLowerPoints[1] = new LeadPoint((int)Math.Ceiling(((_unWarpPoints[6].X - xOffset) * 1.0 / xFactor + 0.5)), (int)Math.Ceiling(((_unWarpPoints[6].Y - yOffset) * 1.0 / yFactor + 0.5)));
                inLowerPoints[2] = new LeadPoint((int)Math.Ceiling(((_unWarpPoints[7].X - xOffset) * 1.0 / xFactor + 0.5)), (int)Math.Ceiling(((_unWarpPoints[7].Y - yOffset) * 1.0 / yFactor + 0.5)));
                inLowerPoints[3] = new LeadPoint((int)Math.Ceiling(((_unWarpPoints[2].X - xOffset) * 1.0 / xFactor + 0.5)), (int)Math.Ceiling(((_unWarpPoints[2].Y - yOffset) * 1.0 / yFactor + 0.5)));
                cmd = new BezierPathCommand(inLowerPoints);
                cmd.Run(_viewer.Image);
                _lowerCurvePath = cmd.PathPoints;

                Invalidate();
            }
        }
Пример #9
0
        private void service_DragStarted(object sender, InteractiveDragStartedEventArgs e)
        {
            if (!CanStartWork(e) || _controlPoints == null)
            {
                return;
            }

            // See if we are on any of our handles first
            // IMPORTANT NOTE: The SelectAreaView we render the control points inside and the shaded area is added to the image viewer item itself
            // and not on the whole image viewer control so we need to map the touch points to item coordinates.
            var testPoint  = ImageViewer.ConvertPoint(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Item, e.Position);
            int thumbIndex = HitTestThumb(testPoint, _controlPoints, _thumbSize);

            if (thumbIndex != -1)
            {
                // We have a hit
                _dragThumbIndex = thumbIndex;
            }
            else
            {
                // Check if we are inside the rectangle, move all of it
                LeadRect selectedAreaRect = GetSelectedAreaRectangle(true);
                if (selectedAreaRect.Contains(testPoint))
                {
                    _isDraggingBody = true;
                }
            }

            if (_dragThumbIndex != -1 || _isDraggingBody)
            {
                // So other interactive modes do not get this event
                e.IsHandled = true;
            }

            if (e.IsHandled)
            {
                OnWorkStarted(EventArgs.Empty);
            }
        }
Пример #10
0
        private void _areaTextBox_LostFocus(object sender, EventArgs e)
        {
            if (_lbZonesList.SelectedItems.Count == 0 || _lbZonesList.SelectedItems.Count > 1)
            {
                return;
            }

            // Make sure it is an integer and in valid range
            OcrZone  zone   = CurrentZone;
            LeadRect bounds = zone.Bounds;

            TextBox tb = sender as TextBox;
            int     val;

            if (!int.TryParse(tb.Text, out val) || val < 0)
            {
                ResetBoundsValue(tb, bounds);
                return;
            }

            LeadRect newBounds = bounds;

            // Calculate the new bounds
            if (tb == _leftTextBox)
            {
                newBounds.X = val;
            }
            else if (tb == _topTextBox)
            {
                newBounds.Y = val;
            }
            else if (tb == _widthTextBox)
            {
                if (val == 0)
                {
                    ResetBoundsValue(tb, bounds);
                    return;
                }
                newBounds.Width = val;
            }
            else if (tb == _heightTextBox)
            {
                if (val == 0)
                {
                    ResetBoundsValue(tb, bounds);
                    return;
                }
                newBounds.Height = val;
            }

            // Make sure the new bounds does not go outside the page
            LeadRect pageBounds = new LeadRect(0, 0, _ocrPage.Width, _ocrPage.Height);

            if (!pageBounds.Contains(newBounds))
            {
                ResetBoundsValue(tb, bounds);
                return;
            }

            // Valid value, update the bounds
            zone.Bounds = newBounds;
            CurrentZone = zone;
        }
Пример #11
0
        private void _areaTextBox_LostFocus(object sender, EventArgs e)
        {
            if (_tvZonesList.SelectedNode == null)
            {
                return;
            }

            // Make sure it is an integer and in valid range
            OcrZone  zone   = CurrentZone;
            LeadRect bounds = zone.Bounds;

            TextBox tb = sender as TextBox;
            int     val;

            if (!int.TryParse(tb.Text, out val) || val < 0)
            {
                ResetBoundsValue(tb, bounds);
                return;
            }

            LeadRect newBounds = bounds;

            // Calculate the new bounds
            if (tb == _leftTextBox)
            {
                newBounds.X = val;
            }
            else if (tb == _topTextBox)
            {
                newBounds.Y = val;
            }
            else if (tb == _widthTextBox)
            {
                if (val == 0)
                {
                    ResetBoundsValue(tb, bounds);
                    return;
                }
                newBounds.Width = val;
            }
            else if (tb == _heightTextBox)
            {
                if (val == 0)
                {
                    ResetBoundsValue(tb, bounds);
                    return;
                }
                newBounds.Height = val;
            }

            // Make sure the new bounds does not go outside the page
            LeadRect pageBounds = new LeadRect(0, 0, _ocrPage.Width, _ocrPage.Height);

            if (!pageBounds.Contains(newBounds))
            {
                ResetBoundsValue(tb, bounds);
                return;
            }

            // Valid value, update the bounds
            zone.Bounds = newBounds;
            CurrentZone = zone;
            OcrZoneCell[] cells = null;
            cells = _zones.GetZoneCells(_zones[(int)_tvZonesList.SelectedNode.Tag]);

            if (_zones[(int)_tvZonesList.SelectedNode.Tag].ZoneType == OcrZoneType.Table &&
                cells != null &&
                _oldValue != val)
            {
                _tvZonesList.SelectedNode.Nodes.Clear();
                _viewerControl.ClearZoneCells((int)_tvZonesList.SelectedNode.Tag);
            }
        }