// create a bitmapped font with a drop-shadow. bool NXFont::InitBitmapCharsShadowed(SDL_Surface *sheet, uint32_t fgcolor, \ uint32_t color, uint32_t shadowcolor) { Uint32 format = screen->Format()->format; NXFont fgfont, shadowfont; SDL_Rect dstrect; // create temporary fonts in the fg and shadow color if (fgfont.InitBitmapChars(sheet, fgcolor, color)) return 1; if (shadowfont.InitBitmapChars(sheet, fgcolor, shadowcolor)) return 1; SDL_PixelFormat* pxformat = SDL_AllocFormat(format); if (!pxformat) { staterr("InitBitmapChars: SDL_AllocFormat failed: %s", SDL_GetError()); return 1; } // now combine the two fonts uint32_t transp = SDL_MapRGB(pxformat, 0, 0, 0); for(int i=0;i<NUM_FONT_LETTERS;i++) { if (fgfont.letters[i]) { letters[i] = SDL_CreateRGBSurface(0, \ BITMAP_CHAR_WIDTH+1, BITMAP_CHAR_HEIGHT+1+SHADOW_OFFSET, pxformat->BitsPerPixel, \ pxformat->Rmask, pxformat->Gmask, pxformat->Bmask, pxformat->Amask); SDL_FillRect(letters[i], NULL, transp); SDL_SetColorKey(letters[i], SDL_TRUE, transp); dstrect.x = 0; dstrect.y = SHADOW_OFFSET; SDL_BlitSurface(shadowfont.letters[i], NULL, letters[i], &dstrect); dstrect.x = 0; dstrect.y = 0; SDL_BlitSurface(fgfont.letters[i], NULL, letters[i], &dstrect); } } SDL_FreeFormat(pxformat); return 0; }
// create a bitmapped font with a drop-shadow. bool NXFont::InitBitmapCharsShadowed(SDL_Surface *sheet, uint32_t fgcolor, \ uint32_t color, uint32_t shadowcolor) { SDL_PixelFormat *format = sdl_screen->format; NXFont fgfont, shadowfont; SDL_Rect dstrect; // create temporary fonts in the fg and shadow color if (fgfont.InitBitmapChars(sheet, fgcolor, color)) return 1; if (shadowfont.InitBitmapChars(sheet, fgcolor, shadowcolor)) return 1; // now combine the two fonts uint32_t transp = SDL_MapRGB(format, 0, 0, 0); for(int i=0;i<NUM_FONT_LETTERS;i++) { if (fgfont.letters[i]) { letters[i] = SDL_CreateRGBSurface(SDL_SRCCOLORKEY, \ BITMAP_CHAR_WIDTH+1, BITMAP_CHAR_HEIGHT+1+SHADOW_OFFSET, format->BitsPerPixel, \ format->Rmask, format->Gmask, format->Bmask, format->Amask); SDL_FillRect(letters[i], NULL, transp); SDL_SetColorKey(letters[i], SDL_SRCCOLORKEY, transp); dstrect.x = 0; dstrect.y = SHADOW_OFFSET; SDL_BlitSurface(shadowfont.letters[i], NULL, letters[i], &dstrect); dstrect.x = 0; dstrect.y = 0; SDL_BlitSurface(fgfont.letters[i], NULL, letters[i], &dstrect); } } return 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; }
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 #if (defined(_320X240) || defined(_480X272)) && defined(_L10N_CP1251) if (false) #elif defined(CONFIG_ENABLE_TTF) if (SCALE == 1) #endif { stat("fonts: using bitmapped from %s", bmpfontfile); SDL_Surface *sheet = SDL_LoadBMP(bmpfontfile); if (!sheet) { staterr("Couldn't open bitmap font file: '%s'", bmpfontfile); return 1; } uint32_t fgindex = SDL_MapRGB(sheet->format, 255, 255, 255); error |= whitefont.InitBitmapChars(sheet, fgindex, 0xffffff); error |= greenfont.InitBitmapChars(sheet, fgindex, 0x00ff80); error |= bluefont.InitBitmapChars(sheet, fgindex, 0xa0b5de); error |= shadowfont.InitBitmapCharsShadowed(sheet, fgindex, 0xffffff, 0x000000); } #ifdef CONFIG_ENABLE_TTF else { stat("fonts: using truetype at %dpt", pointsize[SCALE]); // initilize normal TTF fonts if (TTF_Init() < 0) { staterr("Couldn't initialize SDL_ttf: %s", TTF_GetError()); return 1; } TTF_Font *font = TTF_OpenFont(ttffontfile, pointsize[SCALE]); if (!font) { staterr("Couldn't open font: '%s'", ttffontfile); return 1; } error |= whitefont.InitChars(font, 0xffffff); error |= greenfont.InitChars(font, 0x00ff80); error |= bluefont.InitChars(font, 0xa0b5de); error |= shadowfont.InitCharsShadowed(font, 0xffffff, 0x000000); TTF_CloseFont(font); } #endif error |= create_shade_sfc(); if (error) return 1; fontheight = (whitefont.letters['M']->h / SCALE); initilized = true; return 0; }