Mygui中文换行问题(四)

2014-11-24 09:03:06 · 作者: · 浏览: 2
UString::const_iterator end = _text.end();
UString::const_iterator index = _text.begin();

/*if (index == end)
return;*/

result.height += _height;

for (; index != end; ++index)
{
Char character = *index;

// новая строка
if (character == FontCodeType::CR
|| character == FontCodeType::NEL
|| character == FontCodeType::LF)
{
if (character == FontCodeType::CR)
{
UString::const_iterator peeki = index;
++peeki;
if ((peeki != end) && (*peeki == FontCodeType::LF))
index = peeki; // skip both as one newline
}

line_info.width = (int)ceil(width);
line_info.count = count;
//mLength += line_info.count + 1;
mLength += line_info.offcount;
result.height += _height;
setMax(result.width, line_info.width);
width = 0;
count = 0;

mLineInfo.push_back(line_info);
line_info.clear();

// отменяем откат
roll_back.clear();

continue;
}
// тег
else if (character == L'#')
{
// берем следующий символ
++ index;
if (index == end)
{
--index; // это защита
continue;
}

character = *index;
// если два подряд, то рисуем один шарп, если нет то меняем цвет
if (character != L'#')
{
// парсим первый символ
uint32 colour = convert_colour[(character - 48) & 0x3F];

// и еще пять символов после шарпа
for (char i = 0; i < 5; i++)
{
++ index;
if (index == end)
{
--index; // это защита
continue;
}
colour <<= 4;
colour += convert_colour[ ((*index) - 48) & 0x3F ];
}

// если нужно, то меняем красный и синий компоненты
texture_utility::convertColour(colour, _format);

line_info.simbols.push_back( CharInfo(colour) );

continue;
}
}

GlyphInfo* info = _font->getGlyphInfo(character);

if (info == nullptr)
continue;

if (FontCodeType::Space == character)
{
roll_back.set(line_info.simbols.size(), index, count, width);
}
else if (FontCodeType::Tab == character)
{
roll_back.set(line_info.simbols.size(), index, count, width);
}

float char_width = info->width;
float char_height = info->height;
float char_advance = info->advance;
float char_bearingX = info->bearingX;