Monday, 15 August 2011

python 2.7 - Why does get_linesize() incorrectly return 1 for .fon fonts? -



python 2.7 - Why does get_linesize() incorrectly return 1 for .fon fonts? -

i've had unusual thing happen in pygame1.9.1's font module, .get_linesize() returns 1 fonts glyph height (let lone per-line height) renders greater 1. happens .fon fonts.

here 2 examples, plus 3rd font does work, sake of control. i've run these idle's shell, same thing happens proper modules. in case, pygame has been initialized.

>>> testfont = pygame.font.font("c:/windows/fonts/vga850.fon", 12) >>> testfont.get_linesize() # 1 returns 1. 'terminal regular' 1 >>> otherfont = pygame.font.font("c:/windows/fonts/vgafix.fon", 18) >>> otherfont.get_linesize() # returns 1. 'fixedsys regular' 1 >>> lastfont = pygame.font.font("c:/windows/fonts/ocrastd.otf", 24) >>> lastfont.get_linesize() # returns right value. 'ocr std regular' 29 >>> textsurf = testfont.render("this nightmare!", true, (0,0,0)) >>> textsurf.get_size()[1] # let's height of surface... 12 >>> othersurf = otherfont.render("an inescapable nightmare!", false, (0,0,0)) >>> othersurf.get_size()[1] # one, too. antialiasing makes no difference. 15 >>> lastsurf = lastfont.render("you're okay, ocra.", true, (0,0,0)) >>> lastsurf.get_size()[1] # , finally, control... 25

the height of render command little shorter, since get_linesize() includes gap between lines aesthetic reasons. <font>.size("sample string")[1] works correctly, that's been stopgap line height.

all 3 fonts render correctly.

the mutual thread fonts not respond <font>.get_linesize() share extension .fon, easy 'solution' simply, "do not utilize .get_linesize() .fon fonts; utilize .size('sample')[1] + some_adjustment instead." this, however, inelegant , (worse still!) terribly boring, , i'm much more interested know what causes problem, , if there a way create these fonts work get_linesize() should.

i looked through pygame's documentation , couldn't find issue, , number of web searches proved fruitless well.

pygame's font back upwards depends on sdl_ttf in turn depends on freetype2. suspect there's problem in calculating value line height font goes through layers (specifically sdl_ttf layer, freetype2 reads font data).

consider using pygame.freetype.font instead of pygame.font. freetype module skips sdl_ttf layer , works freetype directly. there a much richer set of options fonts there. i'd seek get_sized_height() replacement get_linesize().

if still doesn't work, freetype bug in reading fon files, or perchance fon files don't have value set correctly.

python-2.7 fonts pygame

No comments:

Post a Comment