Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!ptsfa!well!ewhac From: ewhac@well.UUCP Newsgroups: comp.sys.amiga Subject: Re: Qestions Message-ID: <3315@well.UUCP> Date: Mon, 15-Jun-87 03:34:25 EDT Article-I.D.: well.3315 Posted: Mon Jun 15 03:34:25 1987 Date-Received: Tue, 16-Jun-87 01:41:46 EDT References: <8706122325.AA17348@cogsci.berkeley.edu> Reply-To: ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) Organization: Hole Earth 'Lectronic Loss (or words to that effect) Lines: 45 [ Requiem sacrifice to a line eating bug. ] In article <8706122325.AA17348@cogsci.berkeley.edu> bryce@COGSCI.BERKELEY.EDU (Bryce Nesbitt) writes: >Question: > 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!) > Proportional characters? Hmm, well lemme see. Proportional characters vary in width depending on what letter you have. So I guess that means if you had 320 pixels of width to play with, you could fit 40 characters in them. Of course, that's only if each if them were 8 pixels wide, which is about average. However, if you have a few 'i's sprinkled in there, they're thinner than all the other letters, and take fewer pixels, so that would bring your total up to, oh, let's say 47. 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. 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. Old style printers (ink, lead type, and all that) had this problem all the time, except that they sort of got a "feel" for just how much they could cram into one line. 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. Of course, if you have a fixed width font, the solution is obvious. _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ Leo L. Schwab -- The Guy in The Cape ihnp4!ptsfa -\ \_ -_ Bike shrunk by popular demand, dual ---> !{well,unicom}!ewhac O----^o But it's still the only way to fly. hplabs / (pronounced "AE-wack") "Work FOR? I don't work FOR anybody! I'm just having fun." -- The Doctor