Re: NewEra 3.0 Question
Posted in 1997
"Candy McCall" <candym@olcinc.com> wrote in article <5sj5oh$a13@cssun.mathcs.emory.edu>... > I have a NewEra 3.0 question: > > I'm creating a grid-form supertable in which the columns are determined > at run-time (they are based on a query). When I create the superfields for > the supertable, I want to set the width of the superfield depending on the > length of the title or the max # chars allowed in the field (which ever is > greater). How can I determine the width of a font character in twips > depending on the point size of the font? The font will be a font in which the > width of all characters are the same (such as Courier New). I guess the width > should be from the left-most part of a character to the leftmost part of the next > character. Okey dokey, your question (assuming a 10 point, fixed width character is at most 9 pixels wide with at least one space between the characters (this is true for Courier New, for instance)) boils down to this: "How many twips are in a pixel" The simple answer is : 15. However, this is something of an over simplification as it's only true when using the supplied "small" fonts under Windoze. If (like many folk do) you set your machine to a screen resoulution your monitor/eyes can not cope with, then compensate by switching to "large" fonts, every thing goes wrong as the magic number 15 is now way, way off target. Okay, so how may twips *are* there in a pixel? A more accurate answer is : "it depends". Remember that a twip is 1/1440th of a logical inch at VGA resolution (I got that off a fortune cookie, I really did) and that the number of pixels (hence twips) in the vertical and horizontal planes of a display device is variable and worse still, it's not always in a fixed ratio! So, how does all this help us? Well, it starts to look as though we need a way of finding out how many pixels there are measuring top to bottom and left to right for the current screen resolution and aspect ratio. Strange as it may seem, a Windows SDK function exists to do just that. It's called "GetDeviceCaps()". Remembering the magic number 1440, and reading the BooksOnline entry for GetDeviceCaps() we see that we can ask Windows how many pixels per logical inch there are in a particular axis, so... To find out how wide (in twips) your font character is and set a button to the exact width of the title it's using, do something like this: VARIABLE btn ixButton, twipsPerXPixel SMALLINT, # create the button, with a 17 character title using a fixed width 10 point font. BEGIN_C { HWND hwnd= GetDesktopWindow(); HDC hdc= GetDC(hwnd); twipsperxpixel= 1440 / GetDeviceCaps(hdc, LOGPIXELSX); ReleaseDC(hwnd, hdc); } END_C CALL btn.setSize(NULL, twipsPerXPixel * 10 * 17) Hope this helps. -- David _______________________________________________________________________ David C. Harrison Managing Director DCH Software Ltd. Tel: +44 (0)1276 450030 Fax: +44 (0)1276 450039 Mobile: (0966) 476727 Mail: dch@dchsoftware.co.uk Web: http://www.dchsoftware.co.uk