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);
        }
Exemplo n.º 2
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);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void _rasterImageViewer_MouseDown(object sender, MouseEventArgs e)
        {
            PointF physical = new PointF(e.X, e.Y);
            PointF pixels;

            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);

            pixels = trans.PointToLogical(physical);


            Point bookmarkPosition = new Point((int)pixels.X, (int)pixels.Y);

            if (pixels.X < 0)
            {
                bookmarkPosition.X = 0;
            }
            if (pixels.X > _rasterImageViewer.Image.Width)
            {
                bookmarkPosition.X = _rasterImageViewer.Image.Width;
            }

            if (pixels.Y < 0)
            {
                bookmarkPosition.Y = 0;
            }
            if (pixels.Y > _rasterImageViewer.Image.Height)
            {
                bookmarkPosition.Y = _rasterImageViewer.Image.Height;
            }

            DoAction("UpdateBookmarkPosition", bookmarkPosition);
        }
Exemplo n.º 4
0
        private void _rasterImageViewer_MouseMove(object sender, MouseEventArgs e)
        {
            string str;

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

                PointF physical = new PointF(e.X, e.Y);
                PointF pixels;

                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);
                pixels = trans.PointToLogical(physical);

                // Convert the logical point to inches
                LeadPointD inches = Automation.Container.Mapper.PointFromContainerCoordinates(LeadPointD.Create((int)pixels.X, (int)pixels.Y), AnnFixedStateOperations.Scrolling | AnnFixedStateOperations.Zooming);

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

            _mousePositionLabel.Text = str;
        }
Exemplo n.º 5
0
        private void AddMagicWand(LeadPoint MagicWandPoint)
        {
            ImageViewer imageViewer = this.ImageViewer;

            LeadMatrix  MyMatrix = imageViewer.ImageTransform;
            Transformer t        = new Transformer(new System.Drawing.Drawing2D.Matrix((float)MyMatrix.M11, (float)MyMatrix.M12, (float)MyMatrix.M21, (float)MyMatrix.M22, (float)MyMatrix.OffsetX, (float)MyMatrix.OffsetY));

            LeadPoint pt = MagicWandPoint;

            pt = imageViewer.Image.PointToImage(RasterViewPerspective.TopLeft, pt);

            PointF ptF = t.PointToLogical(new PointF(pt.X, pt.Y));

            RasterColor lowerColor = new RasterColor(Threshold, Threshold, Threshold);
            RasterColor upperColor = new RasterColor(Threshold, Threshold, Threshold);

            if (((int)ptF.X > imageViewer.Image.Width) || ((int)ptF.Y > imageViewer.Image.Height))
            {
                return;
            }
            else
            {
                if (((int)ptF.X > 0) && ((int)ptF.Y > 0))
                {
                    imageViewer.Image.AddMagicWandToRegion((int)ptF.X, (int)ptF.Y, lowerColor, upperColor, RasterRegionCombineMode.Set);
                    imageViewer.ActiveItem.ImageRegionToFloater();
                    imageViewer.Image.SetRegion(null, null, RasterRegionCombineMode.Set);
                }
            }
        }
Exemplo n.º 6
0
        bool IsScaleInRange(LeadMatrix matrix)
        {
            double scaleX = Math.Sqrt(Math.Pow(matrix.M11, 2) + Math.Pow(matrix.M12, 2));
            double scaleY = Math.Sqrt(Math.Pow(matrix.M21, 2) + Math.Pow(matrix.M22, 2));

            return(scaleX < 50 && scaleY < 50);
        }
Exemplo n.º 7
0
        private void DrawHighlightObjects(Graphics g, HighlightObjectsData data, PDFDocumentPage page)
        {
            LeadMatrix  mm    = _rasterImageViewer.GetImageTransformWithDpi(true);
            Matrix      m     = new Matrix((float)mm.M11, (float)mm.M12, (float)mm.M21, (float)mm.M22, (float)mm.OffsetX, (float)mm.OffsetY);
            Transformer trans = new Transformer(m);

            // Clip to the current image bounds
            RectangleF clipRect = new RectangleF(0, 0, _rasterImageViewer.Image.ImageWidth, _rasterImageViewer.Image.ImageHeight);

            clipRect = trans.RectangleToPhysical(clipRect);
            g.SetClip(clipRect);

            // Draw objects
            if (page.Objects != null)
            {
                foreach (PDFObject obj in page.Objects)
                {
                    RectangleF rc = ToRectangleF(page.ConvertRect(PDFCoordinateType.Pdf, PDFCoordinateType.Pixel, obj.Bounds));
                    rc = trans.RectangleToPhysical(rc);

                    // Highlight it
                    Brush brush;

                    if (obj.ObjectType == PDFObjectType.Image)
                    {
                        brush = data.ImageBrush;
                    }
                    else if (obj.ObjectType == PDFObjectType.Rectangle)
                    {
                        brush = data.RetangleBrush;
                    }
                    else
                    {
                        brush = data.TextBrush;
                    }

                    DrawRectangle(g, brush, rc);
                }
            }

            // Draw internal and hyper links
            foreach (PageLink link in _pageLinks)
            {
                RectangleF rc = trans.RectangleToPhysical(new RectangleF(link.ImageBounds.X, link.ImageBounds.Y, link.ImageBounds.Width, link.ImageBounds.Height));

                Brush brush;
                if (link.InternalLinkIndex != -1)
                {
                    brush = data.InternalLinkBrush;
                }
                else
                {
                    brush = data.HyperlinkBrush;
                }

                DrawRectangle(g, brush, rc);
            }
        }
Exemplo n.º 8
0
        public static Matrix Convert(LeadMatrix matrix)
        {
            if (matrix.IsIdentity)
            {
                return(new Matrix());
            }

            return(new Matrix((float)matrix.M11, (float)matrix.M12, (float)matrix.M21, (float)matrix.M22, (float)matrix.OffsetX, (float)matrix.OffsetY));
        }
Exemplo n.º 9
0
        private void _imageViewer_TransformChanged(object sender, EventArgs e)
        {
            if (!DesignMode && IsHandleCreated)
            {
                _viewerTransform = _imageViewer.ViewTransform;

                UpdateZoomValueFromControl();
                UpdateUIState();
                UpdateRulers();
            }
        }
Exemplo n.º 10
0
        private LeadPoint PhysicalToLogical(LeadPoint physical)
        {
            PointF      pixelsF = new PointF(physical.X, physical.Y);
            LeadMatrix  mm      = _rasterImageViewer.GetImageTransformWithDpi(true);
            Matrix      m       = new Matrix((float)mm.M11, (float)mm.M12, (float)mm.M21, (float)mm.M22, (float)mm.OffsetX, (float)mm.OffsetY);
            Transformer trans   = new Transformer(m);

            pixelsF = trans.PointToLogical(pixelsF);

            Point pixels = Point.Round(pixelsF);

            return(new LeadPoint(pixels.X, pixels.Y));
        }
Exemplo n.º 11
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();
            }
        }
Exemplo n.º 12
0
        private Action <EventArgs> OnFocusAction(LeadRect bounds)
        {
            return((e) =>
            {
                if (bounds.IsEmpty)
                {
                    _selectedSectionBounds = bounds;
                    return;
                }

                UpdateCarouselViewState(false);
#if __IOS__
                if (e.GetType() == typeof(FocusEventArgs))
                {
                    _page.ContentLayoutGrid.RowDefinitions[0].Height = new GridLength(PlatformsConstants.PagesHeaderTitleRowHeight, GridUnitType.Absolute);
                    _page.ContentLayoutGrid.RowDefinitions[1].Height = new GridLength(1.3, GridUnitType.Star);
                    _page.ContentLayoutGrid.RowDefinitions[2].Height = new GridLength(1, GridUnitType.Auto);
                    _page.ContentLayoutGrid.RowDefinitions[3].Height = new GridLength(8.7, GridUnitType.Star);
                }
#endif // #if __IOS__

                if (_contact.FocusDisabled)
                {
                    return;
                }
                else
                {
                    // The Entry field has the focus, then resize the main grid rows to make space for the keyboard
                    if (_page.ImageViewer != null)
                    {
                        _imageViewer.Zoom(ControlSizeMode.None, 1.0, _imageViewer.DefaultZoomOrigin);
                    }
                }

                _overlay.IsVisible = true;

                // Save the last selected BC section/field in order to layout the overlay box inside the TransformChanged event of the ImageViewer control
                _selectedSectionBounds = bounds;

                if (_page.ImageViewer != null)
                {
                    LeadMatrix transform = _imageViewer.GetImageTransformWithDpi(true);
                    var boundsD = transform.TransformRect(bounds.ToLeadRectD());

                    boundsD.Inflate(30, 30);
                    _imageViewer.ZoomToRect(boundsD);
                }
            });
        }
Exemplo n.º 13
0
        private void HighlightSelectedWords(Graphics g)
        {
            MyWord[] words = _selectedText[_currentPageNumber];

            // Highlight the selected words
            using (Brush brush = new SolidBrush(Color.FromArgb(128, SystemColors.Highlight)))
            {
                LeadMatrix  mm    = _rasterImageViewer.GetImageTransformWithDpi(true);
                Matrix      m     = new Matrix((float)mm.M11, (float)mm.M12, (float)mm.M21, (float)mm.M22, (float)mm.OffsetX, (float)mm.OffsetY);
                Transformer trans = new Transformer(m);

                // Clip to the current image bounds
                RectangleF clipRect = new RectangleF(0, 0, _rasterImageViewer.Image.ImageWidth, _rasterImageViewer.Image.ImageHeight);
                clipRect = trans.RectangleToPhysical(clipRect);
                g.SetClip(clipRect);

                LeadRect lineBounds = LeadRect.Empty;

                foreach (MyWord word in words)
                {
                    // Get the word boundaries
                    if (lineBounds.IsEmpty)
                    {
                        lineBounds = word.Bounds;
                    }
                    else
                    {
                        lineBounds = LeadRect.Union(lineBounds, word.Bounds);
                    }

                    if (word.IsEndOfLine)
                    {
                        // Highlight this line
                        HighlightLine(g, trans, brush, lineBounds);
                        lineBounds = LeadRect.Empty;
                    }
                }

                if (!lineBounds.IsEmpty)
                {
                    HighlightLine(g, trans, brush, lineBounds);
                }
            }
        }
Exemplo n.º 14
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();
            }
        }
Exemplo n.º 15
0
        private void AddMagicWand(LeadPoint MagicWandPoint)
        {
            ImageViewer imageViewer = this.ImageViewer;

            LeadMatrix  MyMatrix = imageViewer.ImageTransform;
            Transformer t        = new Transformer(new System.Drawing.Drawing2D.Matrix((float)MyMatrix.M11, (float)MyMatrix.M12, (float)MyMatrix.M21, (float)MyMatrix.M22, (float)MyMatrix.OffsetX, (float)MyMatrix.OffsetY));

            LeadPoint pt = MagicWandPoint;

            pt = imageViewer.Image.PointToImage(RasterViewPerspective.TopLeft, pt);

            PointF ptF = t.PointToLogical(new PointF(pt.X, pt.Y));

            RasterColor lowerColor = new RasterColor(255, 255, 255);
            RasterColor upperColor = new RasterColor(0, 0, 0);

            byte[] RegionData = RasterRegionConverter.GetGdiRegionData(ImageViewer.Image, null);

            if (((int)ptF.X > ImageViewer.Image.Width) || ((int)ptF.Y > ImageViewer.Image.Height))
            {
                return;
            }
            else
            if (((int)ptF.X > 0) && ((int)ptF.Y > 0))
            {
                if (RegionData == null)
                {
                    ImageViewer.Image.AddMagicWandToRegion((int)ptF.X, (int)ptF.Y, lowerColor, upperColor, RasterRegionCombineMode.Set);
                }
                else if ((RegionData.Length == 32) && (MagicWandRegionCombineMode == RasterRegionCombineMode.And))
                {
                    ImageViewer.Image.AddMagicWandToRegion((int)ptF.X, (int)ptF.Y, lowerColor, upperColor, RasterRegionCombineMode.Set);
                }
                else
                {
                    ImageViewer.Image.AddMagicWandToRegion((int)ptF.X, (int)ptF.Y, lowerColor, upperColor, MagicWandRegionCombineMode);
                }
            }
        }
Exemplo n.º 16
0
        private void DrawHighlightImageObject(Graphics g, Brush imageBrush, PDFDocumentPage page)
        {
            LeadMatrix  mm    = _rasterImageViewer.GetImageTransformWithDpi(true);
            Matrix      m     = new Matrix((float)mm.M11, (float)mm.M12, (float)mm.M21, (float)mm.M22, (float)mm.OffsetX, (float)mm.OffsetY);
            Transformer trans = new Transformer(m);

            // Clip to the current image bounds
            RectangleF clipRect = new RectangleF(0, 0, _rasterImageViewer.Image.ImageWidth, _rasterImageViewer.Image.ImageHeight);

            clipRect = trans.RectangleToPhysical(clipRect);
            g.SetClip(clipRect);

            // Draw image object
            RectangleF rc = ToRectangleF(page.ConvertRect(PDFCoordinateType.Pdf, PDFCoordinateType.Pixel, _selectedPdfImageObject.Bounds));

            if (!rc.IsEmpty)
            {
                rc = trans.RectangleToPhysical(rc);

                // Highlight it
                DrawRectangle(g, imageBrush, rc);
            }
        }
Exemplo n.º 17
0
        void RectangleInteractiveMode_RubberBandCompleted(object sender, ImageViewerRubberBandEventArgs e)
        {
            Rectangle pixels = new Rectangle(e.InteractiveEventArgs.Origin.X, e.InteractiveEventArgs.Origin.Y, e.InteractiveEventArgs.Position.X - e.InteractiveEventArgs.Origin.X, e.InteractiveEventArgs.Position.Y - e.InteractiveEventArgs.Origin.Y);

            if (pixels.Left > pixels.Right)
            {
                pixels = Rectangle.FromLTRB(pixels.Right, pixels.Top, pixels.Left, pixels.Bottom);
            }
            if (pixels.Top > pixels.Bottom)
            {
                pixels = Rectangle.FromLTRB(pixels.Left, pixels.Bottom, pixels.Right, pixels.Top);
            }

            if (pixels.Width > 2 && pixels.Height > 2)
            {
                RectangleF pixelsF = pixels;


                LeadMatrix  mm    = _rasterImageViewer.GetImageTransformWithDpi(true);
                Matrix      m     = new Matrix((float)mm.M11, (float)mm.M12, (float)mm.M21, (float)mm.M22, (float)mm.OffsetX, (float)mm.OffsetY);
                Transformer trans = new Transformer(m);
                pixelsF = trans.RectangleToLogical(pixelsF);


                pixelsF = RectangleF.Intersect(new RectangleF(0, 0, _rasterImageViewer.Image.ImageWidth, _rasterImageViewer.Image.ImageHeight), pixelsF);
                pixels  = Rectangle.Round(pixelsF);

                LeadRect bounds = new LeadRect(pixels.X, pixels.Y, pixels.Width, pixels.Height);
                BeginInvoke(new DoActionDelegate(DoAction), new object[] { "HighlightText", bounds });
            }

            // Go back to selection mode
            // We must invoke this because the select button will change the
            // interactive mode of the viewer and hence, cancel the current
            // operation
            BeginInvoke(new MethodInvoker(DoSelectMode));
        }
Exemplo n.º 18
0
        private static void DrawBounds(Graphics graphics, Pen pen, Brush brush, Brush textBrush, Font font, string text, LeadRectD bounds, LeadMatrix transform)
        {
            var corners = Tools.GetCornerPoints(bounds);

            transform.TransformPoints(corners);
            var cornersBounds = Tools.GetBoundingRect(corners);

            var cornersF = new PointF[4];

            for (var i = 0; i < cornersF.Length; i++)
            {
                // if any point empty, then return
                if (corners[i].IsEmpty)
                {
                    return;
                }

                cornersF[i] = new PointF((float)corners[i].X, (float)corners[i].Y);
            }

            if (pen != null)
            {
                graphics.DrawPolygon(pen, cornersF);
            }
            if (brush != null)
            {
                graphics.FillPolygon(brush, cornersF);
            }
            if (text != null && textBrush != null)
            {
                graphics.DrawString(text, font, textBrush, (float)cornersBounds.X, (float)cornersBounds.Y);
            }
        }
Exemplo n.º 19
0
 public static Matrix ToMatrix(LeadMatrix leadMatrix)
 {
     return(new Matrix((float)leadMatrix.M11, (float)leadMatrix.M12, (float)leadMatrix.M21, (float)leadMatrix.M22, (float)leadMatrix.OffsetX, (float)leadMatrix.OffsetY));
 }
Exemplo n.º 20
0
 private Matrix ToMatrix(LeadMatrix LMatrix)
 {
     return(new Matrix((float)LMatrix.M11, (float)LMatrix.M12, (float)LMatrix.M21, (float)LMatrix.M22, (float)LMatrix.OffsetX, (float)LMatrix.OffsetY));
 }
Exemplo n.º 21
0
        void _viewer_Panning(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                return;
            }

            var dx = e.X - _currentPoint.X;
            var dy = e.Y - _currentPoint.Y;

            if (dx != 0 || dy != 0)
            {
                var transform = LeadMatrix.Identity;

                bool zoom   = (Control.ModifierKeys & Keys.Control) == Keys.Control;
                bool rotate = (Control.ModifierKeys & Keys.Alt) == Keys.Alt;

                if (zoom)
                {
                    if (dy != 0)
                    {
                        var factor = 1.0 - ((dy * 4.0) / _viewer.ClientSize.Height);
                        factor = factor < 0 ? -factor : factor;
                        var center = _currentPoint.ToLeadPointD();

                        if (_transformAtCenterToolStripMenuItem.Checked)
                        {
                            center = new LeadPointD(_viewer.ImageSize.Width / 2, _viewer.ImageSize.Height / 2);
                            center = _viewer.ConvertPoint(Viewer.CoordinateType.Image, Viewer.CoordinateType.Control, center);
                        }

                        transform.ScaleAt(factor, factor, center.X, center.Y);
                    }
                }
                else if (rotate)
                {
                    if (dx != 0)
                    {
                        const double rotateAngle = 5.0;
                        var          center      = _currentPoint.ToLeadPointD();

                        if (_transformAtCenterToolStripMenuItem.Checked)
                        {
                            center = new LeadPointD(_viewer.ImageSize.Width / 2, _viewer.ImageSize.Height / 2);
                            center = _viewer.ConvertPoint(Viewer.CoordinateType.Image, Viewer.CoordinateType.Control, center);
                        }

                        transform.RotateAt(dx > 0 ? rotateAngle : -rotateAngle, center.X, center.Y);
                    }
                }
                else
                {
                    if (dx != 0 || dy != 0)
                    {
                        transform.Translate(dx, dy);
                    }
                }

                transform = LeadMatrix.Multiply(_viewer.Transform, transform);
                if (IsScaleInRange(transform))
                {
                    _viewer.Transform = transform;
                }
            }

            _currentPoint = new LeadPoint(e.X, e.Y);
        }
Exemplo n.º 22
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);
            }
        }
Exemplo n.º 23
0
 private Matrix GetMatrixFromLeadMatrix(LeadMatrix matrix)
 {
     return(new Matrix((float)matrix.M11, (float)matrix.M12, (float)matrix.M21, (float)matrix.M22, (float)matrix.OffsetX, (float)matrix.OffsetY));
 }
Exemplo n.º 24
0
        public override void Render(AnnContainerMapper mapper, AnnObject annObject)
        {
            if (mapper == null)
            {
                ExceptionHelper.ArgumentNullException("mapper");
            }
            if (annObject == null)
            {
                ExceptionHelper.ArgumentNullException("annObject");
            }

            base.Render(mapper, annObject);
            AnnRichTextObject annRichTextObject = annObject as AnnRichTextObject;

            if (annRichTextObject != null && !String.IsNullOrEmpty(annRichTextObject.Rtf))
            {
                AnnWinFormsRenderingEngine engine = RenderingEngine as AnnWinFormsRenderingEngine;
                if (engine != null && engine.Context != null)
                {
                    AnnRectangleObject tempRect = new AnnRectangleObject();
                    tempRect.Points.Clear();
                    foreach (LeadPointD pt in GetRenderPoints(mapper, annRichTextObject))
                    {
                        tempRect.Points.Add(pt);
                    }

                    double rotation = tempRect.Angle;
                    if (rotation == 180)
                    {
                        rotation = 0;
                    }

                    LeadRectD          boundsPixels   = tempRect.Rect.Clone();
                    AnnContainerMapper identityMapper = mapper.Clone();
                    identityMapper.UpdateTransform(LeadMatrix.Identity);
                    identityMapper.MapResolutions(mapper.SourceDpiX, mapper.SourceDpiY, mapper.SourceDpiX, mapper.SourceDpiY);
                    boundsPixels = identityMapper.RectFromContainerCoordinates(boundsPixels, annRichTextObject.FixedStateOperations);
                    if (tempRect.Stroke != null)
                    {
                        boundsPixels.Inflate(-tempRect.Stroke.StrokeThickness.Value, -tempRect.Stroke.StrokeThickness.Value);
                    }

                    string rtf = annRichTextObject.Rtf;
                    IntPtr hemfDC;
                    if (_richTextBox == null)
                    {
                        _richTextBox = new InternalRichTextEdit();
                    }

                    try
                    {
                        _richTextBox.Rtf = rtf;
                    }
                    catch
                    {
                        using (RichTextBox richTextBox = new RichTextBox())
                        {
                            richTextBox.Text      = rtf;
                            annRichTextObject.Rtf = richTextBox.Rtf;
                            _richTextBox.Rtf      = richTextBox.Rtf;
                        }
                    }

                    Graphics graphics = engine.Context;
                    double   dpiX     = 96;
                    double   dpiY     = 96;

                    _richTextBox.Location = new Point((int)boundsPixels.Location.X, (int)boundsPixels.Location.Y);
                    _richTextBox.Size     = new Size((int)boundsPixels.Size.Width, (int)boundsPixels.Size.Height);
                    IntPtr hdc = graphics.GetHdc();

                    Win32.RECT rc = new Win32.RECT();

                    rc.left   = _richTextBox.ClientRectangle.Left;
                    rc.top    = _richTextBox.ClientRectangle.Top;
                    rc.right  = (int)boundsPixels.Width;
                    rc.bottom = (int)boundsPixels.Height;

                    int iWidthMM    = SafeNativeMethods.GetDeviceCaps(hdc, Win32.HORZSIZE);
                    int iHeightMM   = SafeNativeMethods.GetDeviceCaps(hdc, Win32.VERTSIZE);
                    int iWidthPels  = SafeNativeMethods.GetDeviceCaps(hdc, Win32.HORZRES);
                    int iHeightPels = SafeNativeMethods.GetDeviceCaps(hdc, Win32.VERTRES);

                    rc.left   = (rc.left * iWidthMM * 100) / iWidthPels;
                    rc.top    = (rc.top * iHeightMM * 100) / iHeightPels;
                    rc.right  = (rc.right * iWidthMM * 100) / iWidthPels;
                    rc.bottom = (rc.bottom * iHeightMM * 100) / iHeightPels;

                    hemfDC = SafeNativeMethods.CreateEnhMetaFile(hdc, null, ref rc, null);

                    Win32.RECT emfRect = new Win32.RECT();
                    emfRect.right  = (int)boundsPixels.Width;
                    emfRect.bottom = (int)boundsPixels.Height;

                    IntPtr brush = SafeNativeMethods.GetStockObject(5);
                    SafeNativeMethods.SetBkMode(hemfDC, 1);
                    SafeNativeMethods.FillRect(hemfDC, ref emfRect, brush);
                    SafeNativeMethods.DeleteObject(brush);

                    Print(_richTextBox, _richTextBox.ClientRectangle, hemfDC, (int)dpiX, (int)dpiY, false);
                    IntPtr hemf = SafeNativeMethods.CloseEnhMetaFile(hemfDC);

                    using (Metafile metaFile = new Metafile(hemf, true))
                    {
                        graphics.ReleaseHdc();
                        GraphicsState state = graphics.Save();

                        //the mapper transform dosent contain dpi effect so we will add dpi effect .
                        LeadMatrix matrix = mapper.Transform;
                        //add dpi effect to the transform
                        matrix.Scale((float)(mapper.TargetDpiX / mapper.SourceDpiX), (float)(mapper.TargetDpiY / mapper.SourceDpiY));

                        if ((annRichTextObject.FixedStateOperations & AnnFixedStateOperations.Scrolling) == AnnFixedStateOperations.Scrolling)
                        {
                            matrix.Translate(-matrix.OffsetX, -matrix.OffsetY);
                        }

                        if ((annRichTextObject.FixedStateOperations & AnnFixedStateOperations.Zooming) == AnnFixedStateOperations.Zooming)
                        {
                            double offsetX = matrix.OffsetX;
                            double offsetY = matrix.OffsetY;
                            double scaleX  = 1.0;
                            double scaleY  = 1.0;
                            if (matrix.M11 != 0 && matrix.M22 != 0)
                            {
                                scaleX = 1.0 / Math.Abs(matrix.M11);
                                scaleY = 1.0 / Math.Abs(matrix.M22);
                            }

                            matrix.Scale(scaleX, scaleY);
                        }

                        using (Matrix transform = new Matrix((float)matrix.M11, (float)matrix.M12, (float)matrix.M21, (float)matrix.M22, (float)matrix.OffsetX, (float)matrix.OffsetY))
                        {
                            graphics.MultiplyTransform(transform);
                            graphics.DrawImage(metaFile, new Point((int)boundsPixels.Left, (int)boundsPixels.Top));
                        }
                        graphics.Restore(state);
                    }
                }

                //EndDraw(graphics, gState);
            }
        }