hx_arabic_shaper

A library to help shaping Arabic text and dealing with BIDI.
https://github.com/TerryCavanagh/hx_arabic_shaper

To install, run:

haxelib install hx_arabic_shaper 0.0.1 

See using Haxelib in Haxelib documentation for more information.

README.md

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

  • Arabic reshaper: Ported and tweaked from Python to Haxe from https://github.com/mpcabd/python-arabic-reshaper Original author: Abdullah Diab (mpcabd) and contributors
  • BIDI algorithm: Ported and tweaked from GDScript to Haxe from https://github.com/3akev/godot-arabic-text Original author: 3akev and contributors
  • UTF8String: Copied from Lime Original author: Joshua Granick (jgranick) and contributors

License

This work is licensed under MIT License.

Contributors
mrcdk
TerryCavanagh
Version
0.0.1
Published
5 years ago
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub