# GB LCD Font test -- 2018/10/24 tklua@wifiboy.org

''' 
GB: http://www.khngai.com/chinese/charmap/tblgb.php?page=5
GB converter: https://r12a.github.io/app-encodings/
'''

def gboffset(x):
    x1=x>>8
    x2=x%256
    n=(x1-161)*94*18+(x2-161)*18+120
    return n
    
def showgb(b, x, y, c):
    count = 0
    cx=x
    for i in range(18):
        for j in range(4):
            if b[i]&(2**(7-j)): wb.pix(cx, y, c); 
            cx+=1
        count+=1
        if count % 3 == 0: cx=x; y+=1
        for j in range(4):
            if b[i]&(2**(3-j)): wb.pix(cx, y, c); 
            cx+=1
        count+=1
        if count % 3 == 0: cx=x; y+=1
            
gbstr = [0xBBA5,0xC1AA,0xCDF8,0xB7A2,0xD5B9,0xC7F7,0xCAC6]            
posx, posy = 15, 30
color = wb.WHITE

wb.cls()
with open("/sd/font/FGB12F.PDB", "rb") as f:
    for ch in jisstr:
        f.seek(gboffset(ch))
        showgb(f.read(18), posx, posy, color)
        posx += 14
    f.close()
    