Error : using Font

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

User avatar
noname
Not too shy to talk
Not too shy to talk
Posts: 21
Joined: Wed Jan 12, 2005 12:06

Error : using Font

Postby noname » Wed Feb 23, 2005 08:29

(If the topic has already existed ,I am sorry for repeatting . )
Hi , look at the following code:

utf8* insertGlyphs = (utf8*)"[color=FF0000]CEGUI世界你好[/color]";
CEGUI::Font * font = CEGUI::System::getSingleton().getDefaultFont() ;
try{
CEGUI::String glyphSets(font->getAvailableGlyphs());
glyphSets += insertGlyphs ;
font->defineFontGlyphs(glyphSets);
}catch (CEGUI::Exception & e )
{
// skip the exception and go on
}

The program will not work nicely , words will be lost on the widget
and the excptions said:
Exception: Imageset::defineImage - An image with the name [color=FF0000]'C' already exists[/color] in Imageset 'SimHei-10_auto_glyph_images'.
........

So if some character has already existed , how can I insert Glyphs into the Font dynamicly ? Such as when chatting . :(

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Error : using Font

Postby CrazyEddie » Thu Feb 24, 2005 09:26

Each codepoint passed in the supplied string must be unique. There's nothing to be gained from specifying the same codepoint twice for the same font.

CE.

User avatar
noname
Not too shy to talk
Not too shy to talk
Posts: 21
Joined: Wed Jan 12, 2005 12:06

Re: Error : using Font

Postby noname » Thu Feb 24, 2005 10:05

If there is a few codepoint , I can define a set of Glyphs , but if there is much more codepoints ,it will not work any more ,so I must cache the codepoint dynamicly .
Now ,repeatting will appear . if I initialize all the codepoints at one time ,it will waste long time and there is a lot of wastes. It is a pain .

What can I do ? Would you like give me some suggestions ?

Thanks .

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Error : using Font

Postby CrazyEddie » Thu Feb 24, 2005 10:08

Before adding a codepoint, just see if it already exists, if it does, do not add it again.

CE.

User avatar
noname
Not too shy to talk
Not too shy to talk
Posts: 21
Joined: Wed Jan 12, 2005 12:06

Re: Error : using Font

Postby noname » Fri Feb 25, 2005 00:13

So I should build a manager to manage this ,right ?

By the way , when I turn on the input method , data type of the character which I catched is [color=0000FF]char[/color] and it occupys two bytes(16 bits , such as '好'),I have not found the method to transform it to codepoint,I appreciate if you could help me .

Any way ,thanks.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Error : using Font

Postby CrazyEddie » Fri Feb 25, 2005 09:51

A full blown manager might be overkill, all you really need is a single method to take a CEGUI::Font pointer, and CEGUI::String as input. The method needs to get the currently available glyphs from the font, and then you just compare each codepoint in the string you're adding with what's currently available, any codepoint not in the available string should be added, then you submit the final set back to the font for creation:

Code: Select all

void addFontGlyphs(CEGUI::Font* font, const CEGUI::String& new_glyphs)
{
   using namespace CEGUI;
   
   // get glyphs currently available.
   String glyphset(font->getAvailableGlyphs());
   
   // for each glyph in the given set which we may have to add
   for (int i = 0; i < new_glyphs.length(); ++i)
   {
      // see if the glyph is already defined for the font
      if (glyphset.find(new_glyphs[i]) == String::npos)
      {
         // glyph was not defined so add it to the set which we
         // wil submit back to the font.
         glyphset.append(new_glyphs[i];
      }
   }
   
   // submit the new glyph set back to font for creation.
   font->defineFontGlyphs(glyphset);
}


This is not the only approach you could use for this, but is just a simple example.

Where are you getting your input from, you did not say? If it is via Win32 messages, then the following need to be considered.

Unicode in Win32 is not as wonderful as they'd have you believe, since you're mostly stuck with using a single UTF-16 codeunit to represent any codepoint; so this immediately chucks a whole load of supplementary plane glyph sets straight out of the window.

If you want to use Unicode at all then you must set up and compile your application as a Unicode application as opposed to a Ansi application. The difference is that with Unicode you'll get proper UTF-16 (or UTF-32, more on that in a minute) standard codepoint values, but with Ansi the values you get will be from some locale determined code page, and so will require translation into UTF-32 (which is beyond the scope of what I can go into here).

Once you have the app set up properly, you have two options for getting these inputs; WM_CHAR and WM_UNICHAR.

WM_CHAR will give you a UTF-16 codepoint. I'm not entirely sure whether they use the low 16 bits only, or whether they use the full 32 bits making use of surrogate pairs where required (the MS docs are particularly sketchy on this, so I assume you're stuck with the single 16 bit codeunit). If surrogate pairs are used though, then you'll need to detect and decode those (http://www.unicode.org for info).

WM_UNICHAR in Windows XP give you a UTF-32 codepoint and can be passed directly to CEGUI.

CE.

User avatar
noname
Not too shy to talk
Not too shy to talk
Posts: 21
Joined: Wed Jan 12, 2005 12:06

Re: Error : using Font

Postby noname » Fri Feb 25, 2005 10:18

The flowing

Code: Select all

void addFontGlyphs(CEGUI::Font* font, const CEGUI::String& new_glyphs)
{
   using namespace CEGUI;
   
   // get glyphs currently available.
   String glyphset(font->getAvailableGlyphs());
   
   // for each glyph in the given set which we may have to add
   for (int i = 0; i < new_glyphs.length(); ++i)
   {
      // see if the glyph is already defined for the font
      if (glyphset.find(new_glyphs[i]) == String::npos)
      {
         // glyph was not defined so add it to the set which we
         // wil submit back to the font.
         glyphset.append(new_glyphs[i];
      }
   }
   
   // submit the new glyph set back to font for creation.
   font->defineFontGlyphs(glyphset);
}


I have made it , thanks.

the only left thing is how to use WM_CHAR ,for other reason , I will not use WM_UNICHAR .

I'll go to http://www.unicode.org for some info ,thanks .


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 5 guests