generate loader files for the new font

also sort the font files in alphabetical order now,
instead of relying on arbitrary ordering of os.listdir() :P
This commit is contained in:
bunnie 2023-07-05 14:44:30 +08:00
parent fc9cb5af8c
commit 4454dffe4e
3 changed files with 29 additions and 30 deletions

View file

@ -9,7 +9,7 @@ from collections import OrderedDict
"""
This script should be run whenever the fonts are updated inside the blitstr dependency. The
thought is that this is a rare event, and therefore it's better to run this on the rare occassions
thought is that this is a rare event, and therefore it's better to run this on the rare occasions
that this happens and vendor in the font files as references to their location in the FLASH
memory map.
@ -27,19 +27,17 @@ same level as xous-core, but this can be changed with the `-d` command line argu
def main():
parser = argparse.ArgumentParser(description="Build the Betrusted SoC")
parser.add_argument(
"-d", "--dir", default="../../../blitstr", help="Location of the blitstr source files", type=str
"-d", "--dir", default="../../services/graphics-server/src/blitstr2", help="Location of the blitstr source files", type=str
)
args = parser.parse_args()
fontdir = args.dir + '/src/fonts'
fontdir = args.dir + '/fonts'
fontdict = OrderedDict([]) # we want a deterministic dict
filter = re.compile('.*DATA.*u32.*[0-9]*.*')
with os.scandir(fontdir) as listOfEntries:
for entry in listOfEntries:
if entry.is_file():
print("Processing " + entry.name)
modulename = entry.name.split('.')[0]
with open(entry) as infile, open('fonts/' + entry.name, 'w') as outfile:
filter = re.compile('.*GLYPHS.*u32.*[0-9]*.*')
for entry in sorted(os.listdir(fontdir)):
print("Processing " + entry)
modulename = entry.split('.')[0]
with open(fontdir + "/" + entry) as infile, open('fonts/' + entry, 'w') as outfile:
outfile.write(
"// This file is autogenerated by xous-core/loader/src/generate_fonts.py. Do not edit.\n")
outfile.write("#[allow(dead_code)]\n")
@ -48,7 +46,7 @@ def main():
outfile.write("#[used]\n")
copy = False
for line in infile:
if line.strip() == "/// Packed glyph pattern data.":
if line.strip().startswith('pub const GLYPHS'):
copy = True
if copy:
fixup = line.replace('pub const', 'pub static')
@ -56,7 +54,7 @@ def main():
if matched:
arraylen = re.findall('\d+', matched.group().split(';')[1])[0]
fontdict[modulename] = arraylen
fixup = fixup.replace('DATA', 'DATA_' + modulename.upper())
fixup = fixup.replace('GLYPHS', 'DATA_' + modulename.upper())
outfile.write(fixup)
if line.strip() == "];":
copy = False

View file

@ -34,4 +34,4 @@ debugprint = []
braille = []
gfx-testing = []
ditherpunk = []
default = ["gfx-testing"]
default = []

View file

@ -79,6 +79,7 @@ fn map_fonts() -> MemoryRange {
blitstr2::fonts::regular::GLYPH_LOCATION.store((fontregion.as_ptr() as usize + fontmap::REGULAR_OFFSET as usize) as u32, Ordering::SeqCst);
blitstr2::fonts::small::GLYPH_LOCATION.store((fontregion.as_ptr() as usize + fontmap::SMALL_OFFSET as usize) as u32, Ordering::SeqCst);
blitstr2::fonts::zh::GLYPH_LOCATION.store((fontregion.as_ptr() as usize + fontmap::ZH_OFFSET as usize) as u32, Ordering::SeqCst);
blitstr2::fonts::tall::GLYPH_LOCATION.store((fontregion.as_ptr() as usize + fontmap::TALL_OFFSET as usize) as u32, Ordering::SeqCst);
fontregion
}