What is the text of pageheights

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Jean-marc Radigois
Posts: 10
Joined: Mon Aug 26, 2013 6:49 pm

What is the text of pageheights

Post by Jean-marc Radigois » Sat Jun 08, 2019 4:26 pm

Is there a function to identify the text appearing in a field after a scroll using the pageHeights ?


Hello,
Here is my problem:
I use a field with fixedLineHeight=false. In this field the text is very long and the user can change the textSize of the words, in different locations. Now to print this text (in fact to create a pdf file) I use a repeat with the lines of the pageheights of this field. It works well for the firsts lines appearing in the top of each page, but not for the last line appearing in the page. Because of the height of each line, the last one appears truncked and some time a line appears at the bottom of a page (not very truncked) and at the top of the next page.

To solve this problem I need a function (but I don't know if existing) wich indicates what is the text appearing in a page. If I know this text I can use the formattedHeight of this text and determine if I must ajust the height of the field so the truncked line does not appear at the bottom of the field.

Without such a function, it is possible, but not very fun, to use a loop that looks like
repeat with ANumberWord =1 to the number of words of my field
if the formattedHeight of word 1 to ANumberWord of my field >the pageHeights of this page
then set the height of my field smaller
end repeat
(I can send an script if necessary)

Have you another solution ?
Thanks for all help
Jean-Marc from Nice (France)

Jean-marc Radigois
Posts: 10
Joined: Mon Aug 26, 2013 6:49 pm

Re: What is the text of pageheights

Post by Jean-marc Radigois » Mon Jun 10, 2019 2:38 pm

Since my post, I have found a way to go to a page and shorting the height of the field so it's suit to the text:

Code: Select all

on GoToPage MyField,MyMask,PageToGo
   set the rect of fld MyField to the defaultRect of fld MyField
   repeat with ll=1 to -1+PageToGo
      add line ll of the pageheights of fld MyField to TheScroll
   end repeat
   set the rect of fld MyField to item 1 to 3 of the defaultRect of fld MyField,5+the top of fld MyField+line PageToGo of the pageheights of fld MyField --3/5
   set the scroll of fld MyField to TheScroll
end GoToPage
My fundamental problem remains, how to know what is the text appearing in the field ?
Also I have write a function to do it, but this function use a loop repeat on each char from the beginning ; so it is not very speedy for a very big text. This is the function:

Code: Select all

function CharDisplayFieldChunk MyField
   put 1 into FirstChar
   repeat while the formattedHeight of char 1 to FirstChar of fld MyField<=the scroll of fld MyField
      if FirstChar>=length(fld MyField) then exit repeat
      else add 1 to FirstChar
   end repeat
   put FirstChar into LastChar
   repeat while the formattedHeight of char 1 to LastChar of fld MyField<=the scroll of fld MyField+the height of fld MyField
      if LastChar>=length(fld MyField) then exit repeat
   else add 1 to LastChar
end repeat
if LastChar<length(fld MyField) then subtract 1 from LastChar
return "char"&&FirstChar&&"to"&&LastChar&&"of field"&&MyField
end CharDisplayFieldChunk
If some body knows a better way to do this
Perhaps I try to do something existing in LC
jean-marc

Jean-marc Radigois
Posts: 10
Joined: Mon Aug 26, 2013 6:49 pm

Re: What is the text of pageheights

Post by Jean-marc Radigois » Mon Jun 10, 2019 2:43 pm

Sorry, in the function GoToPage, there is no parameter MyMask :

Code: Select all

on GoToPage MyField,PageToGo

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: What is the text of pageheights

Post by [-hh] » Mon Jun 10, 2019 3:07 pm

If I understand correctly you want to print the field (say fld "Print") to pdf, nothing else?
If so, did you already try (kind of) the following?

Code: Select all

on mouseUp
  ask file "Output to file:" with "test.pdf"
  if it is empty then exit mouseUp
  open printing to pdf it
  revprintField the name of fld "Print"
  close printing
end mouseUp
shiftLock happens

Jean-marc Radigois
Posts: 10
Joined: Mon Aug 26, 2013 6:49 pm

Re: What is the text of pageheights

Post by Jean-marc Radigois » Mon Jun 10, 2019 3:31 pm

hello hh,
Before printing I must assume that the text is correctly well done. So before printing I nead to have a field with it's rect is the printing rect. This field must present exactly the printing pages. So I can go from page to page in this field, I can change text in it so that the new pages will exactly represente the futur printing pages and so on. For this, the pageHeights function is perfect but the difficulty is to know what are the strings (from char to char) appearing visualy in the text. For more explanations, see above. I am not realy satisfy with the function CharDisplayFieldChunk I have created.

Thanks for your interest
Jean-Marc

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: What is the text of pageheights

Post by jacque » Mon Jun 10, 2019 5:02 pm

I can think of a horrible hack which is unprofessional but might work. Simulate a user selection (pseudocode):

Get the topleft of the group
Add 1 to both items
Get the bottomright of the group
Subtract 1 from both items
Click at the first loc
Click at the second loc with shiftkey
Put the selected text into a variable

It's ugly but might work, I didn't try it. If you see a flash, lock the screen.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Jean-marc Radigois
Posts: 10
Joined: Mon Aug 26, 2013 6:49 pm

Re: What is the text of pageheights

Post by Jean-marc Radigois » Mon Jun 10, 2019 5:14 pm

Hello Jaque,
Thanks for your proposal, it's a non-spontaneous idea and interesting, but I cannot use click at that will change the selection. I yet prefere my bad function CharDisplayFieldChunk.
Thanks
jean-marc

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: What is the text of pageheights

Post by jacque » Tue Jun 11, 2019 6:06 pm

You could save the selectedChunk, do the trick, then reset the selectedChunk. It's an ugly hack but I'm sure it would be faster than counting characters.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply