pageHeights ignores new line properties in fields?

David Epstein dfepstein at comcast.net
Sat Jan 18 12:35:09 EST 2014


Thanks to Jan Schenkel for the confirmation and suggestion.   
Unfortunately, when I tried to script my own pageHeights function  
using formattedHeight, I discovered that formattedHeight also gives  
inaccurate results when paragraph properties have been set.  I have  
reported both of these problems as bug #11688.

The scripts below attempt to adjust for these inaccuracies, insofar  
as I have been able to understand them.  I am sure I have not  
accounted for all cases, so amendments are welcome.

The first function reports the scroll values that will put each  
complete paragraph (except the first) at the top of the field.
The second function is more directly comparable to the "pageHeights"  
function, but it reports cumulative scroll values rather than the  
height of each individual page.

function paragraphBottoms fid
   -- report the values of scroll of field id fid that will put the  
top of a full paragraph at the top of the field
   -- returns a return delimited list.  Each line reports  
hScrollValue,adjuster
   -- hScrollValue is a cumulative total, unlike the pageHeights  
function, which reports height of each page
   -- adjuster is the LC-reported value less the true value
   repeat with n = 1 to the number of lines in fld id fid
     add the spaceAbove of line n of fld id fid to a
     if n > 1 then
       add 2 * the padding of line n-1 of fld id fid to a
       add 2 * the borderwidth of line n-1 of fld id fid to a
       add the spaceBelow of line n-1 of fld id fid to a
     end if
     get the formattedHeight of line 1 to n of fld id fid
     put it-a & comma & a & return after myList
   end repeat
   return myList
end paragraphBottoms

function lineBottoms fid
   -- a return delimited list of hScroll values that will show field  
id fid's
   -- content as consecutive "pages", each of which begins with a  
line (could
   -- be the wrapped continuation of a paragraph).
   -- Reports a cumulative total, unlike the pageHeights function,  
which reports height of each page

   put the height of fld id fid - 2 * (the borderWidth of fld id fid  
+ (the margins of fld id fid) - 8) into tgtH
   put tgtH into h -- cumulative height target, increments as we go
   put paragraphBottoms(fid) into pbList
   repeat with p = 1 to the number of lines in pbList
     if item 1 of line p of pbList < h then next repeat
     -- Now work backwards from the bottom of para p, looking for the  
first
     -- visible line bottom < h
     put length(line 1 to p of fld id fid) into c
     put 2+length(line 1 to p-1 of fld id fid) into b
     put empty into s
     put item 2 of line p of pbList into a -- adjustment needed from  
what LC reports as formattedHeight of para 1 to this para
     add the borderWidth of line p of fld id fid to a
     add the padding of line p of fld id fid to a
     -- for chars in all but the last line of a bordered or padded  
para, this further adjustment seems necessary
     repeat with x = c down to b
       get the formattedHeight of char 1 to x of fld id fid
       if it - a < h then
         put it-a into s
         put s & return after newList
         exit repeat
       end if
     end repeat
     if s is empty then
       if p > 1 then
         get (item 1 of line p-1 of pbList)
         if it is not line -1 of newList then
           put it into s
         else put h into s
       else put h into s
       -- i.e., if line is taller than h, accept a value that breaks  
across the line
       put s & return after newList
       put s+tgtH into h
     end if
   end repeat
   return newList
end lineBottoms




More information about the use-livecode mailing list