Re: PDFKit: translate point coordinates from view coordinates into page coordinates
Re: PDFKit: translate point coordinates from view coordinates into page coordinates
- Subject: Re: PDFKit: translate point coordinates from view coordinates into page coordinates
- From: Alvaro Costa Neto <email@hidden>
- Date: Tue, 27 Mar 2012 09:05:00 -0300
Hey Nick, how are you?
Try to use the PDFView's convertPoint/Rect:to/fromPage: methods <http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/QuartzFramework/Classes/PDFView_Class/Reference/Reference.html>. The trick is to always remember to use a common ground (the PDFView itself in this case) before converting to/from page coordinates. I don't know if the convert methods take scale factor into account, but I believe they do.
Best regards,
Alvaro Costa Neto
Em 27/03/2012, às 08:19, Nick escreveu:
> Hello
>
> I would like to place a PDFAnnotation onto a PDF page in a place where
> the user clicked with the mouse.
> Position for PDFAnnotations is specified using "page coordinates".
> Mouse position - using global coordinates, which can be translated
> into PDFView coordinates. However, I can't figure out how to translate
> view coordinates into page coordinates correctly. Here's what I am
> doing:
>
> NSPoint locationInView = [self convertPoint:[theEvent
> locationInWindow] fromView:[[self window] contentView]];
> NSPoint locationOnPage = [self convertPoint:locationInView fromView:self];
> float scaleFactor = 1/[self scaleFactor];
> locationOnPage = NSMakePoint((locationOnPage.x)*scaleFactor,
> (locationOnPage.y)*scaleFactor);
>
> This locationOnPage contains correct values (i.e., the annotation is
> placed where the mouse button was clicked) only if the zooming was
> 100%, and view boundaries exactly matched page boundaries (as shown on
> the picture: http://rghost.net/37251215/image.png).
> However, if the page is zoomed in/out, and does not exactly occupy the
> whole PDFView space (http://rghost.net/37251118/image.png) I do not
> get right coordinates: when I click in the bottom left corner of the
> PDFView, i see annotation appear in the bottom left corner of the
> page, which is not even on the page..
>
> How could I do this right?
> All I need is the page origin position on the view, but there's no
> such a method, as it seems..
>
> Thank you
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden