garya@stan.com (Gary Aitken) (11/18/88)
I would like a good explanation of what the font information in an XFontStruct is supposed to mean. In particular, how does one determine the total space occupied by a font, in order to size a window to enclose it? For example, the courB12 font has characters which extend outside of the width. How does one determine if a font has it's own imbedded interline spacing, as the 9x15 font appears to? For example, the server reports the following font information: courB12 (-Adobe-Courier-Bold-R-Normal--12-120-75-75-M-70-ISO8859-1) ascent descent lbearing rbearing width 10 3 min bounds: -1 -7 0 1 7 max bounds: 11 3 3 8 7 9x15 ascent descent lbearing rbearing width 12 3 min bounds: 0 -7 0 0 9 max bounds: 10 3 5 9 9 For courB12, the font structure says ascent is 10 and descent is 3, yet there are numerous characters with an ascent of 11. If one sums the general font ascent and descent to obtain the total number of vertical pixels where foreground pixels are drawn, one gets the correct answer for 9x15 but an incorrect answer for courB12. If one uses the max character ascent + descent, one gets the correct answer for courB12 but the wrong one for 9x15. Does one have to take the max of the max's?? PPuuuuuuuchchchch!!!! What is the purpose of the general ascent and descent for the font? Is there a reliable way to determine if interline whitespace is already included in the font, and what it is? In the above examples, for 9x15 one can take the font ascent+descent and subtract the max bounds ascent+descent, to get two pixels of whitespace, which is what the font really has. But this totally falls apart for courB12. For fixed width fonts, it should be possible to size a window to contain a specified number of characters. None of the numbers give a reliable hint as to how many pixels must be added at the beginning of a string to accomodate characters which stick out to the left of their bounding box, or at the end for those which stick out to the right. Again, the courB12 font has numerous characters which stick out 1 pixel to the right. Gary Aitken ncar!boulder!stan!garya
rws@EXPO.LCS.MIT.EDU (Bob Scheifler) (11/18/88)
In particular, how does one determine the total space occupied by a font, in order to size a window to enclose it? Since I'm not sure exactly what you mean by this, it's hard to answer exactly. How does one determine if a font has it's own imbedded interline spacing, as the 9x15 font appears to? Read the protocol document; font-ascent and font-descent are logical extents to be used for line spacing. These numbers should be viewed as the font designer's "minimum" line spacing, in a sense. The ink metrics of particular characters might or might not stick out on either side of this; it's up to the font designer. If you want to know the ink extents, look at the ink metrics; if you want to know the logical extents, look at the logical metrics. Is there a reliable way to determine if interline whitespace is already included in the font, and what it is? Yes, get your fonts from a reliable source. None of the numbers give a reliable hint as to how many pixels must be added at the beginning of a string to accomodate characters which stick out to the left of their bounding box, or at the end for those which stick out to the right. I don't understand. Comparing the ink metrics of each character to its width will give you this information. If the font has constant character widths, then comparing the min/max bounds ink metrics against this width will tell you.
garya@stan.com (Gary Aitken) (11/19/88)
My appologies, the required font information is there; my original question, rephrased, is: How does one determine the size of a window to display an arbitrary string in a fixed width font, such that no characters will clip? The answer, I believe, is: XFontStruct *fp ; over_x_left = max(abs(min(fp->min_bounds.lbearing,0)),0) ; /* max # pixels to left of bounding box occupied by any character */ over_x_right = max(fp->max_bounds.rbearing-fp->max_bounds.width,0) ; /* max # pixels to right of bounding box occupied by any character */ over_y_top = max(fp->max_bounds.ascent-fp->ascent,0) ; /* max # pixels above bounding box occupied by any character */ over_y_bottom = max(fp->max_bounds.descent-fp->descent,0) ; /* max # pixels below bounding box occupied by any character */ ascent = fp->max_bounds.ascent + over_y_top ; descent = fp->max_bounds.descent + over_y_bottom ; ht = ascent + descent ; width = over_x_left + n_char*fp->max_bounds.width + over_x_right ; The origin for drawing is then: (over_x_left,ascent) > > Is there a reliable way to determine if interline whitespace is already > included in the font, and what it is? > > Yes, get your fonts from a reliable source. Does this imply we may assume that all fonts from MIT have interline spacing included?
rws@EXPO.LCS.MIT.EDU (Bob Scheifler) (11/21/88)
Does this imply we may assume that all fonts from MIT have interline spacing included? We'd hope that all non-contrib text fonts (as opposed to cursors and other things) have interline spacing. If you notice otherwise, let us know.