What is up with FormattedHeight?

Scott Rossi scott at tactilemedia.com
Thu Feb 9 07:37:46 EST 2012


Hi Ken:

The following function does what you propose using a transitional image and
gets pretty close.  It requires the long id of the target field, and only
works on transparent fields.  You'd have to add additional code to convert
the non-text portion of the field to alphaData, or temporarily convert the
field to transparent and restore after capturing the text rect.


function tmTextRect pField
   lock screen
   ## CREATE IMAGE WITH ALPHADATA
   reset the templateImage
   set lineSize of the templateImage to 0
   create image
   put long id of it into tempImage
   do "export snapshot from" && pField && "to" && tempImage && "as PNG"
   put alphadata of tempImage into theAlphaData
   ## DEFINE GRID
   put width of tempImage into theColumnCount
   delete tempImage
   reset the templateImage
   unlock screen
   ## LOOP THROUGH ALPHA DATA LOOKING FOR
   ## PIXELS THAT MEET VISIBILITY THRESHOLD (> 5)
   put 1 into theRowNum
   put 0 into theColumnNum
   put 0,0,0,0 into theRect
   repeat for each char theByte in theAlphaData
      add 1 to theColumnNum
      put charToNum(theByte) into theValue
      if theValue > 5 then
         if item 1 of theRect is 0 then
            put theColumnNum into item 1 of theRect
            put theRowNum into item 2 of theRect
            put theColumnNum into item 3 of theRect
            put theRowNum into item 4 of theRect
         end if
         put min(theColumnNum, item 1 of theRect) into item 1 of theRect
         put min(theRowNum, item 2 of theRect) into item 2 of theRect
         put max(theColumnNum, item 3 of theRect) into item 3 of theRect
         put max(theRowNum, item 4 of theRect) into item 4 of theRect
      end if
      if theColumnNum = theColumnCount then
         add 1 to theRowNum
         put 0 into theColumnNum
      end if
   end repeat
   add left of pField to item 1 of theRect
   add left of pField to item 3 of theRect
   add top of pField to item 2 of theRect
   add top of pField to item 4 of theRect
   return theRect
end tmTextRect


Regards,

Scott Rossi
Creative Director
Tactile Media, UX Design





Recently, Ken Corey wrote:

> On 06/02/2012 03:30, Howard Bornstein wrote:
>> I need to find the smallest rectangle that will enclose a line of text of
>> arbitrary text size in a field. I thought I could use formattedheight and
>> formattedwidth to do this but it doesn't seem to be working.
> 
> I'm very perplexed too.
> 
> Instead of worrying about what is/is not added to the text image, fonts,
> screen smoothing, margins, whatever (itis bound to have a
> platform-specific element to it), I figured "Why not just ask the bits?"






More information about the use-livecode mailing list