If you have ever opened an old Hindi office file and seen text like Hkkjr ,d fo'kky ns'k gSA, you have met Kruti Dev 010. It is a legacy, non-Unicode font: it draws Hindi shapes on top of plain English keys. Without the font installed, the text is gibberish.
Unicode Hindi (what fonts like Mangal display) stores real Devanagari characters: भारत एक विशाल देश है।. I needed a converter for my free Hindi typing test site, so I wrote a small dependency-free library that goes both ways. Here is what made it interesting.
1. Simple mapping is not enough
The first version is just a lookup table: k -> ा, d -> क, fg ... and so on. Kruti Dev uses multi-character glyphs, so the lookup has to be greedy: always try the longest key first.
function greedy(text, m) { let out = '', i = 0; while (i < text.length) { let l = Math.min(m.max, text.length - i), hit = false; for (; l > 0; l--) { const k = text.substr(i, l); if (k in m.map) { out += m.map[k]; i += l; hit = true; break; } } if (!hit) { out += text[i]; i++; } } return out; } 2. The chhoti i matra is typed in the wrong order
In Kruti Dev you type f (ि) before the consonant, because that is where it appears visually. In Unicode, the matra comes after the consonant (and after the whole conjunct). So fd must become कि, and fLFkj must become स्थिर.
The fix: mark the pre-base matra during mapping, then move it past the next full syllable (consonant + any halant + consonant chain) with a regex.
3. Reph (र्) goes the other way
The reph glyph is typed after the syllable in Kruti Dev, but in Unicode र् comes before it. deZ is कर्म. Same idea, reversed: find the syllable that ends before the reph marker and put र् in front.
4. Half letters and the "aa bar"
Kruti Dev often builds a full consonant from a half glyph plus the vertical bar k. So Hk is भ (half bha + bar), but Hkk is भा. The converter has to know which glyphs are half forms and join them correctly, or you get a stray ा everywhere.
5. Going back: Unicode -> Kruti Dev
The reverse direction needs the same rules undone: move ि before the syllable, move र् after it, and split full consonants into half + bar where the font expects it. Digits are another trap: some people want Devanagari digits, some want 0-9, so it is an option.
KrutiDev.toUnicode("Hkkjr ,d fo'kky ns'k gSA"); // "भारत एक विशाल देश है।" KrutiDev.fromUnicode("भारत एक विशाल देश है।"); // "Hkkjr ,d fo'kky ns'k gSA" Try it or use the code
- The library is MIT licensed on GitHub: kruti-dev-unicode-converter. It also lets you plug in other legacy fonts (DevLys, Shree Lipi) with
registerFont(). - If you just need to convert text, the free online Mangal to Kruti Dev converter runs the same code in your browser. Nothing is uploaded.
I built it for TypingPariksha.in, a free Hindi typing test for SSC, CPCT and RRB exam students, where many practice passages still come in Kruti Dev.
If you have handled other legacy Indic fonts, I would love to hear which edge cases bit you.