2021-05-30 21:00:06 +00:00
|
|
|
/*
|
|
|
|
** razefont.cpp
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2021 Christoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "razefont.h"
|
2021-05-30 22:52:40 +00:00
|
|
|
#include "gamecontrol.h"
|
|
|
|
#include "c_cvars.h"
|
2021-05-30 21:00:06 +00:00
|
|
|
#include "i_interface.h"
|
2021-05-31 09:51:02 +00:00
|
|
|
#include "vm.h"
|
|
|
|
#include "gstrings.h"
|
2021-06-01 09:05:26 +00:00
|
|
|
#include "texturemanager.h"
|
|
|
|
#include "buildtiles.h"
|
2021-05-30 21:00:06 +00:00
|
|
|
|
|
|
|
FGameTexture* GetBaseForChar(FGameTexture* t);
|
|
|
|
void FontCharCreated(FGameTexture* base, FGameTexture* glyph);
|
2023-02-11 09:38:29 +00:00
|
|
|
EXTERN_CVAR(String, language)
|
2021-05-30 21:00:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
FFont* IndexFont;
|
|
|
|
FFont* DigiFont;
|
2021-05-30 22:52:40 +00:00
|
|
|
FFont* BigFont13, * BigFont15;
|
|
|
|
|
|
|
|
CUSTOM_CVAR(Int, duke_menufont, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
|
|
|
|
{
|
|
|
|
if (!(g_gameType & GAMEFLAG_DUKE) || !BigFont13 || !BigFont15) return;
|
|
|
|
if (self < -1 || self > 1) self = -1;
|
2023-02-21 08:30:44 +00:00
|
|
|
// Font info must be copied so that BigFont does not change its address.
|
|
|
|
else if (self == 0 || (self == -1 && isPlutoPak())) OriginalBigFont->CopyFrom(*BigFont15);
|
|
|
|
else if (self == 1 || (self == -1 && !isPlutoPak())) OriginalBigFont->CopyFrom(*BigFont13);
|
2021-05-30 22:52:40 +00:00
|
|
|
}
|
|
|
|
|
2021-06-01 09:05:26 +00:00
|
|
|
#if 0
|
2021-05-30 21:00:06 +00:00
|
|
|
static void SetupHires(FFont *font)
|
|
|
|
{
|
|
|
|
if (!font) return;
|
|
|
|
auto altfont = font->AltFont();
|
|
|
|
if (!altfont) return;
|
|
|
|
// Set up hightile links for the font.
|
|
|
|
for (int i = 33; i < 127; i++)
|
|
|
|
{
|
|
|
|
auto mycode = font->GetCharCode(i, true);
|
|
|
|
if (mycode != i) continue;
|
|
|
|
auto mychar = font->GetChar(i, CR_UNDEFINED, nullptr);
|
|
|
|
if (mychar == nullptr) continue;
|
|
|
|
|
|
|
|
auto altcode = altfont->GetCharCode(i, true);
|
|
|
|
if (altcode != i) continue;
|
|
|
|
auto altchar = altfont->GetChar(i, CR_UNDEFINED, nullptr);
|
|
|
|
if (altchar == nullptr) continue;
|
|
|
|
|
|
|
|
auto base = GetBaseForChar(altchar);
|
|
|
|
if (base == nullptr) continue;
|
|
|
|
FontCharCreated(base, mychar);
|
|
|
|
}
|
|
|
|
}
|
2021-06-01 09:05:26 +00:00
|
|
|
#endif
|
2021-05-30 21:00:06 +00:00
|
|
|
|
|
|
|
void InitFont()
|
|
|
|
{
|
|
|
|
V_InitFonts();
|
|
|
|
BigFont = V_GetFont("BigFont");
|
|
|
|
SmallFont = V_GetFont("SmallFont");
|
|
|
|
SmallFont2 = V_GetFont("SmallFont2");
|
|
|
|
IndexFont = V_GetFont("IndexFont");
|
|
|
|
DigiFont = V_GetFont("DigiFont");
|
|
|
|
|
2021-06-01 09:05:26 +00:00
|
|
|
//SetupHires(BigFont);
|
|
|
|
//SetupHires(SmallFont);
|
2021-05-30 21:00:06 +00:00
|
|
|
|
2021-05-30 22:52:40 +00:00
|
|
|
if (g_gameType & GAMEFLAG_DUKE)
|
|
|
|
{
|
|
|
|
BigFont13 = V_GetFont("BigFont13");
|
|
|
|
BigFont15 = V_GetFont("BigFont15");
|
|
|
|
BigFont = new FFont(0, "BigFont");
|
2021-06-01 09:05:26 +00:00
|
|
|
BigFont->CopyFrom(*BigFont15);
|
2021-05-30 22:52:40 +00:00
|
|
|
}
|
2021-11-28 23:44:28 +00:00
|
|
|
if (!BigFont) BigFont = ConFont;
|
|
|
|
if (!SmallFont) SmallFont = ConFont;
|
|
|
|
|
2021-05-31 19:08:19 +00:00
|
|
|
OriginalSmallFont = SmallFont;
|
|
|
|
OriginalBigFont = BigFont;
|
2021-06-01 09:05:26 +00:00
|
|
|
}
|
2021-05-31 19:08:19 +00:00
|
|
|
|
2021-06-01 09:05:26 +00:00
|
|
|
static int compareChar(int code, FFont* gamefont, FFont* myfont)
|
|
|
|
{
|
|
|
|
auto c1 = gamefont->GetChar(code, CR_UNDEFINED, nullptr);
|
|
|
|
auto c2 = myfont->GetChar(code, CR_UNDEFINED, nullptr);
|
|
|
|
if (c1 == nullptr || c2 == nullptr) return 1; // this should never happen unless one of the fonts is broken.
|
|
|
|
|
|
|
|
if (c1->GetTexelHeight() != c2->GetTexelHeight()) return 0;
|
|
|
|
if (c1->GetTexelWidth() != c2->GetTexelWidth()) return 0;
|
|
|
|
|
|
|
|
// If there's a hires version attached to the base, treat this as the base being different.
|
|
|
|
TexturePick pick;
|
2021-06-01 09:29:39 +00:00
|
|
|
if (PickTexture(c1, 0, pick) && pick.texture != c1) return 0;
|
2021-06-01 09:05:26 +00:00
|
|
|
|
|
|
|
auto t1 = c1->GetTexture();
|
|
|
|
auto t2 = c2->GetTexture();
|
|
|
|
auto buf1 = t1->CreateTexBuffer(0);
|
|
|
|
auto buf2 = t2->CreateTexBuffer(0);
|
|
|
|
// at this point the palette has not yet been fully set up so the alpha channel is not consistent.
|
|
|
|
// We have to mask it out here to be able to compare the two buffers.
|
|
|
|
for (int i = 3; i < buf1.mWidth * buf1.mHeight * 4; i+=4)
|
|
|
|
{
|
|
|
|
buf1.mBuffer[i] = buf2.mBuffer[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int res = memcmp(buf1.mBuffer, buf2.mBuffer, buf1.mWidth * buf1.mHeight * 4);
|
|
|
|
return res == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupFontSubstitution()
|
|
|
|
{
|
2021-05-31 19:08:19 +00:00
|
|
|
auto tilesmallfont = V_GetFont("tilesmallfont");
|
|
|
|
auto tilebigfont = V_GetFont("tilebigfont");
|
|
|
|
|
|
|
|
// Check if the fonts have been altered by a mod.
|
|
|
|
// If that is the case we need to do a bit of remapping to ensure the proper font gets used at least for English text.
|
|
|
|
if (tilesmallfont)
|
|
|
|
{
|
|
|
|
int hits = 0;
|
|
|
|
hits += compareChar('0', tilesmallfont, SmallFont);
|
|
|
|
hits += compareChar('A', tilesmallfont, SmallFont);
|
|
|
|
hits += compareChar('a', tilesmallfont, SmallFont);
|
|
|
|
|
|
|
|
if (hits < 3)
|
|
|
|
{
|
|
|
|
tilesmallfont->SetName(SmallFont->GetName());
|
|
|
|
SmallFont->SetName("OriginalSmallFont");
|
|
|
|
SmallFont = tilesmallfont;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tilebigfont)
|
|
|
|
{
|
|
|
|
int hits = 0;
|
|
|
|
if (g_gameType & GAMEFLAG_DUKE)
|
|
|
|
{
|
|
|
|
hits += compareChar('0', tilebigfont, BigFont13);
|
|
|
|
hits += compareChar('A', tilebigfont, BigFont13);
|
|
|
|
hits += compareChar('0', tilebigfont, BigFont15);
|
|
|
|
hits += compareChar('A', tilebigfont, BigFont15);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hits += compareChar('0', tilebigfont, BigFont);
|
|
|
|
hits += compareChar('A', tilebigfont, BigFont);
|
|
|
|
}
|
2021-05-30 22:52:40 +00:00
|
|
|
|
2021-05-31 19:08:19 +00:00
|
|
|
if (hits < 2)
|
|
|
|
{
|
|
|
|
tilebigfont->SetName(BigFont->GetName());
|
|
|
|
BigFont->SetName("OriginalBigFont");
|
|
|
|
BigFont = tilebigfont;
|
|
|
|
}
|
|
|
|
}
|
2021-05-30 21:00:06 +00:00
|
|
|
}
|
2021-05-31 09:51:02 +00:00
|
|
|
|
|
|
|
FFont* PickBigFont(const char* txt)
|
|
|
|
{
|
|
|
|
if (generic_ui) return NewSmallFont; // Note: Support is incomplete. Translations do not exist anyway for most content.
|
|
|
|
if (!OriginalBigFont || OriginalBigFont == BigFont) return BigFont;
|
|
|
|
if (txt && *txt == '$') txt = GStrings[txt + 1];
|
|
|
|
if (!txt || !*txt) txt = GStrings["REQUIRED_CHARACTERS"];
|
|
|
|
if (!txt || !*txt || BigFont->CanPrint(txt)) return BigFont;
|
|
|
|
return OriginalBigFont;
|
|
|
|
}
|
|
|
|
|
|
|
|
static FFont* PickBigFont_(const FString& str)
|
|
|
|
{
|
|
|
|
return PickBigFont(str.GetChars());
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_ACTION_FUNCTION_NATIVE(_Raze, PickBigFont, PickBigFont_)
|
|
|
|
{
|
|
|
|
PARAM_PROLOGUE;
|
|
|
|
PARAM_STRING(text);
|
|
|
|
//PARAM_POINTER(cr, int);
|
|
|
|
ACTION_RETURN_POINTER(PickBigFont(text));
|
|
|
|
}
|
|
|
|
|
|
|
|
FFont* PickSmallFont(const char* txt)
|
|
|
|
{
|
|
|
|
if (generic_ui) return NewSmallFont; // Note: Support is incomplete. Translations do not exist anyway for most content.
|
|
|
|
if (!OriginalSmallFont || OriginalSmallFont == SmallFont) return SmallFont;
|
|
|
|
if (txt && *txt == '$') txt = GStrings[txt + 1];
|
|
|
|
if (!txt || !*txt) txt = GStrings["REQUIRED_CHARACTERS"];
|
|
|
|
if (!txt || !*txt || SmallFont->CanPrint(txt)) return SmallFont;
|
|
|
|
return OriginalSmallFont;
|
|
|
|
}
|
|
|
|
|
|
|
|
static FFont* PickSmallFont_(const FString& str)
|
|
|
|
{
|
|
|
|
return PickSmallFont(str.GetChars());
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFINE_ACTION_FUNCTION_NATIVE(_Raze, PickSmallFont, PickSmallFont_)
|
|
|
|
{
|
|
|
|
PARAM_PROLOGUE;
|
|
|
|
PARAM_STRING(text);
|
|
|
|
//PARAM_POINTER(cr, int);
|
2021-06-20 13:41:30 +00:00
|
|
|
ACTION_RETURN_POINTER(PickSmallFont(text));
|
2021-05-31 09:51:02 +00:00
|
|
|
}
|