home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.next.programmer
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!spool.mu.edu!umn.edu!csus.edu!news
- From: eps@futon.SFSU.EDU (Eric P. Scott)
- Subject: Re: Determining dimensions of text object
- Message-ID: <1992Nov18.144225.28136@csus.edu>
- Sender: news@csus.edu
- Reply-To: eps@cs.sfsu.edu
- Organization: San Francisco State University
- References: <1992Nov16.080646.2606@worg.questor.wimsey.bc.ca>
- Date: Wed, 18 Nov 1992 14:42:25 GMT
- Lines: 31
-
- In article <1992Nov16.080646.2606@worg.questor.wimsey.bc.ca>
- david@worg.questor.org (David Lau) writes:
- >Suppose I want to make a text object big enough to hold m-by-n characters from
- >a fixed-width font, how do I go about determining its dimensions? I've looked
- >at the NXFontMetrics structure but the widths stored there are not expressed in
- >terms of pixel units.
-
- One way is "after the fact"--e.g., I output the text I want to
- display into a memory stream, stuff that into a resizable Text
- object, and then ask the Text object how big it is:
-
- id t;
- id fwfont; // a fixed width font
- NXStream *aStream; // stream containing text data
- NXRect br;
- // some arbitrary minimum size
- const NXRect trect={ { 0.0, 0.0 }, { 93.0, 24.0 } };
-
- t=[[Text allocFromZone:[self zone]] initFrame:&trect];
- [[[[[t
- setMonoFont:YES]
- setHorizResizable:YES]
- setVertResizable:YES]
- setNoWrap]
- setFont:fwfont];
- [[t readText:aStream] sizeToFit];
- [t getBounds:&br];
-
- br.size contains the desired information.
-
- -=EPS=-
-