hx_arabic_shaper

A library to help shaping Arabic text and dealing with BIDI.


Keywords
cross, utility
License
MIT
Install
haxelib install hx_arabic_shaper 0.0.1

Documentation

Arabic shaper for Haxe

A library to correctly shape Arabic text and deal with BIDI for Haxe

Install and how to use

Install it with:

haxelib install hx_arabic_shaper

Or if you want to use the git version:

haxelib git hx_arabic_shaper https://github.com/TerryCavanagh/hx_arabic_shaper.git

if you aren't going to use this library in a OpenFL/Lime project and you are using Haxe 3.x, install unifill with:

haxelib install unifill

Add it to your build.hxml (or similar) with:

-lib hx_arabic_shaper

or add it to your project.xml if you are using OpenFL/Lime with:

<haxelib>hx_arabic_shaper</haxelib>

You'll need to initialize it to build the ligatures cache and dispose it to destroy that cache:

import hx_arabic_shaper.ArabicReshaper;
import hx_arabic_shaper.bidi.UBA;

...

public static function init() {
  // your init code
  // change the config if you need it, it's optional
  var config = ArabicReshaper.getDefaultConfig();
  config.delete_harakat = true;
  ArabicReshaper.init(config);
}

...

public static function dispose() {
  // your dispose code
  ArabicReshaper.dispose();
}

You can only enable or disable ligatures before initializing the reshaper. Once initialized changing the ligatures config won't do anything. Check ReshaperConfig.hx for the full list of options and ligatures you can enable or disable.

After that, To shape Arabic text you'll need to do:

function print(text:String) {
  // Get the shaped text
  var shaped = ArabicReshaper.reshape(text);
  // Process the BIDI algorithm
  var bidi = UBA.display(shaped);
  // Render it
}

Gotchas

  • Mixing LTR and RTL text in the same sentence may not work correctly. You'll need to use the Unicode directional formatting codes to force part of the text one way or the other depending on the result you want to achieve.
  • Shaping numbers is finicky. Depending on what you want to achieve you'll need to use those Unicode directional formatting codes to format them correctly.
  • The BIDI algorithm might work with other languages but it's untested.

If you find any issues feel free to report them. It'd be really helpful if you could check if the issue can be reproduced in the original library before opening the issue here. Thanks!

Credits

License

This work is licensed under MIT License.