为了把宋体字库做到rockbox上,我用otf2bdf把字库转换成bdf格式,再用rockbox的工具把bdf转换成其特有的字库格式,可是没有办法预览bdf字库的转换效果,很麻烦。于是就写了这个简单的程序。 {{{ #!python # a BDF font viewer import sys, os import string from wxPython.wx import * binstr=[ "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111", ] fonts=[] def OpenFont(fontfilename): global fonts fontfile = open(fontfilename) fonts =[] ishex =0 font = "" for line in fontfile: if line == "BITMAP\n": ishex=1 continue if line == "ENDCHAR\n": ishex=0 fonts.append(font) font="" continue if ishex: font += line fontfile.close() print len(fonts) class DrawPanel(wxPanel): def __init__(self, parent): wxPanel.__init__(self, parent, -1) self.SetBackgroundColour(wxWHITE) self.Bind(EVT_PAINT, self.OnPaint) self.fontStart=0 def SetFontStart(self, start): self.fontStart = start self.Refresh() def DrawFont(self, id, x, y): font = fonts[id] hexlist = string.split(font, "\n") xx=x yy=y DC=wxPaintDC(self) DC.SetPen(wxBLACK_PEN) hexlist.reverse() for line in hexlist: for char in line: v = int(char, 16) for dot in binstr[v]: if dot == "1": DC.DrawPoint(xx,yy) xx +=1 yy -= 1 xx = x def OnPaint(self, evt): dc = wxPaintDC(self) dc.Clear() w, h = self.GetClientSizeTuple() w = (w-5)/20 h = (h-5)/20 try: for x in xrange(0, w): for y in xrange(0, h): fontLoc = self.fontStart + x + y * w if fontLoc=0: self.fontstart -= 400 self.panel.SetFontStart(self.fontstart) def NextPage(self, event): if self.fontstart+400