2010-01-20 73 views

回答

1

不,PIL只能用於渲染文本,不能得到它的指標。您需要使用適當的Windows API函數或FreeType庫(其中沒有穩定的Python綁定)才能獲得核心信息。

+0

是不是建立在freetype上的PIL? – Geo 2010-01-20 11:10:32

+0

是的,但它不公開度量函數。 – 2010-01-20 11:13:02

3

答案是,正如伊格納西奧所說,沒有。

這是這個答案的嚴重部分。而現在,完全不同的東西:

可以近似一個(不,因爲你不能使用PIL知道別說什麼是字體設計EM尺寸)上使用像字距值:

import ImageFont 
SAMPLE_SIZE= 128 # should provide sufficient resolution for kerning values 

def get_a_kerning_value(font_descriptor, char1, char2): 
    """See if there is some kerning value defined for a pair of characters 
    Return the kerning value as an approximated percentage of the row height.""" 

    imagefont= ImageFont.truetype(font_descriptor, SAMPLE_SIZE) 

    width1= imagefont.getsize(char1)[0] 
    width2= imagefont.getsize(char2)[0] 
    widths, height= imagefont.getsize(char1 + char2) 

    return (widths - (width1 + width2))/float(height) 
相關問題