// Text rendering
	void CDX9Renderer::DrawTextCR(FontHandle fh, PCTSTR text, const rect &r, DWORD format, const color &c)
	{
		FlushState();

		CRASSERT(FontExists(fh));

		texts_to_render.push_back(text);

		batch.push_back(new (this) CBatch_DrawText(this, fh, r, c, format));
	}
Exemple #2
0
std::wstring FontSystem::GetBeingFont(std::wstring fonts) {
	// retrieve being font in the system.
	// font candidates are given by "fonts", separated by comma.

	bool vfont;

	if(fonts.c_str()[0] == TJS_W('@')) {     // for vertical writing
		fonts = fonts.c_str() + 1;
		vfont = true;
	} else {
		vfont = false;
	}

	bool prev_empty_name = false;
	while(fonts!=TJS_W("")) {
		std::wstring fontname;
		int pos = fonts.find_first_of(TJS_W(","));
		if( pos != std::string::npos ) {
			fontname = Trim( fonts.substr( 0, pos) );
			fonts = fonts.c_str()+pos+1;
		} else {
			fontname = Trim(fonts);
			fonts=TJS_W("");
		}

		// no existing check if previously specified font candidate is empty
		// eg. ",Fontname"

		if(fontname != TJS_W("") && (prev_empty_name || FontExists(fontname) ) ) {
			if(vfont && fontname.c_str()[0] != TJS_W('@')) {
				return  TJS_W("@") + fontname;
			} else {
				return fontname;
			}
		}

		prev_empty_name = (fontname == TJS_W(""));
	}

	if(vfont) {
		return std::wstring(TJS_W("@")) + std::wstring(TVPGetDefaultFontName());
	} else {
		return std::wstring(TVPGetDefaultFontName());
	}
}
Exemple #3
0
/** return the best existing font family name which matches the specified generic ID 
@see
	eGenericFont
*/
void VFont::GetGenericFontFamilyName(eGenericFont inGenericID, VString& outFontFamilyName, const VGraphicContext *inGC)
{
#if VERSIONWIN
	const Gdiplus::FontFamily *fontFamily = NULL;
	switch( inGenericID)
	{
	case GENERIC_FONT_SERIF:
		fontFamily = Gdiplus::FontFamily::GenericSerif();
		break;
	case GENERIC_FONT_SANS_SERIF:
		fontFamily = Gdiplus::FontFamily::GenericSansSerif();
		break;
	case GENERIC_FONT_CURSIVE:
		//gdiplus implementation constraint: 
		//try with "Comic Sans MS"
		//and if failed fallback to sans-serif
		{
			if (FontExists( "Comic Sans MS", KFS_NORMAL, 12, 0, inGC))
			{
				outFontFamilyName = "Comic Sans MS";
				return;
			}
			fontFamily = Gdiplus::FontFamily::GenericSansSerif();
		}
		break;
	case GENERIC_FONT_FANTASY:
		//gdiplus implementation constraint: fallback to sans-serif
		fontFamily = Gdiplus::FontFamily::GenericSansSerif();
		break;
	case GENERIC_FONT_MONOSPACE:
		fontFamily = Gdiplus::FontFamily::GenericMonospace();
		break;
	default:
		xbox_assert(false);
		fontFamily = Gdiplus::FontFamily::GenericSansSerif();
		break;
	}
	if (fontFamily && fontFamily->IsAvailable())
	{
		WCHAR  name[LF_FACESIZE];
		Gdiplus::Status status = fontFamily->GetFamilyName( name, LANG_NEUTRAL);
		xbox_assert(sizeof(WCHAR) == sizeof(UniChar));
		outFontFamilyName.FromBlock( name, wcslen( name)*sizeof(UniChar), VTC_UTF_16);
	}
	else
		outFontFamilyName = "Times New Roman";
#if ENABLE_D2D
#if VERSION_DEBUG
	//check if font family is supported by DWrite too
	//(should always be the case because GDIPlus has support only for TrueType fonts
	// & all TrueType fonts are supported by D2D)
	if (VWinD2DGraphicContext::IsAvailable())
	{
		if (inGC && inGC->IsD2DImpl())
			xbox_assert(FontExists( outFontFamilyName, KFS_NORMAL, 12, inGC));
	}
#endif
#endif
#else
	//MAC OS implementation constraint:
	//as there is no system-provided feature that can feed us with generic fonts
	//(of course if you know about such a feature feel free to modify code below)
	//we need to provide ourselves generic font family names
	//so we choose to use font family names that are always installed on MAC OS X

	VString fontFamily;
	switch( inGenericID)
	{
	case GENERIC_FONT_SERIF:
		fontFamily = "Times New Roman";
		break;
	case GENERIC_FONT_SANS_SERIF:
		fontFamily = "Helvetica";
		break;
	case GENERIC_FONT_CURSIVE:
		fontFamily = "Apple Chancery";
		break;
	case GENERIC_FONT_FANTASY:
		fontFamily = "American Typewriter";
		break;
	case GENERIC_FONT_MONOSPACE:
		fontFamily = "Courier New";
		break;
	default:
		xbox_assert(false);
		fontFamily = "Times New Roman";
		break;
	}
	if (FontExists( fontFamily, KFS_NORMAL, 12))
		outFontFamilyName = fontFamily;
	else
		//fallback to "Times Roman" just in case...
		outFontFamilyName = "Times New Roman";
#endif
}