Cegui way to add fonts to word load, but not now loaded with more than one word.
I had changed the CEGUIFont.cpp
Code: Select all
const FontGlyph* Font::getGlyphData(utf32 codepoint) const
{
if (codepoint > d_maxCodepoint)
return 0;
if (d_glyphPageLoaded)
{
// Check if glyph page has been rasterised
uint page = codepoint / GLYPHS_PER_PAGE;
uint mask = 1 << (page & (BITS_PER_UINT - 1));
if (!(d_glyphPageLoaded[page / BITS_PER_UINT] & mask))
{
d_glyphPageLoaded[page / BITS_PER_UINT] |= mask;
rasterise(codepoint & ~(GLYPHS_PER_PAGE - 1),
codepoint | (GLYPHS_PER_PAGE - 1),codepoint);
} }
CodepointMap::const_iterator pos = d_cp_map.find(codepoint);
return (pos != d_cp_map.end()) ? &pos->second : 0;
}
and
ceguifreetype.cpp
Code: Select all
void FreeTypeFont::rasterise(utf32 start_codepoint, utf32 end_codepoint,utf32 codepoint) const
{
CodepointMap::const_iterator s = d_cp_map.lower_bound(start_codepoint);
if (s == d_cp_map.end())
return;
CodepointMap::const_iterator pos = d_cp_map.find(codepoint);//对应的文字
CodepointMap::const_iterator e = d_cp_map.upper_bound(end_codepoint);
printf(" textsize \n");
if(pos != d_cp_map.end())
{
printf(" textsize \n");
uint texsize = getTextureSize(s, e);
Imageset& is = ImagesetManager::getSingleton().create(
d_name + "_auto_glyph_images_" + int (pos->first),
System::getSingleton().getRenderer()->createTexture());
d_glyphImages.push_back(&is);
// Create a memory buffer where we will render our glyphs
argb_t *mem_buffer = new argb_t [texsize * texsize];
memset(mem_buffer, 0, texsize * texsize * sizeof(argb_t));
// Go ahead, line by line, top-left to bottom-right
uint x = INTER_GLYPH_PAD_SPACE, y = INTER_GLYPH_PAD_SPACE;
uint yb = INTER_GLYPH_PAD_SPACE;
if (!pos->second.getImage())
{
//Render the glyph
if (FT_Load_Char(d_fontFace, pos->first, FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT |
(d_antiAliased ? FT_LOAD_TARGET_NORMAL : FT_LOAD_TARGET_MONO)))
{
std::stringstream err;
err << "Font::loadFreetypeGlyph - Failed to load glyph for codepoint: ";
err << static_cast<unsigned int>(s->first);
err << ". Will use an empty image for this glyph!";
Logger::getSingleton().logEvent(err.str(), Errors);
//Create a 'null' image for this glyph so we do not seg later
Rect area(0, 0, 0, 0);
Point offset(0, 0);
String name;
name += pos->first;
is.defineImage(name, area, offset);
((FontGlyph &)pos->second).setImage(&is.getImage(name));
}
else
{
uint glyph_w = d_fontFace->glyph->bitmap.width + INTER_GLYPH_PAD_SPACE;
uint glyph_h = d_fontFace->glyph->bitmap.rows + INTER_GLYPH_PAD_SPACE;
//Check if glyph right margin does not exceed texture size
uint x_next = x + glyph_w;
if (x_next > texsize)
{
x = INTER_GLYPH_PAD_SPACE;
x_next = x + glyph_w;
y = yb;
}
//Check if glyph bottom margine does not exceed texture size
uint y_bot = y + glyph_h;
drawGlyphToBuffer(mem_buffer + (y * texsize) + x, texsize);
//Create a new image in the imageset
Rect area(static_cast<float>(x),
static_cast<float>(y),
static_cast<float>(x + glyph_w - INTER_GLYPH_PAD_SPACE),
static_cast<float>(y + glyph_h - INTER_GLYPH_PAD_SPACE));
Point offset(d_fontFace->glyph->metrics.horiBearingX * static_cast<float>(FT_POS_COEF),
-d_fontFace->glyph->metrics.horiBearingY * static_cast<float>(FT_POS_COEF));
String name;
name += pos->first;
is.defineImage(name, area, offset);
((FontGlyph &)pos->second).setImage(&is.getImage(name));
//Advance to next position
x = x_next;
if (y_bot > yb)
{
yb = y_bot;
}
}
}
//Copy our memory buffer into the texture and free it
is.getTexture()->loadFromMemory(mem_buffer, Size(texsize, texsize), Texture::PF_RGBA);
delete [] mem_buffer;
}
printf(" rasterize finished \n");
}
the log
Code: Select all
window renderer 'Falagard/Tree' and Look'N'Feel 'TaharezLook/Tree'. (0012D920)
18/07/2010 19:44:07 (Std) Started creation of Font from XML specification:
18/07/2010 19:44:07 (Std) ---- CEGUI font name: DejaVuSans-10
18/07/2010 19:44:07 (Std) ---- Font type: FreeType
18/07/2010 19:44:07 (Std) ---- Source file: DejaVuSans.ttf in resource group: (Default)
18/07/2010 19:44:07 (Std) ---- Real point size: 10
18/07/2010 19:44:07 (Std) Attempting to create Imageset 'BackgroundImage' using image file 'GPN-2000-001437.tga'.
18/07/2010 19:44:07 (Std) Attempting to create Imageset 'Simhei_auto_glyph_images_F' with texture only.
But I can success to run it.Why ?I will how to changed it.