I have implemented support for '\t' tabs within a string to align the text to the next tab width. It is implemented in the Font class, disabled by default for compatibility. One can choose the width of the tab alignments in pixels. Here is how to use it:
Code: Select all
CEGUI::Font *pFont = CEGUI::FontManager::getSingleton().createFont("verdana.font");
pFont->setTabEnabled(true);
pFont->setTabWidth(100);
This code will make every '\t' sign align the following text to the next 100 pixel margin.
I can't really make a patch as I have other changes pending in the file and I'm not very familiar with the diff command.
in CEGUIFont.cpp, in Font::drawTextLine, change
Code: Select all
glyph = getGlyphData(text[c]);
if (glyph)
{
const Image* img = glyph->getImage();
cur_pos.d_y = base_y - (img->getOffsetY() - img->getOffsetY() * y_scale);
img->draw(cur_pos, glyph->getSize(x_scale, y_scale), clip_rect, curColour);
cur_pos.d_x += glyph->getAdvance(x_scale);
}
to
Code: Select all
// If we encounter a tab character, we go to the next tab line.
if(text[c] == '\t' && d_tabEnabled) {
size_t pixel_now = (size_t)PixelAligned(cur_pos.d_x);
cur_pos.d_x = (float)(pixel_now - (pixel_now % d_tabWidth) + d_tabWidth);
} else {
glyph = getGlyphData(text[c]);
if (glyph)
{
const Image* img = glyph->getImage();
cur_pos.d_y = base_y - (img->getOffsetY() - img->getOffsetY() * y_scale);
img->draw(cur_pos, glyph->getSize(x_scale, y_scale), clip_rect, curColour);
cur_pos.d_x += glyph->getAdvance(x_scale);
}
}
and add this to the constructor and destructor:
Code: Select all
d_tabEnabled(false),
d_tabWidth(80)
in CEGUIFont.h, add this about line 280, under all other variable declarations:
Code: Select all
/// The width (in pixels) of the tab character.
size_t d_tabWidth;
/// Whether to enable support of the tab escape sign (\t) or not.
bool d_tabEnabled;
and around line 455, add this (in the public section):
Code: Select all
void setTabEnabled(bool setting) { d_tabEnabled = setting; }
void setTabWidth(size_t width) { d_tabWidth = width; }
size_t getTabWidth() { return d_tabWidth; }
bool isTabEnabled() { return d_tabEnabled; }
That's all, sorry for the missing patch
