Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!mit-eddie!media-lab!simsong From: simsong@daily-bugle.media.mit.edu (Simson L. Garfinkel) Newsgroups: comp.sys.next Subject: finding line breaks in a Text object Message-ID: <4803@media-lab.MEDIA.MIT.EDU> Date: 10 Jan 91 20:36:51 GMT Sender: news@media-lab.MEDIA.MIT.EDU Lines: 66 For the news reader, I had to be able to find the line breaks inside a Text object. If you use the NeXT methods that return character offsets by lines, you actually get paragraphs, not lines. If you want to get the *real* line breaks, the ones that are displayed on the screen, then you have to decode the internal variable "theBreaks." It took me about 2 hours to figure out how to do that, and I'm posting the code here in case anybody else needs to do the similar thing: /* This piece of code shows how to get line break information out of * a Text object. * * (C) 1990 MIT Media Lab. By Simson L. Garfinkel */ #import "Thing.h" #import #import #import #import @implementation Thing - calc:sender { Text *text = [myScroller docView]; int line; int pos; NXBreakArray *theBreaks=0; int nbreaks; NXLineDesc *breaks; int length = [text textLength]; object_getInstanceVariable(text,"theBreaks",(void **)&theBreaks); nbreaks = theBreaks->chunk.used; breaks = theBreaks->breaks; for(pos=0,line=0;line