Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Text containing "\r" or other paragraph separators raises "raqm_layout() failed." in 13.0.0

未关闭
#10,317 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
54/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
c, python
领域
backend

调研方向

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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

python-pillow/Pillow 的其他 Issue

查看 python-pillow/Pillow 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。