From: "Steve Schafer (TeamB)" Subject: Re: Life, the Universe, and Everything Date: 15 Feb 2000 00:00:00 GMT Message-ID: <16njasoe1v3d4hafgcphi4qqs7i4r33gdv@4ax.com> Content-Transfer-Encoding: 7bit References: Content-Type: text/plain; charset=us-ascii Organization: TeamB Mime-Version: 1.0 Reply-To: pandeng@telepath.com Newsgroups: borland.public.delphi.graphics On Tue, 15 Feb 2000 16:55:52 -0500, Steve Caupp wrote: >A line of text that fits on a single line at one zoom factor wraps at >another. Text that wraps at one screen resolution doesn't at a >different resolution. When printed on different printers, the output >may or may not match the preview. A printer may print a line that >wraps that doesn't wrap on another. Fonts on different printers are >*visibly* different (not some slight caliper-measured difference, but >visibly wider or taller or thicker). > >PowerPoint, Excel, etc. have previews that match their printed output, >why can't we normal mortals? As you've discovered, WYSIWYG is really an illusion. How to make it work: 1) Don't use ANY of the API functions that claim to be able to decide line breaks for you. They work, but they only work at the current resolution, whatever that may be. 1) Decide on a "standard" high resolution that you will use for all of your text placement calculation. (Microsoft recommends 65536 dpi; I actually use a larger value.) 2) Do all of your text width, line spacing, etc. calculations assuming that high resolution, and then round to the actual device resolution. In order to do that, you'll have to scale your fonts accordingly. For example, let's say that your actual screen resolution is 96 dpi, and you've decided to use Microsoft's suggested high resolution. The ratio is 65536/96 = 682.67. Now let's say you want to draw some 10-point text. To determine the width of the line of text (in terms of the high-resolution "device"), you'll need to scale everything by the aforementioned ratio. In other words, in order to simulate 10-point text on a 65536 dpi device, you have to select a 6827-point font into your 96-dpi device context, and work with that. Continuing the example, let's assume that the result of a TextWidth() call on the line of text is 75342. Dividing by the dpi gives 1.150 inches. This is the "ideal" width of that line of text. 3) Place your text on the destination canvas using the "ideal" dimensions calculated using the technique outlined in (2). For good results, you should separately place every word of text. For example, let's say the text is "This is a line of text," and you want to place it on a 600-dpi canvas (a printer canvas, say). Start by calculating the widths of each portion of the sentence: "This " 0.282" 169 pixels "This is " 0.409" 245 pixels "This is a " 0.505" 303 pixels "This is a line " 0.748" 449 pixels "This is a line of " 0.899" 539 pixels So this tells you exactly where to place each word. Since "This " is ideally 0.282 inches wide (which translates to 169 pixels wide at 600 dpi), you know that the word "is" should be placed exactly 169 pixels to the right of the word "This." Similarly, "a" should be placed exactly 245 pixels to the right of the word "This," and so on. For "extreme WYSIWYG" you actually need to separately place each individual glyph, not just each word. A lot of work? You bet. But it's the only way to get true WYSIWYG. -Steve