Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!gatech!hao!husc6!mit-eddie!genrad!decvax!ucbvax!COGSCI.BERKELEY.EDU!bryce From: bryce@COGSCI.BERKELEY.EDU.UUCP Newsgroups: comp.sys.amiga Subject: TextLength() on proportional strings (Was: Questions) Message-ID: <8706160352.AA15691@cogsci.berkeley.edu> Date: Mon, 15-Jun-87 23:52:49 EDT Article-I.D.: cogsci.8706160352.AA15691 Posted: Mon Jun 15 23:52:49 1987 Date-Received: Thu, 18-Jun-87 01:15:56 EDT Sender: daemon@ucbvax.BERKELEY.EDU Lines: 59 In article <> ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) typed: >In article <> >> >> There is a graphics library function called TextLength(). This will >>count how many pixels a string of characters requires. Is there a way to >>count how many CHARACTERS will fit in a specified number of PIXELS? >>(PROPORTIONAL characters, please!) >> > [random garbage deleted] > No, wait. What if you had some 'm's in there? They're a bit wider >than most, so that would take us back down to maybe 42. > No, that won't work either. What if they all were upper-case 'W's? >They're real wide. You'd only get about -- gee, I don't know -- 21 of those >on a line? > > Say, just how is this routine going to know how many proportional >characters are going to fit in a specified number of pixels unless it knows >what the characters are? Looks like an intractable problem to me. No, you have a graphics function that takes a character string... > Seriously, it's not possible to know how many proportional > characters are going to fit into a specified number of pixels until you try > it. [comment] > Your best recourse is to run the string you're interested in > printing through TextLength() and see if it'll fit. If it's too big, search > backwards from the end for the first space, cut it there, and try again. Yes, yes. Not a very ideal situation eh?? I use and *hate* that method now. The amount of processing that adds is silly! *KLUDGE*. BTW: I said characters, not words. A better recourse is to take some stab at how many characters will fit by using the average width of the proportional font, try that with TextLength(), then do a binary search to the actual value. And, in a future version of the operating system, see to it that a new function is implemented; number=TextFit(rastport,string,count,pixels),GfxBase d0 a1 a0 d0.w d1.w a6 ;Count how many of the string's characters will fit in the space given. This would only require *two* passes of the string. Cleanly word-wrapping proportional text is desirable for some applications. More functions like TextCharClip() could do the counting and drawing in one swoop. Ack! (NAK,EOT,SOH) |\ /| . {o O} . bryce@cogsci.berkeley.EDU -or- ucbvax!cogsci!bryce ( " ) U Single tasking? Just say *NO!* Today's trivia: There are 482 library calls that come as standard equipment with every V1.2 Amiga. (Source: 1.2, Gamma 1, fd.files)