[comp.sys.mac.programmer] wrapping text

lim@iris.ucdavis.edu (Lloyd Lim) (08/16/89)

Here's a couple things I haven't figured out to do cleanly.

How would you determine the smallest sized square that you could fit a piece
of text in?  The text should wrap when possible without breaking words.  The
best I've been able to think of is to start with a square that is the same
size as the length of the largest word and keep increasing the size of the
square until it fits.

How would you format a piece of text inside a circle?  Would you just place
the text inside a square that fits in the circle for simplicity (but wasting
some of the circle's area)?  Or would you place each line in its own text
box (for lack of a better term)?  PICT compatibility is necessary so I have
to use solutions that will transport to other apps too.

Any suggestions?  Thanks.

+++
Lloyd Lim     Internet: lim@iris.ucdavis.edu (128.120.57.20)
              Compuserve: 72647,660
              US Mail: 146 Lysle Leach Hall, U.C. Davis, Davis, CA 95616

oster@dewey.soe.berkeley.edu (David Phillip Oster) (08/16/89)

In article <5127@ucdavis.ucdavis.edu> lim@iris.ucdavis.edu (Lloyd Lim) writes:
>How would you determine the smallest sized square that you could fit a piece
>of text in?
	A first guess: The area the text will take, at a minimum is the
(fontInfo.ascent+fontInfo.descent+fontInfo.leading) * 
TextWidth(PtrToText, 0, LengthOfText); Therefore, any square that contains
the text must have at least that as its area, therefore, the minimum side
will be the sqrt() of the above number. So, a good first guess is 1+sqrt()
of the above. You can tell if your guess is correct by measuring the text
with the destRect set to your guess.
	A fast way to measure text is to put it in a TEHandle and do a
TECalText(). For old TEs, the length will be
(**te).nLines*(**te).lineHeight  For TEHandles that contain multiple
fonts, you'll have to sum the line height array.
	You can tell TextEdit to take care of the justifcation for you, so
both the right and left margins will be on the square's boundary.

>How would you format a piece of text inside a circle?
The same argument about minumum area also applies here.  Unfortunately,
you won't be able to use TextEdit to do the measuring for you. You will
also need to manage the lineStarts, the lineEnds, and the scaling of
spacing to get the justification right yourself, instead of just letting
TextEdit do it.  Since anything you write wil eventually bottom out on
operating system calls like DrawText() to actually draw the text, you
dont' need to worry about being compatible with PICT format. Just put your
drawing call between an OpenPicture() and a ClosePicture() and it will
make a PICT for you.
--- David Phillip Oster      7 line signature follows
Keith Sproul, head of microcomputer support at Union Carbide, NJ, complained
about the poorly digitized fellatio on an IBM porno program. "Mac is better
on everything, and this is no execption."  -- "Computer Porn at the Office"
by Reese Erlich, _This_World_, S.F. Chronicle, p.8, Aug 13, 1989

Arpa: oster@dewey.soe.berkeley.edu
Uucp: {uwvax,decvax}!ucbvax!oster%dewey.soe.berkeley.edu