// create managed objects
bool zz_font_d3d::init_device_objects ()
{
	if (!znzin) return true;
	if (!znzin->renderer) return true;
	if (!znzin->renderer->is_a(ZZ_RUNTIME_TYPE(zz_renderer_d3d))) return false;

	_d3d_device = ((zz_renderer_d3d*)(znzin->renderer))->get_device();
	if (!_d3d_device) return true;

	D3DXFONT_DESC fontDesc;

	ZeroMemory( &fontDesc, sizeof( D3DXFONT_DESC ) );

    HDC hDC = GetDC( NULL );
    _logical_pixels_y = GetDeviceCaps( hDC, LOGPIXELSY );
    ReleaseDC( NULL, hDC );
	font_height = (unsigned int)MulDiv( font_size, _logical_pixels_y, 72 ); // why minus in other documents? -MulDiv(?)

	fontDesc.Height					= font_height;
	fontDesc.Width					= 0;
	fontDesc.Weight					= this->get_bold() ? FW_BOLD : FW_THIN; 
	fontDesc.MipLevels				= 1;
	fontDesc.Italic						= this->get_italic();
	fontDesc.CharSet					= this->font_charset;
	fontDesc.OutputPrecision		= OUT_DEFAULT_PRECIS;	
	fontDesc.Quality					= PROOF_QUALITY;
	fontDesc.PitchAndFamily		= FIXED_PITCH | FF_MODERN;
	strcpy( fontDesc.FaceName, font_name.get() );

	HRESULT hr;

	try {
		if (FAILED(hr = D3DXCreateFontIndirect( _d3d_device, &fontDesc, &_d3d_font))) {
			ZZ_LOG("zz_font_d3d: init_device_objects(%s, %d, %d) failed. [%s]\n",
				font_name.get(), font_height, font_charset,
				zz_renderer_d3d::get_hresult_string(hr) );
			zz_msgbox(zz_error::get_text(zz_error::MSG_ERROR), zz_error::get_text(zz_error::CREATE_FONT_FAIL));
			
			strcat(znzin->sysinfo.video_string," <Font failed>");

			zz_msgboxf(zz_error::get_text(zz_error::MSG_ERROR), zz_error::get_text(zz_error::MSG_EXIT_D3DERROR), znzin->sysinfo.video_string);
			exit(EXIT_FAILURE);
			return false;
		}
	}
	catch (...) {
		ZZ_LOG("font_d3d: createfont failed. [%x, %d, %s, %x, %x]\n",
			this, fontDesc.Height, fontDesc.FaceName, _d3d_device, &_d3d_font);
		throw;
	}

	if (_num_font_textures > 0) {
		_d3d_font_texture.init_device_objects();
		_d3d_font_texture.create(*this); // zhotest
	}

	return true;
}
Example #2
0
void zz_msgboxf ( const char * caption, const char * msg_format, ... )
{
	static char buffer[1024];
	
	va_list va;
	va_start(va, msg_format);	
	vsprintf(buffer, msg_format, va);
	va_end(va);	

	zz_msgbox(caption, buffer);
}