[Plib-devel] PUI rendering fixes
Brought to you by:
sjbaker
From: Andy R. <an...@pl...> - 2004-05-04 19:15:36
|
I started chasing down a font rendering issue in FlightGear on Sunday. The original issue was a metrics bug in the afm2txf.pl font generator, a script I wrote for plib a while back. But fixing that didn't quite solve all the problems, so I spent some time hunting around in the PUI rendering code and fixing buglets. The patch is attached. Explanations: There was a hard-coded assumption in fnt.cxx that when rendering multi-line strings the interline distance was 1.333 * pointsize. My guess is that this was there as a workaround for an older bug somewhere; pointsize is, of course, the very definition of interline distance. Likewise, puFont has a getStringHeight() with the same baked-in constant. I rewrote this to use the more common GUI convention that the height of a single line of text is "ascender + descender", instead of the full point size (which includes significant whitespace in many fonts). Once that was changed, it exposed some weirdness in the vertical positioning code in puInput and puObject. I'm honestly not sure what the older formulas were trying to do. I changed them all to adhere to the line height convention above (i.e.: ascender + descender + (Nlines - 1) * pointsize). Vertical centering of text now looks significantly better. The dashed line rendered for the "default" button almost always cut right through the button text. I moved it out by three pixels, which gives it one pixel of margin from the edge of the thickest widget border. I also changed the stipple to a simpler 1010 pattern from the four-pixel dash pattern it originally had. IMHO, the tighter pattern is prettier. The rendering code for the "default" line also had a coordinate aliasing bug: when drawing GL_LINES, you have to use pixel center coordinates or else the GL will see a value exactly on the edge of two pixels and you'll get funny off-by-one artifacts. I fixed a similar coordinate issue with the puInput caret rendering. I also increased its height; most GUIs draw this from the bottom of the descender to the baseline of the next line. I tried this with a bunch of test code (and FlightGear, of course) and it doesn't seem to break anything. Andy |