Flow/wrap text into an irregular shape

Thierry Douez th.douez at gmail.com
Sun Dec 29 11:25:20 EST 2013


Hi Roger,

Here is a quick-and-dirty first attempt.

The char version makes a perfect regular triangle,
the word version works but could probably have to be tuned a bit more..
And I'm using measureText(..) available in LC 6.5.
Feel free to ask anything or I can even send my stack if you prefer.


local Nlines = 19
local Wbase, Sc, theText

on viewtext
   put fld "Fsource" into theText
   put the width of fld "Fview" into Wbase
   set the width of fld "Ftmp" to Wbase
   -- width average of a char
   put measureText(char 1 to 100 of theText,fld "Ftmp")/100 into Sc

   repeat with aLine = 1 to Nlines
      put getString( W( aLine)) into line aLine of fld "Fview"
   end repeat
end viewtext

function W n
   -- length of line n in View Field
   return (Nlines-n+1)*Wbase div Nlines
end W


function getString _width -- char version
   local n
   local flag = false
   set the width of fld "Ftmp" to _width
   -- how many chars fit in (rough estimation)
   put trunc(_width/Sc) into n
   repeat forever
      if _width <  measureText( char 1 to n of theText,fld "Ftmp") then
         subtract 1 from n
         put true into flag
      else
         if flag then exit repeat
         else add 1 to n
      end if
   end repeat
   get char 1 to n of theText
   delete char 1 to n of thetext
   return IT
end getString


function getString _width -- word version
   local n, str
   local flag = false
   set the width of fld "Ftmp" to _width
   -- how many words fit in (rough estimation)
   put char 1 to trunc(_width/Sc)  of theText into str
   put -1 + the number of words of str into n
   repeat forever
      if _width <  measureText( word 1 to n of theText,fld "Ftmp") then
         subtract 1 from n
         put true into flag
      else
         if flag then exit repeat
         else add 1 to n
      end if
   end repeat
   get word 1 to n of theText
   delete word 1 to n of thetext
   return IT
end getString


Happy new year!

Thierry


2013/12/27 Roger Eller <roger.e.eller at sealedair.com>:
>  Imagine a multi-line text field which overlays a triangle polygon, which
> is wide at the top, and comes to a point at the bottom.  I want the text to
> detect the edges of the triangle and wrap at those edges.  The result would
> be a triangle shaped body of text (centered).  My question to you is "How
> can this be achieved?"



------------------------------------------------
Thierry Douez - http://sunny-tdz.com
Maker of sunnYpdf - sunnYperl - sunnYmidi - sunnYmage




More information about the Use-livecode mailing list