From db52d27eb56806e4bab316f60b87f61a39d8e064 Mon Sep 17 00:00:00 2001 From: Jonathan Rico Date: Tue, 22 Aug 2023 22:34:27 +0200 Subject: [PATCH] scripts: Update CFB font generator Update CFB font generator so it works with Pillow version 10. They deprecated some methods, with no direct replacements, so the generated fonts might be slightly different. Signed-off-by: Jonathan Rico --- scripts/build/gen_cfb_font_header.py | 15 +++++++++++++-- scripts/requirements-extras.txt | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/scripts/build/gen_cfb_font_header.py b/scripts/build/gen_cfb_font_header.py index dacb76c4eef75f..0bba785bfe7f9a 100755 --- a/scripts/build/gen_cfb_font_header.py +++ b/scripts/build/gen_cfb_font_header.py @@ -76,7 +76,13 @@ def extract_font_glyphs(): fw_max = 0 fh_max = 0 for i in range(args.first, args.last + 1): - fw, fh = font.getsize(chr(i)) + # returns (left, top, right, bottom) bounding box + size = font.getbbox(chr(i)) + + # calculate width + height + fw = size[2] - size[0] # right - left + fh = size[3] - size[1] # bottom - top + if fw > fw_max: fw_max = fw if fh > fh_max: @@ -100,7 +106,12 @@ def extract_font_glyphs(): image = Image.new('1', (width, height), 'white') draw = ImageDraw.Draw(image) - fw, fh = draw.textsize(chr(i), font=font) + # returns (left, top, right, bottom) bounding box + size = draw.textbbox((0, 0), chr(i), font=font) + + # calculate width + height + fw = size[2] - size[0] # right - left + fh = size[3] - size[1] # bottom - top xpos = 0 if args.center_x: diff --git a/scripts/requirements-extras.txt b/scripts/requirements-extras.txt index 969254e7835e0b..f210f069de9b04 100644 --- a/scripts/requirements-extras.txt +++ b/scripts/requirements-extras.txt @@ -16,7 +16,7 @@ clang-format>=15.0.0 lpc_checksum # used by scripts/build/gen_cfb_font_header.py - helper script for user -Pillow +Pillow>=10.0 # can be used to sign a Zephyr application binary for consumption by a bootloader imgtool>=1.9