arshape
收藏资源简介:
ArShape 是一个用于评估阿拉伯文本渲染正确性的基准测试数据集。它重点验证了在 Python 环境中(特别是使用 Pillow 库时)常见的阿拉伯文本预处理方法(即先使用 arabic_reshaper 进行字形调整,再使用 python-bidi 进行双向文本重排序)是否在已经具备复杂文本布局能力(如通过 libraqm 实现的 HarfBuzz 和 FriBiDi)的渲染器上导致文本损坏。数据集包含 3 种阿拉伯字体(包括 SF Arabic、Geeza Pro 和 IBM Plex Sans Arabic)与 5 个测试字符串(涵盖纯阿拉伯语、含数字和拉丁字母的混合文本)在 4 种渲染路径(现代引擎+原始文本、现代引擎+预处理、无成形引擎+原始文本、无成形引擎+预处理)下的共 60 个评估样本。每个样本记录了形状相似度(verdict:identical、recognisable、broken)以及字体覆盖情况(glyphs_ok 列,指示是否所有字符都被正确绘制)。数据集还提供了复现脚本(render_bench.py)和详细的评估结果文件(results.jsonl)。该数据集适用于评估阿拉伯文本渲染库、字体覆盖检查以及验证文本渲染管线的正确性。
ArShape is a benchmark dataset for evaluating the correctness of Arabic text rendering. It focuses on verifying whether common Arabic text preprocessing methods in Python environments (especially when using the Pillow library), namely first using arabic_reshaper for glyph reshaping and then python-bidi for bidirectional text reordering, cause text corruption on renderers that already have complex text layout capabilities (such as HarfBuzz and FriBiDi implemented via libraqm). The dataset contains 60 evaluation samples across 3 Arabic fonts (including SF Arabic, Geeza Pro, and IBM Plex Sans Arabic) and 5 test strings (covering pure Arabic, mixed text with digits and Latin letters) under 4 rendering paths (modern engine + raw text, modern engine + preprocessing, no shaping engine + raw text, no shaping engine + preprocessing). Each sample records shape similarity (verdict: identical, recognisable, broken) and font coverage (glyphs_ok column, indicating whether all characters are correctly drawn). The dataset also provides reproduction scripts (render_bench.py) and detailed evaluation result files (results.jsonl). It is suitable for evaluating Arabic text rendering libraries, font coverage checking, and verifying the correctness of text rendering pipelines.
ArShape 数据集详情
数据集概述
ArShape 是一个用于评估阿拉伯文本渲染效果的基准测试数据集,由 Syamjith NK 创建。该数据集包含少于 1K 条数据,采用 CC BY 4.0 许可协议,主要面向文本到图像(text-to-image)任务,专注于阿拉伯语排版、文本渲染、国际化、双向文本(bidi)处理等领域。
核心发现
该数据集验证了阿拉伯文本渲染中的一个关键问题:在使用 arabic_reshaper + python-bidi 预处理后,如果渲染器本身已支持复杂文本布局(complex-text layout),会导致输出文本被破坏。以“welcome”一词为例:
- 正确渲染(无预处理):مرحبا بكم
- 经过 reshaper + bidi 后:مكب ابحرم
技术要点
- 运行环境检测:渲染器是否已执行复杂文本布局是运行时属性,而非版本号。Pillow 8.2.0+ 的 wheels 捆绑了 libraqm,但 libraqm 在运行时才连接 FriBiDi,因此同一 wheel 在不同机器上的行为可能不同。建议使用
PIL.features.check("raqm")检测。 - 渲染路径对比:数据集测量了 3 种阿拉伯字体 × 5 个字符串 × 4 种渲染路径,基于形状相似度(IoU)评分:
- 现代引擎 + 原始文本:15 个完全一致
- 现代引擎 + reshaper + bidi:14 个被破坏
- 无 shaping 引擎 + 原始文本:15 个全部被破坏
- 无 shaping 引擎 + reshaper + bidi:6 个被破坏,9 个可识别但仍有缺陷
- 字体覆盖陷阱:通过检查字体 cmap 表发现,SF Arabic 和 Geeza Pro 字体完全不含拉丁字母和数字,
في عام 2026中的年份会被渲染为.notdef方框。IBM Plex Sans Arabic 则具有完整覆盖。
glyphs_ok 列说明
该列(2026年8月21日新增)用于弥补主评分指标的不足。部分行虽然 verdict = identical(IoU 1.000),但字符串中的 2026 和 Pixelogik 实际被渲染为 .notdef 方框,因为字体缺失这些字符。glyphs_ok 作为独立的字体覆盖检测轴,建议用户同时按 verdict 和 glyphs_ok 过滤数据。
实用性建议
- 检测渲染器是否支持复杂文本布局(如 Pillow 中检查 raqm)
- 若支持:直接传入阿拉伯文本,不要预处理
- 若不支持:执行 reshape,并单独测试数字、拉丁字符和变音符号
- 确认字体包含所有待渲染字符
配套资源
- 数据文件:
results.jsonl(test 分割) - 代码:MIT 许可(参见
LICENSE),可运行python render_bench.py重现实验 - 相关数据集:ArNum-TTS(语音合成中的数字问题)、ArPDF(PDF 往返中的阿拉伯语问题)
- 详细技术文章:https://syamjithnk.com/arabic-text-rendering





