home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / next / programm / 7275 < prev    next >
Encoding:
Text File  |  1992-11-18  |  1.5 KB  |  44 lines

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