float FONT_USER7 = 15; // 'user7' slot, userdefined fonts
//builtin definitions:
float findfont(string s) = #356; // find font by fontname and return it's index
-float loadfont(string fontname, string fontmaps, string sizes, float slot) = #357;
+float loadfont(string fontname, string fontmaps, string sizes, float slot, float fix_scale, float fix_voffset) = #357;
// loads font immediately so stringwidth() function can be used just after builtin call
// returns a font slotnum (which is used to set drawfont to)
// first 3 parms are identical to "loadfont" console command ones
// slot could be one of FONT_ constants or result of findfont() or -1 to not use it
// if slot is given, font will be loaded to this slotnum and fontname become new title for it
// this way you can rename user* fonts to something more usable
+// fix_* parms let you fix badly made fonts by applying some transformations to them
+// fix_scale : per-character center-oriented scale (doesn't change line height at all)
+// fix_voffset : vertical offset for each character, it's a multiplier to character height
float stringwidth(string text, float allowColorCodes, vector size) = #327; // get a width of string with given font and char size
float stringwidth_menu(string text, float allowColorCodes, vector size) = #468; // in menu.dat it has different builtin #
//description: engine support for custom fonts in console, hud, qc etc.
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];
static float snap_to_pixel_x(float x, float roundUpAt);
extern int con_linewidth; // to force rewrapping
-void LoadFont(qboolean override, const char *name, dp_font_t *fnt)
+void LoadFont(qboolean override, const char *name, dp_font_t *fnt, float scale, float voffset)
{
int i;
- float maxwidth, scale;
+ float maxwidth;
char widthfile[MAX_QPATH];
char *widthbuf;
fs_offset_t widthbufsize;
// unspecified width == 1 (base width)
for(i = 1; i < 256; ++i)
fnt->width_of[i] = 1;
- scale = 1;
// FIXME load "name.width", if it fails, fill all with 1
if((widthbuf = (char *) FS_LoadFile(widthfile, tempmempool, true, &widthbufsize)))
// fix up maxwidth for overlap
fnt->maxwidth *= scale;
fnt->scale = scale;
+ fnt->voffset = voffset;
if(fnt == FONT_CONSOLE)
con_linewidth = -1; // rewrap console in next frame
}
}
- LoadFont(true, mainfont, f);
+ LoadFont(true, mainfont, f, 1, 0);
}
/*
// load default font textures
for(i = 0; i < dp_fonts.maxsize; ++i)
if (dp_fonts.f[i].title[0])
- LoadFont(false, va("gfx/font_%s", &dp_fonts.f[i].title), &dp_fonts.f[i]);
+ LoadFont(false, va("gfx/font_%s", &dp_fonts.f[i].title), &dp_fonts.f[i], 1, 0);
// draw the loading screen so people have something to see in the newly opened window
SCR_UpdateLoadingScreen(true);
snap = false;
}
- starty -= (fnt->scale - 1) * h * 0.5; // center
+ starty -= (fnt->scale - 1) * h * 0.5 - fnt->voffset*h; // center & offset
w *= fnt->scale;
h *= fnt->scale;
*/
dp_font_t *FindFont(const char *title, qboolean allocate_new);
-void LoadFont(qboolean override, const char *name, dp_font_t *fnt);
+void LoadFont(qboolean override, const char *name, dp_font_t *fnt, float scale, float voffset);
void VM_loadfont(void)
{
const char *fontname, *filelist, *sizes, *c, *cm;
char mainfont[MAX_QPATH];
int i, numsizes;
- float sz;
+ float sz, scale, voffset;
dp_font_t *f;
- VM_SAFEPARMCOUNTRANGE(3,4,VM_loadfont);
+ VM_SAFEPARMCOUNTRANGE(3,6,VM_loadfont);
fontname = PRVM_G_STRING(OFS_PARM0);
if (!fontname[0])
numsizes++;
}
+ // additional scale/hoffset parms
+ scale = 1;
+ voffset = 0;
+ if (prog->argc >= 5)
+ {
+ scale = PRVM_G_FLOAT(OFS_PARM4);
+ if (scale <= 0)
+ scale = 1;
+ }
+ if (prog->argc >= 6)
+ voffset = PRVM_G_FLOAT(OFS_PARM5);
+
// load
- LoadFont(true, mainfont, f);
+ LoadFont(true, mainfont, f, scale, voffset);
// return index of loaded font
PRVM_G_FLOAT(OFS_RETURN) = (f - dp_fonts.f);