Пример #1
0
bool vncScanInput::Tokenize(const TCHAR *line, TCHAR **token){
	int tokenCount = 0;

	// Loop until the end of line or until 4th token found
	for (; _tcslen(line) > 0 && tokenCount < 4;) {
		int len = 0;
		switch (*line) {
		case _T(' ') :
		case _T('\t'): 
			line++; // Eat whitespace
			break;
		case _T('"') : 
			line++; // Eat opening quote
			len = GetQuoteLength(line);
			tokenCount = AddToken(token, tokenCount, &line, len);
			line++; // Eat closing quote
			break;
		default:
			len = GetWordLength(line);
			tokenCount = AddToken(token, tokenCount, &line, len);
			break;
		}
	}
	return (tokenCount == 3 && _tcslen(line) == 0) ? true : false;
}
Пример #2
0
Float Font::CalculateLineLength(const char * text, uint32 textWidth, uint32 textPos) const
{
	Float lineLength = 0;

	while (textPos < strlen(text))
	{
		bool wordBegin = true;
		uint32 wordLength = GetWordLength(text, textPos);
		uint32 wordSpace = GetWordSpace(text, textPos);

		for (uint32 i = textPos; i < textPos + wordLength; i++)
		{
			if (text[i] == '&')
			{
				ParseSpecial(text, i, false);
				continue;
			}
			else if (((text[i] == '\n') || ((text[i] == '\\') && (text[i+1] == 'n')) || (lineLength > textWidth)) || ((wordSpace + lineLength + baseSize >= textWidth) && (wordSpace < textWidth) && (wordBegin == true)))
			{
				return textWidth - lineLength;
				if (text[i] == '\n')
				{
					continue;
				}
				else if ((text[i] == '\\') && (text[i+1] == 'n'))
				{
					i++;
					continue;
				}
			}
			lineLength += width[text[i]];
			wordBegin = false;
		}

		textPos += wordLength + 1;
		if (textPos < strlen(text))
		{
			lineLength += baseSize;
		}
	}

	return textWidth - lineLength;
}
Пример #3
0
Float Font::CalculateTextHeight(const char * text, uint32 textWidth) const
{
	Point2D offset(0, baseSize);

	uint32 textPos = 0;
	while (textPos < strlen(text))
	{
		bool wordBegin = true;
		uint32 wordLength = GetWordLength(text, textPos);
		uint32 wordSpace = GetWordSpace(text, textPos);

		for (uint32 i = textPos; i < textPos + wordLength; i++)
		{
			if (text[i] == '&')
			{
				ParseSpecial(text, i, false);
				continue;
			}
			else if (((text[i] == '\n') || ((text[i] == '\\') && (text[i+1] == 'n')) || (offset.GetX() > textWidth)) || ((wordSpace + offset.GetX() >= textWidth) && (wordSpace < textWidth) && (wordBegin == true)))
			{
				offset.SetValues(0, offset.GetY() + baseSize);
				if (text[i] == '\n')
				{
					continue;
				}
				else if ((text[i] == '\\') && (text[i+1] == 'n'))
				{
					i++;
					continue;
				}
			}
			offset.SetValues(offset.GetX() + width[text[i]], offset.GetY());
			wordBegin = false;
		}

		offset.SetValues(offset.GetX() + baseSize, offset.GetY());
		textPos += wordLength + 1;
	}

	return offset.GetY();
}
Пример #4
0
void Font::PrintText(const char * text, const Point2D& pos, const Rect& bounds, uint8 format) const
{
	Point2D offset;

	glPushMatrix();
	glLoadIdentity();
	glColor(Black);
	glTranslated(pos.GetX(), pos.GetY(), 0);

	uint8 justify = format & 0x03;

	Float lineOffset = (int32)(CalculateLineLength(text, bounds.GetWidth(), 0)/2.0 * justify);
	offset.SetValues(offset.GetX() + lineOffset, offset.GetY());
	glTranslated(lineOffset, 0.0, 0);

	uint32 textPos = 0;
	while (textPos < strlen(text))
	{
		bool wordBegin = true;
		uint32 wordLength = GetWordLength(text, textPos);
		uint32 wordSpace = GetWordSpace(text, textPos);

		for (uint32 i = textPos; i < textPos + wordLength; i++)
		{
			if (text[i] == '&')
			{
				ParseSpecial(text, i, true);
				continue;
			}
			else if (((text[i] == '\n') || ((text[i] == '\\') && (text[i+1] == 'n')) || (offset.GetX() > bounds.GetWidth())) || ((wordSpace + offset.GetX() >= bounds.GetWidth()) && (wordSpace < bounds.GetWidth()) && (wordBegin == true)))
			{
				glTranslated(-offset.GetX(), baseSize, 0);
				offset.SetValues(0, offset.GetY() + baseSize);
				if (offset.GetY() > bounds.GetHeight())
				{
					glPopMatrix();
					return;
				}
				lineOffset = (int32)(CalculateLineLength(text, bounds.GetWidth(), i + 1)/2.0 * justify);
				offset.SetValues(offset.GetX() + lineOffset, offset.GetY());
				glTranslated(lineOffset, 0.0, 0);

				if (text[i] == '\n')
				{
					continue;
				}
				else if ((text[i] == '\\') && (text[i+1] == 'n'))
				{
					i++;
					continue;
				}
			}
			glCallList(text[i] + displayLists);
			offset.SetValues(offset.GetX() + width[text[i]], offset.GetY());
			wordBegin = false;
		}

		offset.SetValues(offset.GetX() + baseSize, offset.GetY());
		glTranslated(baseSize, 0, 0);

		textPos += wordLength + 1;
	}

	glPopMatrix();
}