Re: Does anyone know how to get PIXEL locations of text in a field?

Steve Pothier (starnet!apple!aries.saic.com!pothiers)
Fri, 30 Sep 94 13:55:45 MST

>
>
> I want to set the tabstops of a field based upon some text in the
> field ("edit tab stops"). Its driving me crazy just trying to GUESS
> where the tabs should be set to make my table look right.

There are two types of solutions I can think of. The first would be
to create a UI which would make it easy to set the position of the tab
stops. The basic idea would be to put a button someplace that would
wait until you clicked someplace, then compute which field you clicked
in, then compute what the offset from the left edge of the field was.
Set the tabStops property of the field to this coordinate and you've
got a bare-bones version of the ruler found in most GUI word
processors.

The second solution would be to try to compute the positions
automatically. By putting the text of each "cell" in your table into
a field and then getting the formattedWidth of the field, you could
compute the maximum space used by the "cells" in each column which
would be used to set the tabStops property.
Scott

Thanks. Since its too hard to deal with interior allignment problems
on other fonts, I use courier. This also allowed me to use a
modification of your second solution. I created a function called
"tab_stops" that takes a field name and a list of COLUMN WIDTHS. I
give the column widths in terms of characters. The script puts a
single character in a dummy field and uses formattedWidth of a single
character in the commutations of pixel positions.

Thanks,
-sp-