mears@hpindda.HP.COM (David Mears) (02/21/90)
I have an application which needs to compute the size of an enclosing box around a block of text that will be put into a widget. To determine the size, I determine the max width and height of the font being used and then multiply those values by the number of characters in the widest line, and by the number of lines in the block. My calculations came out fine when used with R2 based fonts, but do not work right with an R3 font. Apparently there was some small change made in the way that the sizing information is stored in the R3 fonts. I would appreciate it if someone could show me how to modify my calculations so they will give the correct results with either an R2 or an R3 font. Right now I determine the font character width and height by the following formulas: TFheight = font->max_bounds.ascent + font->max_bounds.descent; TFwidth = font->max_bounds.rbearing - font->min_bounds.lbearing; BTW, using these formulas tends to give me a value which is slightly small for the R3 fonts. Thanks. David B. Mears Hewlett-Packard Cupertino CA hplabs!hpda!mears mears@hpda.HP.COM
ben@hpcvlx.cv.hp.com (Benjamin Ellsworth) (02/22/90)
I believe that you should be using XTextExtents rather than character box stuff. Get a copy of the Xhp widget source and root around in the StaticText widget. There's a block of code to do exactly what you want. ----------------------------------------------------------------------- Benjamin Ellsworth | ben@cv.hp.com | INTERNET Hewlett-Packard Company | {backbone}!hplabs!hp-pcd!ben | UUCP 1000 N.E. Circle | (USA) (503) 750-4980 | FAX Corvallis, OR 97330 | (USA) (503) 757-2000 | VOICE ----------------------------------------------------------------------- All relevant disclaimers apply. -----------------------------------------------------------------------
rws@EXPO.LCS.MIT.EDU (Bob Scheifler) (02/24/90)
TFheight = font->max_bounds.ascent + font->max_bounds.descent; TFwidth = font->max_bounds.rbearing - font->min_bounds.lbearing; Perhaps the problem is that font->max_bounds.width can be greater than TFwidth as you calculate it? Try using max of these two values. Otherwise, a more explicit example of the problem, the actual fonts involved and the values computed, would be helpful.