PageRanges

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, LCMark

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

PageRanges

Post by Janschenkel » Wed May 15, 2013 9:36 am

Hi All,

Back in January 2012, there was a request by Hugh Senior on the livecode-dev mailing list for 'pageChars' and 'pageChunks' field properties to complement the 'pageHeights' property. I seconded that request, but the RunRev team couldn't fit it in the schedule. But now that LiveCode is open source, I can do it for us all instead :-)

Perhaps some clarification is in order for those who haven't a clue what this is about...

Fields have a property 'pageHeights' which helps to determine the page breaks when printing the field over multiple pages, taking into account the fixed line height property and the height of the individual blocks of text within the field.
Its output is a return-delimited list of integers.
Example:

Code: Select all

168
340
280
Unfortunately, it is difficult to map these onto the character offsets.
Therefore I'd like to add a 'pageRanges' property which maps these page breaks onto the exact character offsets.
Its output would be a return-and-comma delimited list of integers, where each line gives the offset of the first and last characters of the page.
Example:

Code: Select all

1,80
81,168
169,200
This would allow for a nice way to extract the individual pages:

Code: Select all

function getPageHtmlText pSourceField, pPage
  get line pPage of the pageRanges of fld pSourceField
  put item 1 of it into tStartChar
  put item 2 of it into tEndChar
  return the htmlText of char tStartChar to tEndChar of fld pSourceField
end getPageHtmlText
Last week I took a stab at it, and with the help of the RunRev staff at the conference, I now have a working version.
So what's the next step to contribute this back?

Should I file an entry at quality.runrev.com first?
Or just issue a pull request for the team? :-)

TIA,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1209
Joined: Thu Apr 11, 2013 11:27 am

Re: PageRanges

Post by LCMark » Wed May 15, 2013 10:35 am

Just send a pull request to the runrev repo and it will be put in the queue for integration :)

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Re: PageRanges

Post by Janschenkel » Wed May 15, 2013 3:06 pm

Pull request submitted :-)

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany
Contact:

Re: PageRanges

Post by malte » Wed May 15, 2013 3:38 pm

Where is the like button?

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Re: PageRanges

Post by BvG » Wed May 15, 2013 4:10 pm

Quick, report Malte, he's a bot!
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: PageRanges

Post by monte » Wed May 15, 2013 9:53 pm

Cool feature Jan. It will definitely come in handy!
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Re: PageRanges

Post by Janschenkel » Thu May 23, 2013 6:04 pm

Update: it's been accepted and merged into the 'develop' branch so will be available in the next major version...

Cheers,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: PageRanges

Post by mwieder » Tue May 28, 2013 8:04 pm

@Jan- this is great! I just pasted 5k of text into a field and the pageRanges gives me a nice list. But the name...
I think I'd like to see "pageChars" instead of "pageRanges", to allow for "pageLines" as well. I can currently get this with

Code: Select all

put empty into tPageLines
put the pageRanges of field 1 into tRanges
repeat for each line tLine in tRanges
  put item 1 of tLine into tStartChar
  put item 2 of tLine into tEndChar
  put the number of lines in char 1 to tStartChar of field 1 into tStartLine
  put the number of lines in char 1 to tEndChar of field 1 into tEndLine
  put tStartLine,tEndLine & cr after tPageLines
end repeat
so there's a workaround, but it's awkward. It would be nice to say

Code: Select all

put the pageChars of field 1 into tPageChars
put the pageLines of field 1 into tPageLines

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: PageRanges

Post by trevordevore » Tue May 28, 2013 8:14 pm

Mark,

put the lineIndex of char X of field Y

lineIndex and charIindex were added in 5.5 DP1. They convert line/char references back and forth.

--
Trevor DeVore
Blue Mango Learning Systems
www.clarify-it.com - www.screensteps.com
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: PageRanges

Post by mwieder » Tue May 28, 2013 8:31 pm

@Trevor- thanks, I missed that in the release notes. Still would like pageLines and pageChars, though.

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Re: PageRanges

Post by Janschenkel » Tue May 28, 2013 8:39 pm

@mwieder
PageRanges was sufficient for my goals, Mark - but if you want to expand on its ideas, you now have a good place to start from ;-)

Cheers,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: PageRanges

Post by mwieder » Tue May 28, 2013 8:42 pm

@Jan- Dang. I was hoping to make you do all the work. :-P

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1209
Joined: Thu Apr 11, 2013 11:27 am

Re: PageRanges

Post by LCMark » Wed May 29, 2013 10:23 am

I think the 'pageRanges' property is pretty balanced both in terms of name and in terms of function. The name 'pageChars' doesn't really fit because it's a list of char ranges and not char indices, and 'pageLines' doesn't make a great deal of sense in terms of what the action is because you can't actual get an accurate list of line indices which should be used to paginate - remember that pagination takes into account soft line-breaks. i.e. The formatted list of lines is distinct from the list of lines.

Update: Although perhaps it should be 'pageCharRanges'...

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Re: PageRanges

Post by Janschenkel » Wed May 29, 2013 8:58 pm

I pondered the property name for a while before I coded it; originally I had thought of 'pageChunks' but that would have implied that the output would have been something along the lines of

Code: Select all

char 1 to 490
char 491 to 587
char 588 to 675
but that looked awkward and difficult to use further on.
Another option that crossed my mind was 'pageOffsets' with an output along the lines of

Code: Select all

1
491
588
but that would have been equally difficult to use further on.
Eventually I settled for 'pageRanges' instead of 'pageCharRanges' as I didn't think we'd need 'pageItemRanges' or 'pageWordRanges'

That's my story and I'm sticking to it ;-)

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1209
Joined: Thu Apr 11, 2013 11:27 am

Re: PageRanges

Post by LCMark » Thu May 30, 2013 11:28 am

@Janschenkel: I'll retract my musing on 'pageCharRanges' - after all we have 'flaggedRanges' - which are char ranges (which I remembered yesterday afternoon whilst investigating a bug Trevor reported) :)

Locked

Return to “Engine Contributors”