Language Interface Library
From OpenAlchemy.org
Language Interface Library
The liblang library defines a typedef named language for the supported (and to be supported) languages.
typedef enum _language
{KANNADA,
HINDI,
TAMIL,
TELUGU,
BANGLA,
ENGLISH,
GLYPH,
MAX_LANG} language;
The liblang interface is defined by the Class "utf2glyph". The important member functions of this class is:
- void init() : It initializes the tables used by liblang. This function must be called before using any other liblang function.
- string get font name(const string& lang) Returns the font name for the language "lang"
- language get language(const string& text) Returns the language for the UTF-8 text
- string convert(const string& utf_str) Returns the glyph string corresponding the UTF-8 string in "utf_str"
There is also a C-wrapper interface to the above member functions. The corresponding wrapper functions are:
void utf_init(),
char* utf_get_font_name(const char*),
language utf_get_language(const char*), and
char* utf_convert(const char*)
The user of the functions "utf_get_font_name" and "utf_convert" has to take the responsibility of freeing the memory returned by these functions.
The liblang library has been used by Tk, keyboard, Bhasha, pgettext etc. The following pseudocode demonstrates a typical use of liblang:
test_func(){
char *font_name;
language l;
unsigned char text[100];
/*array to hold UTF-8 text*/
unsigned char glyph[100]; /* holds the glyph string*/
utf_init(); /*Initialize the liblang library*/
...
l = utf_get_language(text);
font_name = utf_get_font_name("hindi");
glyph = utf_convert(text);
...
/*Invoke the text drawing function with this glyph and font_name now*/
...
free(glyph);
free(font_name);
}
