Re: text selection for pdfview
Re: text selection for pdfview
- Subject: Re: text selection for pdfview
- From: "David Chan" <email@hidden>
- Date: Tue, 26 Dec 2006 14:41:21 +0800
Thanks for the suggestions, everyone. I had tried John's suggestion
and the problem with that approach is that the addSelection function
did not remove the overlapping part. So both the initial incomplete
word and the newly added complete word are inside the selection. There
seems to be hope though heh. I will try to see if I can do something
about it efficiently.
Thanks..
Regards,
David
On 12/22/06, John Calhoun <email@hidden> wrote:
On Dec 21, 2006, at 1:27 AM, David Chan wrote:
I am currently using pdfview and I am trying to emulate the function
in adobe acrobat where user can drag a rectangle over the text and
have all the text inside the rect selected. I tried to use
selectionForRect function to get the pdfselection.
However, I notice that this function will only select the part of the
words that is inside the rect. If my rect only cover the part "sam"
from the word "sample", then only "sam" will be selected. This is
different from adobe's behavior where the whole word will be selected
as long as one of its character is inside the rect.
Yeah, it would be gross....
One way to do it though would be to:
• Start with your -[selectionForRect] since that would get everything bounded by the rect.
• But then (here's the gross part) you would want to walk the edges of the rectangle. You need only walk the leading and trailing edges of the rect (top and bottom are not interesting). I think a rotated pages will give you grief though since leading and trailing edge of the rect will get mapped around I think. In any event, start for example at the top right of the rect. Call -[PDFPage selectionfOrWordAtPoint:] and add that selection to your starting selection (you can add selections).
• Now all hope is not lost. You need not go down a single pixel. You can get the bounds of the recent [PDFPage selectionfOrWordAtPoint:] selection and move down to the bottom of that selection. Call -[PDFPage selectionfOrWordAtPoint:] as before and add result to initial selection as well.
• Repeat until you have extended off the bottom of the rect.
• Then repeat for other edge of rect.
• And be prepared to get back NULL from [PDFPage selectionfOrWordAtPoint:]. In that case, you may want to move down a few pixels at a time and try again....
So, it isn't pretty. Perhaps a future PDFKit can give you: - [PDFPage selectionForRect: includeWholeWords:]
john calhoun—
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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