diff --git a/doomsday/build/codeblocks/doomsday.cbp b/doomsday/build/codeblocks/doomsday.cbp
index e20fadebc4..25c6b7c8c6 100644
--- a/doomsday/build/codeblocks/doomsday.cbp
+++ b/doomsday/build/codeblocks/doomsday.cbp
@@ -245,10 +245,10 @@
+
-
@@ -323,6 +323,7 @@
+
@@ -519,13 +520,11 @@
+
-
-
-
@@ -734,6 +733,7 @@
+
diff --git a/doomsday/build/win32/doomsday_cl.rsp b/doomsday/build/win32/doomsday_cl.rsp
index c6e1eda552..d2c5902c02 100644
--- a/doomsday/build/win32/doomsday_cl.rsp
+++ b/doomsday/build/win32/doomsday_cl.rsp
@@ -33,6 +33,7 @@
.\..\..\engine\portable\src\fi_main.c
.\..\..\engine\portable\src\filedirectory.c
.\..\..\engine\portable\src\finaleinterpreter.c
+ .\..\..\engine\portable\src\fonts.c
.\..\..\engine\portable\src\gameinfo.c
.\..\..\engine\portable\src\gl_defer.c
.\..\..\engine\portable\src\gl_texmanager.c
@@ -42,7 +43,6 @@
.\..\..\engine\portable\src\gl_pcx.c
.\..\..\engine\portable\src\gl_main.c
.\..\..\engine\portable\src\gl_hq2x.c
- .\..\..\engine\portable\src\gl_font.c
.\..\..\engine\portable\src\gl_draw.c
.\..\..\engine\portable\src\gl_drawvectorgraphic.c
.\..\..\engine\portable\src\texture.c
@@ -62,6 +62,7 @@
.\..\..\engine\portable\src\rend_list.c
.\..\..\engine\portable\src\rend_halo.c
.\..\..\engine\portable\src\rend_fakeradio.c
+ .\..\..\engine\portable\src\rend_font.c
.\..\..\engine\portable\src\rend_dyn.c
.\..\..\engine\portable\src\rend_decor.c
.\..\..\engine\portable\src\rend_clip.c
diff --git a/doomsday/build/win32/vs8/doomsday.vcproj b/doomsday/build/win32/vs8/doomsday.vcproj
index cb16018a3c..b7162581ad 100644
--- a/doomsday/build/win32/vs8/doomsday.vcproj
+++ b/doomsday/build/win32/vs8/doomsday.vcproj
@@ -1092,6 +1092,10 @@
RelativePath="..\..\..\engine\portable\src\finaleinterpreter.c"
>
+
+
@@ -1108,10 +1112,6 @@
RelativePath="..\..\..\engine\portable\src\gl_drawvectorgraphic.c"
>
-
-
@@ -1404,6 +1404,10 @@
RelativePath="..\..\..\engine\portable\src\rend_fakeradio.c"
>
+
+
@@ -2786,19 +2790,19 @@
>
+
+
diff --git a/doomsday/engine/api/dd_fontrenderer.h b/doomsday/engine/api/dd_fontrenderer.h
index 14aacc562d..b64fae6966 100644
--- a/doomsday/engine/api/dd_fontrenderer.h
+++ b/doomsday/engine/api/dd_fontrenderer.h
@@ -29,12 +29,6 @@
#ifndef LIBDENG_API_FONT_RENDERER_H
#define LIBDENG_API_FONT_RENDERER_H
-/**
- * Unique identifier allocated by this subsystem and associated to each
- * known font. Used as a logical public reference/handle to a font.
- */
-typedef uint32_t fontid_t;
-
/**
* Font attributes are managed as a finite stack of attribute sets.
* This value defines the maximum allowed depth of the attribute stack.
@@ -68,14 +62,6 @@ typedef uint32_t fontid_t;
#define DTF_ONLY_SHADOW (DTF_NO_TYPEIN|DTF_NO_GLITTER)
/*@}*/
-/**
- * Find the associated font for @a name.
- *
- * @param name Name of the font to lookup.
- * @return Unique id of the found font.
- */
-fontid_t FR_FindFontForName(const char* name);
-
/// @return Unique identifier associated with the current font.
fontid_t FR_Font(void);
diff --git a/doomsday/engine/api/dd_types.h b/doomsday/engine/api/dd_types.h
index 505f1347f6..9b13d94560 100644
--- a/doomsday/engine/api/dd_types.h
+++ b/doomsday/engine/api/dd_types.h
@@ -122,6 +122,12 @@ typedef unsigned short nodeindex_t;
typedef unsigned short thid_t;
typedef double timespan_t;
+/**
+ * Unique identifier allocated by this subsystem and associated to each
+ * known font. Used as a logical public reference/handle to a font.
+ */
+typedef uint32_t fontid_t;
+
#define LUMPNAME_T_MAXLEN 9
#define LUMPNAME_T_LASTINDEX 8
typedef signed char lumpname_t[LUMPNAME_T_MAXLEN];
diff --git a/doomsday/engine/api/doomsday.def b/doomsday/engine/api/doomsday.def
index 8d0f1cc7b3..9f6666d05c 100644
--- a/doomsday/engine/api/doomsday.def
+++ b/doomsday/engine/api/doomsday.def
@@ -492,7 +492,7 @@ EXPORTS
GL_EndBorderedProjection @510 NONAME
; Graphics: Text
- FR_FindFontForName @97 NONAME
+ Fonts_IdForName @97 NONAME
FR_Font @106 NONAME
FR_SetFont @107 NONAME
diff --git a/doomsday/engine/api/doomsday.h b/doomsday/engine/api/doomsday.h
index 461e0d4dc3..49d817d614 100644
--- a/doomsday/engine/api/doomsday.h
+++ b/doomsday/engine/api/doomsday.h
@@ -444,6 +444,14 @@ void Con_SetString(const char* name, const char* text);
boolean DD_IterateThinkers(think_t type, boolean (*func) (thinker_t *th, void*), void* data);
+//------------------------------------------------------------------------
+//
+// UI.
+//
+//------------------------------------------------------------------------
+
+fontid_t Fonts_IdForName(const char* name);
+
//------------------------------------------------------------------------
//
// Refresh.
diff --git a/doomsday/engine/portable/include/bitmapfont.h b/doomsday/engine/portable/include/bitmapfont.h
index 954afc691b..aba8a5b3a4 100644
--- a/doomsday/engine/portable/include/bitmapfont.h
+++ b/doomsday/engine/portable/include/bitmapfont.h
@@ -108,7 +108,7 @@ patchid_t BitmapFont_CharPatch(bitmapfont_t* font, unsigned char ch);
void BitmapFont_CharSetPatch(bitmapfont_t* font, unsigned char ch, const char* patchName);
/// @return GL-texture name.
-DGLuint BitmapFont_GLTextureName(bitmapfont_t* font);
+DGLuint BitmapFont_GLTextureName(const bitmapfont_t* font);
int BitmapFont_TextureHeight(const bitmapfont_t* font);
int BitmapFont_TextureWidth(const bitmapfont_t* font);
diff --git a/doomsday/engine/portable/include/de_graphics.h b/doomsday/engine/portable/include/de_graphics.h
index 0d4d4d14a7..933045bfde 100644
--- a/doomsday/engine/portable/include/de_graphics.h
+++ b/doomsday/engine/portable/include/de_graphics.h
@@ -1,10 +1,10 @@
-/**\file
+/**\file de_graphics.h
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2010 Jaakko Keränen
- *\author Copyright © 2006-2010 Daniel Swanson
+ *\author Copyright © 2006-2011 Daniel Swanson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,22 +23,21 @@
*/
/**
- * de_graphics.h: Graphics Subsystem
+ * Graphics Subsystem
*/
-#ifndef __DOOMSDAY_GRAPHICS__
-#define __DOOMSDAY_GRAPHICS__
+#ifndef LIBDENG_GRAPHICS
+#define LIBDENG_GRAPHICS
#include "gl_main.h"
#include "gl_draw.h"
#include "gl_texmanager.h"
#include "gl_tex.h"
#include "gl_hq2x.h"
-#include "gl_font.h"
#include "gl_model.h"
#include "gl_pcx.h"
#include "gl_png.h"
#include "gl_tga.h"
#include "gl_defer.h"
-#endif
+#endif /* LIBDENG_GRAPHICS */
diff --git a/doomsday/engine/portable/include/de_render.h b/doomsday/engine/portable/include/de_render.h
index 070e37b3bd..cadd69b1c0 100644
--- a/doomsday/engine/portable/include/de_render.h
+++ b/doomsday/engine/portable/include/de_render.h
@@ -1,10 +1,10 @@
-/**\file
+/**\file de_render.h
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2009 Jaakko Keränen
- *\author Copyright © 2006-2009 Daniel Swanson
+ *\author Copyright © 2006-2011 Daniel Swanson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,11 +23,11 @@
*/
/**
- * de_render.h: Rendering Subsystem
+ * Rendering Subsystem
*/
-#ifndef __DOOMSDAY_RENDERER__
-#define __DOOMSDAY_RENDERER__
+#ifndef LIBDENG_RENDERER
+#define LIBDENG_RENDERER
#include "rend_main.h"
#include "rend_clip.h"
@@ -40,8 +40,9 @@
#include "rend_model.h"
#include "rend_shadow.h"
#include "rend_fakeradio.h"
+#include "rend_font.h"
#include "rend_bias.h"
#include "rend_decor.h"
#include "rend_console.h"
-#endif
+#endif /* LIBDENG_RENDERER */
diff --git a/doomsday/engine/portable/include/de_ui.h b/doomsday/engine/portable/include/de_ui.h
index 6697e25478..46103b71a3 100644
--- a/doomsday/engine/portable/include/de_ui.h
+++ b/doomsday/engine/portable/include/de_ui.h
@@ -1,10 +1,10 @@
-/**\file
+/**\file de_ui.h
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
- *\author Copyright © 2003-2010 Jaakko Keränen
- *\author Copyright © 2006-2010 Daniel Swanson
+ *\author Copyright © 2003-2011 Jaakko Keränen
+ *\author Copyright © 2006-2011 Daniel Swanson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,12 +23,13 @@
*/
/**
- * User Interface Subsystem.
+ * User Interface Subsystem
*/
#ifndef LIBDENG_USER_INTERFACE_H
#define LIBDENG_USER_INTERFACE_H
+#include "fonts.h"
#include "ui_main.h"
#include "ui_mpi.h"
#include "ui_panel.h"
diff --git a/doomsday/engine/portable/include/fonts.h b/doomsday/engine/portable/include/fonts.h
new file mode 100644
index 0000000000..276d01125b
--- /dev/null
+++ b/doomsday/engine/portable/include/fonts.h
@@ -0,0 +1,72 @@
+/**\file fonts.h
+ *\section License
+ * License: GPL
+ * Online License Link: http://www.gnu.org/licenses/gpl.html
+ *
+ *\author Copyright © 2003-2011 Jaakko Keränen
+ *\author Copyright © 2005-2011 Daniel Swanson
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifndef LIBDENG_FONTS_H
+#define LIBDENG_FONTS_H
+
+#include "bitmapfont.h"
+
+struct ded_compositefont_s;
+
+/// Register the console commands, variables, etc..., of this module.
+void Fonts_Register(void);
+
+/**
+ * Initialize the font renderer.
+ * @return @c 0 iff there are no errors.
+ */
+int Fonts_Init(void);
+void Fonts_Shutdown(void);
+
+/**
+ * Mark all fonts as requiring a full update. Called during engine/renderer reset.
+ */
+void Fonts_Update(void);
+
+/**
+ * Load the specified font as a "system font".
+ */
+fontid_t Fonts_LoadSystemFont(const char* name, const char* path);
+
+fontid_t Fonts_CreateFromDef(struct ded_compositefont_s* def);
+
+int Fonts_ToIndex(fontid_t id);
+
+/// @return Ptr to the font associated with the specified id.
+bitmapfont_t* Fonts_FontForId(fontid_t id);
+bitmapfont_t* Fonts_FontForIndex(int index);
+
+/**
+ * Find the associated font for @a name.
+ *
+ * @param name Name of the font to lookup.
+ * @return Unique id of the found font.
+ */
+fontid_t Fonts_IdForName(const char* name);
+
+void Fonts_DestroyFont(fontid_t id);
+
+ddstring_t** Fonts_CollectNames(int* count);
+
+#endif /* LIBDENG_FONTS_H */
diff --git a/doomsday/engine/portable/include/p_materialmanager.h b/doomsday/engine/portable/include/p_materialmanager.h
index 4b08584c2d..636a5aaf79 100644
--- a/doomsday/engine/portable/include/p_materialmanager.h
+++ b/doomsday/engine/portable/include/p_materialmanager.h
@@ -22,8 +22,8 @@
* Boston, MA 02110-1301 USA
*/
-#ifndef LIBDENG2_MATERIALS_H
-#define LIBDENG2_MATERIALS_H
+#ifndef LIBDENG_MATERIALS_H
+#define LIBDENG_MATERIALS_H
#include "gl_texmanager.h"
#include "def_data.h"
@@ -171,4 +171,4 @@ void Materials_ClearTranslation(struct material_s* mat);
// @todo Refactor interface, doesn't fit the current design.
boolean Materials_IsPrecacheAnimGroup(int groupNum);
-#endif /* LIBDENG2_MATERIALS_H */
+#endif /* LIBDENG_MATERIALS_H */
diff --git a/doomsday/engine/portable/include/gl_font.h b/doomsday/engine/portable/include/rend_font.h
similarity index 72%
rename from doomsday/engine/portable/include/gl_font.h
rename to doomsday/engine/portable/include/rend_font.h
index 30779c21e8..00fe7b6dad 100644
--- a/doomsday/engine/portable/include/gl_font.h
+++ b/doomsday/engine/portable/include/rend_font.h
@@ -1,4 +1,4 @@
-/**\file gl_font.h
+/**\file rend_font.h
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
@@ -23,13 +23,11 @@
*/
/**
- * Font Management.
+ * Font Renderer
*/
-#ifndef LIBDENG_GL_FONT_H
-#define LIBDENG_GL_FONT_H
-
-#include "bitmapfont.h"
+#ifndef LIBDENG_FONT_RENDERER
+#define LIBDENG_FONT_RENDERER
#define DEFAULT_INITIALCOUNT (0) /// Used for animating type-in effects.
@@ -48,9 +46,6 @@
*/
#define FR_SMALL_TEXT_BUFFER_SIZE (160)
-/// Register the console commands, variables, etc..., of this module.
-void FR_Register(void);
-
/**
* Initialize the font renderer.
* @return @c 0 iff there are no errors.
@@ -60,28 +55,10 @@ void FR_Shutdown(void);
void FR_Ticker(timespan_t ticLength);
-/**
- * Mark all fonts as requiring a full update. Called during engine/renderer reset.
- */
-void FR_Update(void);
-
-/**
- * Load the specified font as a "system font".
- */
-fontid_t FR_LoadSystemFont(const char* name, const char* path);
-
-fontid_t FR_CreateFontFromDef(ded_compositefont_t* def);
-
-/**
- * @return Ptr to the font associated with the specified id.
- */
-bitmapfont_t* FR_BitmapFontForId(fontid_t id);
-void FR_DestroyFont(fontid_t id);
+void FR_SetNoFont(void);
// Utility routines:
int FR_SingleLineHeight(const char* text);
int FR_GlyphTopToAscent(const char* text);
-ddstring_t** FR_CollectFontNames(int* count);
-
-#endif /* LIBDENG_GL_FONT_H */
+#endif /* LIBDENG_FONT_RENDERER */
diff --git a/doomsday/engine/portable/src/bitmapfont.c b/doomsday/engine/portable/src/bitmapfont.c
index a457fcd750..b3aaafe26b 100644
--- a/doomsday/engine/portable/src/bitmapfont.c
+++ b/doomsday/engine/portable/src/bitmapfont.c
@@ -541,7 +541,7 @@ int BitmapFont_Leading(bitmapfont_t* font)
return font->_leading;
}
-DGLuint BitmapFont_GLTextureName(bitmapfont_t* font)
+DGLuint BitmapFont_GLTextureName(const bitmapfont_t* font)
{
assert(font);
return font->_tex;
diff --git a/doomsday/engine/portable/src/con_busy.c b/doomsday/engine/portable/src/con_busy.c
index 6a6af48b77..bc7601a422 100644
--- a/doomsday/engine/portable/src/con_busy.c
+++ b/doomsday/engine/portable/src/con_busy.c
@@ -278,7 +278,7 @@ static void Con_BusyLoadTextures(void)
{ "normal18", "}data/fonts/normal18.dfn" }
};
int fontIdx = !(theWindow->width > 640)? 0 : 1;
- if(0 != (busyFont = FR_LoadSystemFont(fonts[fontIdx].name, fonts[fontIdx].path)))
+ if(0 != (busyFont = Fonts_LoadSystemFont(fonts[fontIdx].name, fonts[fontIdx].path)))
{
FR_SetFont(busyFont);
busyFontHgt = FR_TextHeight("A");
@@ -300,7 +300,7 @@ static void Con_BusyDeleteTextures(void)
if(0 != busyFont)
{
- FR_DestroyFont(busyFont);
+ Fonts_DestroyFont(busyFont);
busyFont = 0;
}
}
diff --git a/doomsday/engine/portable/src/con_main.c b/doomsday/engine/portable/src/con_main.c
index 66b1770039..9b8504a3bf 100644
--- a/doomsday/engine/portable/src/con_main.c
+++ b/doomsday/engine/portable/src/con_main.c
@@ -2318,7 +2318,7 @@ D_CMD(Font)
Con_Printf("Usage: %s (cmd) (args)\n", argv[0]);
Con_Printf("Commands: default, name, size, xsize, ysize.\n");
Con_Printf("Names: ");
- list = FR_CollectFontNames(&listCount);
+ list = Fonts_CollectNames(&listCount);
for(i = 0; i < listCount-1; ++i)
{
Con_Printf("%s, ", Str_Text(list[i]));
@@ -2333,7 +2333,7 @@ D_CMD(Font)
if(!stricmp(argv[1], "default"))
{
- fontid_t newFont = FR_FindFontForName(GL_ChooseFixedFont());
+ fontid_t newFont = Fonts_IdForName(GL_ChooseFixedFont());
if(0 != newFont)
{
Con_SetFont(newFont);
@@ -2344,11 +2344,11 @@ D_CMD(Font)
if(!stricmp(argv[1], "name") && argc == 3)
{
- fontid_t newFont = FR_FindFontForName(argv[2]);
+ fontid_t newFont = Fonts_IdForName(argv[2]);
if(0 != newFont)
{
Con_SetFont(newFont);
- if(0 == BitmapFont_TextureWidth(FR_BitmapFontForId(newFont)))
+ if(0 == BitmapFont_TextureWidth(Fonts_FontForId(newFont)))
{
Con_SetFontScale(1.5f, 2);
}
diff --git a/doomsday/engine/portable/src/dd_main.c b/doomsday/engine/portable/src/dd_main.c
index c471e3171f..b73a145496 100644
--- a/doomsday/engine/portable/src/dd_main.c
+++ b/doomsday/engine/portable/src/dd_main.c
@@ -1390,6 +1390,7 @@ int DD_Main(void)
}
Sys_Init();
+ Fonts_Init();
FR_Init();
// Enter busy mode until startup complete.
diff --git a/doomsday/engine/portable/src/def_main.c b/doomsday/engine/portable/src/def_main.c
index 547c8a32ce..658c2bcd5b 100644
--- a/doomsday/engine/portable/src/def_main.c
+++ b/doomsday/engine/portable/src/def_main.c
@@ -40,6 +40,8 @@
#include "de_audio.h"
#include "de_misc.h"
#include "de_graphics.h"
+#include "de_ui.h"
+
#include "r_data.h"
#include "texture.h"
@@ -982,9 +984,9 @@ void Def_Read(void)
for(i = defs.count.compositeFonts.num; i-- > 0; )
{
ded_compositefont_t* cfont = defs.compositeFonts + i;
- if(0 != FR_FindFontForName(cfont->id))
+ if(0 != Fonts_IdForName(cfont->id))
continue;
- FR_CreateFontFromDef(cfont);
+ Fonts_CreateFromDef(cfont);
}
// Sprite names.
diff --git a/doomsday/engine/portable/src/finaleinterpreter.c b/doomsday/engine/portable/src/finaleinterpreter.c
index ce5f941bb8..539dbf822d 100644
--- a/doomsday/engine/portable/src/finaleinterpreter.c
+++ b/doomsday/engine/portable/src/finaleinterpreter.c
@@ -1967,7 +1967,7 @@ DEFFC(PredefinedFont)
{
const char* fontName = OP_CSTRING(1);
fontid_t font;
- if((font = FR_FindFontForName(fontName)))
+ if((font = Fonts_IdForName(fontName)))
{
int idx = MINMAX_OF(1, OP_INT(0), FIPAGE_NUM_PREDEFINED_FONTS)-1;
FIPage_SetPredefinedFont(fi->_pages[PAGE_TEXT], idx, font);
@@ -2043,7 +2043,7 @@ DEFFC(Font)
fi_object_t* obj = getObject(fi, FI_TEXT, OP_CSTRING(0));
const char* fontName = OP_CSTRING(1);
fontid_t font;
- if((font = FR_FindFontForName(fontName)))
+ if((font = Fonts_IdForName(fontName)))
{
FIData_TextSetFont(obj, font);
return;
diff --git a/doomsday/engine/portable/src/fonts.c b/doomsday/engine/portable/src/fonts.c
new file mode 100644
index 0000000000..ca512e6fbf
--- /dev/null
+++ b/doomsday/engine/portable/src/fonts.c
@@ -0,0 +1,412 @@
+/**\file fonts.c
+ *\section License
+ * License: GPL
+ * Online License Link: http://www.gnu.org/licenses/gpl.html
+ *
+ *\author Copyright © 2003-2011 Jaakko Keränen
+ *\author Copyright © 2005-2011 Daniel Swanson
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+/**
+ * Font Collection
+ */
+
+#include "de_base.h"
+#include "de_console.h"
+#include "de_render.h"
+#include "de_system.h"
+#include "de_ui.h"
+
+#include "bitmapfont.h"
+#include "m_misc.h"
+
+D_CMD(ListFonts);
+
+static int inited = false;
+
+static int numFonts = 0;
+static bitmapfont_t** fonts = 0; // The list of fonts.
+
+void Fonts_Register(void)
+{
+ C_CMD("listfonts", NULL, ListFonts)
+}
+
+static void errorIfNotInited(const char* callerName)
+{
+ if(inited) return;
+ Con_Error("%s: fonts module is not presently initialized.", callerName);
+ // Unreachable. Prevents static analysers from getting rather confused, poor things.
+ exit(1);
+}
+
+static fontid_t getNewFontId(void)
+{
+ int i;
+ fontid_t max = 0;
+ for(i = 0; i < numFonts; ++i)
+ {
+ const bitmapfont_t* font = fonts[i];
+ if(BitmapFont_Id(font) > max)
+ max = BitmapFont_Id(font);
+ }
+ return max + 1;
+}
+
+static fontid_t findFontIdForName(const char* name)
+{
+ if(name && name[0])
+ {
+ int i;
+ for(i = 0; i < numFonts; ++i)
+ {
+ const bitmapfont_t* font = fonts[i];
+ if(!Str_CompareIgnoreCase(BitmapFont_Name(font), name))
+ return BitmapFont_Id(font);
+ }
+ }
+ return 0; // Not found.
+}
+
+static int findFontIdxForName(const char* name)
+{
+ if(name && name[0])
+ {
+ int i;
+ for(i = 0; i < numFonts; ++i)
+ {
+ const bitmapfont_t* font = fonts[i];
+ if(!Str_CompareIgnoreCase(BitmapFont_Name(font), name))
+ return i;
+ }
+ }
+ return -1;
+}
+
+static int compareFontByName(const void* e1, const void* e2)
+{
+ return Str_CompareIgnoreCase(BitmapFont_Name(*(const bitmapfont_t**)e1), Str_Text(BitmapFont_Name(*(const bitmapfont_t**)e2)));
+}
+
+static int findFontIdxForId(fontid_t id)
+{
+ if(id != 0)
+ {
+ int i;
+ for(i = 0; i < numFonts; ++i)
+ {
+ const bitmapfont_t* font = fonts[i];
+ if(BitmapFont_Id(font) == id)
+ return i;
+ }
+ }
+ return -1;
+}
+
+static void destroyFontIdx(int idx)
+{
+ BitmapFont_Destruct(fonts[idx]);
+ memmove(&fonts[idx], &fonts[idx + 1], sizeof(*fonts) * (numFonts - idx - 1));
+ --numFonts;
+ fonts = realloc(fonts, sizeof(*fonts) * numFonts);
+}
+
+static void destroyFonts(void)
+{
+ while(numFonts) { destroyFontIdx(0); }
+ fonts = 0;
+ FR_SetNoFont();
+}
+
+static bitmapfont_t* addFont(bitmapfont_t* font)
+{
+ assert(NULL != font);
+ fonts = (bitmapfont_t**)realloc(fonts, sizeof(*fonts) * ++numFonts);
+ if(NULL == fonts)
+ Con_Error("addFont: Failed on (re)allocation of %lu bytes.", (unsigned long)(sizeof(*fonts) * numFonts));
+ fonts[numFonts-1] = font;
+ return font;
+}
+
+/**
+ * Creates a new font record for a file and attempts to prepare it.
+ */
+static bitmapfont_t* loadFont(const char* name, const char* path)
+{
+ bitmapfont_t* font = addFont(BitmapFont_Construct(getNewFontId(), name, path));
+ if(NULL != font)
+ {
+ VERBOSE( Con_Message("New font '%s'.\n", Str_Text(BitmapFont_Name(font))) )
+ }
+ return font;
+}
+
+int Fonts_Init(void)
+{
+ if(inited)
+ return -1; // No reinitializations...
+
+ inited = true;
+ numFonts = 0;
+ fonts = 0; // No fonts!
+
+ return 0;
+}
+
+void Fonts_Shutdown(void)
+{
+ if(!inited)
+ return;
+ destroyFonts();
+ inited = false;
+}
+
+fontid_t Fonts_CreateFromDef(ded_compositefont_t* def)
+{
+ bitmapfont_t* font;
+ fontid_t id;
+
+ // Valid name?
+ if(!def->id[0])
+ Con_Error("Fonts_CreateFontFromDef: A valid name is required (not NULL or zero-length).");
+
+ // Already a font by this name?
+ if(0 != (id = Fonts_IdForName(def->id)))
+ {
+ Con_Error("Fonts_CreateFontFromDef: Failed to create font '%s', name already in use.");
+ return 0; // Unreachable.
+ }
+
+ // A new font.
+ font = addFont(BitmapFont_Construct(getNewFontId(), def->id, 0));
+ { int i;
+ for(i = 0; i < def->charMapCount.num; ++i)
+ {
+ ddstring_t* path;
+ if(!def->charMap[i].path)
+ continue;
+ if(0 != (path = Uri_Resolved(def->charMap[i].path)))
+ {
+ BitmapFont_CharSetPatch(font, def->charMap[i].ch, Str_Text(path));
+ Str_Delete(path);
+ }
+ }}
+ return BitmapFont_Id(font);
+}
+
+fontid_t Fonts_LoadSystemFont(const char* name, const char* searchPath)
+{
+ assert(name && searchPath && searchPath[0]);
+ {
+ bitmapfont_t* font;
+
+ errorIfNotInited("Fonts_LoadSystemFont");
+
+ if(0 != findFontIdForName(name) || 0 == F_Access(searchPath))
+ {
+ return 0; // Error.
+ }
+
+ VERBOSE2( Con_Message("Preparing font \"%s\"...\n", F_PrettyPath(searchPath)) );
+ font = loadFont(name, searchPath);
+ if(NULL == font)
+ {
+ Con_Message("Warning: Unknown format for %s\n", searchPath);
+ return 0; // Error.
+ }
+
+ // Make this the current font.
+ FR_SetFont(BitmapFont_Id(font));
+ return BitmapFont_Id(font);
+ }
+}
+
+void Fonts_DestroyFont(fontid_t id)
+{
+ int idx;
+ errorIfNotInited("Fonts_DestroyFont");
+ idx = findFontIdxForId(id);
+ if(idx == -1) return;
+
+ if(id == FR_Font())
+ FR_SetNoFont();
+
+ destroyFontIdx(idx);
+}
+
+void Fonts_Update(void)
+{
+ if(!inited || novideo || isDedicated)
+ return;
+ { int i;
+ for(i = 0; i < numFonts; ++i)
+ {
+ BitmapFont_DeleteGLTextures(fonts[i]);
+ BitmapFont_DeleteGLDisplayLists(fonts[i]);
+ }}
+}
+
+bitmapfont_t* Fonts_FontForId(fontid_t id)
+{
+ assert(inited);
+ { int idx;
+ if(-1 != (idx = findFontIdxForId(id)))
+ return fonts[idx];
+ }
+ return 0;
+}
+
+bitmapfont_t* Fonts_FontForIndex(int index)
+{
+ assert(inited);
+ if(index >= 0 && index < numFonts)
+ return fonts[index];
+ return NULL;
+}
+
+/// \note Member of the Doomsday public API.
+fontid_t Fonts_IdForName(const char* name)
+{
+ errorIfNotInited("Fonts_IdForName");
+ return findFontIdForName(name);
+}
+
+int Fonts_ToIndex(fontid_t id)
+{
+ int idx;
+ errorIfNotInited("Fonts_ToIndex");
+ idx = findFontIdxForId(id);
+ if(idx == -1)
+ {
+ Con_Message("Warning:Fonts_ToIndex: Unknown ID %u.\n", id);
+ }
+ return idx;
+}
+
+static int C_DECL compareFontName(const void* a, const void* b)
+{
+ return Str_CompareIgnoreCase(*((const ddstring_t**)a), Str_Text(*((const ddstring_t**)b)));
+}
+
+ddstring_t** Fonts_CollectNames(int* count)
+{
+ errorIfNotInited("Fonts_CollectNames");
+ if(numFonts != 0)
+ {
+ ddstring_t** list = malloc(sizeof(*list) * (numFonts+1));
+ int i;
+ for(i = 0; i < numFonts; ++i)
+ {
+ list[i] = Str_New();
+ Str_Copy(list[i], BitmapFont_Name(fonts[i]));
+ }
+ list[i] = 0; // Terminate.
+ qsort(list, numFonts, sizeof(*list), compareFontName);
+ if(count)
+ *count = numFonts;
+ return list;
+ }
+ if(count)
+ *count = 0;
+ return 0;
+}
+
+static void printFontInfo(const bitmapfont_t* font)
+{
+ int numDigits = M_NumDigits(numFonts);
+ Con_Printf(" %*u: \"system:%s\" ", numDigits, (unsigned int) BitmapFont_Id(font), Str_Text(BitmapFont_Name(font)));
+ if(BitmapFont_GLTextureName(font))
+ {
+ Con_Printf("bitmap (texWidth:%i, texHeight:%i)", BitmapFont_TextureWidth(font), BitmapFont_TextureHeight(font));
+ }
+ else
+ {
+ Con_Printf("bitmap_composite");
+ }
+ Con_Printf("\n");
+}
+
+static bitmapfont_t** collectFonts(const char* like, size_t* count, bitmapfont_t** storage)
+{
+ size_t n = 0;
+ int i;
+
+ for(i = 0; i < numFonts; ++i)
+ {
+ bitmapfont_t* font = fonts[i];
+ if(like && like[0] && strnicmp(Str_Text(BitmapFont_Name(font)), like, strlen(like)))
+ continue;
+ if(storage)
+ storage[n++] = font;
+ else
+ ++n;
+ }
+
+ if(storage)
+ {
+ storage[n] = 0; // Terminate.
+ if(count)
+ *count = n;
+ return storage;
+ }
+
+ if(n == 0)
+ {
+ if(count)
+ *count = 0;
+ return 0;
+ }
+
+ storage = malloc(sizeof(bitmapfont_t*) * (n+1));
+ return collectFonts(like, count, storage);
+}
+
+static size_t printFonts(const char* like)
+{
+ size_t count = 0;
+ bitmapfont_t** foundFonts = collectFonts(like, &count, 0);
+
+ Con_FPrintf(CBLF_YELLOW, "Known Fonts:\n");
+
+ if(!foundFonts)
+ {
+ Con_Printf(" None found.\n");
+ return 0;
+ }
+
+ // Print the result index key.
+ Con_Printf(" uid: \"(namespace:)name\" font-type\n");
+ Con_FPrintf(CBLF_RULER, "");
+
+ // Sort and print the index.
+ qsort(foundFonts, count, sizeof(*foundFonts), compareFontByName);
+
+ { bitmapfont_t* const* ptr;
+ for(ptr = foundFonts; *ptr; ++ptr)
+ printFontInfo(*ptr);
+ }
+
+ free(foundFonts);
+ return count;
+}
+
+D_CMD(ListFonts)
+{
+ printFonts(argc > 1? argv[1] : NULL);
+ return true;
+}
diff --git a/doomsday/engine/portable/src/gl_main.c b/doomsday/engine/portable/src/gl_main.c
index bc7dc196d5..afcf5036f1 100644
--- a/doomsday/engine/portable/src/gl_main.c
+++ b/doomsday/engine/portable/src/gl_main.c
@@ -441,7 +441,7 @@ static fontid_t loadSystemFont(const char* name)
Str_Free(&searchPath);
searchPath2 = Uri_Resolved(path);
Uri_Destruct(path);
- result = FR_LoadSystemFont(name, Str_Text(searchPath2));
+ result = Fonts_LoadSystemFont(name, Str_Text(searchPath2));
if(searchPath2)
Str_Delete(searchPath2);
@@ -607,7 +607,8 @@ void GL_Shutdown(void)
return; // Not yet initialized fully.
GL_ShutdownDeferredTask();
- FR_Shutdown();
+ Fonts_Shutdown();
+ FR_Shutdown();
glFontFixed =
glFontVariable[GLFS_NORMAL] =
glFontVariable[GLFS_BOLD] =
@@ -836,11 +837,13 @@ void GL_TotalReset(void)
// Delete all textures.
GL_ResetTextureManager();
- FR_Shutdown();
+ Fonts_Shutdown();
+ FR_Shutdown();
glFontFixed =
glFontVariable[GLFS_NORMAL] =
glFontVariable[GLFS_BOLD] =
glFontVariable[GLFS_LIGHT] = 0;
+ Fonts_Init();
FR_Init();
GL_ReleaseReservedNames();
diff --git a/doomsday/engine/portable/src/gl_texmanager.c b/doomsday/engine/portable/src/gl_texmanager.c
index 27e7b44490..0860e586ac 100644
--- a/doomsday/engine/portable/src/gl_texmanager.c
+++ b/doomsday/engine/portable/src/gl_texmanager.c
@@ -47,9 +47,9 @@
#include "de_system.h"
#include "de_misc.h"
#include "de_play.h"
+#include "de_ui.h"
#include "def_main.h"
-#include "ui_main.h"
#include "p_particle.h"
#include "colorpalette.h"
@@ -2986,7 +2986,7 @@ void GL_TexReset(void)
boolean useBusyMode = !Con_IsBusy();
GL_ClearTextureMemory();
- FR_Update();
+ Fonts_Update();
Con_Printf("All DGL textures deleted.\n");
if(useBusyMode)
diff --git a/doomsday/engine/portable/src/r_main.c b/doomsday/engine/portable/src/r_main.c
index 875069e7e2..e06334d981 100644
--- a/doomsday/engine/portable/src/r_main.c
+++ b/doomsday/engine/portable/src/r_main.c
@@ -126,7 +126,6 @@ void R_Register(void)
C_CMD("viewgrid", "ii", ViewGrid);
P_MaterialsRegister();
- FR_Register();
}
boolean R_IsSkySurface(const surface_t* suf)
diff --git a/doomsday/engine/portable/src/rend_console.c b/doomsday/engine/portable/src/rend_console.c
index 864c71ad19..d6b0ed0c3b 100644
--- a/doomsday/engine/portable/src/rend_console.c
+++ b/doomsday/engine/portable/src/rend_console.c
@@ -32,6 +32,7 @@
#include "de_console.h"
#include "de_graphics.h"
#include "de_refresh.h"
+#include "de_render.h"
#include "de_ui.h"
#include "math.h"
@@ -602,7 +603,7 @@ static void drawConsole(float consoleAlpha)
FR_LoadDefaultAttrib();
FR_SetColorAndAlpha(1, 1, 1, consoleAlpha);
- cfont = FR_BitmapFontForId(FR_Font());
+ cfont = Fonts_FontForId(FR_Font());
lineHeight = FR_SingleLineHeight("Con");
Con_FontScale(&scale[0], &scale[1]);
fontScaledY = lineHeight * scale[1];
diff --git a/doomsday/engine/portable/src/gl_font.c b/doomsday/engine/portable/src/rend_font.c
similarity index 80%
rename from doomsday/engine/portable/src/gl_font.c
rename to doomsday/engine/portable/src/rend_font.c
index 2340452b55..f949b9151b 100644
--- a/doomsday/engine/portable/src/gl_font.c
+++ b/doomsday/engine/portable/src/rend_font.c
@@ -38,6 +38,7 @@
#include "de_system.h"
#include "de_refresh.h"
#include "de_render.h"
+#include "de_ui.h"
#include "bitmapfont.h"
#include "m_misc.h"
@@ -89,8 +90,6 @@ typedef struct {
} caseMod[2]; // 1=upper, 0=lower
} drawtextstate_t;
-D_CMD(ListFonts);
-
static __inline fr_state_attributes_t* currentAttribs(void);
static int topToAscent(bitmapfont_t* font);
static int lineHeight(bitmapfont_t* font, unsigned char ch);
@@ -103,16 +102,8 @@ static char smallTextBuffer[FR_SMALL_TEXT_BUFFER_SIZE+1];
static char* largeTextBuffer = NULL;
static size_t largeTextBufferSize = 0;
-static int numFonts = 0;
-static bitmapfont_t** fonts = 0; // The list of fonts.
-
static int typeInTime;
-void FR_Register(void)
-{
- C_CMD("listfonts", NULL, ListFonts)
-}
-
static void errorIfNotInited(const char* callerName)
{
if(inited) return;
@@ -121,111 +112,6 @@ static void errorIfNotInited(const char* callerName)
exit(1);
}
-static fontid_t getNewFontId(void)
-{
- int i;
- fontid_t max = 0;
- for(i = 0; i < numFonts; ++i)
- {
- const bitmapfont_t* font = fonts[i];
- if(BitmapFont_Id(font) > max)
- max = BitmapFont_Id(font);
- }
- return max + 1;
-}
-
-static fontid_t findFontIdForName(const char* name)
-{
- if(name && name[0])
- {
- int i;
- for(i = 0; i < numFonts; ++i)
- {
- const bitmapfont_t* font = fonts[i];
- if(!Str_CompareIgnoreCase(BitmapFont_Name(font), name))
- return BitmapFont_Id(font);
- }
- }
- return 0; // Not found.
-}
-
-static int findFontIdxForName(const char* name)
-{
- if(name && name[0])
- {
- int i;
- for(i = 0; i < numFonts; ++i)
- {
- const bitmapfont_t* font = fonts[i];
- if(!Str_CompareIgnoreCase(BitmapFont_Name(font), name))
- return i;
- }
- }
- return -1;
-}
-
-static int compareFontByName(const void* e1, const void* e2)
-{
- return Str_CompareIgnoreCase(BitmapFont_Name(*(const bitmapfont_t**)e1), Str_Text(BitmapFont_Name(*(const bitmapfont_t**)e2)));
-}
-
-static int findFontIdxForId(fontid_t id)
-{
- if(id != 0)
- {
- int i;
- for(i = 0; i < numFonts; ++i)
- {
- const bitmapfont_t* font = fonts[i];
- if(BitmapFont_Id(font) == id)
- return i;
- }
- }
- return -1;
-}
-
-static void destroyFontIdx(int idx)
-{
- BitmapFont_Destruct(fonts[idx]);
-
- memmove(&fonts[idx], &fonts[idx + 1], sizeof(*fonts) * (numFonts - idx - 1));
- --numFonts;
- fonts = realloc(fonts, sizeof(*fonts) * numFonts);
-
- if(fr.fontIdx == idx)
- fr.fontIdx = -1;
-}
-
-static void destroyFonts(void)
-{
- while(numFonts) { destroyFontIdx(0); }
- fonts = 0;
- fr.fontIdx = -1;
-}
-
-static bitmapfont_t* addFont(bitmapfont_t* font)
-{
- assert(NULL != font);
- fonts = (bitmapfont_t**)realloc(fonts, sizeof(*fonts) * ++numFonts);
- if(NULL == fonts)
- Con_Error("addFont: Failed on (re)allocation of %lu bytes.", (unsigned long)(sizeof(*fonts) * numFonts));
- fonts[numFonts-1] = font;
- return font;
-}
-
-/**
- * Creates a new font record for a file and attempts to prepare it.
- */
-static bitmapfont_t* loadFont(const char* name, const char* path)
-{
- bitmapfont_t* font = addFont(BitmapFont_Construct(getNewFontId(), name, path));
- if(NULL != font)
- {
- VERBOSE( Con_Message("New font '%s'.\n", Str_Text(BitmapFont_Name(font))) )
- }
- return font;
-}
-
static int topToAscent(bitmapfont_t* font)
{
int lineHeight = BitmapFont_Leading(font);
@@ -253,8 +139,6 @@ int FR_Init(void)
return -1; // No reinitializations...
inited = true;
- numFonts = 0;
- fonts = 0; // No fonts!
fr.fontIdx = -1;
FR_LoadDefaultAttrib();
typeInTime = 0;
@@ -266,95 +150,9 @@ void FR_Shutdown(void)
{
if(!inited)
return;
- destroyFonts();
inited = false;
}
-fontid_t FR_CreateFontFromDef(ded_compositefont_t* def)
-{
- bitmapfont_t* font;
- fontid_t id;
-
- // Valid name?
- if(!def->id[0])
- Con_Error("FR_CreateFontFromDef: A valid name is required (not NULL or zero-length).");
-
- // Already a font by this name?
- if(0 != (id = FR_FindFontForName(def->id)))
- {
- Con_Error("FR_CreateFontFromDef: Failed to create font '%s', name already in use.");
- return 0; // Unreachable.
- }
-
- // A new font.
- font = addFont(BitmapFont_Construct(getNewFontId(), def->id, 0));
- { int i;
- for(i = 0; i < def->charMapCount.num; ++i)
- {
- ddstring_t* path;
- if(!def->charMap[i].path)
- continue;
- if(0 != (path = Uri_Resolved(def->charMap[i].path)))
- {
- BitmapFont_CharSetPatch(font, def->charMap[i].ch, Str_Text(path));
- Str_Delete(path);
- }
- }}
- return BitmapFont_Id(font);
-}
-
-fontid_t FR_LoadSystemFont(const char* name, const char* searchPath)
-{
- assert(name && searchPath && searchPath[0]);
- {
- bitmapfont_t* font;
-
- errorIfNotInited("FR_LoadSystemFont");
-
- if(0 != findFontIdForName(name) || 0 == F_Access(searchPath))
- {
- return 0; // Error.
- }
-
- VERBOSE2( Con_Message("Preparing font \"%s\"...\n", F_PrettyPath(searchPath)) );
- font = loadFont(name, searchPath);
- if(NULL == font)
- {
- Con_Message("Warning: Unknown format for %s\n", searchPath);
- return 0; // Error.
- }
-
- // Make this the current font.
- fr.fontIdx = numFonts-1;
-
- return BitmapFont_Id(font);
- }
-}
-
-void FR_DestroyFont(fontid_t id)
-{
- int idx;
- errorIfNotInited("FR_DestroyFont");
- idx = findFontIdxForId(id);
- if(idx == -1) return;
-
- destroyFontIdx(idx);
- if(fr.fontIdx == idx)
- fr.fontIdx = -1;
-}
-
-void FR_Update(void)
-{
- if(!inited || novideo || isDedicated)
- return;
- { int i;
- for(i = 0; i < numFonts; ++i)
- {
- BitmapFont_DeleteGLTextures(fonts[i]);
- BitmapFont_DeleteGLDisplayLists(fonts[i]);
- }}
-}
-
void FR_Ticker(timespan_t ticLength)
{
static trigger_t fixed = { 1 / 35.0 };
@@ -375,52 +173,29 @@ void FR_ResetTypeinTimer(void)
typeInTime = 0;
}
-bitmapfont_t* FR_BitmapFontForId(fontid_t id)
-{
- assert(inited);
- { int idx;
- if(-1 != (idx = findFontIdxForId(id)))
- return fonts[idx];
- }
- return 0;
-}
-
-/// \note Member of the Doomsday public API.
-fontid_t FR_FindFontForName(const char* name)
-{
- errorIfNotInited("FR_FindFontForName");
- return findFontIdForName(name);
-}
-
-int FR_GetFontIdx(fontid_t id)
-{
- int idx;
- errorIfNotInited("FR_GetFontIdx");
- idx = findFontIdxForId(id);
- if(idx == -1)
- {
- Con_Message("Warning:FR_GetFontIdx: Unknown ID %u.\n", id);
- }
- return idx;
-}
-
/// \note Member of the Doomsday public API.
void FR_SetFont(fontid_t id)
{
int idx;
errorIfNotInited("FR_SetFont");
- idx = FR_GetFontIdx(id);
+ idx = Fonts_ToIndex(id);
if(idx == -1)
return; // No such font.
fr.fontIdx = idx;
}
+void FR_SetNoFont(void)
+{
+ errorIfNotInited("FR_SetNoFont");
+ fr.fontIdx = -1;
+}
+
/// \note Member of the Doomsday public API.
fontid_t FR_Font(void)
{
errorIfNotInited("FR_Font");
if(fr.fontIdx != -1)
- return BitmapFont_Id(fonts[fr.fontIdx]);
+ return BitmapFont_Id(Fonts_FontForIndex(fr.fontIdx));
return 0;
}
@@ -653,7 +428,7 @@ void FR_SetCaseScale(boolean value)
void FR_CharDimensions(int* width, int* height, unsigned char ch)
{
errorIfNotInited("FR_CharDimensions");
- BitmapFont_CharDimensions(fonts[fr.fontIdx], width, height, ch);
+ BitmapFont_CharDimensions(Fonts_FontForIndex(fr.fontIdx), width, height, ch);
}
/// \note Member of the Doomsday public API.
@@ -661,7 +436,7 @@ int FR_CharWidth(unsigned char ch)
{
errorIfNotInited("FR_CharWidth");
if(fr.fontIdx != -1)
- return BitmapFont_CharWidth(fonts[fr.fontIdx],ch);
+ return BitmapFont_CharWidth(Fonts_FontForIndex(fr.fontIdx), ch);
return 0;
}
@@ -670,7 +445,7 @@ int FR_CharHeight(unsigned char ch)
{
errorIfNotInited("FR_CharHeight");
if(fr.fontIdx != -1)
- return BitmapFont_CharHeight(fonts[fr.fontIdx], ch);
+ return BitmapFont_CharHeight(Fonts_FontForIndex(fr.fontIdx), ch);
return 0;
}
@@ -679,11 +454,11 @@ int FR_SingleLineHeight(const char* text)
errorIfNotInited("FR_SingleLineHeight");
if(fr.fontIdx == -1 || !text)
return 0;
- { int ascent = BitmapFont_Ascent(fonts[fr.fontIdx]);
+ { int ascent = BitmapFont_Ascent(Fonts_FontForIndex(fr.fontIdx));
if(ascent != 0)
return ascent;
}
- return BitmapFont_CharHeight(fonts[fr.fontIdx], (unsigned char)text[0]);
+ return BitmapFont_CharHeight(Fonts_FontForIndex(fr.fontIdx), (unsigned char)text[0]);
}
int FR_GlyphTopToAscent(const char* text)
@@ -692,10 +467,10 @@ int FR_GlyphTopToAscent(const char* text)
errorIfNotInited("FR_GlyphTopToAscent");
if(fr.fontIdx == -1 || !text)
return 0;
- lineHeight = BitmapFont_Leading(fonts[fr.fontIdx]);
+ lineHeight = BitmapFont_Leading(Fonts_FontForIndex(fr.fontIdx));
if(lineHeight == 0)
return 0;
- return lineHeight - BitmapFont_Ascent(fonts[fr.fontIdx]);
+ return lineHeight - BitmapFont_Ascent(Fonts_FontForIndex(fr.fontIdx));
}
static int textFragmentWidth(const char* fragment)
@@ -750,7 +525,7 @@ static int textFragmentHeight(const char* fragment)
height = MAX_OF(height, FR_CharHeight(c));
}
- return topToAscent(fonts[fr.fontIdx]) + height;
+ return topToAscent(Fonts_FontForIndex(fr.fontIdx)) + height;
}
}
@@ -765,7 +540,7 @@ static void textFragmentDrawer(const char* fragment, int x, int y, int alignFlag
{
assert(fragment && fragment[0] && fr.fontIdx != -1);
{
- bitmapfont_t* cf = fonts[fr.fontIdx];
+ bitmapfont_t* cf = Fonts_FontForIndex(fr.fontIdx);
fr_state_attributes_t* sat = currentAttribs();
boolean noTypein = (textFlags & DTF_NO_TYPEIN) != 0;
boolean noGlitter = (sat->glitterStrength <= 0 || (textFlags & DTF_NO_GLITTER) != 0);
@@ -1082,34 +857,6 @@ static void drawFlash(int x, int y, int w, int h, int bright)
GL_BlendMode(BM_NORMAL);
}
-static int C_DECL compareFontName(const void* a, const void* b)
-{
- return Str_CompareIgnoreCase(*((const ddstring_t**)a), Str_Text(*((const ddstring_t**)b)));
-}
-
-ddstring_t** FR_CollectFontNames(int* count)
-{
- errorIfNotInited("FR_CollectFontNames");
- if(numFonts != 0)
- {
- ddstring_t** list = malloc(sizeof(*list) * (numFonts+1));
- int i;
- for(i = 0; i < numFonts; ++i)
- {
- list[i] = Str_New();
- Str_Copy(list[i], BitmapFont_Name(fonts[i]));
- }
- list[i] = 0; // Terminate.
- qsort(list, numFonts, sizeof(*list), compareFontName);
- if(count)
- *count = numFonts;
- return list;
- }
- if(count)
- *count = 0;
- return 0;
-}
-
/**
* Expected: =
*/
@@ -1248,9 +995,9 @@ static void parseParamaterBlock(char** strPtr, drawtextstate_t* state, int* numB
if(!strnicmp((*strPtr), "font", 4))
{
(*strPtr) += 4;
- if((fontId = FR_FindFontForName(*strPtr)))
+ if((fontId = Fonts_IdForName(*strPtr)))
{
- (*strPtr) += Str_Length(BitmapFont_Name(FR_BitmapFontForId(fontId)));
+ (*strPtr) += Str_Length(BitmapFont_Name(Fonts_FontForId(fontId)));
state->font = fontId;
continue;
}
@@ -1274,7 +1021,7 @@ static void parseParamaterBlock(char** strPtr, drawtextstate_t* state, int* numB
static void initDrawTextState(drawtextstate_t* state)
{
fr_state_attributes_t* sat = currentAttribs();
- state->font = BitmapFont_Id(fonts[fr.fontIdx]);
+ state->font = BitmapFont_Id(Fonts_FontForIndex(fr.fontIdx));
memcpy(state->rgba, sat->rgba, sizeof(state->rgba));
state->tracking = sat->tracking;
state->glitterStrength = sat->glitterStrength;
@@ -1609,88 +1356,3 @@ int FR_TextHeight(const char* string)
return h;
}
-
-static void printFontInfo(const bitmapfont_t* font)
-{
- int numDigits = M_NumDigits(numFonts);
- Con_Printf(" %*u: \"system:%s\" ", numDigits, (unsigned int) BitmapFont_Id(font), Str_Text(BitmapFont_Name(font)));
- if(BitmapFont_GLTextureName(font))
- {
- Con_Printf("bitmap (texWidth:%i, texHeight:%i)", BitmapFont_TextureWidth(font), BitmapFont_TextureHeight(font));
- }
- else
- {
- Con_Printf("bitmap_composite");
- }
- Con_Printf("\n");
-}
-
-static bitmapfont_t** collectFonts(const char* like, size_t* count, bitmapfont_t** storage)
-{
- size_t n = 0;
- int i;
-
- for(i = 0; i < numFonts; ++i)
- {
- bitmapfont_t* font = fonts[i];
- if(like && like[0] && strnicmp(Str_Text(BitmapFont_Name(font)), like, strlen(like)))
- continue;
- if(storage)
- storage[n++] = font;
- else
- ++n;
- }
-
- if(storage)
- {
- storage[n] = 0; // Terminate.
- if(count)
- *count = n;
- return storage;
- }
-
- if(n == 0)
- {
- if(count)
- *count = 0;
- return 0;
- }
-
- storage = malloc(sizeof(bitmapfont_t*) * (n+1));
- return collectFonts(like, count, storage);
-}
-
-static size_t printFonts(const char* like)
-{
- size_t count = 0;
- bitmapfont_t** foundFonts = collectFonts(like, &count, 0);
-
- Con_FPrintf(CBLF_YELLOW, "Known Fonts:\n");
-
- if(!foundFonts)
- {
- Con_Printf(" None found.\n");
- return 0;
- }
-
- // Print the result index key.
- Con_Printf(" uid: \"(namespace:)name\" font-type\n");
- Con_FPrintf(CBLF_RULER, "");
-
- // Sort and print the index.
- qsort(foundFonts, count, sizeof(*foundFonts), compareFontByName);
-
- { bitmapfont_t* const* ptr;
- for(ptr = foundFonts; *ptr; ++ptr)
- printFontInfo(*ptr);
- }
-
- free(foundFonts);
- return count;
-}
-
-D_CMD(ListFonts)
-{
- printFonts(argc > 1? argv[1] : NULL);
- return true;
-}
diff --git a/doomsday/engine/portable/src/ui_main.c b/doomsday/engine/portable/src/ui_main.c
index 2f073809e1..36f3f4399b 100644
--- a/doomsday/engine/portable/src/ui_main.c
+++ b/doomsday/engine/portable/src/ui_main.c
@@ -37,6 +37,7 @@
#include "de_refresh.h"
#include "de_system.h"
#include "de_graphics.h"
+#include "de_render.h"
#include "de_ui.h"
#include "de_misc.h"
@@ -136,6 +137,7 @@ void UI_Register(void)
C_CMD_FLAGS("uicolor", "sfff", UIColor, CMDF_NO_DEDICATED);
CP_Register();
+ Fonts_Register();
}
void UI_PageInit(boolean halttime, boolean tckui, boolean tckframe, boolean drwgame, boolean noescape)
diff --git a/doomsday/engine/portable/src/ui_panel.c b/doomsday/engine/portable/src/ui_panel.c
index 36cccf0bde..bce0a7c324 100644
--- a/doomsday/engine/portable/src/ui_panel.c
+++ b/doomsday/engine/portable/src/ui_panel.c
@@ -34,6 +34,7 @@
#include "de_base.h"
#include "de_console.h"
#include "de_graphics.h"
+#include "de_render.h"
#include "de_ui.h"
#include "rend_main.h"
diff --git a/doomsday/plugins/common/src/g_game.c b/doomsday/plugins/common/src/g_game.c
index 2cbbc83e50..24820c8247 100644
--- a/doomsday/plugins/common/src/g_game.c
+++ b/doomsday/plugins/common/src/g_game.c
@@ -803,7 +803,7 @@ void R_LoadVectorGraphics(void)
*/
fontid_t R_MustFindFontForName(const char* name)
{
- fontid_t id = FR_FindFontForName(name);
+ fontid_t id = Fonts_IdForName(name);
if(id == 0)
Con_Error("Failed loading font \"%s\".", name);
return id;