Updated 2014-06-09 09:56:38 by Superlinux

Very Important edit

The contents of this page does compile and does work when you try to load the shared library file mentioned here fribidi_tcl.so.

However this DOES NOT take you to the required goal of rendering the Arabic text to be easily readable

Please move to this page [1] to see a perfectly working method.


This will help you build a shared library that will let you display mixed languages like Arabic and Latin characters in the proper visual way. FriBidi is the library which does it.

Required Debian packages

  1. apt-get install swig ; swig is the one that can let us use any C/C++ library and transform its methods and functions into Tcl commands, Perl functions, PHP functions.
  2. apt-get install libfribidi-dev ; we need this to build the Tcl version of FriBiDi
  3. apt-get install tcl8.6-dev ; Swig needs this to include the Tcl bindings and make us the Tcl commands; If you have ActiveTcl installed you don't need this. Please don't confine yourself to version 8.6 .. check if it works too for 8.5. I think it must.

Building steps

select one and only one of the following 3 options:

If you use tcl8.5-dev package then type in the terminal:

If you use tcl8.6-dev package then type in the terminal:

If you use ActiveTcl 8.6 package then type in the terminal:

So I ask you to change the version of Tcl accordingly.

And then open a new ascii text file, using a text editor like gEdit or vi or kate. Name the file fribidi.i.

Add the following instructions used by swig to fribidi.i
  %module fribidi
   #include <fribidi/fribidi.h>

  %include "/usr/include/fribidi/fribidi-common.h";
  %include "/usr/include/fribidi/fribidi-unicode.h";
  %include "/usr/include/fribidi/fribidi-types.h";
  %include "/usr/include/fribidi/fribidi-flags.h";
  %include "/usr/include/fribidi/fribidi-bidi-types.h";
  %include "/usr/include/fribidi/fribidi-bidi.h";
  %include "/usr/include/fribidi/fribidi-joining-types.h";
  %include "/usr/include/fribidi/fribidi-joining.h";
  %include "/usr/include/fribidi/fribidi-mirroring.h";
  %include "/usr/include/fribidi/fribidi-arabic.h";
  %include "/usr/include/fribidi/fribidi-shape.h";
  %include "/usr/include/fribidi/fribidi-char-sets.h";
  %include "/usr/include/fribidi/fribidi-deprecated.h";
  %include "/usr/include/fribidi/fribidi-begindecls.h";
  %include "/usr/include/fribidi/fribidi-enddecls.h";

Run the following command:
  swig -tcl fribidi.i

This will produce a new file named fribidi_wrap.c in the current directory.

The following is warning that will result from using swig. Ignore the warning:
  /usr/include/fribidi/fribidi-unicode.h:55: Warning 451: Setting a const char * variable may leak memory

Then generate the object file free_wrap.o by compiling fribidi_wrap.c. Read carefully:

If you are on 32 bit system, run the following command on the terminal:
 gcc -c fribidi_wrap.c -o fribidi_wrap.o -I $tcl_include

If you are on 64 bit system, run the following command on the terminal. Notice that we added the option -fPIC:
 gcc -c fribidi_wrap.c -o fribidi_wrap.o -I $tcl_include -fPIC

finally we can get our shared library as the file fribidi_tcl.so, run the following command on the terminal :
   gcc -Wall -shared -I $tcl_include  fribidi_wrap.o -lm -lfribidi -o fribidi_tcl.so

Then in your Tcl code, you may use fribidi_tcl.so using the load command:
 load fribidi_tcl.so

To see all the commands provided by fribidi_tcl.so, run the following command on the terminal
  nm fribidi_tcl.so | more

The tcl terminal tkcon can also help in listing some of fribidi commands. Only type fribidi and use text completion by pressing the TAB key twice.