Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / artificial-intelligence / machine-learning

Porting Open Source Indix Library to BREW

5.00/5 (2 votes)
1 Jun 2010CPOL7 min read 21.6K   142  
‘Indix’ is an open source component written in C for Indian font rendering. Indix is a de facto implementation of the rules of Indian languages by CDAC.

A quick approach to render Indian languages on mobile devices.

Introduction

Mobiles have been popular among the urban masses for ages. Adoption of mobile devices is increasing among the rural masses for not only making phone calls but also application usage. More and more people have started exploring and using mobiles for various other purposes like entertainment in the form of music, games, chatting and also utility applications like banking and trading.

The growth of users of mobile phones in the rural areas is also increasing at a very fast rate. A major hindrance to their application usage is language barrier. Provision of applications in native language helps personalize the entire application for a user and increases the interest of the rural masses in the application and motivates them to use the application.

The urban masses can also enjoy the content displayed in their native language in specific contexts. This can hold true in cases for e.g. when an application displays the summary of a novel or a movie review in one of the Indian languages. This small customization enhances the experience of the readers to a great extent because no matter how good a translation is done, the punch of dialogues is lost at times when the language is changed.

Economic benefits can be easily accrued by making native language applications available to the rural masses. A majority of the existing applications can be made available to them by providing native language support. Hence established mobile domain companies are targeting the rural population to increase their income. A faster time to market will ensure early success in this domain.

Various approaches and font engines are adopted by developers to render Indian languages on the handset. A common approach to draw custom fonts is based on image clipping and using language grammar rules to order and display the clipped images. The rules for each language being different, the language under consideration has to be studied and integrated within the code of the application.

There is a huge amount of research done on the front of grammar rules for Indian languages. The central government has an authorized body and standard for rules of Indian languages. For any font engine to claim Indian language rendering, it must comply with all these standards.

‘Indix’ is an open source component written in C for Indian font rendering. Indix is a de facto implementation of the rules of Indian languages by CDAC. By porting this library to BREW, we can provide Indian language support for the applications. This library is also capable of displaying multi lingual text effortlessly.

Indix contains the rules of all the languages and does the computation of the glyphs that need to be displayed. It uses FreeType to render the calculated glyphs from a font file (TTF file). Click here to know more about Indix.

Requirements

Steps to port INDIX

Pre-requisites

  • Install BREW sdk 3.1.2(or higher version) and RVDS 3.0
  • Download elf2mod utility
  • Download Freetype sources
  • Download Indix sources

Step 1: Setting up Visual Studio Workspace and Linking

Create a new BREW workspace and include all the Indix and Free Type sources (src and include folders). Specify all the required paths in the properties of the project to eliminate all linking errors.

Step 1: Setting up Visual Studio Workspace and Linking

IO functions present in stdio.h do not work in BREW. We have to provide definitions for the same which work in BREW. Give all the definitions of the standard IO and file operations which work in BREW. Give it a name, say ‘brew_stdio.h’.

C++
int b_fclose(IFile *pIFile)
{
if (pIFile == stdin || pIFile == stderr || pIFile == stdout) {
DBGPRINTF("fclose: cannot close stdin, stdout or stderr.");
      return 1;
}

      IFILE_Release(pIFile);
return 0;
 }

Include ".\brew_stdio.h" in {PATH}.\include\ft2build.h.

Step 3: Modifications in Files

Replace all #include<stdlib.h> with #include “AEEStdlib.h”.

Make changes in the following files.

  1. File: .\include\indix\indic\include\indictypes.h

    Paste the following definitions at the start of the file.

    C++
    typedef signed char int8_t;
    typedef unsigned char u_int8_t;
    typedef short int16_t;
    typedef unsigned short u_int16_t;
    typedef int int32_t;
    typedef unsigned int u_int32_t;
    typedef long long int64_t;
    typedef unsigned long long u_int64_t;
    typedef int32_t register_t;
  2. File: .\include\freetype\config\ftstdlib.h

    Override the definitions of macros as shown below:

    Substitute C functions with BREW macros wherever applicable for example for memory and string operations.

    E.g.: Substitute definitions like:

    C++
    #define ft_memchr   memchr
    #define ft_memcmp   memcmp
    #define ft_memcpy   memcpy
    #define ft_memmove  memmove
    		.
    		.
    		.

    With macros like:

    C++
    #define ft_memchr   MEMCHR
    #define ft_memcmp   MEMCMP
    #define ft_memcpy   MEMCPY
    #define ft_memmove  MEMMOVE
    		.
    		.
    		.

    Substitute C functions with functions in .\brew_stdio.h – file operations.

    E.g.: Substitute definitions like:

    C++
    #include <stdio.h />
    
    #define FT_FILE     FILE
    #define ft_fclose   fclose
    #define ft_fopen    fopen
    #define ft_fread    fread
    #define ft_fseek    fseek
    #define ft_ftell    ftell
    		.
    		.
    		.

    With:

    C++
    #include "brew_stdio.h" 	// to override the c function definitions 
    			// with BREW definitions.
    
    #define FT_FILE     IFile
    #define ft_fclose   b_fclose
    #define ft_fopen    b_fopen
    #define ft_fread    b_fread
    #define ft_fseek    b_fseek
    #define ft_ftell    b_ftell
    		.
    		.
    		.
  3. File: .\include\indix\otlayout\include\fterrcompat.h

    Indix was developed against FreeType 1.4. However the latest source is Free Type 2.3.9. There is a small modification in the function macros ALLOC_ARRAY and REALLOC_ARRAY. The definitions need to be modified as per the new sources.

    C++
    //#define ALLOC_ARRAY( _pointer_, _count_, _type_ ) \
    //  FT_SET_ERROR (FT_MEM_ALLOC_ARRAY( _pointer_, _count_, _type_))
    
    #define ALLOC_ARRAY( _pointer_, _count_, _type_ ) \
    FT_SET_ERROR (FT_MEM_ALLOC( _pointer_, _count_* sizeof ( _type_ )))
    
    /* FT_MEM_REALLOC macro broken in 2.1.0 */
    //#define REALLOC_ARRAY( _pointer_, _old_, _new_, _type_ ) \
    //  FT_SET_ERROR ( FT_MEM_REALLOC( _pointer_, (_old_) * sizeof ( _type_ ),   \
    //                (_new_) * sizeof ( _type_ ) ) )
    
    #define REALLOC_ARRAY( _pointer_, _old_, _new_, _type_ ) \
    FT_SET_ERROR ( FT_REALLOC( _pointer_, (_old_) * sizeof ( _type_ ),\
                    (_new_) * sizeof ( _type_ ) ) )"

Step 4: Optimization (optional)

Indix supports font rendering from ‘ttf’ font files. However, freetype provides support for many more font formats. In order to optimize the executable size, only relevant drivers and modules should be loaded.

Freetype upfront loads all the default modules. This can be optimized by commenting out the unnecessary modules and loading only relevant modules in ftmodule.h.

File: .\include\freetype\config\ftmodule.h

C++
FT_USE_MODULE( FT_Driver_ClassRec, tt_driver_class )
//FT_USE_MODULE( FT_Driver_ClassRec, t1_driver_class )
//FT_USE_MODULE( FT_Driver_ClassRec, pcf_driver_class )
		.
		.
		.
Step 5: Sample Program

Indix lets you render multi-lingual text. Indix and freetype together return individual bitmap images corresponding to 1 or n glyph indices. It does not return the entire concatenated image.

In order to display a string, the sample program concatenates the individual bitmaps and writes a BMP file. This image is then rendered using BREW APIs to display text on the screen. To render new language supported by indix, we have to just add .ttf file and need to initialise that font in initialiazeFont() function as shown below:

C++
nCurrScriptId = IX_IndicGetScriptId(ch);
			if(nCurrScriptId == IX_S_DEVA)
				ftError = IX_openAnOpenTypeFont
				(&anOTFont, FONTFILE, IX_S_DEVA);
			else if(nCurrScriptId == IX_S_TELU)
				ftError = IX_openAnOpenTypeFont
				(&anOTFont, FONTTELUGU, IX_S_TELU);

			else if(nCurrScriptId == IX_S_TAML)
				ftError = IX_openAnOpenTypeFont
				(&anOTFont, FONTTAMIL, IX_S_TAML);
			else if(nCurrScriptId == IX_S_ORYA)
				ftError = IX_openAnOpenTypeFont
				(&anOTFont, FONTORIYA, IX_S_ORYA);
			else if(nCurrScriptId == IX_S_GUJR)
				ftError = IX_openAnOpenTypeFont
				(&anOTFont, FONTGUJARATI, IX_S_GUJR);

			else /*if(nCurrScriptId == IX_S_LATIN)*/
				ftError = IX_openAnOpenTypeFont
				(&anOTFont, FONTENGLISH, IX_S_LATIN);

Refer ft_BREW.c from attachments for more details on how to render text.

Step 6: Compilation and linking in RVDS

Include all the source files into a workspace and use the default BREW settings.

target_path.JPG

Target Settings: Post linker was disabled because we make use of brew elf2mod utility to generate .mod file from .elf.

Access Paths: Specify all the required paths in the Access Path tab of the project to eliminate all linking errors.

compiler_settings.JPG

Compiler settings: armcc --split_sections --apcs=inter -O0 -DDYNAMIC_APP

linker_settings.JPG

Linker settings: armlink --reloc --split --verbose --ro_base=0x0 --datacompressor=off --errors=err.txt --first=AEEMod_Load --output=ft.elf

Final Step: Generate .mod File

Convert the elf into BREW executable (.mod) using elf2mod utility as shown below.

elf2mod ft.elf

A ft.mod file would be created in the same folder.

Add ft.mod into build files with corresponding .ttf files for the languages to be rendered.

Using BREW Apploader, load build files on to the handset and start the application.
Press 1 to view demo string “Welcome” displayed in Hindi font.

For more details, check the sample code attached with article (ft_BREW.7z). For a quick look at the sample code output, check the attached build files for the same (ft_BREW/build).

Related Resources

Authors

Deepti Chunduru

Deepti Chunduru is a Bachelor in Computer Engineering, Mumbai University. She is associated with Tata Consultancy Services Limited. Her research interests are Mobile Computing.

Prashant Gotarne

Prashant Gotarne is a Bachelor in Computer Engineering, Mumbai University. He is a research team member with Mumbai Innovation Labs, Tata Consultancy Services Limited. His research interests are Mobile Computing, Computer Security and Image Processing.

Pankaj Doke

Pankaj Doke is a Bachelor in Computer Engineering, Mumbai University. He is a research team lead with Mumbai Innovation Labs, Tata Consultancy Services Limited. His research interests are Mobile computing, Computer Security, Pattern Recognition, Machine Learning and Large Scale Systems.

Sanjay Kimbahune

Sanjay Kimbahune is a Bachelor of Engineering in Electronics, Amravati University. He is a research scientist with Mumbai Innovation Labs, Tata Consultancy Services Limited. His research interests are Mobile Computing and Telecom Systems.

Copyright © 2010 Tata Consultancy Services Ltd. All Rights Reserved

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)