git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10218
d7cf8633-e32d-0410-b094-
e92efae38249
typedef struct ft2_settings_s
{
typedef struct ft2_settings_s
{
// cvar parameters (only read on loadfont command)
int antialias, hinting;
float outline, blur, shadowx, shadowy, shadowz;
// cvar parameters (only read on loadfont command)
int antialias, hinting;
float outline, blur, shadowx, shadowy, shadowz;
rtexture_t *tex;
float width_of[256]; // width_of[0] == max width of any char; 1.0f is base width (1/16 of texture width); therefore, all widths have to be <= 1 (does not include scale)
float maxwidth; // precalculated max width of the font (includes scale)
rtexture_t *tex;
float width_of[256]; // width_of[0] == max width of any char; 1.0f is base width (1/16 of texture width); therefore, all widths have to be <= 1 (does not include scale)
float maxwidth; // precalculated max width of the font (includes scale)
- float scale; // scales the font (without changing line height!)
- float voffset; // offsets the font up/down (without changing line position)
char texpath[MAX_QPATH];
char title[MAX_QPATH];
char texpath[MAX_QPATH];
char title[MAX_QPATH];
if(override || !fnt->texpath[0])
{
strlcpy(fnt->texpath, name, sizeof(fnt->texpath));
if(override || !fnt->texpath[0])
{
strlcpy(fnt->texpath, name, sizeof(fnt->texpath));
-
- // load the cvars when the font is FIRST loaded
+ // load the cvars when the font is FIRST loader
+ fnt->settings.scale = scale;
+ fnt->settings.voffset = voffset;
fnt->settings.antialias = r_font_antialias.integer;
fnt->settings.hinting = r_font_hinting.integer;
fnt->settings.outline = r_font_postprocess_outline.value;
fnt->settings.antialias = r_font_antialias.integer;
fnt->settings.hinting = r_font_hinting.integer;
fnt->settings.outline = r_font_postprocess_outline.value;
{
if(!COM_ParseToken_Simple(&p, false, false))
return;
{
if(!COM_ParseToken_Simple(&p, false, false))
return;
- scale = atof(com_token);
+ fnt->settings.scale = atof(com_token);
fnt->maxwidth = maxwidth;
// fix up maxwidth for overlap
fnt->maxwidth = maxwidth;
// fix up maxwidth for overlap
- fnt->maxwidth *= scale;
- fnt->scale = scale;
- fnt->voffset = voffset;
+ fnt->maxwidth *= fnt->settings.scale;
if(fnt == FONT_CONSOLE)
con_linewidth = -1; // rewrap console in next frame
if(fnt == FONT_CONSOLE)
con_linewidth = -1; // rewrap console in next frame
static void LoadFont_f(void)
{
dp_font_t *f;
static void LoadFont_f(void)
{
dp_font_t *f;
const char *filelist, *c, *cm;
const char *filelist, *c, *cm;
+ float sz, scale, voffset;
char mainfont[MAX_QPATH];
if(Cmd_Argc() < 2)
char mainfont[MAX_QPATH];
if(Cmd_Argc() < 2)
Con_Printf("Available font commands:\n");
for(i = 0; i < dp_fonts.maxsize; ++i)
if (dp_fonts.f[i].title[0])
Con_Printf("Available font commands:\n");
for(i = 0; i < dp_fonts.maxsize; ++i)
if (dp_fonts.f[i].title[0])
- Con_Printf(" loadfont %s gfx/tgafile[...] [sizes...]\n", dp_fonts.f[i].title);
+ Con_Printf(" loadfont %s gfx/tgafile[...] [custom switches] [sizes...]\n", dp_fonts.f[i].title);
Con_Printf("A font can simply be gfx/tgafile, or alternatively you\n"
"can specify multiple fonts and faces\n"
"Like this: gfx/vera-sans:2,gfx/fallback:1\n"
Con_Printf("A font can simply be gfx/tgafile, or alternatively you\n"
"can specify multiple fonts and faces\n"
"Like this: gfx/vera-sans:2,gfx/fallback:1\n"
"You can also specify a list of font sizes to load, like this:\n"
"loadfont console gfx/conchars,gfx/fallback 8 12 16 24 32\n"
"In many cases, 8 12 16 24 32 should be a good choice.\n"
"You can also specify a list of font sizes to load, like this:\n"
"loadfont console gfx/conchars,gfx/fallback 8 12 16 24 32\n"
"In many cases, 8 12 16 24 32 should be a good choice.\n"
+ "custom switches:\n"
+ " scale x : scale all characters by this amount when rendering (doesnt change line height)\n"
+ " voffset x : offset all chars vertical when rendering, this is multiplied to character height\n"
for(i = 1; i < MAX_FONT_SIZES; ++i)
f->req_sizes[i] = -1;
for(i = 1; i < MAX_FONT_SIZES; ++i)
f->req_sizes[i] = -1;
+ scale = 1;
+ voffset = 0;
+ if(Cmd_Argc() >= 4)
- for(i = 0; i < Cmd_Argc()-3; ++i)
+ for(sizes = 0, i = 3; i < Cmd_Argc(); ++i)
- sz = atof(Cmd_Argv(i+3));
+ // special switches
+ if (!strcmp(Cmd_Argv(i), "scale"))
+ {
+ i++;
+ if (i < Cmd_Argc())
+ scale = atof(Cmd_Argv(i));
+ continue;
+ }
+ if (!strcmp(Cmd_Argv(i), "voffset"))
+ {
+ i++;
+ if (i < Cmd_Argc())
+ voffset = atof(Cmd_Argv(i));
+ continue;
+ }
+ // parse one of sizes
+ sz = atof(Cmd_Argv(i));
if (sz > 0.001f && sz < 1000.0f) // do not use crap sizes
if (sz > 0.001f && sz < 1000.0f) // do not use crap sizes
+ {
+ f->req_sizes[sizes] = sz;
+ sizes++;
+ }
- LoadFont(true, mainfont, f, 1, 0);
+ LoadFont(true, mainfont, f, scale, voffset);
snap = false;
}
// do this in the end
snap = false;
}
// do this in the end
- w *= fnt->scale;
- h *= fnt->scale;
+ w *= fnt->settings.scale;
+ h *= fnt->settings.scale;
// find the most fitting size:
if (ft2 != NULL)
// find the most fitting size:
if (ft2 != NULL)
- starty -= (fnt->scale - 1) * h * 0.5 - fnt->voffset*h; // center & offset
- w *= fnt->scale;
- h *= fnt->scale;
+ starty -= (fnt->settings.scale - 1) * h * 0.5 - fnt->settings.voffset*h; // center & offset
+ w *= fnt->settings.scale;
+ h *= fnt->settings.scale;