Exemplo n.º 1
0
void TextLayout::_RenderRaw(float maxWidth) const
{
	TextureFont *font = Gui::Screen::GetFont();
	float py = 0;
	init_clip_test();

	glPushMatrix();

	const float spaceWidth = font->GetGlyph(' ').advx;

	std::list<word_t>::const_iterator wpos = this->words.begin();
	// build lines of text
	while (wpos != this->words.end()) {
		float len = 0;
		int num = 0;

		std::list<word_t>::const_iterator i = wpos;
		len += (*i).advx;
		num++;
		bool overflow = false;
		bool explicit_newline = false;
		if ((*i).word != 0) {
			++i;
			for (; i != this->words.end(); ++i) {
				if ((*i).word == 0) {
					// newline
					explicit_newline = true;
					num++;
					break;
				}
				if (len + spaceWidth + (*i).advx > maxWidth) { overflow = true; break; }
				len += (*i).advx + spaceWidth;
				num++;
			}
		}

		float _spaceWidth;
		if ((m_justify) && (num>1) && overflow) {
			float spaceleft = maxWidth - len;
			_spaceWidth = spaceWidth + (spaceleft/float(num-1));
		} else {
			_spaceWidth = spaceWidth;
		}

		if (line_clip_test(py, py+font->GetHeight()*2.0)) {
			float px = 0;
			for (int j=0; j<num; j++) {
				if ((*wpos).word) font->RenderMarkup((*wpos).word, round(px), round(py));
				px += (*wpos).advx + _spaceWidth;
				wpos++;
			}
		} else {
			for (int j=0; j<num; j++) wpos++;
		}
		py += font->GetHeight() * (explicit_newline ? PARAGRAPH_SPACING : LINE_SPACING);
	}
	glPopMatrix();
}
Exemplo n.º 2
0
void TextLayout::_MeasureSizeRaw(const float layoutWidth, float outSize[2]) const
{
	TextureFont *font = Gui::Screen::GetFont();
	outSize[0] = 0;
	outSize[1] = 0;

	const float spaceWidth = font->GetGlyph(' ').advx;

	// build lines of text
	for (std::list<word_t>::const_iterator wpos = words.begin(); wpos != words.end(); ) {
		float len = 0;
		int num = 0;
		bool explicit_newline = false;

		std::list<word_t>::const_iterator i = wpos;
		len += (*i).advx;
		num++;
		bool overflow = false;
		if ((*i).word != 0) {
			++i;
			for (; i != words.end(); ++i) {
				if ((*i).word == 0) {
					// newline
					explicit_newline = true;
					num++;
					break;
				}
				if (len + spaceWidth + (*i).advx > layoutWidth) { overflow = true; break; }
				len += (*i).advx + spaceWidth;
				num++;
			}
		}

		float _spaceWidth;
		if ((m_justify) && (num>1) && overflow) {
			float spaceleft = layoutWidth - len;
			_spaceWidth = spaceWidth + (spaceleft/float(num-1));
		} else {
			_spaceWidth = spaceWidth;
		}

		float lineLen = 0;
		for (int j=0; j<num; j++) {
			word_t word = (*wpos);
			lineLen += word.advx;
			if (j < num-1) lineLen += _spaceWidth;
			wpos++;
		}
		if (lineLen > outSize[0]) outSize[0] = lineLen;
		outSize[1] += font->GetHeight() * (explicit_newline ? PARAGRAPH_SPACING : LINE_SPACING);
	}
	if (outSize[1]) outSize[1] += font->GetDescender();
}