Skip to content

Commit

Permalink
Added: CCmd "listfonts" - list known fonts which match the search cri…
Browse files Browse the repository at this point in the history
…teria (if specified).
  • Loading branch information
danij-deng committed Jun 30, 2011
1 parent 09939d6 commit 846ff09
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 4 deletions.
3 changes: 3 additions & 0 deletions doomsday/engine/data/cphelp.txt
Expand Up @@ -384,6 +384,9 @@ desc = List all console commands.
[listwadfiles]
desc = List all loaded WAD data files.

[listfonts]
desc = List all known fonts.

[listgames]
desc = List all games.

Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/include/bitmapfont.h
Expand Up @@ -110,8 +110,8 @@ void BitmapFont_CharSetPatch(bitmapfont_t* font, unsigned char ch, const char* p
/// @return GL-texture name.
DGLuint BitmapFont_GLTextureName(bitmapfont_t* font);

int BitmapFont_TextureHeight(bitmapfont_t* font);
int BitmapFont_TextureWidth(bitmapfont_t* font);
int BitmapFont_TextureHeight(const bitmapfont_t* font);
int BitmapFont_TextureWidth(const bitmapfont_t* font);

/**
* Accessor methods.
Expand Down
3 changes: 3 additions & 0 deletions doomsday/engine/portable/include/gl_font.h
Expand Up @@ -48,6 +48,9 @@
*/
#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.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/bitmapfont.c
Expand Up @@ -547,13 +547,13 @@ DGLuint BitmapFont_GLTextureName(bitmapfont_t* font)
return font->_tex;
}

int BitmapFont_TextureWidth(bitmapfont_t* font)
int BitmapFont_TextureWidth(const bitmapfont_t* font)
{
assert(font);
return font->_texWidth;
}

int BitmapFont_TextureHeight(bitmapfont_t* font)
int BitmapFont_TextureHeight(const bitmapfont_t* font)
{
assert(font);
return font->_texHeight;
Expand Down
97 changes: 97 additions & 0 deletions doomsday/engine/portable/src/gl_font.c
Expand Up @@ -89,6 +89,8 @@ 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);
Expand All @@ -106,6 +108,11 @@ 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;
Expand Down Expand Up @@ -157,6 +164,11 @@ static int findFontIdxForName(const char* name)
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)
Expand Down Expand Up @@ -1597,3 +1609,88 @@ 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;
}
1 change: 1 addition & 0 deletions doomsday/engine/portable/src/r_main.c
Expand Up @@ -126,6 +126,7 @@ void R_Register(void)
C_CMD("viewgrid", "ii", ViewGrid);

P_MaterialsRegister();
FR_Register();
}

boolean R_IsSkySurface(const surface_t* suf)
Expand Down

0 comments on commit 846ff09

Please sign in to comment.