ja1yaz’s diary

感動したいおやじの備忘録的ブログ 

AQM1248Aを使いこなしたい。(6)

AQM1248で漢字を出したいがために出水フォントのBDFファイルを12x8ビットのビットマップに変換することを目標に変換プログラムを作成していた。

何とか変化プログラムはできたのだが、作成したビットマップフォントを以前の「Hello World」の表示プログラムに入れ込んでみた。

 

Python  AQM1248A 漢字データ付加

出水フォントは約4000個のデータがあったが、それを先のデータと同じように入れ込んでみたが、エラーが出てしまった。

たしかに、フォントデータだけで230kByteあったがリストで128kByte以上は駄目なようだ。

「MemoryError: memory allocation failed, allocating 8640 bytes」

というエラーが出て、その先はウンともスンとも動かない。

やはり、漢字の入力はあきらめねばならないか?

 

BDFの変換プログラムは下記だ。

せっかく変換プログラムを作成したのに・・・無念。

 

#BDF file converter for IZFL16.BDF 8x16 bit map font

path='k12x8.bdf'
with open(path) as f:
    s = f.read()
    print(type(s))
f.close()


bm_pos=0
s_lists=0
s_lists1=0
#read the data of boundingbox  ['12', '8', '0', '-1']
msg='FONTBOUNDINGBOX '
s_lists=s.find(msg,bm_pos)
s_lists1=s.find(chr(10),s_lists+len(msg))

i=0
b=''
fbbx=
while i<s_lists1-(s_lists+len(msg)):
    if ord(s[s_lists+(len(msg))+i])==32:
        fbbx.append(b)
        b=''
        i+=1
    b=b+chr(ord(s[s_lists+(len(msg))+i]))
    if i==s_lists1-(s_lists+len(msg))-1:
       fbbx.append(b)
       b=''       
    i+=1
#print(fbbx)
fbbx_xsize=int(fbbx[0])
fbbx_ysize=int(fbbx[1])
fbbx_x0=int(fbbx[2])
fbbx_y0=int(fbbx[3])
#print(fbbx_xsize,fbbx_ysize,fbbx_x0,fbbx_y0)

#make the lists of start location of encoding number 
bm_pos=s_lists1
msg='ENCODING '
s_lists=s.find(msg,bm_pos)
#print(s_lists)
s_lists1=s.find(chr(10),s_lists+len(msg))
#print(s_lists1)

enc_lists=
msg='ENCODING '
while s_lists!=-1:
    bm_pos=s_lists1
    s_lists=s.find(msg,bm_pos)
    if s_lists>s_lists1:
        enc_lists.append(s_lists+len(msg))
    #print(s_lists)
    s_lists1=s.find(chr(10),s_lists+len(msg))
    #print(s_lists1)
print(enc_lists)

#make the lists of start location of boundingbox 
bbx_lists=
s_lists=0
msg='BBX '
i=0
while i<len(enc_lists):    
    s_lists=s.find(msg,enc_lists[i])
    bbx_lists.append(s_lists+len(msg))
    i+=1
#print(bbx_lists)
#######################################

#make the bmp location list######
bmp_lists=
s_lists=0
msg='BITMAP'+chr(10)
i=0
while i<len(enc_lists):    
    s_lists=s.find(msg,enc_lists[i])
    bmp_lists.append(s_lists+len(msg))
    i+=1
#print(bmp_lists)
##############################
    
#make the BBX lists####################
enc_bbx_lists=
j=0
while j<len(bbx_lists):
    s_lists=bbx_lists[j]
    s_lists1=s.find(chr(10),s_lists)
    i=0
    b=''
    abbx=

    while i<s_lists1-s_lists:
        if ord(s[s_lists +i])==32:
            abbx.append(b)
            b=''
            i+=1
        b=b+chr(ord(s[s_lists+i]))
        #print(chr(ord(s[s_lists++i])),s_lists+i,s_lists1,i)
        if i==s_lists1-s_lists-1:
           abbx.append(b)
           b=''       
        i+=1
    enc_bbx_lists.append(abbx)
    j+=1
    

#######################################
    
    
#make the bmp data lists####################
bmp_data_lists=
#k=len(enc_bbx_lists)-3
k=0
while k<len(enc_bbx_lists):
    a=enc_bbx_lists[k]
    s_lists=bmp_lists[k]
    s_lists1=s.find(chr(10),s_lists)
    j=0
    abbx=

    while j<int(a[1]):
        if int(a[1])==0:
            j+=1
        i=0
        b=''
        while i<s_lists1-s_lists:
            if s_lists1-s_lists==0:
                i+=1
            b=b+chr(ord(s[s_lists+i]))
            i+=1
        abbx.append(b)
        s_lists=s_lists1+1
        s_lists1=s.find(chr(10),s_lists)
        
        j+=1
    #print(abbx)
    bmp_data_lists.append(abbx)
    k+=1
#print(bmp_data_lists)
#######################################
edit_bmp_lists=
i=0
a=

d=
while i<len(enc_bbx_lists):
    
    a=enc_bbx_lists[i]
    bbx_xsize=int(a[0])
    bbx_ysize=int(a[1])
    bbx_x0=int(a[2])
    bbx_y0=int(a[3])
    d=bmp_data_lists[i]
    #print(a,d)
    #print(bbx_xsize,bbx_ysize,bbx_x0,bbx_y0)
    j=0
    a=

    while j<fbbx_ysize+fbbx_y0-(bbx_y0+bbx_ysize):
        if fbbx_ysize+fbbx_y0-(bbx_y0+bbx_ysize)==0:
            j+=1
        a.append('0x000')
        j+=1
    
    j=0
    b=0
    c=0
    n_sft=0
    font_data=0
    while j<bbx_ysize:
        if bbx_ysize==0:
            j+=1
        c=len(d[j])
        #print(c)
        b=int(d[j],16)
        #print(b)
        
        nsft=fbbx_xsize-bbx_x0-c*4    
        if nsft>=0:
            font_data=b<<abs(nsft)
            #print(nsft,i,d)
        else:
            
            font_data=b>>abs(nsft)
        #if c>3:
            #print(i,j,c,hex(b),nsft)
        a.append(hex(font_data))
        j+=1
        
    j=0
    while j<bbx_y0-fbbx_y0:
        if bbx_y0-fbbx_y0==0:
            j+=1
        a.append('0x000')
        j+=1
    #print(a,enc_bbx_lists[i])
    edit_bmp_lists.append(a)
    i+=1
flname='12x8_bmp_data.txt'


j=0
b=''
num_enc=0
while j<len(enc_lists):
    s_lists=enc_lists[j]
    s_lists1=s.find(chr(10),s_lists)
    i=0
    b=''
    while i<s_lists1-s_lists:
        b=b+chr(ord(s[s_lists+i]))
        i+=1
    num_enc=int(b)
    
    i=0
    a=edit_bmp_lists[j]
    dat=''
    b='f_dat['+hex(num_enc)+']=['
    while i<fbbx_ysize:
        if i==fbbx_ysize-1:
            b=b+a[i]
        else:
            b=b+a[i]+','
        i+=1
    b=b+']'
    #print(b,bmp_data_lists[j])
    with open(flname,mode='a') as f:
        f.write(b+'\n')
    print(b)
    j+=1