Chinaunix首页 | 论坛 | 博客
  • 博客访问: 819755
  • 博文数量: 756
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 4980
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 14:40
文章分类

全部博文(756)

文章存档

2011年(1)

2008年(755)

我的朋友

分类:

2008-10-13 16:11:38

Some stuffs of the OGRE patch

I have to admit that if I had tried the first, I would not make this patch. Since I have finished it, and this patch has something different with CEGUI, I decide to put it on the site at last.


What features the OGRE patch provides?

This patch provides these features:
1. A static and a dynamic code convertor class and convertor manager class.
2. A flexible UNICODE and multibyte code support natively.
3. An l10n Input Method support with SDL().

First, let us see the two pictures:
OGRE InputMethod support
(picture 1 -- OGRE InputMethod support)

[About picture 1]
This is the InputMethod support with buffered or unbuffered input example.


OGRE multicode support
(picture 2 -- OGRE multicode support)

[About picture 2]
The first line is Japanese with SHIFT_JIS code.
The second line is Korean with EUCKR code.
The third line is Arabic with WINDOWS-1256 code.
The fourth line is Thai with ISO-8859-11 code.
The fifth line is vietnamese with UTF8 code.
The sixth line is Hebrew with WINDOWS-1255 code.
The seventh line is Chinese with BIG5 code.


Where can I get this patch and how to apply it?

You can get OGRE patch from , and the version(> 1.0.3) of OGRE I modify , or you can get the OGRE source from OGRE official web site:  .

To apply this patch and compile:
1.$tar zxvf ogrenew-20050717cvs-20050730.tar.gz
2.$gzip -d ogre_patch-20050717cvs-20050730.diff.gz
3.$mv ogre_patch-20050717cvs-20050730.diff ogrenew/
4.$cd ogrenew/
5.$patch -p1 < ogre_patch-20050717cvs-20050730.diff
6.$./bootstrap
7.$./configure --with-platform=SDL
8.$make

Here is the sample of the new features:
 
(with full Media pack)

The concepts of OGRE i18n patch

The implement of original Ogre::font is to make a texture which contains fonts' images all you may need, and to save the font's uv coordinate for this font texture in an array. When we need a character, just send the character code to get the coordinate of the font image texture.This is good enough for Latin system language, but not suitable for others' language, especially not for ideogram.

In the ideogram(ex. Chinese) system, there is no "alphabet" to be combined to a word. It's usually a character as a word. To see the character code range of CJK(Chinese, Japanese, Korean) language from , the range is from 0x4E00 to 0x9FBF . It means that in order to create a CJK font texture by Ogre::font, we have to create 20927 fonts images. It's really a big texture!
So we have to create a part what we need of the CJK code set  flexibly.


The improvement of Ogre::font

1. Add  setExtCodeName() and getExtCodeName() members.
2. Add setCodeRange() and getCodeRange() members.
3. Re-define OGRE_GLYPH_INDEX(). If the character can not be found in Ogre::font, OGRE_GLYPH_INDEX() will return zero. It means that if the character can not be found, you will always receive the coordinate of the first font image.(Important!)
4. Add getUncreatedCode() to get a set which stores the code of the uncreated fonts you require.

After applying this patch, we have to check if the macro OGRE_UNICODE_STRINGS in ogrenew/OgreMain/include/OgreConfig.h is enabled as 1, then when we compile and install OGRE completely, we have to set the new identity  "code" and "coderange" in the fontdef file in the Media pack.

For example:

TW
{
    type    truetype
    source     fireflysung.ttf
    code    BIG5
    coderange 0xA141,0xA141.0xA143,0xA143.0xA4DF,0xA4DF.0xA7D3,0xA7D3.0xABE4,0xABE4.0xB4BC,0xB4BC.0xBC7B,0xBC7B.0xBCDD,0xBCDD.
    size 14
    resolution 96
    antialias_colour false
}

The string after the identity "code" is the code name which is the external code we want Ogre::font to receive, and OGRE will convert the external code to wchar_t UNICODE. The external code has to be the char type encoding code, like UTF8, BIG5, SHIFT_JIS....etc, and not the wide char type(wchar_t, unsigned short) encoding code, likes UCS, UTF16, UTF32...et.

The string after the identity "coderange", the code range of the "code", is the range which we want Ogre::font to create fonts image. The string is a line without space, and it uses comma(,) and decimal(.)  to separate and to end the first code and the last code.

For example, it means to specify a BIG5 code 0xA141 to create:

code   BIG5
coderange 0xA141,0xA141.


For example, it means to specify three BIG5 codes 0xA141, 0xA142, 0xA143 to create:

code   BIG5
coderange   0xA141,0xA143.


Additionally, we can specify multi coderange like this:

code   BIG5
coderange   0xA141,0xA143.0xA240,0xA2DD.0xA4AF,0xA4DF.


Note: If you do not specify code and coderange in the fontdef file, or not use the TrueType font, the behavior of the patched Ogre::font will be the same as the original one.


The little tools to make code range

There are two little tools to help us to make code range and export external code to octal string easily:


The improvement of Ogre::TextAreaOverlayElement

In order to show UNICODE words, I modify the Ogre::TextAreaOverlayElement to convert external string to UNICODE automatically. Its interface is not changed.


The improvement of Ogre::Input

1. Add a new KeyCode define "KC_IM_FLUSH". "KC_IM_FLUSH" represents that the OGRE Application has received a string from IM(InputMethod). We could use "isKeyDown()" member function to check if the IM string is flushed.

2. Add a new member "getIMString()" to get the local code string from IM.

3. Add a new member "setIMPosition()" to set the absolute pixel position to IM widget.

You could see the sample 01_buffered_input and 02_unbuffered_input in to get the further information.


The Code Convertor system

Ogre::CodeConv(ogrenew/OgreMain/include/OgreCodeConv.h) provides an interface and a template wrapper for helping users to create code convertor that OGRE needs.

The sample 04_manual_conv demonstrates how to inherit the interface, use the template wrapper to create code convertors, and set convertors to Ogre::CodeConvManager manually.

Moreover, like the demonstration which the sample 03_multilang shows, we  can usually let OGRE create code convertors automatically, not manually.


Changes log:
2005/07/25: commit this page.
2005/07/30: split ogretest and update patch.


Copyright 2004-2005 L.Y.C., Taiwan(Formosa).






























--------------------next---------------------

阅读(582) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~