]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
DP_GFX_FONTS: add 2 additional parms to loadfont() - char scale and vertical offset...
authorvortex <vortex@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 22 May 2010 23:52:10 +0000 (23:52 +0000)
committervortex <vortex@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 22 May 2010 23:52:10 +0000 (23:52 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10214 d7cf8633-e32d-0410-b094-e92efae38249

dpdefs/csprogsdefs.qc
draw.h
gl_draw.c
prvm_cmds.c

index ea8c318b5af36ed8da5486e5bc0a6a1361ee0829..cb22966dae7e63558d3bcdb19c4bff0cd13046c1 100644 (file)
@@ -801,13 +801,16 @@ float FONT_USER6 = 14;     // 'user6', userdefined fonts
 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.
diff --git a/draw.h b/draw.h
index 538a44ba0da248dcf26f64f01b9cc2ea287ad800..1744419b2dc01c918fac9565c5b22f39bdcffad6 100644 (file)
--- a/draw.h
+++ b/draw.h
@@ -105,6 +105,7 @@ typedef struct dp_font_s
        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];
 
index 1a7785ec9118637b321ce1766587b8063b70689c..039a9c91ece200b32dd04ae8bf07df8659e59299 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -541,10 +541,10 @@ void Draw_FreePic(const char *picname)
 
 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;
@@ -605,7 +605,6 @@ void LoadFont(qboolean override, const char *name, dp_font_t *fnt)
        // 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)))
@@ -682,6 +681,7 @@ void LoadFont(qboolean override, const char *name, dp_font_t *fnt)
        // 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
@@ -849,7 +849,7 @@ static void LoadFont_f(void)
                }
        }
 
-       LoadFont(true, mainfont, f);
+       LoadFont(true, mainfont, f, 1, 0);
 }
 
 /*
@@ -870,7 +870,7 @@ static void gl_draw_start(void)
        // 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);
@@ -1378,7 +1378,7 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                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;
 
index 6b8fde316ccffe48a9087f2d62c1692aee140a2a..cb78833cd54fcd65c81a6041679d9028d967acfc 100644 (file)
@@ -3513,16 +3513,16 @@ float loadfont(string fontname, string fontmaps, string sizes, float slot)
 */
 
 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])
@@ -3629,8 +3629,20 @@ void VM_loadfont(void)
                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);