Text containing "\r" or other paragraph separators raises "raqm_layout() failed." in 13.0.0
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start with ImageText._split and the single-line font methods mentioned in the issue, then compare Pillow’s paragraph handling with the reported RAQM 0.11.0 behavior. Reproduce with the supplied script using RAQM and the listed separators. Done means the affected calls handle these inputs consistently with the intended multiline behavior, or return a clear documented error instead of raqm_layout() failed.
由索引模型根据 Issue 内容生成。
描述
What did you do?
Upgraded from Pillow 12.3.0 to 13.0.0 (manylinux wheels) on a system with fribidi, so text uses the RAQM layout engine. Text containing a paragraph separator now raises instead of rendering:
import PIL
from PIL import Image, ImageDraw, ImageFont, features
print(PIL.__version__, "raqm", features.version_feature("raqm"))
font = ImageFont.load_default(size=40).font_variant(layout_engine=ImageFont.Layout.RAQM)
draw = ImageDraw.Draw(Image.new("RGB", (400, 200)))
for text in ["a\rb", "a\r\nb", "a\nb", "a\x85b", "a
b", "a\x1cb"]:
for name, call in [
("draw.text", lambda: draw.text((10, 10), text, font=font)),
("draw.textbbox", lambda: draw.textbbox((10, 10), text, font=font)),
("font.getbbox", lambda: font.getbbox(text)),
("font.getlength", lambda: font.getlength(text)),
]:
try:
call()
except Exception as e:
print(repr(text), name, type(e).__name__, e)
What did you expect to happen?
The same as 12.3.0, where every call succeeds; or, if this input is no longer supported, a documented change and an error that says why.
What actually happened?
On 13.0.0 (raqm 0.11.0), 22 of the 24 calls raise RuntimeError: raqm_layout() failed.:
| Text | draw.text |
draw.textbbox |
font.getbbox |
font.getlength |
|---|---|---|---|---|
"a\rb" |
RuntimeError | RuntimeError | RuntimeError | RuntimeError |
"a\r\nb" |
RuntimeError | RuntimeError | RuntimeError | RuntimeError |
"a\nb" |
ok | ok | RuntimeError | RuntimeError |
"a\x85b" (NEL) |
RuntimeError | RuntimeError | RuntimeError | RuntimeError |
"a
b" (PARAGRAPH SEPARATOR) |
RuntimeError | RuntimeError | RuntimeError | RuntimeError |
"a\x1cb" (also \x1d, \x1e) |
RuntimeError | RuntimeError | RuntimeError | RuntimeError |
With 12.3.0 (raqm 0.10.5) in the same image, all 24 succeed. With Layout.BASIC, all succeed on both versions.
The cause appears to be libraqm 0.11.0 (bundled in the wheels since #9819), which now deliberately fails raqm_layout() when the text contains any Bidi class B character (HOST-Oman/libraqm@a7c86959a6b1f590b586fdb55a76440d074298ee, "Reject input that spans multiple paragraphs"). Pillow's multiline handling splits on "\n" only (ImageText._split), so "\r\n" line breaks leave a trailing "\r" on each line, and the other separators reach raqm unchanged. The single-line font methods pass "\n" through as well.
This is easy to hit with user input: browsers submit <textarea> line breaks as "\r\n", so code that renders multi-line form input with draw.text() or draw.multiline_text() worked on 12.3 and fails on 13.0 when RAQM is available. It also only shows up where fribidi is installed, so it can pass tests on macOS or slim images and fail in production.
Possible fixes, for whoever knows the codebase better:
- treat all paragraph separators (at least
"\r\n"and"\r") as line breaks in the multiline path; - in the single-line path, handle or reject separators before calling raqm, with an error message naming the character, rather than a bare
raqm_layout() failed.; - mention the behaviour change in the 13.0.0 release notes.
What are your OS, Python and Pillow versions?
- OS: Debian 12 (amd64 and arm64 containers); also reproduced on Amazon Linux 2023 and Ubuntu 24.04 arm64 (fribidi 1.0.13)
- Python: 3.11
- Pillow: 13.0.0 (12.3.0 not affected)
--------------------------------------------------------------------
Pillow 13.0.0
Python 3.11.2 (main, Oct 7 2026, 12:35:07) [GCC 12.2.0]
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 13.0.0
*** TKINTER support not installed
--- FREETYPE2 support ok, loaded 2.14.3
--- LITTLECMS2 support ok, loaded 2.19
--- WEBP support ok, loaded 1.6.0
--- AVIF support ok, loaded 1.4.2
--- JPEG support ok, compiled for libjpeg-turbo 3.2.0
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.4
--- ZLIB (PNG/ZIP) support ok, loaded 1.2.13, compiled for zlib-ng 2.3.3
--- LIBTIFF support ok, loaded 4.7.2
--- RAQM (Bidirectional Text) support ok, loaded 0.11.0, fribidi 1.0.8, harfbuzz 14.5.0
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------
- 主要语言
- Python
- 星标
- 13.9k
- 派生
- 2.6k
- 平均合并
- 1 天 6 小时
- 30 天内合并 PR
- 172
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python-pillow/Pillow 的其他 Issue
-
TIFF without XResolution/YResolution reports dpi (1, 1)可能已有人在做 @brettdavies 今天认领。 未关闭🤖-assisted TIFF
难度 2/5 1-3 小时 新手友好度 75/100
python-pillow/Pillow#10332 · 2 条评论 ·
维护者通常 1 天内回复
-
Warn that pre-applying arabic_reshaper + python-bidi corrupts text on a Raqm build可能已有人在做 @Syamjith-NK 于 59 天前认领。 未关闭Documentation Font Rendering PNG Third Party Framework
难度 2/5 1-3 小时 新手友好度 78/100
python-pillow/Pillow#9907 · 2 条评论 ·
维护者通常 1 天内回复
-
Image.putpixel incorrectly labels supported arguments in type annotations可能已有人在做 @radarhere 于 187 天前认领。 未关闭PNG
难度 2/5 1-3 小时 新手友好度 70/100
python-pillow/Pillow#9584 · 1 条评论 ·
维护者通常 1 天内回复
-
JPEG dpi read from EXIF uses XResolution for both axes可能已有人在做 @unvisible789 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 20/100
python-pillow/Pillow#10331 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 58/100
python-pillow/Pillow#10330 · 1 条评论 ·
维护者通常 1 天内回复
查看 python-pillow/Pillow 的全部 Issue
相似的 Issue
-
lesson-submission pending-review
难度 2/5 1-3 小时 新手友好度 72/100
Ikalus1988/MisakaNet#3956 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
aws-samples/sample-per-model-bedrock#574 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 70/100
521xueweihan/HelloGitHub#4133 ·
-
plot_components fails for logistic models with minmax scaling and no floor可能已有人在做 @RaphaelFakhri 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 4 天内回复
-
Update migen未关闭
难度 2/5 1-3 小时 新手友好度 70/100
YosysHQ/oss-cad-suite-build#220 ·