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(); } }
public override void MouseDown(MouseEventArgs e, System.Drawing.Point location) { int pageNum = docView.GetPageByCoord(location); if (pageNum == -1) { return; } captured = true; capturedPage = pageNum; Datalogics.PDFL.Point startPoint = docView.ViewToPdf(location, pageNum); Datalogics.PDFL.Rect rect = new Rect(startPoint.H, startPoint.V, startPoint.H + 1, startPoint.V + 1); Quad[] quads = new Quad[] { Utils.Quad(rect) }; // quad list cannot be empty, TODO: don't create annotation in this case properties.BoundingRect = rect; properties.Quads = quads; BaseAnnotationEditor editor = docView.CreateAnnotation(pageNum, properties); if (editor.Annotation is HighlightAnnotation) { editor.Properties.ForeColor = System.Drawing.Color.Yellow; } capturedGuide = editor.Guides[1]; // endpoint guide }
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 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); }
public void linkAnnProp_FormClosed(object sender, EventArgs e) { if (linkAnnProp.DialogResult == DialogResult.OK) { string fitMode = "XYZ"; double zoom = 0; location = new System.Drawing.Point(docView.Scroll.X, docView.Scroll.Y); Datalogics.PDFL.Point destPoint = docView.ViewToPdf(location, docView.CurrentPage); if (linkAnnProp.IsCustom) { if (docView.CurrentFit == FitModes.FitPage || docView.CurrentFit == FitModes.FitWidth) { fitMode = docView.CurrentFit == FitModes.FitPage ? "Fit" : "FitH"; zoom = ViewDestination.NullValue; destRect = new Rect(ViewDestination.NullValue, ViewDestination.NullValue, ViewDestination.NullValue, docView.CurrentFit == FitModes.FitWidth && linkAnnProp.IsPosition ? destPoint.V : ViewDestination.NullValue); } else { zoom = linkAnnProp.IsZoom ? docView.Zoom : ViewDestination.NullValue; destRect = new Rect(linkAnnProp.IsPosition ? destPoint.H : ViewDestination.NullValue, ViewDestination.NullValue, ViewDestination.NullValue, linkAnnProp.IsPosition ? destPoint.V : ViewDestination.NullValue); } } else { fitMode = "FitR"; Rectangle bRect = docView.PageInfo[docView.CurrentPage].boundingRectangle; Rectangle pRect = new Rectangle(docView.Scroll, docView.Size); pRect.Intersect(bRect); Datalogics.PDFL.Point LeftBottom = new Datalogics.PDFL.Point(); Datalogics.PDFL.Point RightTop = new Datalogics.PDFL.Point(); System.Drawing.Point leftBottom = new System.Drawing.Point(pRect.Left, pRect.Bottom); System.Drawing.Point rightTop = new System.Drawing.Point(pRect.Right, pRect.Top); LeftBottom = docView.ViewToPdf(leftBottom, docView.CurrentPage); RightTop = docView.ViewToPdf(rightTop, docView.CurrentPage); destRect = new Rect(LeftBottom.H, LeftBottom.V, RightTop.H, RightTop.V); } int pageNum = docView.EditPage; if (pageNum != -1) { ViewDestination viewDestination = new ViewDestination(docView.Document, docView.CurrentPage, fitMode, destRect, zoom); Rect rc = viewDestination.DestRect; //docView.ActiveAnnotation.Properties.Action = new GoToAction(viewDestination); docView.ActiveAnnotation.Properties.ActionData = new ActionData(viewDestination); docView.Scroll = oldScroll; docView.RequestZoom(new ZoomEventArgs(oldZoom, oldFit)); captured = false; } } docView.FunctionMode = ApplicationFunctionMode.AnnotationEditMode; }
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(); } }
private Rect TransformRectByPageParam(Rect rect, Datalogics.PDFL.Point scale) { Matrix tMatrix = new Matrix(); double xShift = rect.LLx + rect.Width / 2.0; double yShift = rect.LLy + rect.Height / 2.0; double xShiftModified = xShift * scale.H; double yShiftModified = yShift * scale.V; tMatrix = (IsPageSideWays()) ? tMatrix.Translate(yShiftModified, xShiftModified) : tMatrix.Translate(xShiftModified, yShiftModified); tMatrix = tMatrix.Rotate(RotateAngle).Scale(scale.H, -scale.V); tMatrix = tMatrix.Translate(-xShift, -yShift); return(rect.Transform(tMatrix)); }
public void Load(Document doc, Page page, Datalogics.PDFL.Point scale, OptionalContentContext occ) { Clear(); SetPageParam(doc, page, scale, occ); Tile fullPage = Create(CropRect); if (fullPage.IsValid) { fullBitmap = fullPage.TileBitmap; } else { tiles[0, 0] = Create(tiles[0, 0].TileRect); } }
public void SetPageParam(Document doc, Page page, Datalogics.PDFL.Point scale, OptionalContentContext occ) { this.scale = scale; //this.page = page; this.doc = doc; this.pageNum = page.PageNumber; this.occ = occ; SetPageRotate(page.Rotation); Rect cropBoxScaled = TransformRectByPageParam(page.CropBox, scale); cropRect = new Rectangle(); cropRect.Width = (int)cropBoxScaled.Width; cropRect.Height = (int)cropBoxScaled.Height; TileSize = new Size(1600, 1600); CreatePageTiles(); }
/** * Transforming: move sticked guide. */ public override void MouseMove(MouseEventArgs e, System.Drawing.Point location) { if (!docView.EditPermission) { return; } SetCursor(location, captured); if (!captured) { return; } // move guide that is sticked to cursor Datalogics.PDFL.Point pdfPoint = docView.ViewToPdf(location, capturedPage); capturedGuide = docView.ActiveAnnotation.MoveGuide(capturedGuide, pdfPoint); docView.Invalidate(); }
public override void MouseMove(MouseEventArgs e, System.Drawing.Point location) { int pageNum = docView.GetPageByCoord(location); SetCursor(location, captured); if (!captured) { return; } if ((pageNum == -1) || (pageNum != capturedPage)) { return; } Datalogics.PDFL.Point pdfPoint = docView.ViewToPdf(location, docView.EditPage); scribbles[scribbles.Count - 1].Add(pdfPoint); docView.ActiveAnnotation.Properties.Scribbles = scribbles; }
/** * 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 (e.Button != MouseButtons.Left) { return; } int pageNum = docView.GetPageByCoord(location); if (pageNum == -1) { return; } Datalogics.PDFL.Point pdfPoint = docView.ViewToPdf(location, pageNum); captured = true; if (scribbles == null) // adding first scribble - need to create annotation first { capturedPage = pageNum; scribbles = new List <IList <Point> >(); properties.Scribbles = scribbles; docView.CreateAnnotation(pageNum, properties); } else { if (pageNum != capturedPage) { return; } } scribbles.Add(new List <Datalogics.PDFL.Point>()); scribbles[scribbles.Count - 1].Add(pdfPoint); docView.ActiveAnnotation.Properties.Scribbles = scribbles; }
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(); } }
// clones point public static Datalogics.PDFL.Point Clone(Datalogics.PDFL.Point p) { return(new Datalogics.PDFL.Point(p.H, p.V)); }
/** * 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; } }
/** * Mouse click handler, checks annotation's guide rect hit */ public override void MouseDown(MouseEventArgs e, System.Drawing.Point location) { bool isControlPressed = Control.ModifierKeys == Keys.Control; bool isShiftPressed = Control.ModifierKeys == Keys.Shift; if (e.Button == MouseButtons.Left) { int pageNum = docView.GetPageByCoord(location); if (pageNum != -1) { docView.EditPage = pageNum; } captured = true; capturedPoint = location; capturedGuide = null; } if (!docView.EditPermission || docView.EditPage == -1 || docView.EditAnnotations == null || docView.EditAnnotations.Count == 0) { return; } Datalogics.PDFL.Point pdfPoint = docView.ViewToPdf(location, docView.EditPage); cachedIndex = FindAnnotation(pdfPoint, cachedIndex); if (cachedIndex == -1 || isControlPressed) { /*if (docView.ActiveAnnotation != null) * { * SaveFinalState(); * CreateEditCommand(); * }*/ docView.ActiveAnnotation = null; return; } if (isShiftPressed) { docView.SelectAnnotation(docView.EditPage, cachedIndex, false); } else // no shift pressed { if ((docView.ActiveAnnotation is GroupAnnotationEditor) && (docView.ActiveAnnotation as GroupAnnotationEditor).Contains(docView.EditAnnotations[cachedIndex])) { // if we clicked on annotation that is member of group - then do nothing (save selection unchanged) } else { docView.SelectAnnotation(docView.EditPage, cachedIndex, true); } } Hit hit = docView.ActiveAnnotation.TestHit(pdfPoint); capturedGuide = hit.guide; if (capturedGuide != null) { Datalogics.PDFL.Point guideLocation = capturedGuide.Location; capturedOffset = new Datalogics.PDFL.Point(guideLocation.H - pdfPoint.H, guideLocation.V - pdfPoint.V); } }