From 6f39451d88002ff9c9ecbcbf8d59d0128779e3e8 Mon Sep 17 00:00:00 2001 From: Sasi Olin Date: Sat, 20 Nov 2021 21:09:32 +0100 Subject: [PATCH 1/2] Add a script that generates pbl from the files --- .gitignore | 1 + autogen/generate_pbl.py | 56 ++++++++++ emoji.json | 236 ++++++++++++++++++++++++++++++++++++++++ emoji/1f3b6-lg.png | Bin 261 -> 250 bytes emoji/2728-lg.png | Bin 231 -> 258 bytes emoji/2728-sm.png | Bin 191 -> 202 bytes emoji/2757-lg.png | Bin 186 -> 179 bytes emoji/2757-sm.png | Bin 186 -> 173 bytes emoji/3456-lg.png | Bin 0 -> 152 bytes emoji/3456-sm.png | Bin 0 -> 150 bytes 10 files changed, 293 insertions(+) create mode 100755 autogen/generate_pbl.py create mode 100644 emoji.json create mode 100644 emoji/3456-lg.png create mode 100644 emoji/3456-sm.png diff --git a/.gitignore b/.gitignore index cdb5f04..b8f8813 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ readme.md +build/ diff --git a/autogen/generate_pbl.py b/autogen/generate_pbl.py new file mode 100755 index 0000000..9193921 --- /dev/null +++ b/autogen/generate_pbl.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 + +import os +import json +import glob +import shutil +import re +from PIL import Image + +outputs = [ + { "name": "emoji_14", "suffix": "sm", "size": 14, "top": 0, "export": ["001", "002"] }, + { "name": "emoji_18", "suffix": "sm", "size": 18, "top": 2, "export": ["003", "004"] }, + { "name": "emoji_24", "suffix": "lg", "size": 24, "top": 0, "export": ["005", "006"] }, + { "name": "emoji_28", "suffix": "lg", "size": 28, "top": 2, "export": ["007", "008"] } +] + +if os.path.exists("emoji.json"): + os.makedirs("build", exist_ok=True) + os.system("cd build && git clone https://github.com/MarSoft/pebble-firmware-utils.git && cd ..") + emojis_file = open("emoji.json") + emojis_json = json.load(emojis_file) + for folder in ["sm", "lg"]: + files = glob.glob("emoji/*-%s.png" % folder) + os.makedirs("build/%s" % folder, exist_ok=True) + for file in files: + shutil.copyfile(file, "build/%s/%05X.png" % (folder, int(file[file.find('/')+1 : file.find('-')], 16))) + for output in outputs: + output_json = {} + output_json['metadata'] = [] + suffix = output["suffix"] + for emoji in emojis_json: + image = Image.open("build/%s/%05X.png" % (suffix, ord(emoji["character"]))) + metrics = emoji[suffix] + width, height = image.size + output_json['metadata'].append({ + 'codepoint': ord(emoji["character"]), + 'advance': width + 2, # 1 padding on left and right side + 'top': metrics["top"] + output["top"], + 'left': 1 + }) + with open('build/%s.json' % output["name"], 'w') as f: + json.dump(output_json, f) + os.system("cd build && python2 pebble-firmware-utils/fontgen.py pfo %d %s %s.pfo --list %s.json && cd .." % (output['size'], suffix, output['name'], output["name"])) + os.makedirs("build/resources", exist_ok=True) + for export in output["export"]: + shutil.copyfile("build/%s.pfo" % output["name"], "build/resources/%s" % export) + os.remove("build/%s.pfo" % output["name"]) + if not os.path.exists("build/resources/000"): + os.mknod("build/resources/000") + for n in range(10): + filepath = "build/resources/%03d" % (n + 9) + if not os.path.exists(filepath): + os.mknod(filepath) + os.system("cd build && python2 pebble-firmware-utils/pbpack.py resources/ emoji.pbl && cd ..") +else: + print("You are in a wrong directory to build the fonts") diff --git a/emoji.json b/emoji.json new file mode 100644 index 0000000..e831c6d --- /dev/null +++ b/emoji.json @@ -0,0 +1,236 @@ +[ + { + "character": "\u3456", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\uD83E\uDD29", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\ud83d\ude43", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\ud83d\ude44", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\ud83e\udd23", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\ud83e\udd24", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\ud83e\udd7a", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\ud83e\udd70", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\u26a7", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\u2705", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\u274e", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\u2728", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\u2757", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\u2763", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\u2b50", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\ud83c\udf1f", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\ud83d\udcaf", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\ud83c\udfb6", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\ud83c\udff3", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\u231a", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\ud83e\udd18", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\ud83e\udd1d", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\ud83e\udd2a", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\ud83c\udf40", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\ud83e\udd17", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + }, + { + "character": "\ud83d\udca5", + "lg": { + "top": 1 + }, + "sm": { + "top": 1 + } + } +] diff --git a/emoji/1f3b6-lg.png b/emoji/1f3b6-lg.png index c909abb6f5b19ea40e188313c6fb7765440ad545..4a999cb0b129a95f8ad38216094fdb01908ec1d2 100644 GIT binary patch delta 236 zcmZo=`o*Z&8Q|y6%O%Cdz`(%k>ERLtqy>Rkh=UDC?)_;RGSN<=Ub4hBq9iy!t)x7$ zD3zhSyj(9cFS|H7u^?41zbJk7I~ysW;&x9L#}JF&xj~*n2NZaW`u_hnvMqU&PAwfi7;>3%~)Y6@FC-(3h_;b5l`O=GX9BaD*L>WGGRp_QjX6X3s`yKGvM=j^F z_4`GCatmMWdY*UUQly#FXAjZR<%ezEg%ewp`wo3`;TO!evI^nftW+`~FK7FK=PI|m jwbkvH)mn85Sf<$Mg$8JuWWM+VbQ6Q8tDnm{r-UW|bPZV5 delta 247 zcmVe~?J)2K x|EmzhMTx`7d03pMn0mrP+m+L_OmX5;dI2svU=%bBjE(>R002ovPDHLkV1k07WD)=X diff --git a/emoji/2728-lg.png b/emoji/2728-lg.png index e13bc7fe983dd83bd5538a09e07137d7280c0444..3b7ad8339203caf4cabe0872489117d3e0e1e9a3 100644 GIT binary patch delta 244 zcmV>PaAR;YmQD686gUl2w!d;C^GbxH!A+UNaJ;uxN_IJ`Nc}fmD%yNa0AU<#3Km(&vMlkt?9$~QaGSU8 u9kG+jMTF&=Ms%7t#x!P?w`*r7>J=W6_I?vgG|cA!0000ERLtq(y*OfP)E0&a67&1Ed&>gWR1M)}51i3FNS( zJNh~@Fl_AS{*%Z$QBk74#?!?y#KOO~*ORG1frt6$|K%HJ2|4o~ipem`{o8ZRr+8Bi zbI!4j+DyTveGR-aT*@As3eunF*Vyw{2~0ITRnD?>mCy>y)b-lD++4rix*BJt#jt5* zPkGO<@vgY>3e|4~46`OIF%z-+T_|8!ZQ(KT!RL)v{r!$LzLl)n&(P#A^jE%Pjb97U OWelFKelF{r5}E)lCrf|; diff --git a/emoji/2728-sm.png b/emoji/2728-sm.png index 40562b5a1ee0f643a259dbe1bc4f48bf1162f1c7..5f26ee31da725bd42231104c6758a75bd1405e26 100644 GIT binary patch delta 188 zcmdnbc#2W6Gr-TCmrII^fq{Y7)59eQNb`W$9Be>xu4cc}L_3Lk$r9IylHmNblJdl& zREF~Ma=pyF?Be9af>gcyqV(DCY@~pS!#!ObLo_DN4Rqu?V8Fq&`G5V*xe;>?9y=?o zu~xy@*igjtOPSB%;MTZbDg{ap&$V|nPu+fi*Ka=~L$;T+emLtTtA$n9O5!&^s^7RP l^oXqf-p+4=IqwUY&E^Q{h^^akbqCN622WQ%mvv4FO#r*mLnQzJ delta 176 zcmX@bxS!FkGr-TCmrII^fq{Y7)59eQM1wE~6OjDdS*#7D7>k44ofy`glX(f`u%tWs zIx;Y9?C1WI$U0F`A~VF(#W6%9cxq2H7lR=O^WOhUV@+QsH`kRcxS-PfOg8P-{t92~ z%I^&l2I9r4sr%kZByjT=ygVU#sqJ*r+i!JOn|7X1&`mlJV{k$tsKBP?zzfb-JL~Hf Wr>(fr|MNG{LIzJ)KbLh*2~7YMP(Pyp diff --git a/emoji/2757-lg.png b/emoji/2757-lg.png index b219661bd86452d971c709dcbbf9e4879603601e..93a05fd994070bd03118ea51e5bee0975bef24b4 100644 GIT binary patch literal 179 zcmeAS@N?(olHy`uVBq!ia0vp^tUxTp!3HEJ?-4l$q&N#aB8wRq_zr_GKGf)C0Eq|1NpyD0XJCHD9;^IM<(uzDCZcv;llT~*E8 Xx?YMe+EGXuXcmK~tDnm{r-UW|%;P(I literal 186 zcmeAS@N?(olHy`uVBq!ia0vp^{6H+k!3HE-=Cy!0jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sDEfH31!Z9ZwBpueY!V~B-+@*jQ{o{WZx69rE>G3cC diff --git a/emoji/2757-sm.png b/emoji/2757-sm.png index be99fe698d261187ae1282e1abd9a9a7260bdfac..e0d0e5f0a2d5cb62e66fb6618fbdbe9d5519bb46 100644 GIT binary patch literal 173 zcmeAS@N?(olHy`uVBq!ia0vp^tU%1q!3HFCzOXg}Db50q$YKTtzQZ8Qcszea3Q$n8 z#5JNMI6tkVJh3R1p}f3YFEcN@I61K(RWH9NefB#WDWD=NPZ!4!iK$EbJ-HYZc$n26 z{ogO+FB&Z(Qmo0N+RYGrMXREvY}=NG3cCC?$2RghH bd3YE~vSdVh6V`G7jb`w4^>bP0l+XkKlZ`Xs diff --git a/emoji/3456-lg.png b/emoji/3456-lg.png new file mode 100644 index 0000000000000000000000000000000000000000..681f7b983e68407b98e3e937afaa2a1281ae539b GIT binary patch literal 152 zcmeAS@N?(olHy`uVBq!ia0vp^{6H+k!3HE-=Cy!0oCO|{#S9F5he4R}c>anMprB-l zYeY$Kep*R+Vo@qXd3m{BW?pu2a$-TMUVc&f>~}U&Kt-yaE{-7anMprB-l zYeY$Kep*R+Vo@qXd3m{BW?pu2a$-TMUVc&f>~}U&Kt;-)E{-7@6O&UC5`LU_U{nbI rT(9PpBYV|mRi!|7TFL^2a7Kohl`P_`mdH2(l{0v{`njxgN@xNA=fNsT literal 0 HcmV?d00001 From 78d5917d74453de0081e4a687aa0401a994428ad Mon Sep 17 00:00:00 2001 From: Sasi Olin Date: Sun, 21 Nov 2021 11:24:04 +0100 Subject: [PATCH 2/2] Add submodule and split into two scripts --- .gitmodules | 3 ++ autogen/generate_fonts.py | 48 +++++++++++++++++++++++++++ autogen/generate_pbl.py | 70 ++++++++++++--------------------------- pebble-firmware-utils | 1 + 4 files changed, 74 insertions(+), 48 deletions(-) create mode 100644 .gitmodules create mode 100755 autogen/generate_fonts.py create mode 160000 pebble-firmware-utils diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..72295eb --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "pebble-firmware-utils"] + path = pebble-firmware-utils + url = https://github.com/MarSoft/pebble-firmware-utils.git diff --git a/autogen/generate_fonts.py b/autogen/generate_fonts.py new file mode 100755 index 0000000..433c15c --- /dev/null +++ b/autogen/generate_fonts.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 + +import os +import json +import glob +import shutil +from PIL import Image + +outputs = [ + { "name": "emoji_14", "suffix": "sm", "size": 14, "top": 0 }, + { "name": "emoji_18", "suffix": "sm", "size": 18, "top": 2 }, + { "name": "emoji_24", "suffix": "lg", "size": 24, "top": 0 }, + { "name": "emoji_28", "suffix": "lg", "size": 28, "top": 2 } +] + +if not os.path.exists("emoji.json"): + print("You are in a wrong directory to build the fonts") + quit() + +os.makedirs("build", exist_ok=True) +emojis_file = open("emoji.json") +emojis_json = json.load(emojis_file) +for folder in ["sm", "lg"]: + files = glob.glob("emoji/*-%s.png" % folder) + os.makedirs("build/%s" % folder, exist_ok=True) + for file in files: + shutil.copyfile(file, "build/%s/%05X.png" % (folder, int(file[file.find('/')+1 : file.find('-')], 16))) +for output in outputs: + output_json = {} + output_json['metadata'] = [] + suffix = output["suffix"] + for emoji in emojis_json: + image = Image.open("build/%s/%05X.png" % (suffix, ord(emoji["character"]))) + metrics = emoji[suffix] + width, height = image.size + output_json['metadata'].append({ + 'codepoint': ord(emoji["character"]), + 'advance': width + 2, # 1 padding on left and right side + 'top': metrics["top"] + output["top"], + 'left': 1 + }) + with open('build/%s.json' % output["name"], 'w') as f: + json.dump(output_json, f) + os.system("cd build && python2 ../pebble-firmware-utils/fontgen.py pfo %d %s %s.pfo --list %s.json && cd .." % (output['size'], suffix, output['name'], output["name"])) + print("Generated build/%s.pfo" % output['name']) + os.remove('build/%s.json' % output["name"]) +for folder in ["sm", "lg"]: + shutil.rmtree("build/%s" % folder) diff --git a/autogen/generate_pbl.py b/autogen/generate_pbl.py index 9193921..ef9406b 100755 --- a/autogen/generate_pbl.py +++ b/autogen/generate_pbl.py @@ -1,56 +1,30 @@ #!/usr/bin/env python3 import os -import json -import glob import shutil -import re -from PIL import Image outputs = [ - { "name": "emoji_14", "suffix": "sm", "size": 14, "top": 0, "export": ["001", "002"] }, - { "name": "emoji_18", "suffix": "sm", "size": 18, "top": 2, "export": ["003", "004"] }, - { "name": "emoji_24", "suffix": "lg", "size": 24, "top": 0, "export": ["005", "006"] }, - { "name": "emoji_28", "suffix": "lg", "size": 28, "top": 2, "export": ["007", "008"] } + { "name": "emoji_14", "export": ["001", "002"] }, + { "name": "emoji_18", "export": ["003", "004"] }, + { "name": "emoji_24", "export": ["005", "006"] }, + { "name": "emoji_28", "export": ["007", "008"] } ] -if os.path.exists("emoji.json"): - os.makedirs("build", exist_ok=True) - os.system("cd build && git clone https://github.com/MarSoft/pebble-firmware-utils.git && cd ..") - emojis_file = open("emoji.json") - emojis_json = json.load(emojis_file) - for folder in ["sm", "lg"]: - files = glob.glob("emoji/*-%s.png" % folder) - os.makedirs("build/%s" % folder, exist_ok=True) - for file in files: - shutil.copyfile(file, "build/%s/%05X.png" % (folder, int(file[file.find('/')+1 : file.find('-')], 16))) - for output in outputs: - output_json = {} - output_json['metadata'] = [] - suffix = output["suffix"] - for emoji in emojis_json: - image = Image.open("build/%s/%05X.png" % (suffix, ord(emoji["character"]))) - metrics = emoji[suffix] - width, height = image.size - output_json['metadata'].append({ - 'codepoint': ord(emoji["character"]), - 'advance': width + 2, # 1 padding on left and right side - 'top': metrics["top"] + output["top"], - 'left': 1 - }) - with open('build/%s.json' % output["name"], 'w') as f: - json.dump(output_json, f) - os.system("cd build && python2 pebble-firmware-utils/fontgen.py pfo %d %s %s.pfo --list %s.json && cd .." % (output['size'], suffix, output['name'], output["name"])) - os.makedirs("build/resources", exist_ok=True) - for export in output["export"]: - shutil.copyfile("build/%s.pfo" % output["name"], "build/resources/%s" % export) - os.remove("build/%s.pfo" % output["name"]) - if not os.path.exists("build/resources/000"): - os.mknod("build/resources/000") - for n in range(10): - filepath = "build/resources/%03d" % (n + 9) - if not os.path.exists(filepath): - os.mknod(filepath) - os.system("cd build && python2 pebble-firmware-utils/pbpack.py resources/ emoji.pbl && cd ..") -else: - print("You are in a wrong directory to build the fonts") +for output in outputs: + if not os.path.exists("build/%s.pfo" % output["name"]): + print("You are in a wrong directory to build the pbl. build/%s.pfo is missing" % output["name"]) + quit() + +os.makedirs("build/resources/", exist_ok=True) +for output in outputs: + for export in output["export"]: + shutil.copyfile("build/%s.pfo" % output["name"], "build/resources/%s" % export) +if not os.path.exists("build/resources/000"): + os.mknod("build/resources/000") +for n in range(10): + filepath = "build/resources/%03d" % (n + 9) + if not os.path.exists(filepath): + os.mknod(filepath) +os.system("cd build && python2 ../pebble-firmware-utils/pbpack.py resources/ emoji.pbl && cd ..") +print("Generated build/emoji.pbl") +shutil.rmtree("build/resources/") diff --git a/pebble-firmware-utils b/pebble-firmware-utils new file mode 160000 index 0000000..c3271e1 --- /dev/null +++ b/pebble-firmware-utils @@ -0,0 +1 @@ +Subproject commit c3271e14427861b9efa0abd41ec9a06f31f401da