Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitmap missing for glyph #8272

Open
joaohaas opened this issue Jul 31, 2024 · 4 comments · May be fixed by #8324
Open

Bitmap missing for glyph #8272

joaohaas opened this issue Jul 31, 2024 · 4 comments · May be fixed by #8324

Comments

@joaohaas
Copy link

What did you do?

Tried to call ImageDraw.text((15, 36), "A B") with the following font:
FS Lola Medium Regular.zip

What did you expect to happen?

Either a successful call, since that font is rendered correctly on browsers and as a system font, or the usage of one of the 'unidentified characters' (□, �).

What actually happened?

Because of the whitespace, the call fails with a OSError: Bitmap missing for glyph exception on PIL/ImageFont.py:607. I'm not exactly sure if there's any actual error with the font file, but as mentioned, it works fine on browsers and as a system font.

What are your OS, Python and Pillow versions?

  • OS: MacOS 13.3.1, Ubuntu 20.04
  • Python: 3.8
  • Pillow: 10.4
--------------------------------------------------------------------
Pillow 10.4.0
Python 3.8.18 (default, Nov  2 2023, 16:50:59)
       [Clang 14.0.3 (clang-1403.0.22.14.1)]
--------------------------------------------------------------------
Python executable is /Users/joaohaas/dev/server/env/bin/python3
Environment Python files loaded from /Users/joaohaas/dev/server/env
System Python files loaded from /opt/homebrew/Cellar/[email protected]/3.8.18_1/Frameworks/Python.framework/Versions/3.8
--------------------------------------------------------------------
Python Pillow modules loaded from /Users/joaohaas/dev/server/env/lib/python3.8/site-packages/PIL
Binary Pillow modules loaded from /Users/joaohaas/dev/server/env/lib/python3.8/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 10.4.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.13.2
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.4.0
--- WEBP Transparency support ok
--- WEBPMUX support ok
--- WEBP Animation support ok
--- JPEG support ok, compiled for libjpeg-turbo 3.0.3
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.2
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1
--- LIBTIFF support ok, loaded 4.6.0
--- RAQM (Bidirectional Text) support ok, loaded 0.10.1, fribidi 1.0.14, harfbuzz 8.5.0
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------
from PIL import Image, ImageDraw, ImageFont

font = ImageFont.truetype("<path>/FS Lola Medium Regular.ttf", size=27)
image = Image.new("RGB", (440, 58), (255, 255, 255))
draw_object = ImageDraw.Draw(image)
draw_object.text((15, 36), "A B", font=font)
@apodtele
Copy link

It is absolutely normal for FreeType to render a NULL-buffer without any errors returned. particularly for whitespace characters. The size of such bitmaps will also be 0x0, with advance properly assigned, however.

@radarhere radarhere linked a pull request Aug 23, 2024 that will close this issue
@radarhere
Copy link
Member

radarhere commented Aug 23, 2024

Thanks very much @apodtele

I've created #8324 to resolve this by drawing an empty character.

@apodtele
Copy link

The font is interesting indeed. The space character contains a degenerate contour of two points (0,0) and (0,1). So the output is NULL of size 0x1 (one raw of zero pixels each), i.e. bitmap.width = 0, bitmap.rows = 1. But it could be something else depending on the rendering mode.

I opened https://gitlab.freedesktop.org/freetype/freetype/-/issues/1295, if you have an opinion.

@radarhere
Copy link
Member

If it is degenerate (https://lists.nongnu.org/archive/html/freetype-devel/2012-04/msg00068.html, "A degenerate contour is one that does not change the rendering if removed.") and I presume the size of the glyph doesn't affect the advance, then output makes no difference for rendering operations that use the same settings, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants