import fontforge
import unicodedata

gen=open("la_icon.h", "w")

written=0;
no_name=[]
categories=[]
f=[]

gen.write("#pragma once\n\n")

def find_glyph(unicode):
    glyph=None
    for i in range(len(f)):
        try:
            glyph=f[i][unicode]
        except:
            glyph=None
        if glyph:
            break
    return glyph

groups=[
[73, "currency", []],#Currency Symbols]
[77, "arrows", []],#Arrows]
[78, "dingbats", []],#Mathematical Operators]
[79, "tech", []],#Miscellaneous Technical]
#[83, "box", []],#Box Drawing]
#[84, "block", []],#Block Elements]
[85, "geom", []],#Geometric Shapes]
[86, "misc", []],#Miscellaneous Symbols]
[87, "dingbats", []],#Dingbats]
[88, "math", []],#Miscellaneous Mathematical Symbols-A]
[89, "arrows", []],#Supplemental Arrows-A]
[90, "braille", []],#Braille Patterns]
[91, "arrows", []],#Supplemental Arrows-B]
[92, "math", []],#Miscellaneous Mathematical Symbols-B]
[93, "math", []],#Supplemental Mathematical Operators]
[94, "misc", []],#Miscellaneous Symbols and Arrows]
#[163, "linear_b_s", []],#Linear B Syllabary]
#[164, "linear_b_i", []],#Linear B Ideograms]
#[238,, []],# Cuneiform]
#[239,, []],# Cuneiform Numbers and Punctuation]
#[240, "edc", []],#Early Dynastic Cuneiform]
[241, "egyptian", []],#Egyptian Hieroglyphs]
#[242,, []],# Egyptian Hieroglyph Format Controls]
#[243, "anatonllian", []],#Anatolian Hieroglyphs]
#[244, "bamum", []],#Bamum Supplement]
#[257, "duployan", []],#Duployan]
[259, "musical", []],#Byzantine Musical Symbols]
[260, "musical", []],#Musical Symbols]
[261, "musical", []],#Ancient Greek Musical Notation]
[262, "mayan_num", []],#Mayan Numerals]
[263, "taixuan", []],#Tai Xuan Jing Symbols]
[264, "rod", []],#Counting Rod Numerals]
#[274, "arabic_math", []],#Arabic Mathematical Alphabetic Symbols]
#[275,, []],# Mahjong Tiles]
#[276,, []],# Domino Tiles]
#[277,, []],# Playing Cards]
[278, "enclosed", []],#Enclosed Alphanumeric Supplement]
[279, "enclosed", []],#Enclosed Ideographic Supplement]
[280, "misc", []],#Miscellaneous Symbols and Pictographs]
[281, "emo", []],#Emoticons]
[282, "dingbats", []],#Ornamental Dingbats]
[283, "transport", []],#Transport and Map Symbols]
[284, "alchemical", []],#Alchemical Symbols]
[285, "geom", []],#Geometric Shapes Extended]
[286, "arrows", []],#Supplemental Arrows-C]
[287, "pic", []],#Supplemental Symbols and Pictographs]
[288, "chess", []],#Chess Symbols]
[289, "pic", []],#Symbols and Pictographs Extended-A]
#[290, "", []],#legact computing]
]

f.append(fontforge.open("/home/yiming/.local/share/fonts/NotoSansSymbols-Regular.ttf"))
f.append(fontforge.open("/home/yiming/.local/share/fonts/NotoSansSymbols2-Regular.ttf"))
f.append(fontforge.open("/home/yiming/.local/share/fonts/NotoEmoji-Regular.ttf"))
f.append(fontforge.open("/home/yiming/.local/share/fonts/NotoMusic-Regular.ttf"))
f.append(fontforge.open("/home/yiming/.local/share/fonts/NotoSansEgyptianHieroglyphs-Regular.ttf"))

for i in range(len(groups)):
    begin=fontforge.UnicodeBlockStartFromLib(groups[i][0])
    end=fontforge.UnicodeBlockEndFromLib(groups[i][0])+1
    for c in range(begin,end):
        glyph=find_glyph(c)
        if glyph is not None:
            groups[i][2].append(glyph)

for i in range(len(groups)):
    for j in range(i+1,len(groups)):
        if groups[j][1]!=groups[i][1] or len(groups[j][2])==0:
            continue;
        groups[i][2].extend(groups[j][2])
        groups[j][2]=[]

irow=0;
row=40;

for i in range(len(groups)):
    irow=0;
    if len(groups[i][2])==0:
        continue;
    gen.write("// "+groups[i][1]+"\n#ifndef _LA_ICO_"+groups[i][1].upper()+"\n#define _LA_ICO_"+groups[i][1].upper()+"\\\n")
    for c in groups[i][2]:
        if (irow%row==0):
            gen.write("\"")
        gen.write(str(chr(c.unicode)));
        written+=1;
        irow+=1
        if (irow%row==0):
            gen.write("\"\\\n")
    if (irow%row!=0):
            gen.write("\"\n")
    gen.write(";\n#endif\n\n")

gen.write("// Generated %s characters\n"%(written));
gen.write("// Glyphs with no names: %d\n// "%len(no_name));
for n in no_name:
    gen.write(chr(n));

gen.close()