Peter Reid wrote:
> I'm trying to display information as pseudo tables in text field
> using MC2.3.1 on both Mac and Win.
>
> I have created field with a set of tabStops and the horizontal and
> vertical grid liens are displayed. The text in the field is in Arial
> 12pt, plain, say. What I'm trying to do is write a function that
> will truncate a chunk of text such that it is guaranteed to fit
> inside the available pixel width in any given column.
>
> I need such a function as I want to be sure that any arbitrary text
> placed in a column will not overflow and cause content in the columns
> to the right to overflow.
A script can't use the textheight to determine the width of a string.
Even with monspaced fonts, there is no relationship between the width of
the character letters and the textsize, and even worse, the textsize
will vary from font to font, and from platform to platform. Luckily
MetaCard has a "formattedwidth" property that lets the script determine
the actual width of a string in pixels.
This seems to work:
on insertItem theText, theField, theCol
put "1," & the tabstops of fld theField & comma & the width of fld
theField into theTabStops
put (item theCol+1 of theTabStops) - (item theCol of theTabStops) into thePixelWidth
set itemdelimiter to tab
repeat for each char i in theText
put i after temp
put temp into item theCol of fld theField
select item theCol of fld theField
if the formattedwidth of the selectedchunk >= thePixelWidth-10 then
-- 10 pixels for a margin; adjust
delete last char of item theCol of fld theField
exit repeat
end if
end repeat
end insertItem
This script assumes that the field has no tab stops that extend past its
right edge. If it does, you'll have to change the way the last column's
width is calculated. You'll also probably want to lock the screen while
this runs.
--
Jacqueline Landman Gay | [EMAIL PROTECTED]
HyperActive Software | [EMAIL PROTECTED]
Custom hypermedia solutions | http://www.hyperactivesw.com
612.724.1596 | 612.724.1562 - fax
Archives: http://www.mail-archive.com/metacard%40lists.best.com/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.