Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!dewey.soe.berkeley.edu!oster From: oster@dewey.soe.berkeley.edu (David Phillip Oster) Newsgroups: comp.sys.mac.programmer Subject: Re: wrapping text Message-ID: <30670@ucbvax.BERKELEY.EDU> Date: 16 Aug 89 03:04:38 GMT References: <5127@ucdavis.ucdavis.edu> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: oster@dewey.soe.berkeley.edu.UUCP (David Phillip Oster) Distribution: usa Organization: School of Education, UC-Berkeley Lines: 35 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