Issue in toolchain 2.5.0, error extracting fonts. gen_cfb_font_header.py, missing getsize.

Hi,

I have been trying to update a project from SDK and Toolchain 2.2.0 to 2.5.0 for both.

But I find that I get an error extracting fonts.

  File "/home/user/ncs/v2.5.0/zephyr/scripts/build/gen_cfb_font_header.py", line 80, in extract_font_glyphs
    fw, fh = font.getsize(chr(i))
AttributeError: 'FreeTypeFont' object has no attribute 'getsize'

It seems to me the reason is that getsize no longer exists in Python PIL package. At some point after Toolchain 2.2.0, PIL version 10 seems to be required, which no longer implements this method.

See: https://pillow.readthedocs.io/en/stable/deprecations.html#font-size-and-offset-methods

I tried editing the code, exchanging the method with the suggested code, but it seems to not give the exact same output anymore as I get an error further on... this could have been my error, never the less the issue remains in toolchain 2.5.0.

  • Hello Jon0,

    Could you please provide more details about your setup?

    In particular:

    • How are the toolchains and SDKs installed?
    • What is going on when this error occurs?
      • Can you provide the full log, if there is nothing confidential?
      • Does this happen while building your application, or while running some helper scripts in the SDK/Tolchain?
    • What are the steps to reproduce this error?
    • Can this error be produced with a sample on NCS v2.5.0?
      Or does it only happen when upgrading a sample from an earlier NCS version?

    If you can think of any other details that might be relevant, please share them as well.

    Please note that it is the Christmas - New Year holiday season here. We are thus severely understaffed, and there would be delays in responses. Our apologies for the inconveniences. 

    Hieu

  • Hello Hieu,

    No worries, it is not critical for me at this point, but I thought it good to start a ticket as there definitely seems to be something broken.

    It is an inherited code base so I'm not entirely clear how it is supposed to work... I think there is a vector font being converted to a bitmap, to be used on an LCD display.

    Here is one of the lines from the CMakeLists.txt:

    generate_cfb_font_for_target(app fonts/bigfont.ttf ${gen_dir}/big_font.h 8 16 -s 12 --center-x --first 32 --last 126)

    I will come back to this in the coming weeks.

  • Hello Jon0,

    I found the only sample in the SDK that makes use of generate_cfb_font_for_target(). It's the Custom Fonts sample. (see its CMakeLists.txt)

    I had hoped to be able to reproduce it to be sure, but it seems to require a Zephyr display node in the Devicetree to compile properly. Thus, I am facing some unrelated compilation error.

    I have looked into the Python requirement for Pillow. It looks like that rather than Pillow version 10+ is required in v2.5.0, Pillow version has never been strictly required. Thus, when a new version of Pillow was released, it was simply installed into the SDK's Python instance.

    Could you please try to revert all of your changes to the .py files, and instead install a compatible version of Pillow into the SDK's Python instance?

    In case it helps, for my copy of the Toolchain installed with the Toolchain Manager, the Python instance is located in C:\ncs\toolchains\c57af46cb7\opt\bin\python.exe.

    If that doesn't work, could you please share the relevant part of your project's Devicetree that can help us setup the Zephyr display node required for compilation of the Custom Fonts sample? We can try to reproduce the issue and debug further.

  • Good -freezing- morning, (it's -33 degrees celsius here)

    It is good to hear the Pillow version can be safely downgraded, it sounds reasonable this will fix the issue.

    I will try to run it later this week to make sure.

  • A little late but I finally were able to test downgrading the Pillow version to 9.01 in toolchain v2.5.0 (as is used in toolchain 2.3.0 at least).

    Just wanted to report that this workaround does fix the issue.

Related