PHPackages                             imsoft-dev/devanagari-reshaper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. imsoft-dev/devanagari-reshaper

ActiveLibrary[Templating &amp; Views](/categories/templating)

imsoft-dev/devanagari-reshaper
==============================

PHP library for correcting Devanagari i-matra (ि) visual rendering order for legacy renderers (PDF, canvas, etc.)

v1.0.1(2mo ago)012↓88.9%MITPHPPHP &gt;=8.0

Since Apr 28Pushed 2mo agoCompare

[ Source](https://github.com/imsoft-dev/devanagari-reshaper)[ Packagist](https://packagist.org/packages/imsoft-dev/devanagari-reshaper)[ RSS](/packages/imsoft-dev-devanagari-reshaper/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

devanagari/reshaper
===================

[](#devanagarireshaper)

A lightweight PHP library for correcting **Devanagari i-matra (ि) rendering order** in systems that do not perform Unicode shaping — such as legacy PDF generators, canvas renderers, or custom font engines.

---

The Problem
-----------

[](#the-problem)

In Unicode logical order, the short-i matra (`U+093F`) is stored **after** its consonant:

```
क + ि  →  stored as  U+0915 U+093F

```

Modern browsers and OS text stacks reorder this visually. But legacy renderers (FPDF, TCPDF, canvas, some PDF libs) render characters left-to-right in byte order, producing:

```
कि  →  displays as  कि  ✓  (modern)
कि  →  displays as  कि  ✗  (legacy — matra appears on the wrong side)

```

This library physically swaps the bytes so legacy renderers display the correct result.

---

Features
--------

[](#features)

- ✅ Simple consonants: `क + ि → ि + क`
- ✅ Combining nukta forms: `ड + ़ + ि → ि + ड + ़`
- ✅ Pre-composed nukta forms: `ज़ (U+095B) + ि → ि + ज़`
- ✅ Deep conjunct clusters: `स्त्र + ि → ि + स्त्र` (unlimited depth)
- ✅ HTML-safe: only text nodes are processed, attributes are untouched
- ✅ Invisible marker stripping (BOM, ZWNJ, ZWJ)
- ✅ Batch array reshaping
- ✅ Cheap pre-check via `needsReshaping()`

---

Requirements
------------

[](#requirements)

- PHP **8.0+**
- `ext-mbstring`

---

Installation
------------

[](#installation)

```
composer require imsoft-dev/devanagari-reshaper
```

---

Usage
-----

[](#usage)

### Plain text

[](#plain-text)

```
use Devanagari\Reshaper\DevanagariReshaper;

$reshaped = DevanagariReshaper::reshapeText('किताब');
```

### HTML (tag-safe)

[](#html-tag-safe)

```
$html = 'किसानविकास';
$out  = DevanagariReshaper::reshapeHtml($html);
// Tag attributes are never modified — only text node content is reshaped
```

### Array of strings

[](#array-of-strings)

```
$rows = DevanagariReshaper::reshapeArray(['किसान', 'विकास', 'Hello']);
```

### Guard check (performance)

[](#guard-check-performance)

```
if (DevanagariReshaper::needsReshaping($text)) {
    $text = DevanagariReshaper::reshapeText($text);
}
```

---

How it works
------------

[](#how-it-works)

A consonant cluster is defined as:

```
cluster = consonant_unit (virama consonant_unit)*

```

Where a `consonant_unit` is:

```
consonant_unit = (pre-composed-nukta-form | base-consonant + optional-combining-nukta)

```

The regex finds every `cluster + i-matra` sequence and moves the i-matra to the front:

```
[cluster][U+093F]  →  [U+093F][cluster]

```

---

Running tests
-------------

[](#running-tests)

```
composer install
./vendor/bin/phpunit
```

---

License
-------

[](#license)

MIT

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance83

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

86d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/182763980?v=4)[imsoft-dev](/maintainers/imsoft-dev)[@imsoft-dev](https://github.com/imsoft-dev)

---

Top Contributors

[![imsoft-dev](https://avatars.githubusercontent.com/u/182763980?v=4)](https://github.com/imsoft-dev "imsoft-dev (1 commits)")

---

Tags

pdfunicodeRenderingdevanagarihindireshaperi-matraimsoft-dev

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/imsoft-dev-devanagari-reshaper/health.svg)

```
[![Health](https://phpackages.com/badges/imsoft-dev-devanagari-reshaper/health.svg)](https://phpackages.com/packages/imsoft-dev-devanagari-reshaper)
```

###  Alternatives

[phpoffice/phpword

PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)

7.6k39.0M249](/packages/phpoffice-phpword)[twig/string-extra

A Twig extension for Symfony String

22150.9M240](/packages/twig-string-extra)[anourvalar/office

Generate documents from existing Excel &amp; Word templates | Export tables to Excel (Grids)

23995.2k](/packages/anourvalar-office)[helhum/typoscript-rendering

Can render a TypoScript path by URL, especially useful for Ajax dispatching

68663.3k12](/packages/helhum-typoscript-rendering)[view-components/view-components

Flexible Framework-Agnostic UI for Enterprise Web Applications

24113.3k7](/packages/view-components-view-components)[nextras/forms-rendering

Rendering helpers for Nette Framework Forms.

16103.8k2](/packages/nextras-forms-rendering)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
