ee163ahe@sdcc13.UUCP (VICTOR ROMANO) (04/20/85)
S I am trying to impliment tabs in a TextEdit window, similar to the Consulair's Edit program. I don't know exactly how to do it, but I have tried using SetStdProcs to change the standard text measuring and text drawing routines for that window. The following is my section of code (in MegaMax C): #define TABSTOP 100 /* In units of pixels, not char widths */ mystdtxmeas (info, denom, numer, textbuf, bytecount) /* Parameters are normally reversed in MegaMax C */ reg char *textbuf; point *numer, *denom; finfo *finfo; reg int bytecount; { reg int size; reg char *s; size = theport->pnloc.a.h; /* Actually, the pen location isn't always right, but I have a way to make it so. */ s = textbuf; /* We start at beginning of buffer */ /* Scan each character in buffer for tabs */ while (bytecount--) { /* If tab occurs, bring to next tabstop */ if (*textbuf++ == '\t') { /* <<< */ size += stdtxmeas(info, denom, numer, s, textbuf-s-1) + TABSTOP+1; size -= size % TABSTOP + 1; s = textbuf; /* >>> */ } } size += stdtxmeas(info, denom, numer, s, textbuf-s) - theport->pnloc.a.h; return (size); /* Returning is really a little more involved in MegaMax. This isn't the problem. */ } Of course, then I make the qdprocs pointer txmeas in theport point to this procedure. This works great, EXCEPT, that it is very slow. I looked at the code, and it looked very optimal. I even hand-optimized it, and it is STILL slow. To test the speed of the division, I replace the lines between <<< and >>> with: size += stdtxmeas(info, denom, numer, s, textbuf-s); This simulates the normal stdtxmeas, but without tabstops, and it is STILL slow. Then, I replaced the "if" statement with if(0) and it became fast. It told me that calling stdtxmeas several times slows it down considerable, even though I am still measuring the size of each character only once. What can I do, then, to speed up this whole operation? Obviously, Consulair did it, so it must be possible. Maybe there is a better way to begin with? Incidently, I disassembled some of the code in ROM's stdtxmeas, and it looks like there is a lot of setting up of things before any measuring of text begins. I think this is what is slowing everything down -- my way causes this initialization to occur repetitively. Is there perhaps a way to bypass the initializing routines? Incidently, I have a fast working version that only works for fixed fonts. This was easy because I don't have to call stdtxmeas at all. But I need to do all this with proportional fonts as well. Thanks very much for any help anyone can give. Victor Romano