Multicolumn Printing (Text Flow)

depstein at att.net depstein at att.net
Wed Nov 17 11:35:35 CST 2004


I like Cubist's binary search idea, but I recall that when I originally stepped through the text by "word" rather than by "char" I was stymied by the fact that a quoted series of words is understood as a single word, even though a proper page break could fall within that series.  I assume a binary search by char would work.  Thanks.

David Epstein

> sez depstein at att.net: 
> >Here's another approach to the text overflow calculation: 
> Nice idea, but do you really need to test every character in sequence? I 
> was under the impression that Rev doesn't believe in hyphenation, so you could 
> speed up this handler by testing words rather than characters; a further 
> speedup could be gained by starting with the entire field (what if the text 
> doesn't 
> actually overflow?) and doing a binary search. With that in mind, here's my 
> modified version of your handler ('ware the line wraps!)... 
function ExtraText2 FldName
-- removes from fld FldName, and returns, the htmlText that overflows size of 
fld FldName
  put (the number of words in fld FldName) into WordKount
  put max (WordKount div 2, 1) into DerDelta
  put the height of fld FldName into DerHeight

  put the formattedHeight of word 1 to WordKount of fld FldName into 
CurrentHeight
  if CurrentHeight <= DerHeight then return "" -- no overflow, right?

  -- now comes the binary search
  put WordKount into HiEnd
  put CurrentHeight into MaxH
  put DerDelta into LoEnd
  put the formattedHeight of word 1 to LoEnd of fld Fldname into MinH

  repeat
    put max (DerDelta div 2, 1) into DerDelta
    if MinH > DerHeight then -- even the minimum is too long
      put LoEnd into HiEnd
      put MinH into MaxH
      subtract DerDelta from LoEnd
      put the formattedHeight of word 1 to LoEnd of fld Fldname into MinH
    else if MinH = DerHeight then -- *just* right!
      return the htmlText of word (LoEnd + 1) to -1 of fld FldName
    else -- the minimum is too small
      if MaxH - MinH = 1 then -- we've discovered the overflow point
        return the htmlText of word (LoEnd + 1) to -1 of fld FldName
      end if
      add DerDelta to LoEnd
    end if
    put the formattedHeight of word 1 to LoEnd of fld Fldname into MinH
  end repeat
end extraText2


More information about the use-livecode mailing list