Re: Storing PDF selection

2008-05-17 Thread Laurent Cerveau

On May 16, 2008, at 9:40 PM, John Calhoun wrote:

On May 15, 2008, at 11:43 PM, Laurent Cerveau wrote:
If I have a PDF View , select part of it and get the  
currentSelection, showing it tells something like

Page index = 2, Range = (0, 21]

However I do not see where I could get the range of the  
PDFSelection and later recreate a selection with this value


Not the range, but you can get the bounds for each page the  
selection covers:  -[PDFSelection boundsForPage: (PDFPage *) page].


To unflatten you can call [PDFPage selectionForRect:] for each  
partial selection you saved off.  Selections can be added then  
[PDFSelection addSelection: (PDFSelection *) selection].


Yeah, a little hacky


Indeed this is and it fails. When I call
PDFSelection *aSel = [aPage selectionForRect:aRec];
the PDFKit returns me empty selection

More to dig ...

Many Thanks

laurent

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Storing PDF selection

2008-05-17 Thread Antonio Nunes

On May 17, 2008, at 2:02 PM, Laurent Cerveau wrote:


On May 16, 2008, at 9:11 AM, Antonio Nunes wrote:



You ask the page for a selection for the range you provide, and  
assign that to PDFView's current selection:
			[somePDFView setCurrentSelection:[yourRememberedPage  
selectionForRange:yourRememberedRange]];


Selections can span multiple pages of course, so covering that  
requires a bit more work, but it's not difficult.



But the problem here  is to get the yourRememberedRange. Access to  
it does not seem to exist on a PDFSelection. As John Calhoun  
suggested in another email I tried with rect but this fails also.


I would suggest you try to verify why John's suggestion fails, as one  
would expect it to work. Alternatively try this:


Untested:
1. Ask for the bounds of the selection
2. Get the string of the selection
3. Get the string of the page
4. Use rangeOfString:options:range: on the page-string to search for  
the selection-string (or you can use an NSScanner, but I think this is  
simpler)
5. If you get a match you have a range. Use it to call  
selectionForRange: on the page
6. If the bounds of the returned selection match the bounds returned  
in step 1 you've found your range. If not continue searching the page- 
string until you find the match.


I guess we should file a bug requesting PDFSelections be able to  
return their rangeForPage: and also their rangeForDocument or  
similarly named method that would yield the range within the full text  
of the document.


António

---
And could you keep your heart in wonder
at the daily miracles of your life,
your pain would not seem less wondrous
than your joy.

--Kahlil Gibran
---



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Storing PDF selection

2008-05-17 Thread Laurent Cerveau

On May 17, 2008, at 6:57 PM, Antonio Nunes wrote:

I would suggest you try to verify why John's suggestion fails, as  
one would expect it to work. Alternatively try this:


Untested:
1. Ask for the bounds of the selection
2. Get the string of the selection
3. Get the string of the page
4. Use rangeOfString:options:range: on the page-string to search for  
the selection-string (or you can use an NSScanner, but I think this  
is simpler)
5. If you get a match you have a range. Use it to call  
selectionForRange: on the page
6. If the bounds of the returned selection match the bounds returned  
in step 1 you've found your range. If not continue searching the  
page-string until you find the match.




I have not tested this yes but after a few test found out that using  
directly rect returned by [PDFSelection boundsForPage: ()] is not  
possible. However first going through NSIntegralRect on the result of  
[PDFSelection boundsForPage: ()]  leads to correct behavior. To me  
this looks like an inconsistency in the API and I will enter a bug



I guess we should file a bug requesting PDFSelections be able to  
return their rangeForPage: and also their rangeForDocument or  
similarly named method that would yield the range within the full  
text of the document.


Will do.

Thanks

laurent
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Storing PDF selection

2008-05-16 Thread Antonio Nunes

On May 16, 2008, at 7:43 AM, Laurent Cerveau wrote:

If I have a PDF View , select part of it and get the  
currentSelection, showing it tells something like

Page index = 2, Range = (0, 21]

However I do not see where I could get the range of the PDFSelection  
and later recreate a selection with this value


You ask the page for a selection for the range you provide, and assign  
that to PDFView's current selection:
			[somePDFView setCurrentSelection:[yourRememberedPage  
selectionForRange:yourRememberedRange]];


Selections can span multiple pages of course, so covering that  
requires a bit more work, but it's not difficult.


António


---
Touch is a language without words
---




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Storing PDF selection

2008-05-16 Thread John Calhoun


On May 15, 2008, at 11:43 PM, Laurent Cerveau wrote:
If I have a PDF View , select part of it and get the  
currentSelection, showing it tells something like

Page index = 2, Range = (0, 21]

However I do not see where I could get the range of the PDFSelection  
and later recreate a selection with this value


Not the range, but you can get the bounds for each page the selection  
covers:  -[PDFSelection boundsForPage: (PDFPage *) page].


To unflatten you can call [PDFPage selectionForRect:] for each  
partial selection you saved off.  Selections can be added then  
[PDFSelection addSelection: (PDFSelection *) selection].


Yeah, a little hacky

John Calhoun—___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]