Example #1
0
/////////
// Print
void OpenGLText::Print(String text, Vector2f pos, Vector2f align, float origScale)
{
	// Adjust scale
	float scale = origScale / Video::GetScale();

	// Adjust position
	pos -= align * (scale * GetExtent(text));

	// Draw outline
	if (outline != 0) {
		shared_ptr<OpenGLText> bord = GetOutline(outline);
		bord->SetColour(borderCol);
		bord->Print(text, pos, Vector2f(0,0), origScale);
	}

	// Set OpenGL
	glEnable(GL_BLEND);
	glEnable(GL_TEXTURE_2D);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

	// Draw primary string
	glColor4f(col.r,col.g,col.b,col.a);
	DrawString(text.GetUTF32(),pos,scale);

	// Disable blend
	glDisable(GL_BLEND);
}
Example #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;
}
Example #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);
}
Example #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;
}
Example #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);
}
Example #6
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;
}