我在Pygame1.9.1的字體模塊中發生了這種奇怪的事情,其中.get_linesize()
返回1的字形高度(更不用說每行高度)呈現大於1的字體。它只發生在.fon
字體上。爲什麼get_linesize()不正確地爲.fon字體返回1?
這裏有兩個例子,加上第三個字體,確實爲工作,爲了控制。我從IDLE的shell中運行了這些,但同樣的事情發生在適當的模塊上。 無論如何,Pygame已經被初始化了。
>>> testfont = pygame.font.Font("C:/Windows/Fonts/vga850.fon", 12)
>>> testfont.get_linesize() # This one returns 1. For 'Terminal Regular'
1
>>> otherfont = pygame.font.Font("C:/Windows/Fonts/vgafix.fon", 18)
>>> otherfont.get_linesize() # This also returns 1. For 'Fixedsys Regular'
1
>>> lastfont = pygame.font.Font("C:/Windows/Fonts/OCRAStd.otf", 24)
>>> lastfont.get_linesize() # This returns the correct value. For 'OCR A Std Regular'
29
>>> textsurf = testfont.render("This is a nightmare!", True, (0,0,0))
>>> textsurf.get_size()[1] # Let's get the height of this surface...
12
>>> othersurf = otherfont.render("An inescapable nightmare!", False, (0,0,0))
>>> othersurf.get_size()[1] # This one, too. Antialiasing makes no difference.
15
>>> lastsurf = lastfont.render("You're okay, OCRA.", True, (0,0,0))
>>> lastsurf.get_size()[1] # And finally, the control...
25
的呈現該控件的高度是短一點,由於get_linesize()
包括出於美學原因線之間的間隙。 <Font>.size("sample string")[1]
工作正常,所以這是我的行高的權宜之計。
所有三種字體都可以正確渲染。
與不正確地響應<Font>.get_linesize()
字體的共同點是,他們都有着擴展.fon
,所以易「解決方案」是根本,「不要用.get_linesize()
與.FON字體;使用.size('sample')[1] + some_adjustment
代替「。 然而,這是有點不雅和(更糟!)非常無聊的,我更想知道是什麼原因導致這個問題,如果有辦法讓這些字體與get_linesize()
工作,因爲他們應該。
我查看了Pygame的文檔,找不到任何與此問題有關的事情,許多網絡搜索也無果而終。
我試過去freetype,實際上,但我仍然使用Python1.9.1。當我第一次考慮這個模塊時,醫生說它仍然是實驗性的,可能會變得不可預知或者一起消失,所以我得到了冷靜的腳並且一個人留下了它。 雖然看起來像時代變化(在過去的一個月),我也需要更新。 – Augusta