/**
         * Creates rich text box while editing FreeText annotation.
         */
        private void CreateRichTextBox()
        {
            if (!docView.EditPermission)
            {
                return;
            }

            AnnotationProperties props = docView.ActiveProps;

            Datalogics.PDFL.Rect rect    = props.BoundingRect;
            Datalogics.PDFL.Rect newRect = Utils.Transform(rect, docView.GetPagePdfToWinCoordMatrix(docView.EditPage));

            textBox = new RichTextBox();
            docView.Controls.Add(textBox);
            textBox.Bounds       = new Rectangle((int)newRect.LLx, (int)newRect.LLy, (int)newRect.Width, (int)newRect.Height);
            textBox.Text         = props.Contents;
            textBox.BorderStyle  = BorderStyle.None;
            textBox.TextChanged += new EventHandler(TextBoxTextChanged);
            textBox.Leave       += new EventHandler(TextBoxLeaveHandler);
            textBox.KeyDown     += new KeyEventHandler(TextBoxKeyDownHandler);
            props.Update        += UpdateRichTextBox;
            textBox.Visible      = true;
            textBox.Focus();

            UpdateRichTextBox(false);
        }
        public override void MouseDown(MouseEventArgs e, System.Drawing.Point location)
        {
            if (!docView.EditPermission)
            {
                return;
            }
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            int pageNum = docView.GetPageByCoord(location);

            if (!captured && pageNum == -1)
            {
                return;
            }

            if (!captured) // first click, start point
            {
                captured     = true;
                capturedPage = pageNum;

                // create initial rectangle
                Datalogics.PDFL.Point pdfPoint = docView.ViewToPdf(location, capturedPage);
                Datalogics.PDFL.Rect  rect     = new Datalogics.PDFL.Rect(pdfPoint.H - 1, pdfPoint.V - 1, pdfPoint.H, pdfPoint.V);

                properties.BoundingRect = rect;
                BaseAnnotationEditor editor = docView.CreateAnnotation(pageNum, properties);

                capturedGuide = editor.Guides[2]; // guide: bottom-right corner of rectangle
                docView.Invalidate();
            }
        }
Esempio n. 3
0
 // creates quad by given rect
 public static Datalogics.PDFL.Quad Quad(Datalogics.PDFL.Rect rect)
 {
     return(new Quad(
                new Datalogics.PDFL.Point(rect.LLx, rect.URy),
                new Datalogics.PDFL.Point(rect.URx, rect.URy),
                new Datalogics.PDFL.Point(rect.LLx, rect.LLy),
                new Datalogics.PDFL.Point(rect.URx, rect.LLy)));
 }
Esempio n. 4
0
        public static Datalogics.PDFL.Rect Transform(Datalogics.PDFL.Rect rect, Datalogics.PDFL.Matrix matrix)
        {
            Datalogics.PDFL.Point lowerLeft  = new Datalogics.PDFL.Point(rect.LLx, rect.LLy);
            Datalogics.PDFL.Point upperRight = new Datalogics.PDFL.Point(rect.URx, rect.URy);
            lowerLeft  = Transform(lowerLeft, matrix);
            upperRight = Transform(upperRight, matrix);

            Datalogics.PDFL.Rect result = new Datalogics.PDFL.Rect(lowerLeft.H, lowerLeft.V, upperRight.H, upperRight.V);

            return(result);
        }
        public override void MouseDown(MouseEventArgs e, System.Drawing.Point location)
        {
            if (!docView.EditPermission)
            {
                return;
            }
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            int pageNum = docView.GetPageByCoord(location);

            if (!captured && pageNum == -1)
            {
                return;
            }

            if (!captured) // first click, add start & end points, stick end-point to cursor
            {
                captured     = true;
                capturedPage = pageNum;

                // create 2 initial points
                pointCount = 2;

                IList <Datalogics.PDFL.Point> vertices = new List <Datalogics.PDFL.Point>();
                Datalogics.PDFL.Point         pdfPoint = docView.ViewToPdf(location, capturedPage);
                vertices.Add(pdfPoint);
                vertices.Add(pdfPoint); // end point is equal to start point

                Datalogics.PDFL.Rect rect = new Datalogics.PDFL.Rect(pdfPoint.H, pdfPoint.V, pdfPoint.H, pdfPoint.V);

                properties.BoundingRect = rect;
                properties.Vertices     = vertices;
                BaseAnnotationEditor editor = docView.CreateAnnotation(pageNum, properties);
                capturedGuide = editor.Guides[9]; // endpoint guide
                docView.Invalidate();
            }
            else // every next click - add new point
            {
                Datalogics.PDFL.Point newVertex = docView.ViewToPdf(location, capturedPage);
                ++pointCount;
                Page page = docView.Document.GetPage(capturedPage);
                BaseAnnotationEditor          editor   = docView.ActiveAnnotation;
                IList <Datalogics.PDFL.Point> vertices = editor.Properties.Vertices;
                vertices.Add(newVertex);
                editor.Properties.Vertices = vertices;
                capturedGuide = editor.Guides[8 + pointCount - 1];
                docView.Invalidate();
            }
        }
        /**
         * Searches for annotation using given location.
         * Location - pixel coordinate in view, including scroll offsets.
         * Index - index of last annotation found, to increase performance,
         * and for prioritized annotation selection
         * (it means that even if point belongs to several annotations, the one with given index will be chosen)
         */
        private int FindAnnotation(Datalogics.PDFL.Point location, int index)
        {
            Dictionary <int, BaseAnnotationEditor> editors = docView.EditAnnotations;

            if (editors == null)
            {
                return(-1);
            }
            if (editors.ContainsKey(index) && (editors[index].TestHit(location).flags != HitFlags.NoHit))
            {
                return(index);
            }

            bool   firstHit         = true;
            double distance         = 0;
            int    nearestAnnoIndex = -1;

            foreach (BaseAnnotationEditor editor in editors.Values)
            {
                if ((editor.Index == index) || (editor.TestHit(location).flags == HitFlags.NoHit))
                {
                    continue;
                }

                Datalogics.PDFL.Rect  rect   = editor.Properties.BoundingRect;
                Datalogics.PDFL.Point center = new Datalogics.PDFL.Point((rect.Left + rect.Right) / 2, (rect.Top + rect.Bottom) / 2);
                double d = (center.H - location.H) * (center.H - location.H) + (center.V - location.V) * (center.V - location.V);
                if (firstHit)
                {
                    distance         = d;
                    firstHit         = false;
                    nearestAnnoIndex = editor.Index;
                }
                else if (d < distance)
                {
                    distance         = d;
                    nearestAnnoIndex = editor.Index;
                }
            }
            return(nearestAnnoIndex);
        }
        public override void MouseDown(MouseEventArgs e, System.Drawing.Point location)
        {
            int pageNum = docView.GetPageByCoord(location);

            if (!captured && pageNum == -1)
            {
                return;
            }
            if (!captured)
            {
                captured     = true;
                capturedPage = pageNum;
                Datalogics.PDFL.Point pdfPoint = docView.ViewToPdf(location, pageNum);
                Datalogics.PDFL.Rect  rect     = new Datalogics.PDFL.Rect(pdfPoint.H - 1, pdfPoint.V - 1, pdfPoint.H, pdfPoint.V);

                properties.BoundingRect = rect;
                BaseAnnotationEditor editor = docView.CreateAnnotation(pageNum, properties);

                capturedGuide = editor.Guides[2]; // guide: bottom-right corner of rectangle
                docView.Invalidate();
            }
            done = true;
        }
        public override void MouseDown(MouseEventArgs e, System.Drawing.Point location)
        {
            if (!docView.EditPermission)
            {
                return;
            }
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            int pageNum = docView.GetPageByCoord(location);

            if (!captured && pageNum == -1)
            {
                return;
            }

            if (!captured) // first click, put start point, stick endpoint to cursor
            {
                captured     = true;
                capturedPage = pageNum;

                Datalogics.PDFL.Point pdfStartPoint = docView.ViewToPdf(location, pageNum);
                Datalogics.PDFL.Point pdfEndPoint   = new Point(pdfStartPoint.H + 1, pdfStartPoint.V + 1);
                Datalogics.PDFL.Rect  rect          = new Datalogics.PDFL.Rect(pdfStartPoint.H, pdfStartPoint.V, pdfEndPoint.H, pdfEndPoint.V);

                properties.BoundingRect = rect;
                properties.StartPoint   = pdfStartPoint;
                properties.EndPoint     = pdfEndPoint;
                BaseAnnotationEditor editor = docView.CreateAnnotation(pageNum, properties);

                capturedGuide = editor.Guides[1]; // endpoint guide
                docView.Invalidate();
            }
        }