}
}
-/*
-Note : We need to search for the right >>> PIXEL SIZE <<< and NOT point size!!
-If a user has a resolution other than approximately 72dpi then
-they will get a small or larger font and this won't work. This might look
-weird since we'll load and delete multiple fonts, but it works...
-*/
-void Graphics::loadFont(int i, const char *filename, int pixelSize)
+void Graphics::loadFont(int i, const char *filename, int pointSize)
{
- int minx, maxx, miny, maxy, advance;
-
- debug(("Attempting to load a font with pixel size of %d...\n", pixelSize));
+ debug(("Attempting to load font %s with point size of %d...\n", filename, pointSize));
if (font[i])
{
TTF_CloseFont(font[i]);
}
- char tempPath[PATH_MAX];
-
- snprintf(tempPath, sizeof tempPath, "%sfont.ttf", engine->userHomeDirectory);
+ #if USEPAK
+ char tempPath[PATH_MAX];
+ snprintf(tempPath, sizeof tempPath, "%sfont.ttf", engine->userHomeDirectory);
+ font[i] = TTF_OpenFont(tempPath, pointSize);
+ #else
+ font[i] = TTF_OpenFont("data/vera.ttf", pointSize);
+ #endif
- bool found = false;
- int size = 0;
-
- while (!found)
+ if (!font[i])
{
- if (font[i])
- {
- TTF_CloseFont(font[i]);
- }
-
- #if USEPAK
- font[i] = TTF_OpenFont(tempPath, ++size);
- #else
- font[i] = TTF_OpenFont("data/vera.ttf", ++size);
- #endif
-
- if (!font[i])
- {
- engine->reportFontFailure();
- }
-
- TTF_GlyphMetrics(font[i], '8', &minx, &maxx, &miny, &maxy, &advance);
-
- // great! we have an exact match
- if (maxx == pixelSize)
- {
- break;
- }
-
- // we've overshot, so we'll use the previous size!
- if (maxx > pixelSize)
- {
- TTF_CloseFont(font[i]);
-
- #if USEPAK
- font[i] = TTF_OpenFont(tempPath, size - 1);
- #else
- font[i] = TTF_OpenFont("data/vera.ttf", size - 1);
- #endif
-
- TTF_GlyphMetrics(font[i], '8', &minx, &maxx, &miny, &maxy, &advance);
-
- break;
- }
-
- if (size >= 100)
- {
- debug(("Pixel size has exceeded 99 pixels! I'm giving up!\n"));
- engine->reportFontFailure();
- }
+ engine->reportFontFailure();
}
TTF_SetFontStyle(font[i], TTF_STYLE_NORMAL);
-
- debug(("Got a match for font size %d - Nearest = %d\n", pixelSize, maxx));
}
Sprite *Graphics::addSprite(const char *name)
text = TTF_RenderUTF8_Shaded(font[fontSize], "FONT_ERROR", fontForeground, fontBackground);
}
+ if (!text)
+ {
+ fprintf(stderr, "Unable to render text: %s\n", SDL_GetError());
+ abort();
+ }
+
if (transparent)
setTransparent(text);
debug(("Loading Fonts...\n"));
#if USEPAK
-
- char tempPath[PATH_MAX];
- snprintf(tempPath, sizeof tempPath, "%sfont.ttf", engine.userHomeDirectory);
- remove(tempPath);
-
if (!engine.unpack("data/vera.ttf", PAK_FONT))
{
engine.reportFontFailure();
}
#endif
- debug(("Trying to load correct font pixel sizes using a really half arsed routine!\n"));
- debug(("If it crashes then you'll know why!\n"));
-
- graphics.loadFont(0, "data/vera.ttf", 7);
- graphics.loadFont(1, "data/vera.ttf", 9);
- graphics.loadFont(2, "data/vera.ttf", 11);
- graphics.loadFont(3, "data/vera.ttf", 13);
- graphics.loadFont(4, "data/vera.ttf", 15);
-
+ graphics.loadFont(0, "data/vera.ttf", 12);
+ graphics.loadFont(1, "data/vera.ttf", 15);
+ graphics.loadFont(2, "data/vera.ttf", 19);
+ graphics.loadFont(3, "data/vera.ttf", 23);
+ graphics.loadFont(4, "data/vera.ttf", 24);
+
debug(("Font sizes all loaded!!\n"));
audio.loadSound(SND_CHEAT, "sound/Lock And Load!!!");