Feb 6, 2010

Pango Note

Pango
Text layout library
Supports different font technologies:
    * Classic X fonts
    * TrueType fonts (using FreeType)
    * OpenType fonts (using Xft/XRender/FreeType)
• Win32 fonts

Pango architecture
http://fishsoup.net/bib/PangoGuadec2001/slide009.html

Supported Language
    * European languages
    * Asian languages (Chinese, Japanese, Korean, ...)
    * Middle Eastern languages (Arabic, Hebrew, Farsi,...)
    * Indic languages (Devanagari, Bengali, Gujarati, Gurmukhi, Burmese)

Pango has markup language !!!

Pango GL patch http://www.mail-archive.com/pysoy-svn@pysoy.org/msg00761.html
PangoOpenGLRenderer A tale of
http://mail.gnome.org/archives/gtk-i18n-list/2006-July/msg00002.html

http://behdad.org/text/
http://software.schmorp.de/pkg/deliantra/Deliantra-Client.html

Thebes: alternative to Pango used in Mozilla
http://mxr.mozilla.org/seamonkey/source/gfx/src/thebes/
https://developer.mozilla.org/devnews/index.php/2007/12/17/aboutmozilla-beta-2-shipping-firefox-3-icon-preview-add-ons-compatibility-gfx-architecture-and-more/#gfx
http://blog.vlad1.com/2007/12/11/graphics-in-mozilla/

http://people.redhat.com/otaylor/gtk/guadec2-i18n/

Cairo vs. Qt
https://www.kitware.com/InfovisWiki/index.php/Cairo_rendering

http://kcchao.wikidot.com/gtk

Some text layouting link
• http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&item_id=CmplxRndExamples
The main characteristics of CTL language complexity are:
    * Bi-directional text, where characters may be written from either right-to-left or left-to-right direction.
    * Context-sensitive shaping (ligatures), where a character may change its shape, dependent on its location and/or the surrounding characters. For example, a character in Arabic script can have at least four different shape forms, depending on context.
    * Ordering, the displayed order of the characters is not the same as the logical order. For example, in Devanagari, which is written from left to right, the grapheme for "short i" appears to the left of ("before") the preceding consonant: in कि ki, the ि -i should render on the left, its bow reaching until above the क k- to the right.


FreeType
Performs font rasterization. Given font data (file or data in memory), it does simple (non-complex) mapping of Unicode characters to glyph indices and rendering glyphs to images.
Fontconfig
Performs font selection based on a pattern of desired font characteristics. These characteristics typically include a family name, style, weight, slant, size, as well as language. Font configuration happens by way of a set of very expressive XML rules. Fontconfig uses FreeType to inspect fonts and caches the results in an mmap()able architecture-specific binary cache.
FriBidi
GNU FriBidi is an implementation of the Unicode Bidirectional Algorithm. Pango uses FriBidi and has an internal copy of it. AbiWord is the other major user of FriBidi. Many other projects use FriBidi as the simplest route to add support for Hebrew and Arabic scripts without adding support for a full complex text rendering engine.
HarfBuzz
HarfBuzz is the meat of the modern GNU/Linux text rendering stack. With OpenType emerging as the universal font format supporting complex text rendering, HarfBuzz, as an OpenType Layout engine, is where all the magic happens. In fact it is of such importance to the stack that it deserves an entire section of its own in this document.
Pango
Pango is, for the most part, the roof of the text rendering stack. Components sitting on top of Pango (eg. GTK+) need not know about complexities of i18n text and are expected to simply use these opaque objects called PangoLayout's. Pango has been designed to satisfy GTK+'s needs for i18n text. However, Pango still provides a low-level API on which one can build their own layout engine. This is what Firefox, Webkit-GTK, etc do, but it has proved to be a cumbersome practice. We will expand on that later.


A good link on software stack - http://maemo.org/maemo_release_documentation/maemo4.1.x/node6.html

Jan 3, 2010

Setup Buildroot for Beagleboard Development

Currently, when development with Beagleboard we often use OE distribution. The OE is hard to maintain for
me, and it requires to open everything so that I use buildroot to develop on Beagleboard.

Here is how to setup one.
1) Download the buildroot from http://www.buildroot.org/
2) You might want to use external toolchain by downloading the ARM toolchain from CodeSourcery (http://www.codesourcery.com/) or build using crosstool-ng
3) You might also want to use the omap linux kernel by downloading it using git (git clone git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap-2.6.git)
4) Extract the buildroot into a folder and type `make menuconfig` to configure it.
   * Target Architecture: arm
   * Target Architecture Variant: generic_arm
   * Target ABI: EABI
   * For my Beagleboard, I need to configure the Target Options > Generic serial port config (y) > and change Serial port to run a getty on to (ttyS2) instead of (ttyS0)
      - If using ttyS0, the my board cannot boot and stuck at `ip: RTNETLINK answers: File exists` (http://forums.xilinx.com/xlnx/board/message?board.id=ELINUX&thread.id=1677)
   * Go to Toolchain settings
      - If you are using External Toolchain, select Toolchain type to External binary toolchain and set the External toolchain path to correct path of your toolchain (i.e. /usr/local/xtools/armunknownlinuxuclibcgnueabi. This is my crosstool-ng installed location)
      - If you are using Internal Toolchain (the toolchain built by buildroot), select  Toolchain type to Buildroot toolchain.

    * Go to Target filesystem options and select the target fs to build.
      - If you are building the u-boot, you need to enter the Das U-Boot Monitor and select
         + board name: omap3_beagle
    * Go to kernel settings
      - If you are using Internal Kernel, select Kernel type to linux (Advanced Configuration) and select the kernel version as well as the configuration file to use (in the Linux Kernel Configuration), I copied the omap3_beagle_defconfig from arch/arm/configs to a specified location and customized it.
      - If you are using External Kernel, select Kernel type to none.
5) Save the configuration and type `make` to build the system. After finished, the image is located at binaries/[project_name]/

NOTE:
   + If using external kernel, you will need to copy the kernel module into the root filesystem at project_build_arm/[project_name]/root or into the NFS root folder. (in kernel folder: make ... INSTALL_MOD_PATH=...)
   + The crosstool-ng cannot compile the uboot because of some bugs (http://old.nabble.com/-U-Boot---PATCH-2-2--ARM:-fix-build-error-with-gcc-4.4.2-about-inline-function-declared-weak-p26188857.html)

TODO:
   + The internal kernel is getting from kernel.org and doesn't contain the patches for omap platform. Need to sync with omap git repository to create the patch and put it under the target/.../ folder inside the buildroot
   + The internal toolchain is generic arm, and does not have omap specified optimization, need to sync with OE repository to create the patch and put it under the toolchain/.../ folder inside the buildroot
   + The internal kernel cannot have USB Gadget Driver, maybe missing some patch for omap
   + Add _defconfig (or board specific into the buildroot)

Dec 18, 2009

[Job] Junior and Senior Developer

My company Global CyberSoft (http://www.globalcybersoft.com) is looking for lot of both Junior and Senior developers which have knowledge of Java or C/C++ & Linux.

Experience in Graphics and one of following technique OpenGL, DirectX, Clutter, Webkit, Flash, Driver Development. 

Wishlist:
- Experience in Consumer Electronics, with Set Top Box experience being a plus
- Employment history: Graphics/UI Game Development, Apple, etc

Contact hieult@globalcybersoft.com for more information.

Sep 8, 2009

How to build Valgrind for Beagleboard

1) Get Valgrind source code from SVN using revision 9648 and 1888 for VEX
svn co -r 9648 svn://svn.valgrind.org/valgrind/trunk
cd VEX
svn update -r 1888


3) Apply the patch into the source code
cd valgrind
patch -p1 < [path to the patch]

4) Run autogen.sh to run autotools

5) Configure the source code
./configure --host=arm-angstrom-linux-gnueabi

The patch still has some bugs such as CPU instruction alignment you can 'cat /proc/cpu/alignment' to find out if the kernel is configured to fix unaligned accesses, and you can enable it by executing 'echo 2 > /proc/cpu/alignment' but it's enough to use for simple application.
Have fun with Valgrind :-)

Sep 4, 2009

How to build Clutter for Beagleboard

The Clutter need to be configured with =flavour=eglnative= so that it can work with SGX driver
The following is the configure command

./configure --with-flavour=eglnative --host=arm-angstrom-linux-gnueabi PKG_CONFIG=/data/workspace/OE/tmp/staging/i686-linux/usr/bin/pkg-config PKG_CONFIG_PATH=/data/workspace/OE/tmp/staging/armv7a-angstrom-linux-gnueabi/usr/lib/pkgconfig CFLAGS="--sysroot=/data/workspace/OE/tmp/staging/armv7a-angstrom-linux-gnueabi/ -I/data/workspace/OE/tmp/staging/armv7a-angstrom-linux-gnueabi/usr/include" --with-x=no --with-gles=1.1 --with-imagebackend=internal

with
  • --host: set the target for the build, need to be arm-angstrom-linux-gnueabi
  • PKG_CONFIG: use the pgk-config command from OE distribution
  • PKG_CONFIG_PATH: the path to search for *.pc file, need to be pointed to OE distribution
  • --with-x: not using X
  • --with-imagebackend: specific the image backend to use
  • --with-gles: specific the GLES version to use (1.1 or 2.0)
  • CFLAGS: override some C compiler flags
  • --sysroot: the root directory to search for library and header files
  • -I[include_dir]: some optional include directories to search for

Fix undefined rpl_malloc on autoconf tool in cross compile mode

When using autoconf tool in cross compile environment, sometime there is error like this `undefined reference to `rpl_malloc'`

It is the bug of autoconf tool in the test function AC_FUNC_MALLOC. To fix it we need define an environment variable that forces the test to pass. Define it in the environment prior to calling ./configure and the script will act as if the AC_FUNC_MALLOC check has passed.

export ac_cv_func_malloc_0_nonnull=yes

Aug 16, 2009

Draw Text with OpenGL and Cairo

The OpenGL just supports capability to draw primitive, not text. In order to draw text on screen we need support of other package such as Cairo or Pango. The following topic describe how to use Cairo with OpenGL.
1 First we need to create a Cairo surface for drawing (text)
2 Then we will load the surface into GL texture using glTextureXXX function
3 After all, we will apply texture mapping into our primitive (for example a rectangle for displaying text)


Create Cairo Context
inline cairo_t*
create_cairo_context (int width,
int height,
int channels,
cairo_surface_t** surf,
unsigned char** buffer)
{
cairo_t* cr;

/* create cairo-surface/context to act as OpenGL-texture source */
*buffer = (unsigned char*)calloc (channels * width * height, sizeof (unsigned char));
if (!*buffer)
{
printf ("create_cairo_context() - Couldn't allocate surface-buffer\n");
return NULL;
}

*surf = cairo_image_surface_create_for_data (*buffer,
CAIRO_FORMAT_ARGB32,
width,
height,
channels * width);
if (cairo_surface_status (*surf) != CAIRO_STATUS_SUCCESS)
{
free (*buffer);
printf ("create_cairo_context() - Couldn't create surface\n");
return NULL;
}

cr = cairo_create (*surf);
if (cairo_status (cr) != CAIRO_STATUS_SUCCESS)
{
free (*buffer);
printf ("create_cairo_context() - Couldn't create context\n");
return NULL;
}

return cr;
}

Draw text into the Cairo surface and then load it into GL Texture
inline int DrawText(int x, int y, int width, int height, char *string, COLOR &textColor, COLOR &background)
{
cairo_surface_t* surface = NULL;
cairo_t* cr;
unsigned char* surfData;
GLuint textureId;

/* create cairo-surface/context to act as OpenGL-texture source */
cr = create_cairo_context (256,
256,
4,
&surface,
&surfData);

/* clear background */
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
cairo_set_source_rgb(cr, background.red, background.green, background.blue);
cairo_paint (cr);

cairo_move_to(cr, 256/10, 256/2);
cairo_set_font_size(cr, 30);
cairo_select_font_face(cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_source_rgb(cr, textColor.red, textColor.green, textColor.blue);
cairo_show_text(cr, string);

glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA,
256,
256,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
surfData);
TestEGLError("glTexImage2D");

free (surfData);
cairo_destroy (cr);

return textureId;

}

Texture Mapping
The texture mapping is so simple, we need to provide them the UV coordinate. The UV coordinate is range from 0 to 1 which 0 is the start point, and 1 is the end point. The following is an example usage


GLfloat textureCoord[] = {
f2vt(0.0f), f2vt(0.35f),
f2vt(1.0f), f2vt(0.35f),
f2vt(0.0f), f2vt(0.55f),
f2vt(1.0f), f2vt(0.55f)
};
COLOR clrText = {255,255,255};
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
GLuint textureId = DrawText(clipRect[0], clipRect[1], clipRect[2], clipRect[3], data, clrText, this->m_clrBackground);

glVertexPointer(2, VERTTYPEENUM, 0, rect);
glTexCoordPointer(2, VERTTYPEENUM, 0, textureCoord);

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

glDeleteTextures(1, &textureId);

Phu Ha

GlossyBlue Blogger by Black Quanta. Theme & Icons by N.Design Studio
Entries RSS Comments RSS