Metadata-Version: 2.4
Name: banglapdf
Version: 0.1.0
Summary: Correctly shaped Bangla (Bengali) text in ReportLab PDFs — conjuncts, kars and mixed Bangla+English that just work
Author-email: "MD. MAHBUB ALOM" <hsmahbub@gmail.com>
License: MIT
Project-URL: Homepage, https://github.com/mahbub-dev/banglapdf
Project-URL: Issues, https://github.com/mahbub-dev/banglapdf/issues
Keywords: bangla,bengali,pdf,reportlab,unicode,harfbuzz,shaping
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: Bengali
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Text Processing :: Fonts
Classifier: Topic :: Printing
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: reportlab>=4.1
Requires-Dist: uharfbuzz>=0.39
Requires-Dist: fonttools>=4.40
Dynamic: license-file

# banglapdf

**Correctly shaped Bangla (Bengali) text in [ReportLab](https://www.reportlab.com/opensource/) PDFs.**

রিপোর্টল্যাবে বাংলা লিখলে যুক্তাক্ষর ভেঙে যায়, ি-কার ভুল জায়গায় বসে — `banglapdf` সেই সমস্যার সমাধান।

## The problem

Out of the box, ReportLab renders Bangla like this:

> বিজ্‌ঞান, স্‌বাস্‌থ্‌য, প্‌রক্‌রিয়া (broken conjuncts, misplaced kars)

Two things are needed to fix it, and both are easy to get wrong:

1. **HarfBuzz shaping** must be enabled (`shaping=1` on the paragraph style,
   with `uharfbuzz` installed) — otherwise conjuncts (ক্ষ, স্থ, দ্ধ) and
   vowel signs never form.
2. **No inline font switching** inside shaped paragraphs. Mixed
   Bangla+English text ("Python-এর সাথে বাংলা") crashes or garbles if
   you switch fonts mid-word, because shaping runs per text fragment. The fix
   is a single font that covers both scripts — `banglapdf` builds one at
   runtime by merging Noto Sans (Latin) with Noto Sans Bengali using
   fontTools, and caches it in `~/.cache/banglapdf/`.

`banglapdf` packages both fixes behind a two-line API.

## Install

```bash
pip install banglapdf
```

You also need the Noto fonts (already present on most desktop Linux systems):

```bash
sudo apt install fonts-noto-core        # Debian / Ubuntu
```

Any other Latin+Bangla font pair also works — pass explicit paths to
`register_fonts()`.

## Quickstart

```python
from reportlab.platypus import SimpleDocTemplate
from banglapdf import register_fonts, BanglaParagraph, bangla_style

register_fonts()   # merge + cache + register fonts (names: "Bangla", "BanglaB")

story = [
    BanglaParagraph("আমার সোনার বাংলা, আমি তোমায় ভালোবাসি",
                    bangla_style(bold=True, fontSize=16)),
    BanglaParagraph("যুক্তাক্ষর (ক্ষ, স্থ, দ্ধ), ি-কার এবং English শব্দ — "
                    "সব একসাথে নিখুঁতভাবে render হয়।"),
]
SimpleDocTemplate("demo.pdf").build(story)
```

## API

| Function | What it does |
|---|---|
| `register_fonts(regular="Bangla", bold="BanglaB", latin_regular=..., bangla_regular=..., ...)` | Merges a Latin + a Bangla TTF into one font (cached), registers it with ReportLab, and sets up the font family so `<b>` tags work. |
| `bangla_style(name, bold=False, **ParagraphStyle_kwargs)` | A `ParagraphStyle` with the merged font and `shaping=1` preset. |
| `BanglaParagraph(text, style=None, markup=False, **style_overrides)` | A `Paragraph` that escapes markup characters by default; pass `markup=True` to use ReportLab inline tags yourself. |
| `merged_font_path(weight, latin, bangla, force=False)` | Path to the cached merged TTF (builds it on first call). |
| `escape(text)` | Escapes `&`, `<`, `>` for paragraph markup. |

Everything else is plain ReportLab — tables, frames, doc templates and canvas
drawing all work unchanged; just use the `"Bangla"`/`"BanglaB"` font names and
`shaping=1` (which `bangla_style` already sets).

## Requirements

- Python ≥ 3.9
- reportlab ≥ 4.1 (HarfBuzz shaping support)
- uharfbuzz, fonttools (installed automatically)
- A Latin and a Bangla TTF on the system (Noto recommended)

## License

MIT © MD. MAHBUB ALOM

The Noto fonts used at runtime are licensed under the [SIL Open Font
License](https://openfontlicense.org/); this package does not redistribute
them — it merges the copies already installed on your system.
