Example #1
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);
        }
Example #2
0
        public static Datalogics.PDFL.Point Transform(Datalogics.PDFL.Point point, Datalogics.PDFL.Matrix matrix)
        {
            Datalogics.PDFL.Point result = new Datalogics.PDFL.Point();

            double x = point.H;
            double y = point.V;

            result.H = x * matrix.A + y * matrix.B + matrix.H;
            result.V = x * matrix.C + y * matrix.D + matrix.V;

            return(result);
        }
        /**
         * Mouse move handler, tracks a guide rect movings.
         */
        public override void MouseMove(MouseEventArgs e, System.Drawing.Point location)
        {
            // if no annotation is currently selected then just drag view like in ScrollViewMode
            if (captured && docView.ActiveAnnotation == null)
            {
                // drag page like in ScrollViewMode
                System.Drawing.Point delta = location;
                delta.X -= capturedPoint.X;
                delta.Y -= capturedPoint.Y;
                System.Drawing.Point scroll = docView.Scroll;
                scroll.X      -= delta.X;
                scroll.Y      -= delta.Y;
                docView.Scroll = scroll;
                docView.Cursor = Cursors.Default;
                return;
            }

            if (!docView.EditPermission ||
                docView.EditPage == -1 ||
                docView.EditAnnotations == null ||
                docView.EditAnnotations.Count == 0)
            {
                docView.Cursor = Cursors.Default;
                return;
            }

            // calculate pdf coordinate on the page
            Datalogics.PDFL.Point pdfPoint = docView.ViewToPdf(location, docView.EditPage);

            // left mouse button dragging: move or resize annotation
            if (e.Button == MouseButtons.Left && docView.ActiveAnnotation != null)
            {
                if (capturedGuide != null) // if guide is selected - move it
                {
                    Datalogics.PDFL.Point newGuideLocation = new Datalogics.PDFL.Point(pdfPoint.H + capturedOffset.H, pdfPoint.V + capturedOffset.V);
                    capturedGuide  = docView.MoveGuide(capturedGuide, newGuideLocation);
                    docView.Cursor = capturedGuide.CursorForRotation(docView.Document.GetPage(docView.EditPage).Rotation);
                }
                else // if no guides is selected - move the whole annotation
                {
                    if (capturedPoint.Equals(location))
                    {
                        return;
                    }
                    Datalogics.PDFL.Point  oldPdfPoint = docView.ViewToPdf(capturedPoint, docView.EditPage);
                    Datalogics.PDFL.Matrix matrix      = new Datalogics.PDFL.Matrix()
                                                         .Translate(pdfPoint.H - oldPdfPoint.H, pdfPoint.V - oldPdfPoint.V);
                    capturedPoint = location;
                    docView.TransformAnnotation(matrix);
                    docView.Cursor = Cursors.Hand;
                }
                docView.IsDocumentChanged = true;
                return;
            }

            // no left mouse button down, just process cursor
            int index = FindAnnotation(pdfPoint, cachedIndex);

            if (index == -1)
            {
                docView.HoverAnnotation = null;
                docView.Cursor          = Cursors.Default;
            }
            else // when no mouse dragging, we track annotation under cursor just to draw it's bounding rectangle
            {
                BaseAnnotationEditor anno = docView.EditAnnotations[index];
                Hit hit = anno.TestHit(pdfPoint);
                if (anno == docView.ActiveAnnotation && (hit.flags & HitFlags.GuideHit) != 0)
                {
                    docView.Cursor = hit.guide.CursorForRotation(docView.Document.GetPage(docView.EditPage).Rotation);
                }
                else if ((hit.flags & (HitFlags.BorderHit | HitFlags.RectHit)) != 0)
                {
                    docView.Cursor = Cursors.Hand;
                }
                else
                {
                    docView.Cursor = Cursors.Default;
                }
                docView.HoverAnnotation = anno;
            }
        }
        /*
         * printDocument_PrintPage -
         * Is an event handler that gets called each time a
         * page is to be printed. This handles the settings to
         * use while printing.
         */
        private void printDocument_PrintPage(object sender, PrintPageEventArgs ev)
        {
            RectangleF bounds     = ev.PageSettings.PrintableArea;
            double     currentPos = bounds.Top;

            if (singlePage)
            {
                Rect cbox;
                using (Page page = iDoc.GetPage(currentPage)) cbox = page.CropBox;

                // add to the width to correct for math errors
                double maxPageWidth  = (cbox.Right - cbox.Left + 1.0) * 100.0 / (double)GlobalConsts.pdfDPI;
                double maxPageHeight = (cbox.Top - cbox.Bottom) * 100.0 / (double)GlobalConsts.pdfDPI;

                // some print drivers are misleading about their printable area
                // corrected by doubling the reported offset from the top left corner of the physical sheet of paper
                // and make it a "buffer zone" around the print image
                maxPageWidth  += (bounds.X * 2.0);
                maxPageHeight += (bounds.Y * 2.0);

                if (shrinkToFit && (maxPageWidth > bounds.Width || maxPageHeight > bounds.Height))
                {
                    horizontalSquish = verticalSquish = bounds.Width / maxPageWidth;

                    if ((bounds.Height / maxPageHeight) < horizontalSquish)
                    {
                        horizontalSquish = verticalSquish = bounds.Height / maxPageHeight;
                    }
                }
                else
                {
                    horizontalSquish = 1.0;
                    verticalSquish   = 1.0;
                }
            }

            while (currentPos < bounds.Bottom)
            {
                using (Page p = iDoc.GetPage(currentPage))
                {
                    Rect cb = p.CropBox;

                    // Draw the page at the currentPosition here
                    double pageWidthInPDFUserUnits     = cb.Right - cb.Left + 1.0;
                    double pageHeightInPDFUserUnits    = cb.Top - cb.Bottom;
                    int    pageWidthInPrinterRezUnits  = (int)(pageWidthInPDFUserUnits * horizontalSquish * (double)ev.Graphics.DpiX / (double)GlobalConsts.pdfDPI);
                    int    pageHeightInPrinterRezUnits = (int)(pageHeightInPDFUserUnits * verticalSquish * (double)ev.Graphics.DpiY / (double)GlobalConsts.pdfDPI);

                    // DLADD dtom 10Jul2009: Set up CropBox offsets.
                    int shiftx = (int)cb.LLx;
                    int shifty = (int)cb.LLy;

                    // Invert the page to get from PDFL coordinates to .Net coordinates
                    Datalogics.PDFL.Matrix matrix = new Datalogics.PDFL.Matrix().Scale((horizontalSquish * (double)ev.Graphics.DpiX / (double)GlobalConsts.pdfDPI),
                                                                                       -(verticalSquish * (double)ev.Graphics.DpiY / (double)GlobalConsts.pdfDPI)).Translate(-shiftx, -pageHeightInPDFUserUnits - shifty);

                    Rect updateRect = new Rect(cb.LLx, cb.LLy, cb.LLx + pageWidthInPDFUserUnits, cb.LLy + pageHeightInPDFUserUnits);

                    drawParams.UpdateRect  = updateRect;
                    drawParams.SmoothFlags = SmoothFlags.Image | SmoothFlags.LineArt | SmoothFlags.Text;
                    drawParams.Flags       = DrawFlags.UseAnnotFaces;

#if DRAWWITHBITMAPS
                    drawParams.Matrix = matrix;

                    using (Bitmap bitmap = new Bitmap(pageWidthInPrinterRezUnits, pageHeightInPrinterRezUnits, ev.Graphics))
                    {
                        Graphics graphics = Graphics.FromImage(bitmap);

                        graphics.Clear(System.Drawing.Color.White);

                        p.DrawContents(bitmap, drawParams);
                        ev.Graphics.DrawImageUnscaled(bitmap, 0, (int)(currentPos - offset));
                    }
#else
                    Datalogics.PDFL.Matrix matrix2 = new Datalogics.PDFL.Matrix();
                    matrix2 = matrix2.Translate(0, (offset - currentPos) * (double)GlobalConsts.pdfDPI / 100.0);
                    matrix2 = matrix2.Concat(matrix);

                    drawParams.Matrix = matrix2;
                    p.DrawContents(ev.Graphics, drawParams);
#endif

                    currentPos += (double)pageHeightInPrinterRezUnits * 100.0 / (double)ev.Graphics.DpiX - offset;
                    offset      = 0;

                    if (++currentPage >= printerSettings.ToPage)
                    {
                        break;
                    }

                    if (singlePage)
                    {
                        break;
                    }
                }
            }

            if (notCollating && currentPos <= bounds.Bottom)
            {
                if (currentCopies < localCopies)
                {
                    currentPage--;
                    currentCopies++;
                }
                else
                {
                    currentCopies = 1;
                }
            }

            if (currentPage >= printerSettings.ToPage)
            {
                ev.HasMorePages = false;
            }
            else
            {
                ev.HasMorePages = true;
            }
        }
Example #5
0
 public static Datalogics.PDFL.Point Transform(System.Drawing.Point point, Datalogics.PDFL.Matrix matrix)
 {
     return(Transform(new Datalogics.PDFL.Point(point.X + 0.5, point.Y - 0.5), matrix));
 }