Beispiel #1
0
/////////////////
// Draw a string
void OpenGLText::DrawString(StringUTF32 text,Vector2f pos, float scale)
{
	// Variables
	float x = pos.x;
	float y = pos.y;
	size_t len = text.length();
	OpenGLTextGlyph glyph;
	lineHeight = 0;
	float dx=x,dy=y;

	// Draw string
	for (size_t i=0;i<len;i++) {
		// Get current character
		int curChar = text[i];

		// Handle carriage returns
		if (curChar == '\n') {
			dx = x;
			dy -= lineHeight * scale;
		}

		// Handle normal glyphs
		else {
			glyph = GetGlyph(curChar);
			glyph.Draw(dx,dy,scale);
			float gw = glyph.GetAdvanceX();
			float gh = glyph.GetAdvanceY();
			dx += gw * scale;
			if (gh > lineHeight) lineHeight = gh;
		}
	}
}
Beispiel #2
0
StringVector KanaConverter::GetPronunciationChanges(const String _kana)
{
	StringUTF32 kana = _kana.GetUTF32();
	StringVector result;
	size_t len = kana.length();
	if (len == 0) return result;

	int firstChar = kana[0];
	int lastChar = kana[len-1];
	int firstCharKata = KanaToKatakana(firstChar);
	int lastCharKata = KanaToKatakana(lastChar);

	// tsu -> little tsu
	if (lastCharKata == 0x30C4) {
		result.push_back(String(kana.substr(0,len-1) + StringUTF32(1, lastChar-1)));
	}

	// k->g, s->z, t->d
	if (firstCharKata >= 0x30AB && firstCharKata <= 0x30C1 && firstCharKata % 2 == 1) {
		result.push_back(String(StringUTF32(1, firstChar+1) + kana.substr(1)));
	}

	// t->d
	if (firstCharKata >= 0x30C4 && firstCharKata <= 0x30C8 && firstCharKata % 2 == 0) {
		result.push_back(String(StringUTF32(1, firstChar+1) + kana.substr(1)));
	}

	// h->b, h->p
	if (firstCharKata >= 0x30CF && firstCharKata <= 0x30DD && firstCharKata % 3 == 0) {
		result.push_back(String(StringUTF32(1, firstChar+1) + kana.substr(1)));
		result.push_back(String(StringUTF32(1, firstChar+2) + kana.substr(1)));
	}

	return result;
}
Beispiel #3
0
void KanaConverter::OffsetCharacterValues(String &_str,int offset)
{
	StringUTF32 str = _str.GetUTF32();
	size_t n = str.length();
	for (size_t i=0; i<n; i++) {
		str[i] += offset;
	}
	_str = String(str);
}
Beispiel #4
0
bool KanaConverter::IsKana(const String _kana)
{
	StringUTF32 kana = _kana.GetUTF32();
	size_t len = kana.length();
	for (size_t i=0; i<len; i++) {
		if (!IsKana(kana[i])) return false;
	}
	return true;
}
Beispiel #5
0
String KanaConverter::KanaToHiragana(const String str)
{
	StringUTF32 result = str.GetUTF32();
	size_t n = result.length();
	for (size_t i=0;i<n;i++) {
		if (IsKatakana(result[i])) {
			result[i] -= HIRA_TO_KATA_OFFSET;
		}
	}
	return String(result);
}
Beispiel #6
0
StringUTF32 UINumericValidator::onTextChanged(StringUTF32 src)
{
	std::vector<utf32type> result(src.length());
	size_t j = 0;
	for (size_t i = 0; i < result.size(); ++i) {
		if ((src[i] >= '0' && src[i] <= '9') || (i == 0 && src[i] == '-' && allowNegative) || (src[i] == '.' && allowFloat)) {
			result[j++] = src[i];
		}
	}
	return StringUTF32(result.data(), j);
}
Beispiel #7
0
/////////////////////////
// Calculate text extent
Vector2f OpenGLText::GetExtent(String _text)
{
	// Variables
	StringUTF32 text = _text.GetUTF32();
	size_t len = text.length();
	OpenGLTextGlyph glyph;
	lineHeight = 0;
	int dx=0,dy=0;
	Vector2f pos;

	// Simulate drawing of string
	for (size_t i=0;i<len;i++) {
		// Get current character
		int curChar = text[i];

		// Handle carriage returns
		if (curChar == '\n') {
			if (dx > pos.x) pos.x = dx;
			dx = 0;
			dy += lineHeight;
			lineHeight = 0;
		}

		// Handle normal glyphs
		else {
			glyph = GetGlyph(curChar);
			dx += glyph.GetAdvanceX();
			if (glyph.h > lineHeight) lineHeight = glyph.GetAdvanceY();
		}
	}

	// Finish computing
	if (dx > pos.x) pos.x = dx;
	pos.y = dy+lineHeight;

	// Scale and return
	//pos /= Video::GetScale();
	return pos;
}