universal-render 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- universal_render-0.1.0/LICENSE +21 -0
- universal_render-0.1.0/PKG-INFO +189 -0
- universal_render-0.1.0/README.md +165 -0
- universal_render-0.1.0/pyproject.toml +43 -0
- universal_render-0.1.0/setup.cfg +4 -0
- universal_render-0.1.0/tests/test_universal_render.py +397 -0
- universal_render-0.1.0/universal_render/__init__.py +277 -0
- universal_render-0.1.0/universal_render/backend.py +375 -0
- universal_render-0.1.0/universal_render/compat.py +128 -0
- universal_render-0.1.0/universal_render/diagnostics.py +249 -0
- universal_render-0.1.0/universal_render/fonts.py +516 -0
- universal_render-0.1.0/universal_render/highlevel.py +378 -0
- universal_render-0.1.0/universal_render/layout.py +967 -0
- universal_render-0.1.0/universal_render/mpl_support.py +1144 -0
- universal_render-0.1.0/universal_render/renderer.py +806 -0
- universal_render-0.1.0/universal_render/scripts.py +311 -0
- universal_render-0.1.0/universal_render.egg-info/PKG-INFO +189 -0
- universal_render-0.1.0/universal_render.egg-info/SOURCES.txt +19 -0
- universal_render-0.1.0/universal_render.egg-info/dependency_links.txt +1 -0
- universal_render-0.1.0/universal_render.egg-info/requires.txt +3 -0
- universal_render-0.1.0/universal_render.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mrinal Basak Shuvo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: universal-render
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Universal complex-script text rendering for Matplotlib and Seaborn using Qt/HarfBuzz shaping.
|
|
5
|
+
Author-email: Mrinal Basak Shuvo <mbs.jr.2009@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/mbs57/universal-render
|
|
8
|
+
Project-URL: Repository, https://github.com/mbs57/universal-render
|
|
9
|
+
Project-URL: Issues, https://github.com/mbs57/universal-render/issues
|
|
10
|
+
Keywords: matplotlib,unicode,complex scripts,text shaping,multilingual,visualization
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
16
|
+
Classifier: Topic :: Text Processing :: Fonts
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: numpy
|
|
21
|
+
Requires-Dist: matplotlib>=3.5
|
|
22
|
+
Requires-Dist: PySide6>=6.4
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
<p align="center">
|
|
26
|
+
<img src="https://raw.githubusercontent.com/mbs57/universal-render/master/assets/universal_render.jpg" alt="universal-render" width="720">
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
<h1 align="center">universal-render</h1>
|
|
30
|
+
|
|
31
|
+
<p align="center">
|
|
32
|
+
<b>Universal complex-script text rendering for Matplotlib and Seaborn, powered by Qt/HarfBuzz shaping.</b>
|
|
33
|
+
</p>
|
|
34
|
+
|
|
35
|
+
<p align="center">
|
|
36
|
+
<img alt="Python" src="https://img.shields.io/badge/python-3.9%2B-blue">
|
|
37
|
+
<img alt="License" src="https://img.shields.io/badge/license-MIT-green">
|
|
38
|
+
<img alt="Scripts" src="https://img.shields.io/badge/scripts%20verified-22-orange">
|
|
39
|
+
<img alt="Tests" src="https://img.shields.io/badge/tests-34%20passing-brightgreen">
|
|
40
|
+
</p>
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
Matplotlib's text engine cannot shape complex scripts — Bengali conjuncts break apart, Arabic letters don't join, Tamil and Thai vowels land in the wrong place, and often all you get is tofu boxes (▯▯▯). `universal_render` routes text through Qt's shaping engine (HarfBuzz) and embeds the correctly shaped result into your figures, with **automatic script detection and per-script font fallback** — no font configuration needed.
|
|
45
|
+
|
|
46
|
+
## Before / After
|
|
47
|
+
|
|
48
|
+
Left: Matplotlib's own text engine. Right: the same text through `universal_render` — 22 scripts, same machine, zero configuration.
|
|
49
|
+
|
|
50
|
+
<p align="center">
|
|
51
|
+
<img src="https://raw.githubusercontent.com/mbs57/universal-render/master/assets/comparison_before_after.png" alt="Matplotlib default vs universal_render across 22 scripts" width="900">
|
|
52
|
+
</p>
|
|
53
|
+
|
|
54
|
+
And it isn't just tofu: even with the *correct font installed*, Matplotlib (and, on Windows, mplcairo and Pillow — their official wheels ship without Raqm/HarfBuzz) silently renders complex scripts unshaped: Arabic unjoined, Bengali conjuncts split, with **zero warnings**. See [`evaluation/`](evaluation/) for the measured comparison.
|
|
55
|
+
|
|
56
|
+
## ✨ Features
|
|
57
|
+
|
|
58
|
+
- Automatic Unicode script detection (`detect_script`, `segment_runs`)
|
|
59
|
+
- Per-script font fallback with glyph-coverage validation (`auto_font_fallback`)
|
|
60
|
+
- Correct shaping for Indic (Bengali, Hindi, Tamil, Telugu, …), RTL (Arabic, Hebrew), Southeast Asian (Thai, Khmer, Lao, Myanmar), CJK, and more — **22 scripts verified** by the built-in `self_test()`
|
|
61
|
+
- Mixed-script text: Bengali + English + numbers in one string
|
|
62
|
+
- Native numerals for 16 scripts (`to_native_numerals(2026, "Bengali")` → `২০২৬`)
|
|
63
|
+
- Drop-in replacements for titles, axis labels, tick labels, legends, annotations, and heatmap cell text
|
|
64
|
+
- Matplotlib-style text options: `weight="bold"`, `italic=True`, `alpha=0.5`, `rotation=45` (any angle, including rotated tick labels), multiline `"\n"` strings, title `loc="left"/"center"/"right"`, and a proper figure `suptitle`
|
|
65
|
+
- DPI-safe layout: titles, labels, and ticks stay correctly placed at any `savefig(dpi=..., bbox_inches="tight")`
|
|
66
|
+
- Works headless (Colab/Kaggle/CI) via Qt offscreen mode
|
|
67
|
+
- Drop-in `bangla_render` compatibility: `import universal_render.compat as br`
|
|
68
|
+
|
|
69
|
+
## 🚀 Quick Example
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
import matplotlib.pyplot as plt
|
|
73
|
+
import universal_render as ur
|
|
74
|
+
|
|
75
|
+
fig, ax = plt.subplots()
|
|
76
|
+
ax.plot([1, 2, 3], [3, 1, 4])
|
|
77
|
+
|
|
78
|
+
ur.set_multilingual_title(ax, "বাংলা শিরোনাম") # Bengali — font auto-selected
|
|
79
|
+
ur.set_multilingual_xlabel(ax, "أشهر السنة") # Arabic — shaped + RTL
|
|
80
|
+
ur.set_multilingual_ylabel(ax, "மாத விற்பனை") # Tamil
|
|
81
|
+
|
|
82
|
+
ur.set_multilingual_xticks(ax, [1, 2, 3], ["एक", "दो", "तीन"]) # Hindi
|
|
83
|
+
ur.apply_multilingual_layout(fig, auto=True)
|
|
84
|
+
|
|
85
|
+
plt.savefig("plot.png", dpi=300)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
<p align="center">
|
|
89
|
+
<img src="https://raw.githubusercontent.com/mbs57/universal-render/master/assets/line_plot_six_scripts.png" alt="Line plot with Bengali, Cyrillic, Tamil, Arabic, Hindi, Thai and English labels" width="640">
|
|
90
|
+
</p>
|
|
91
|
+
|
|
92
|
+
### One-call APIs
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
# Label a whole plot at once — each string picks its own script's font
|
|
96
|
+
ur.localize_axes(
|
|
97
|
+
ax,
|
|
98
|
+
title="বিক্রয় প্রতিবেদন ২০২৬",
|
|
99
|
+
xlabel="महीना", ylabel="மதிப்பு",
|
|
100
|
+
xticklabels=["জানু", "फ़र", "மார்", "April"],
|
|
101
|
+
legend_labels=["পূর্বাভাস"],
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# Annotated heatmap with native Bengali digits and auto text contrast
|
|
105
|
+
ur.multilingual_heatmap(
|
|
106
|
+
ax, data, value_format=".2f", value_script="Bengali",
|
|
107
|
+
row_labels=["ঢাকা", "চট্টগ্রাম", "খুলনা"],
|
|
108
|
+
col_labels=["جودة", "คุณภาพ", "Quality"],
|
|
109
|
+
title="গুণমান ম্যাট্রিক্স",
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
# Verify this machine renders all 22 supported scripts
|
|
113
|
+
ur.self_test()
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
<p align="center">
|
|
117
|
+
<img src="https://raw.githubusercontent.com/mbs57/universal-render/master/assets/heatmap_six_scripts.png" alt="Heatmap with per-cell text in five scripts" width="480">
|
|
118
|
+
<img src="https://raw.githubusercontent.com/mbs57/universal-render/master/assets/styling_showcase.png" alt="Bold suptitle, left-aligned mixed-script title, rotated Bengali ticks" width="480">
|
|
119
|
+
</p>
|
|
120
|
+
|
|
121
|
+
## 📦 API Overview
|
|
122
|
+
|
|
123
|
+
| Area | Functions |
|
|
124
|
+
|---|---|
|
|
125
|
+
| High-level (one call) | `localize_axes`, `multilingual_heatmap`, `multilingual_bar_labels`, `language_to_script`, `set_language_font`, `font_for_language`, `localized_numerals`, `supported_languages` |
|
|
126
|
+
| Script detection | `detect_script`, `segment_runs`, `is_rtl_text`, `is_mixed_script`, `describe_text`, `to_native_numerals`, `script_direction` |
|
|
127
|
+
| Fonts | `auto_font_fallback`, `find_font_for_script`, `set_script_font`, `register_font`, `validate_font`, `font_covers_text`, `coverage_report` |
|
|
128
|
+
| Rendering | `render_text`, `render_text_array`, `render_mixed_text`, `render_paragraph`, `measure_text`, `set_render_defaults`, render cache controls |
|
|
129
|
+
| Matplotlib | `set_multilingual_title/xlabel/ylabel/suptitle`, `set_multilingual_xticks/yticks/numeric_ticks`, `set_multilingual_legend`, `multilingual_text`, `annotate_multilingual`, `add_multilingual_cell_text`, `multilingual_paragraph`, `apply_multilingual_layout` |
|
|
130
|
+
| Diagnostics / evaluation | `self_test` (per-script render check), `benchmark_render` (cold/warm latency), `save_comparison_figure` (before/after figure) |
|
|
131
|
+
| bangla-render compat | `import universal_render.compat as br` — every `set_bangla_*` name works unchanged |
|
|
132
|
+
|
|
133
|
+
## 🌍 Supported Script Families
|
|
134
|
+
|
|
135
|
+
| Family | Scripts (verified by `self_test()`) | Direction |
|
|
136
|
+
|---|---|---|
|
|
137
|
+
| Indic / Brahmic | Bengali, Devanagari (Hindi/Marathi/Nepali), Tamil, Telugu, Kannada, Malayalam, Gujarati, Gurmukhi (Punjabi), Odia, Sinhala | LTR |
|
|
138
|
+
| Right-to-left | Arabic (Arabic/Urdu/Persian), Hebrew | RTL |
|
|
139
|
+
| Southeast Asian | Thai, Lao, Khmer, Myanmar | LTR |
|
|
140
|
+
| East Asian | Han (Chinese), Hangul (Korean), Hiragana (Japanese) | LTR |
|
|
141
|
+
| European | Latin, Greek, Cyrillic | LTR |
|
|
142
|
+
|
|
143
|
+
Script *detection* additionally covers Katakana, Tibetan, Georgian, Armenian, and Ethiopic. One script serves many languages — `language_to_script()` maps ~60 language names.
|
|
144
|
+
|
|
145
|
+
## 📊 Evaluation
|
|
146
|
+
|
|
147
|
+
[`evaluation/compare_backends.py`](evaluation/compare_backends.py) renders the same text with the same font file through every backend, so the shaping engine is the only variable. Findings on Windows (Python 3.11):
|
|
148
|
+
|
|
149
|
+
| Backend | Bengali | Arabic | Notes |
|
|
150
|
+
|---|---|---|---|
|
|
151
|
+
| `universal_render` | ✅ correct | ✅ correct | reference (Qt/HarfBuzz) |
|
|
152
|
+
| Matplotlib, default font | ▯▯▯ tofu (104 warnings) | unjoined | at least it warns |
|
|
153
|
+
| Matplotlib, correct font | broken conjuncts, **0 warnings** | unjoined, **0 warnings** | silent failure |
|
|
154
|
+
| mplcairo 0.6.1 (pip wheel) | broken conjuncts, **0 warnings** | unjoined, **0 warnings** | wheel ships without Raqm |
|
|
155
|
+
| Pillow (pip wheel) | — | — | `PIL.features.check("raqm")` → `False` |
|
|
156
|
+
|
|
157
|
+
## 🛠 Installation
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
pip install PySide6 matplotlib numpy
|
|
161
|
+
pip install git+https://github.com/mbs57/universal-render.git
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Fonts: on Windows, everything works out of the box (Nirmala UI, Segoe UI, Leelawadee UI…). On Linux/Colab, install Noto fonts (`fonts-noto` / `fonts-noto-cjk`) — the fallback tables pick them up automatically. Verify any environment with:
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
import universal_render as ur
|
|
168
|
+
ur.self_test() # prints a per-script pass/fail table
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## 🧪 Tests
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
py tests/test_universal_render.py # or: pytest tests/
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Limitations
|
|
178
|
+
|
|
179
|
+
- Text is embedded as high-resolution raster images; SVG/PDF exports contain images rather than selectable vector glyphs.
|
|
180
|
+
- Arbitrary-angle rotated tick labels are center-anchored under their tick (Matplotlib anchors the label end).
|
|
181
|
+
- Scripts requiring vertical layout (e.g. traditional Mongolian) are not supported.
|
|
182
|
+
|
|
183
|
+
## Citation
|
|
184
|
+
|
|
185
|
+
If you use universal-render in academic work, please cite the bangla-render paper (SoftwareX) for now — a dedicated paper for the universal framework is in preparation.
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
[MIT](LICENSE) © 2026 Mrinal Basak Shuvo
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/mbs57/universal-render/master/assets/universal_render.jpg" alt="universal-render" width="720">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">universal-render</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<b>Universal complex-script text rendering for Matplotlib and Seaborn, powered by Qt/HarfBuzz shaping.</b>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<img alt="Python" src="https://img.shields.io/badge/python-3.9%2B-blue">
|
|
13
|
+
<img alt="License" src="https://img.shields.io/badge/license-MIT-green">
|
|
14
|
+
<img alt="Scripts" src="https://img.shields.io/badge/scripts%20verified-22-orange">
|
|
15
|
+
<img alt="Tests" src="https://img.shields.io/badge/tests-34%20passing-brightgreen">
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
Matplotlib's text engine cannot shape complex scripts — Bengali conjuncts break apart, Arabic letters don't join, Tamil and Thai vowels land in the wrong place, and often all you get is tofu boxes (▯▯▯). `universal_render` routes text through Qt's shaping engine (HarfBuzz) and embeds the correctly shaped result into your figures, with **automatic script detection and per-script font fallback** — no font configuration needed.
|
|
21
|
+
|
|
22
|
+
## Before / After
|
|
23
|
+
|
|
24
|
+
Left: Matplotlib's own text engine. Right: the same text through `universal_render` — 22 scripts, same machine, zero configuration.
|
|
25
|
+
|
|
26
|
+
<p align="center">
|
|
27
|
+
<img src="https://raw.githubusercontent.com/mbs57/universal-render/master/assets/comparison_before_after.png" alt="Matplotlib default vs universal_render across 22 scripts" width="900">
|
|
28
|
+
</p>
|
|
29
|
+
|
|
30
|
+
And it isn't just tofu: even with the *correct font installed*, Matplotlib (and, on Windows, mplcairo and Pillow — their official wheels ship without Raqm/HarfBuzz) silently renders complex scripts unshaped: Arabic unjoined, Bengali conjuncts split, with **zero warnings**. See [`evaluation/`](evaluation/) for the measured comparison.
|
|
31
|
+
|
|
32
|
+
## ✨ Features
|
|
33
|
+
|
|
34
|
+
- Automatic Unicode script detection (`detect_script`, `segment_runs`)
|
|
35
|
+
- Per-script font fallback with glyph-coverage validation (`auto_font_fallback`)
|
|
36
|
+
- Correct shaping for Indic (Bengali, Hindi, Tamil, Telugu, …), RTL (Arabic, Hebrew), Southeast Asian (Thai, Khmer, Lao, Myanmar), CJK, and more — **22 scripts verified** by the built-in `self_test()`
|
|
37
|
+
- Mixed-script text: Bengali + English + numbers in one string
|
|
38
|
+
- Native numerals for 16 scripts (`to_native_numerals(2026, "Bengali")` → `২০২৬`)
|
|
39
|
+
- Drop-in replacements for titles, axis labels, tick labels, legends, annotations, and heatmap cell text
|
|
40
|
+
- Matplotlib-style text options: `weight="bold"`, `italic=True`, `alpha=0.5`, `rotation=45` (any angle, including rotated tick labels), multiline `"\n"` strings, title `loc="left"/"center"/"right"`, and a proper figure `suptitle`
|
|
41
|
+
- DPI-safe layout: titles, labels, and ticks stay correctly placed at any `savefig(dpi=..., bbox_inches="tight")`
|
|
42
|
+
- Works headless (Colab/Kaggle/CI) via Qt offscreen mode
|
|
43
|
+
- Drop-in `bangla_render` compatibility: `import universal_render.compat as br`
|
|
44
|
+
|
|
45
|
+
## 🚀 Quick Example
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import matplotlib.pyplot as plt
|
|
49
|
+
import universal_render as ur
|
|
50
|
+
|
|
51
|
+
fig, ax = plt.subplots()
|
|
52
|
+
ax.plot([1, 2, 3], [3, 1, 4])
|
|
53
|
+
|
|
54
|
+
ur.set_multilingual_title(ax, "বাংলা শিরোনাম") # Bengali — font auto-selected
|
|
55
|
+
ur.set_multilingual_xlabel(ax, "أشهر السنة") # Arabic — shaped + RTL
|
|
56
|
+
ur.set_multilingual_ylabel(ax, "மாத விற்பனை") # Tamil
|
|
57
|
+
|
|
58
|
+
ur.set_multilingual_xticks(ax, [1, 2, 3], ["एक", "दो", "तीन"]) # Hindi
|
|
59
|
+
ur.apply_multilingual_layout(fig, auto=True)
|
|
60
|
+
|
|
61
|
+
plt.savefig("plot.png", dpi=300)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
<p align="center">
|
|
65
|
+
<img src="https://raw.githubusercontent.com/mbs57/universal-render/master/assets/line_plot_six_scripts.png" alt="Line plot with Bengali, Cyrillic, Tamil, Arabic, Hindi, Thai and English labels" width="640">
|
|
66
|
+
</p>
|
|
67
|
+
|
|
68
|
+
### One-call APIs
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
# Label a whole plot at once — each string picks its own script's font
|
|
72
|
+
ur.localize_axes(
|
|
73
|
+
ax,
|
|
74
|
+
title="বিক্রয় প্রতিবেদন ২০২৬",
|
|
75
|
+
xlabel="महीना", ylabel="மதிப்பு",
|
|
76
|
+
xticklabels=["জানু", "फ़र", "மார்", "April"],
|
|
77
|
+
legend_labels=["পূর্বাভাস"],
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
# Annotated heatmap with native Bengali digits and auto text contrast
|
|
81
|
+
ur.multilingual_heatmap(
|
|
82
|
+
ax, data, value_format=".2f", value_script="Bengali",
|
|
83
|
+
row_labels=["ঢাকা", "চট্টগ্রাম", "খুলনা"],
|
|
84
|
+
col_labels=["جودة", "คุณภาพ", "Quality"],
|
|
85
|
+
title="গুণমান ম্যাট্রিক্স",
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
# Verify this machine renders all 22 supported scripts
|
|
89
|
+
ur.self_test()
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
<p align="center">
|
|
93
|
+
<img src="https://raw.githubusercontent.com/mbs57/universal-render/master/assets/heatmap_six_scripts.png" alt="Heatmap with per-cell text in five scripts" width="480">
|
|
94
|
+
<img src="https://raw.githubusercontent.com/mbs57/universal-render/master/assets/styling_showcase.png" alt="Bold suptitle, left-aligned mixed-script title, rotated Bengali ticks" width="480">
|
|
95
|
+
</p>
|
|
96
|
+
|
|
97
|
+
## 📦 API Overview
|
|
98
|
+
|
|
99
|
+
| Area | Functions |
|
|
100
|
+
|---|---|
|
|
101
|
+
| High-level (one call) | `localize_axes`, `multilingual_heatmap`, `multilingual_bar_labels`, `language_to_script`, `set_language_font`, `font_for_language`, `localized_numerals`, `supported_languages` |
|
|
102
|
+
| Script detection | `detect_script`, `segment_runs`, `is_rtl_text`, `is_mixed_script`, `describe_text`, `to_native_numerals`, `script_direction` |
|
|
103
|
+
| Fonts | `auto_font_fallback`, `find_font_for_script`, `set_script_font`, `register_font`, `validate_font`, `font_covers_text`, `coverage_report` |
|
|
104
|
+
| Rendering | `render_text`, `render_text_array`, `render_mixed_text`, `render_paragraph`, `measure_text`, `set_render_defaults`, render cache controls |
|
|
105
|
+
| Matplotlib | `set_multilingual_title/xlabel/ylabel/suptitle`, `set_multilingual_xticks/yticks/numeric_ticks`, `set_multilingual_legend`, `multilingual_text`, `annotate_multilingual`, `add_multilingual_cell_text`, `multilingual_paragraph`, `apply_multilingual_layout` |
|
|
106
|
+
| Diagnostics / evaluation | `self_test` (per-script render check), `benchmark_render` (cold/warm latency), `save_comparison_figure` (before/after figure) |
|
|
107
|
+
| bangla-render compat | `import universal_render.compat as br` — every `set_bangla_*` name works unchanged |
|
|
108
|
+
|
|
109
|
+
## 🌍 Supported Script Families
|
|
110
|
+
|
|
111
|
+
| Family | Scripts (verified by `self_test()`) | Direction |
|
|
112
|
+
|---|---|---|
|
|
113
|
+
| Indic / Brahmic | Bengali, Devanagari (Hindi/Marathi/Nepali), Tamil, Telugu, Kannada, Malayalam, Gujarati, Gurmukhi (Punjabi), Odia, Sinhala | LTR |
|
|
114
|
+
| Right-to-left | Arabic (Arabic/Urdu/Persian), Hebrew | RTL |
|
|
115
|
+
| Southeast Asian | Thai, Lao, Khmer, Myanmar | LTR |
|
|
116
|
+
| East Asian | Han (Chinese), Hangul (Korean), Hiragana (Japanese) | LTR |
|
|
117
|
+
| European | Latin, Greek, Cyrillic | LTR |
|
|
118
|
+
|
|
119
|
+
Script *detection* additionally covers Katakana, Tibetan, Georgian, Armenian, and Ethiopic. One script serves many languages — `language_to_script()` maps ~60 language names.
|
|
120
|
+
|
|
121
|
+
## 📊 Evaluation
|
|
122
|
+
|
|
123
|
+
[`evaluation/compare_backends.py`](evaluation/compare_backends.py) renders the same text with the same font file through every backend, so the shaping engine is the only variable. Findings on Windows (Python 3.11):
|
|
124
|
+
|
|
125
|
+
| Backend | Bengali | Arabic | Notes |
|
|
126
|
+
|---|---|---|---|
|
|
127
|
+
| `universal_render` | ✅ correct | ✅ correct | reference (Qt/HarfBuzz) |
|
|
128
|
+
| Matplotlib, default font | ▯▯▯ tofu (104 warnings) | unjoined | at least it warns |
|
|
129
|
+
| Matplotlib, correct font | broken conjuncts, **0 warnings** | unjoined, **0 warnings** | silent failure |
|
|
130
|
+
| mplcairo 0.6.1 (pip wheel) | broken conjuncts, **0 warnings** | unjoined, **0 warnings** | wheel ships without Raqm |
|
|
131
|
+
| Pillow (pip wheel) | — | — | `PIL.features.check("raqm")` → `False` |
|
|
132
|
+
|
|
133
|
+
## 🛠 Installation
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
pip install PySide6 matplotlib numpy
|
|
137
|
+
pip install git+https://github.com/mbs57/universal-render.git
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Fonts: on Windows, everything works out of the box (Nirmala UI, Segoe UI, Leelawadee UI…). On Linux/Colab, install Noto fonts (`fonts-noto` / `fonts-noto-cjk`) — the fallback tables pick them up automatically. Verify any environment with:
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
import universal_render as ur
|
|
144
|
+
ur.self_test() # prints a per-script pass/fail table
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## 🧪 Tests
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
py tests/test_universal_render.py # or: pytest tests/
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Limitations
|
|
154
|
+
|
|
155
|
+
- Text is embedded as high-resolution raster images; SVG/PDF exports contain images rather than selectable vector glyphs.
|
|
156
|
+
- Arbitrary-angle rotated tick labels are center-anchored under their tick (Matplotlib anchors the label end).
|
|
157
|
+
- Scripts requiring vertical layout (e.g. traditional Mongolian) are not supported.
|
|
158
|
+
|
|
159
|
+
## Citation
|
|
160
|
+
|
|
161
|
+
If you use universal-render in academic work, please cite the bangla-render paper (SoftwareX) for now — a dedicated paper for the universal framework is in preparation.
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
[MIT](LICENSE) © 2026 Mrinal Basak Shuvo
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "universal-render"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Universal complex-script text rendering for Matplotlib and Seaborn using Qt/HarfBuzz shaping."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Mrinal Basak Shuvo", email = "mbs.jr.2009@gmail.com" },
|
|
14
|
+
]
|
|
15
|
+
keywords = [
|
|
16
|
+
"matplotlib",
|
|
17
|
+
"unicode",
|
|
18
|
+
"complex scripts",
|
|
19
|
+
"text shaping",
|
|
20
|
+
"multilingual",
|
|
21
|
+
"visualization",
|
|
22
|
+
]
|
|
23
|
+
classifiers = [
|
|
24
|
+
"Development Status :: 3 - Alpha",
|
|
25
|
+
"Intended Audience :: Science/Research",
|
|
26
|
+
"License :: OSI Approved :: MIT License",
|
|
27
|
+
"Programming Language :: Python :: 3",
|
|
28
|
+
"Topic :: Scientific/Engineering :: Visualization",
|
|
29
|
+
"Topic :: Text Processing :: Fonts",
|
|
30
|
+
]
|
|
31
|
+
dependencies = [
|
|
32
|
+
"numpy",
|
|
33
|
+
"matplotlib>=3.5",
|
|
34
|
+
"PySide6>=6.4",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Homepage = "https://github.com/mbs57/universal-render"
|
|
39
|
+
Repository = "https://github.com/mbs57/universal-render"
|
|
40
|
+
Issues = "https://github.com/mbs57/universal-render/issues"
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.packages.find]
|
|
43
|
+
include = ["universal_render*"]
|