Esempio n. 1
0
bool font_init(void)
{
bool error = false;

	// we'll be bypassing the NXSurface automatic scaling features
	// and drawing at the real resolution so we can get better-looking fonts.
//	sdl_screen = screen->GetSDLSurface();
	
	// at 320x240 switch to bitmap fonts for better appearance
	#ifdef CONFIG_ENABLE_TTF
	if (SCALE == 1)
	#endif
	{
		stat("fonts: using bitmapped from %s", bmpfontfile);
		
		SDL_RWops* rwops = fileopen_SDL_RWops_RO(bmpfontfile);
		if (!rwops) { staterr("Couldn't open bitmap font file %s: SDL_RWFromFP: %s", bmpfontfile, SDL_GetError()); return 1; }
		SDL_Surface *sheet = SDL_LoadBMP_RW(rwops, 1);
		if (!sheet) { staterr("Couldn't open bitmap font file: SDL_LoadBMP_RW: %s", SDL_GetError()); return 1; }
		
		uint32_t fgindex = SDL_MapRGB(sheet->format, 255, 255, 255);
		
		error = error || whitefont.InitBitmapChars(sheet, fgindex, 0xffffff);
		error = error || greenfont.InitBitmapChars(sheet, fgindex, 0x00ff80);
		error = error || bluefont.InitBitmapChars(sheet, fgindex, 0xa0b5de);
		error = error || shadowfont.InitBitmapCharsShadowed(sheet, fgindex, 0xffffff, 0x000000);
	}
	#ifdef CONFIG_ENABLE_TTF
	else
	{
		// It will get size 8, 17, 26, 35, ...
		// Hope ot will look nice on higher resolutions
		int pointsize = 8 + 9 * (SCALE - 1);
        
		stat("fonts: using truetype at %dpt", pointsize);

		// initilize normal TTF fonts
		if (TTF_Init() < 0)
		{
			staterr("Couldn't initialize SDL_ttf: %s", TTF_GetError());
			return 1;
		}
		
		TTF_Font *font = TTF_OpenFontRW(SDL_RWFromFP(fileopenRO(ttffontfile), SDL_TRUE), 1, pointsize);
		if (!font)
		{
			staterr("Couldn't open font: '%s'", ttffontfile);
			return 1;
		}
		
		error = error || whitefont.InitChars(font, 0xffffff);
		error = error || greenfont.InitChars(font, 0x00ff80);
		error = error || bluefont.InitChars(font, 0xa0b5de);
		error = error || shadowfont.InitCharsShadowed(font, 0xffffff, 0x000000);
		
		TTF_CloseFont(font);
	}
	#endif

	error = error || whitefont.InitTextures();
	error = error || greenfont.InitTextures();
	error = error || bluefont.InitTextures();
	error = error || shadowfont.InitTextures();
	
	error = error || create_shade_sfc();
	if (error) return 1;
	
	fontheight = (whitefont.letters['M']->h / SCALE);
	initilized = true;
	return 0;
}