From: divverent Date: Tue, 29 Jul 2008 09:42:13 +0000 (+0000) Subject: add a new "scale" property in font files. Specifying, e.g., "scale 1.2" in a font... X-Git-Tag: xonotic-v0.1.0preview~2152 X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=6148e497eca98a1816ff1bd9d890c06c04fd2b16;hp=4a387dfae946c0d01c34f10fe0b11a6c6c1e2358 add a new "scale" property in font files. Specifying, e.g., "scale 1.2" in a font means that it gets rendered at 1.2 the usual size (by using 10% more space to the top and to the bottom). This may cause overlap between characters of adjacent lines, so use this with care (e.g. to support a font with large over- or underlengths). git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8429 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/console.c b/console.c index ab1af14e..14642f1b 100644 --- a/console.c +++ b/console.c @@ -1195,7 +1195,7 @@ float Con_WordWidthFunc(void *passthrough, const char *w, size_t *length, float if(w == NULL) { ti->colorindex = -1; - return ti->fontsize * ti->font->width_of[0]; + return ti->fontsize * ti->font->maxwidth; } if(maxWidth >= 0) return DrawQ_TextWidth_Font_UntilWidth(w, length, false, ti->font, maxWidth / ti->fontsize) * ti->fontsize; diff --git a/draw.h b/draw.h index 17c366bc..c4bf81d9 100644 --- a/draw.h +++ b/draw.h @@ -81,7 +81,9 @@ DRAWFLAG_NUMFLAGS typedef struct dp_font_s { 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 + 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!) char texpath[MAX_QPATH]; char title[MAX_QPATH]; } diff --git a/gl_draw.c b/gl_draw.c index f6a7532c..6bb31b20 100644 --- a/gl_draw.c +++ b/gl_draw.c @@ -601,7 +601,7 @@ extern int con_linewidth; // to force rewrapping static void LoadFont(qboolean override, const char *name, dp_font_t *fnt) { int i; - float maxwidth; + float maxwidth, scale; char widthfile[MAX_QPATH]; char *widthbuf; fs_offset_t widthbufsize; @@ -624,6 +624,7 @@ static 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))) @@ -643,6 +644,12 @@ static void LoadFont(qboolean override, const char *name, dp_font_t *fnt) return; extraspacing = atof(com_token); } + else if(!strcmp(com_token, "scale")) + { + if(!COM_ParseToken_Simple(&p, false, false)) + return; + scale = atof(com_token); + } else fnt->width_of[ch++] = atof(com_token) + extraspacing; } @@ -653,7 +660,11 @@ static void LoadFont(qboolean override, const char *name, dp_font_t *fnt) maxwidth = fnt->width_of[1]; for(i = 2; i < 256; ++i) maxwidth = max(maxwidth, fnt->width_of[i]); - fnt->width_of[0] = maxwidth; + fnt->maxwidth = maxwidth; + + // fix up maxwidth for overlap + fnt->maxwidth *= scale; + fnt->scale = scale; if(fnt == FONT_CONSOLE) con_linewidth = -1; // rewrap console in next frame @@ -908,6 +919,8 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors(const char *text, size_t *maxl else colorindex = *outcolor; + maxwidth /= fnt->scale; + for (i = 0;i < *maxlen && text[i];i++) { if (text[i] == ' ') @@ -941,7 +954,7 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors(const char *text, size_t *maxl if (outcolor) *outcolor = colorindex; - return x; + return x * fnt->scale; } float DrawQ_String_Font(float startx, float starty, const char *text, size_t maxlen, float w, float h, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt) @@ -960,6 +973,10 @@ float DrawQ_String_Font(float startx, float starty, const char *text, size_t max tw = R_TextureWidth(fnt->tex); th = R_TextureHeight(fnt->tex); + starty -= (fnt->scale - 1) * h * 0.5; // center + w *= fnt->scale; + h *= fnt->scale; + if (maxlen < 1) maxlen = 1<<30; diff --git a/sbar.c b/sbar.c index f1b5ab58..5594495e 100644 --- a/sbar.c +++ b/sbar.c @@ -1690,9 +1690,9 @@ float Sbar_PrintScoreboardItem(scoreboard_t *s, float x, float y) // // c = palette_rgb_pantsscoreboard[(s->colors & 0xf0) >> 4]; - DrawQ_Fill(x + 14*8*FONT_SBAR->width_of[0], y+1, 40*FONT_SBAR->width_of[0], 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), sbar_alpha_fg.value, 0); + DrawQ_Fill(x + 14*8*FONT_SBAR->maxwidth, y+1, 40*FONT_SBAR->maxwidth, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), sbar_alpha_fg.value, 0); c = palette_rgb_shirtscoreboard[s->colors & 0xf]; - DrawQ_Fill(x + 14*8*FONT_SBAR->width_of[0], y+4, 40*FONT_SBAR->width_of[0], 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), sbar_alpha_fg.value, 0); + DrawQ_Fill(x + 14*8*FONT_SBAR->maxwidth, y+4, 40*FONT_SBAR->maxwidth, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), sbar_alpha_fg.value, 0); // print the text //DrawQ_String(x, y, va("%c%4i %s", myself ? 13 : ' ', (int) s->frags, s->name), 0, 8, 8, 1, 1, 1, 1 * sbar_alpha_fg.value, 0, NULL, true); if (s->qw_ping || s->qw_packetloss) @@ -1714,9 +1714,9 @@ float Sbar_PrintScoreboardItem(scoreboard_t *s, float x, float y) { // draw colors behind score c = palette_rgb_pantsscoreboard[(s->colors & 0xf0) >> 4]; - DrawQ_Fill(x + 9*8*FONT_SBAR->width_of[0], y+1, 40*FONT_SBAR->width_of[0], 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), sbar_alpha_fg.value, 0); + DrawQ_Fill(x + 9*8*FONT_SBAR->maxwidth, y+1, 40*FONT_SBAR->maxwidth, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), sbar_alpha_fg.value, 0); c = palette_rgb_shirtscoreboard[s->colors & 0xf]; - DrawQ_Fill(x + 9*8*FONT_SBAR->width_of[0], y+4, 40*FONT_SBAR->width_of[0], 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), sbar_alpha_fg.value, 0); + DrawQ_Fill(x + 9*8*FONT_SBAR->maxwidth, y+4, 40*FONT_SBAR->maxwidth, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), sbar_alpha_fg.value, 0); // print the text //DrawQ_String(x, y, va("%c%4i %s", myself ? 13 : ' ', (int) s->frags, s->name), 0, 8, 8, 1, 1, 1, 1 * sbar_alpha_fg.value, 0, NULL, true); if (s->qw_ping || s->qw_packetloss) @@ -1774,9 +1774,9 @@ void Sbar_DeathmatchOverlay (void) ymax = 40 + 8 + (Sbar_IsTeammatch() ? (teamlines * 8 + 5): 0) + scoreboardlines * 8 - 1; if (cls.protocol == PROTOCOL_QUAKEWORLD) - xmin = (vid_conwidth.integer - (26 + 15) * 8 * FONT_SBAR->width_of[0]) / 2; // 26 characters until name, then we assume 15 character names (they can be longer but usually aren't) + xmin = (vid_conwidth.integer - (26 + 15) * 8 * FONT_SBAR->maxwidth) / 2; // 26 characters until name, then we assume 15 character names (they can be longer but usually aren't) else - xmin = (vid_conwidth.integer - (16 + 25) * 8 * FONT_SBAR->width_of[0]) / 2; // 16 characters until name, then we assume 25 character names (they can be longer but usually aren't) + xmin = (vid_conwidth.integer - (16 + 25) * 8 * FONT_SBAR->maxwidth) / 2; // 16 characters until name, then we assume 25 character names (they can be longer but usually aren't) xmax = vid_conwidth.integer - xmin; if(gamemode == GAME_NEXUIZ)