ย้ายเอกสาร Qtopia 2.1 - Thai localization project

อัดรูปดิจิตอล ทำสมุดภาพของคุณเอง
รอรับได้. ท่องเที่ยว แต่งงาน ฯลฯ

www.tanabutr.co.th/photobook


บทความนี้เขียนเมื่อเดือนกุมภาพันธ์ปีที่แล้ว (2005). เก็บไว้ที่ linux.thai.net แต่เอามารวมไว้ที่นี่ดีกว่า เป็นหลักแหล่งดี.

About Qtopia

Qtopia is a framework for creating GUI program for PDA or smart phone. Normally, these kind of devices will run Linux, for example, Lineo linux by Metrowerks. Qtopia will display graphic through frame buffer device. The first application will act as the controller and must be run with -qws option. Other applications can run after without -qws option.
n

Recently Trolltech releases Qtopia 2.1 GPL version. This version can be used to develop free software under GPL license. For proprietary work should use commercial vesion. Qtopia 2.1 has 2 editions, PDA edition and phone edition. In Qtopia GPL license, only PDA version is available.

Required packages

  • Qtopia 2.1.0
  • Qt/Embedded 2.3.9 (or higher, but always a 2.3 version)

    Qt/Embedded 2.3.9 is not available on the Internet. We will use Qt/Embedded 2.3.10 instead. This version can be obtained from snapshots folder in Trolltech ftp site. Also, the modification of file include/qglobal.h is required. We have to modify QT_VERSION from 2310 to 239.
  • Qt 2.3.2 for X11 (for emulated desktop development). Qvfb will use shared library from this package.
  • Qt 3.3.0 (or higher) for X11 (required for the language tools and the phone simulator)
  • tmake 1.13 (or higher)

Building from sources

  • For convenience, create a diretory for the project, say $PROJECT. In this directory we will create sub-directory like this.
    • env - keep environment setting files
    • build - keep extraced sources
    • sources - downloaded sources
  • Extract all sources in $PROJECT/build.
  • Create configuration file to set environment variables, say build.env.
    # build.env for setting enviornment variables
    export TMAKEDIR=$PROJECT/build/tmake-1.13
    export QT2DIR=$PROJECT/build/qt-2.3.2
    export QT3DIR=$PROJECT/build/qt-x11-free-3.3.0
    export QTEDIR=$PROJECT/build/qt-2.3.10-snapshot-20050127
    export QPEDIR=$PROJECT/build/qtopia-free-2.1.0
    
  • We use Qt/Embedded 2.3.10, version number is written in include file include/qglobal.h.
    // NOTE:
    // to allow for a two digit patch release number we have jumped from 239 to 2310// for future reference, if we ever release a Qt 2.4.0 the version number will jump to 2400, i.e. 2.4.00
    #define QT_VERSION      2310
    #define QT_VERSION_STR  "2.3.10-snapshot-20050127"
    

    From my experience, Qtopia configure which is perl script will cut 0 from 2310 and will note work. Also in Qtopia source the is macro to check the version if QT_VERSION is greater than 300 (version 3.0.0) it will use another API and building will fail. We have to change this number to 239.

    // NOTE:
    // to allow for a two digit patch release number we have jumped from 239 to 2310// for future reference, if we ever release a Qt 2.4.0 the version number will jump to 2400, i.e. 2.4.00
    #define QT_VERSION      239
    #define QT_VERSION_STR  "2.3.10-snapshot-20050127"
    
  • Source file build.env once to set environment variable.
    $ source $PROJECT/env/build.env
    
  • Modify script $QPEDIR/scripts/build_qtopia. Delete -no-qtopiadesktop, from
        echo "***********************************"
        echo "**** Build and install Qtopia *****"
        echo "***********************************"
        cd $QPEDIR
        export QTDIR=$QTEDIR
        export PATH=$QPEDIR/bin:$QTOPIA_BASE_PATH
        if test -d $QPEDIR/src/libraries/qtopiaphone; then
            ./configure -edition phone -no-qtopiadesktop -displaysize 176x208 -dqt $QT3DIR
        elif test -d $QPEDIR/src/libraries/qtopiapim; then
            ./configure -edition pda -no-qtopiadesktop -displaysize 240x320 -dqt $QT3DIR
        else
            ./configure -edition core -no-qtopiadesktop -displaysize 240x320 -dqt $QT3DIR
        fi
    

    change to

        echo " "
        echo "***********************************"
        echo "**** Build and install Qtopia *****"
        echo "***********************************"
        cd $QPEDIR
        export QTDIR=$QTEDIR
        export PATH=$QPEDIR/bin:$QTOPIA_BASE_PATH
        if test -d $QPEDIR/src/libraries/qtopiaphone; then
            ./configure -edition phone -displaysize 176x208 -dqt $QT3DIR
        elif test -d $QPEDIR/src/libraries/qtopiapim; then
            ./configure -edition pda -displaysize 240x320 -dqt $QT3DIR
        else
            ./configure -edition core -displaysize 240x320 -dqt $QT3DIR
        fi
    
    
  • Build Qtopia by using provided script build_qtopia.

    $ cd $QPEDIR/scripts
    $ ./build_qtopia
    

    Everything will be smooth.

  • Compiled packacge will be in $QPEDIR/images.
  • Copy $QPEDIR/image/opt whole directory to root directory
  • Add these lines in /etc/ld.so.conf.
    /opt/Qtopia/lib
    $QTEDIR/lib
    $QT2DIR/lib
    
  • Update ld.so.cache by run ldconfig with root privilege.

Preparing environment

There are two environments.

  1. Qvfb environment

    This environment is for running application, testing in vitual frame buffer. Here is a configure file to set environment variables.

    # filename: qvfb.env
    export QPEDIR=/opt/Qtopia
    export QTDIR=$QPEDIR
    export PATH=$QPEDIR/bin:$PATH
    export LD_LIBRARY_PATH=$QPEDIR/lib:$LD_LIBRARY_PATH
    export PS1="Qvfb [\W] \$ "
    

    Source this file when we want to emulate PDA on X11 desktop.

  2. SDK environment

    This environment is for building apllication which runs on qvfb.

    # filename: sdk.env
    export QPEDIR=$PROJECT/build/qtopia-free-2.1.0
    export QTDIR=$QPEDIR
    export DQTDIR=$QPEDIR
    export PATH=$QPEDIR/bin:$PATH
    export QMAKESPEC=qws/linux-generic-g++
    export LD_LIBRARY_PATH=$QPEDIR/lib:$LD_LIBRARY_PATH
    export PS1='SDK [\W]$ '
    

Running QPE

  • Source qvfb.env.
    $ source $PROJECT/env/qvfb.env
    
    
  • Run qvfb.

  • Run qpe.

Test building

There are some examples in directory examples under Qtopia 2.1.0 source.

$ source $PROJECT/env/sdk.env
$ cp -r $PROJECT/build/qtopia-free-2.1.0/examples $PROJECT
$ cd $PROJECT/examples
$ which qmake
/home/poonlap/Qtopia_project/build/qtopia-free-2.1.0/bin/qmake
$ cd inputmethod/popup
$ qmake popup.pro
$ make
$ ls 
Makefile        libpopupim.so.1@      popup.pro         popupim.h
README          libpopupim.so.1.0@    popupextimpl.cpp  popupimpl.cpp
libpopupim.prl  libpopupim.so.1.0.0*  popupextimpl.h    popupimpl.h
libpopupim.so@  main.cpp              popupim.cpp
$ make install INSTALL_ROOT=/opt/Qtopia
install -c "libpopupim.so.1.0.0" "/opt/Qtopia/plugins/inputmethods/libpopupim.so.1.0.0"
strip --strip-unneeded -R .note -R .comment "/opt/Qtopia/plugins/inputmethods/libpopupim.so.1.0.0"
ln -sf "libpopupim.so.1.0.0" "/opt/Qtopia/plugins/inputmethods/libpopupim.so"
ln -sf "libpopupim.so.1.0.0" "/opt/Qtopia/plugins/inputmethods/libpopupim.so.1"
ln -sf "libpopupim.so.1.0.0" "/opt/Qtopia/plugins/inputmethods/libpopupim.so.1.0"

This example is a plugin example of how to write virtual keyboard for QPE.

We can use this example to create Thai virtual keyboard.

Fonts

Fonts in QPE will be in $QPE/lib/fonts, which is /opt/Qtopia/lib/fonts. Font format is .qpf (packed font). The program which is used to create these fonts is "makeqpf". Makeqpf is additional tool in Qt/Embedded source. It is better to separate source to make sure it work.

Build makeqpf

$ tar xzvf $PROJECT/sources/qt-embedded-2.3.10-snapshot-20050127.tar.gz
$ cd qt-2.3.10-snapshot-20050127
$ source $PROJECT/env/build.env
$ export QTDIR=$QTEDIR
$ export PATH=$QTDIR/bin:$PATH
$ echo yes | ./configure -qvfb -depths 4,8,16,32 -system-jpeg -gif -D QT_TRANSFORM_VFB
$ make sub-src
$ cd tools/makeqpf
$ make

First we will make sub-src to create library and go to makeqpf to create makeqpf.

Test makeqpf

  • Run qvfb
  • There is a script makeall in makeqpf directory. Run that script to show all available fonts in qvfb.

  • There is an example program in $QTEDIT/example/i18n. Here is the result.

Add new font

Sample fonts are created in $QTEDIR/lib/fonts but not all fonts are available in /opt/Qtopia/lib/fonts. To add new fonts, we can simple copy *.qpf into /opt/Qtopia/lib/fonts then restart qpe.

$ cp $QTEDIR/lib/fonts/unifont_* /opt/Qtopia/libs/fonts
$ pkill qpe
$ qpe

Create Thai fonts

  • Qpf font can be created from BDF, TTF and PFA. Here is an excerpt from file fontdir in $QTEDIR/lib/fonts.

    # see fonts-qws.html for mor information on this file.
    # format is
    #
    # name file renderer italic weight size [flags [sizerange]]
    #
    # set size as 0 to use sizerange.  flags are option if no sizerange
    # name is the name of the resulting font
    # file is the file to generate or render the font from
    # renderer is either FT or BDF indicating the rendering engine to use
    # italic is y for an italic font, n for not italic
    # weight is 50 for regular font, 75 for bold
    # size is 10* point size.  e.g. 120 for 12pt font.
    # flags include
    #    u = unicode font.  characters from 0-65535
    #    a = ascii font.  characters from 0-127
    #      <neither of the above is font with characters 0-255>
    
    #    s = smooth or blended font.
    # flags is optional if no sizerange is to be used (size is 0)
    # sizerange is optional unless size is 0.
    #    sizerange is comma separated list of font sizes to generate
    #
    fixed 5x7.bdf BDF n 50 70 u
    # Small basic demonstration font...
    japanese helvR12ja.bdf BDF n 50 230 u
    
  • In the case of Thai font, try copying Loma*ttf, Kinnari*ttf, Narasi*ttf, Garuda*ttf, TlwgTypewriter*ttf to $QTEDIR/lib/fonts.
  • Edit file $QTEDIR/lib/fonts/fontdir. Add following lines.

    loma Loma.ttf FT n 50 0 u 90,100,110,120,130,140
    loma Loma-Bold.ttf FT n 75 0 u 90,100,110,120,130,140
    loma Loma-Oblique.ttf FT y 50 0 u 90,100,110,120,130,140
    loma Loma-BoldOblique.ttf FT y 75 0 u 90,100,110,120,130,140
    kinnari Kinnari.ttf FT n 50 0 u 90,100,110,120,130,140
    kinnari Kinnari-Bold.ttf FT n 75 0 u 90,100,110,120,130,140
    kinnari Kinnari-Oblique.ttf FT y 50 0 u 90,100,110,120,130,140
    kinnari Kinnari-BoldOblique.ttf FT y 75 0 u 90,100,110,120,130,140
    norasi Norasi.ttf FT n 50 0 u 90,100,110,120,130,140
    norasi Norasi-Bold.ttf FT n 75 0 u 90,100,110,120,130,140
    norasi Norasi-Oblique.ttf FT y 50 0 u 90,100,110,120,130,140
    norasi Norasi-BoldOblique.ttf FT y 75 0 u 90,100,110,120,130,140
    garuda Garuda.ttf FT n 50 0 u 90,100,110,120,130,140
    garuda Garuda-Bold.ttf FT n 75 0 u 90,100,110,120,130,140
    garuda Garuda-Oblique.ttf FT y 50 0 u 90,100,110,120,130,140
    garuda Garuda-BoldOblique.ttf FT y 75 0 u 90,100,110,120,130,140
    tlwgtt TlwgTypewriter.ttf FT n 50 0 u 90,100,110,120,130,140
    tlwgtt TlwgTypewriter-Bold.ttf FT n 75 0 u 90,100,110,120,130,140
    tlwgtt TlwgTypewriter-Oblique.ttf FT y 50 0 u 90,100,110,120,130,140
    tlwgtt TlwgTypewriter-BoldOblique.ttf FT y 75 0 u 90,100,110,120,130,140
    
  • Run $QTEDIR/tools/makeqpf/makeqpf -A. It will create qpf fonts listed in fontdir file.
  • Here is the screen shot of Thai fonts.

  • New fonts will be in $QTEDIR/lib/fonts. We can simply copy to /opt/Qtopia/lib/fonts.
  • Here is the sample of Loma font.

Using bitmap font

  • Thai bitmap fonts in Linux is in PCF format. We have convert to BDF with utility like pcftobdf. Then use fontforge to change the encoding to unicode, re-generate BDF font. Here is the sample.

Translation

Input

To create input method such as virtual keyboard, we have to create plugin (.so). There is an example in examples/inputmethod.

  • Writing plugin
  • Document about input method plugin.
  • We can divide inputmethod plugin into 2 parts, one is interface and logic (create plugin).
  • Interface can be anything from QPushbutton to custom widget. The widget should have signal such as
    signals:
        void keyPress( ushort unicode, ushort keycode,
                ushort modifiers, bool press, bool repeat );
    
    Parameter Notes
    unicode The unicode value of the character, or 0xFFFF if it is a non-printing key.
    keycode The key code as specified in qnamespace.h
    modifiers A combination of zero or more of the following OR'ed together:
    Qt::ShiftButton, Qt::ControlButton and Qt::AltButton
    press TRUE for a key press, FALSE for a key release.
    repeat TRUE if this is a repeating keypress. Repeating key presses are the additional events that occur when a key is held down for a period of time.
  • Qt key names are listed in qnamespace.h.
  • The widget must implement sizeHint() to give the proper size when it is called.
  • To create input plugin, there are two ways subclassing InputMethodInterface and subclassing ExtInputMethodInterface. Subclassing InputMethodInterface is compatible with Qtopia 1.5 (for example Zaurus).
  • Here is the primitive implement of Thai keyboard, thkeyboard.tar.gz.
  • Some screenshots

Documents

Trolltech Qtopia 2.1 online.

AttachmentSize
thkeyboard.tar.gz.txt350.51 KB