2020-04-11 17:51:22 +00:00
|
|
|
#pragma once
|
2016-03-01 15:47:10 +00:00
|
|
|
/*
|
|
|
|
** v_font.h
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 1998-2008 Randy Heit
|
|
|
|
** 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.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-04-11 11:36:23 +00:00
|
|
|
#include "filesystem.h"
|
2019-02-17 18:15:57 +00:00
|
|
|
#include "vectors.h"
|
2020-04-11 17:10:22 +00:00
|
|
|
#include "palentry.h"
|
|
|
|
#include "name.h"
|
2023-11-09 21:55:49 +00:00
|
|
|
#include "palettecontainer.h"
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2020-04-13 23:23:37 +00:00
|
|
|
class FGameTexture;
|
2020-03-16 16:23:30 +00:00
|
|
|
struct FRemapTable;
|
2021-07-11 07:51:59 +00:00
|
|
|
class FFont;
|
|
|
|
|
|
|
|
FFont* V_GetFont(const char* fontname, const char* fontlumpname = nullptr);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-02-10 10:44:46 +00:00
|
|
|
enum EColorRange : int
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
CR_UNDEFINED = -1,
|
2021-07-11 07:51:59 +00:00
|
|
|
CR_NATIVEPAL = -1,
|
2016-03-01 15:47:10 +00:00
|
|
|
CR_BRICK,
|
|
|
|
CR_TAN,
|
|
|
|
CR_GRAY,
|
|
|
|
CR_GREY = CR_GRAY,
|
|
|
|
CR_GREEN,
|
|
|
|
CR_BROWN,
|
|
|
|
CR_GOLD,
|
|
|
|
CR_RED,
|
|
|
|
CR_BLUE,
|
|
|
|
CR_ORANGE,
|
|
|
|
CR_WHITE,
|
|
|
|
CR_YELLOW,
|
|
|
|
CR_UNTRANSLATED,
|
|
|
|
CR_BLACK,
|
|
|
|
CR_LIGHTBLUE,
|
|
|
|
CR_CREAM,
|
|
|
|
CR_OLIVE,
|
|
|
|
CR_DARKGREEN,
|
|
|
|
CR_DARKRED,
|
|
|
|
CR_DARKBROWN,
|
|
|
|
CR_PURPLE,
|
|
|
|
CR_DARKGRAY,
|
|
|
|
CR_CYAN,
|
2017-09-23 08:01:07 +00:00
|
|
|
CR_ICE,
|
|
|
|
CR_FIRE,
|
|
|
|
CR_SAPPHIRE,
|
|
|
|
CR_TEAL,
|
2017-02-03 23:19:25 +00:00
|
|
|
NUM_TEXT_COLORS,
|
2016-03-01 15:47:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern int NumTextColors;
|
|
|
|
|
2020-04-13 23:23:37 +00:00
|
|
|
using GlyphSet = TMap<int, FGameTexture*>;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
class FFont
|
|
|
|
{
|
2020-05-04 18:06:54 +00:00
|
|
|
friend void V_LoadTranslations();
|
2016-03-01 15:47:10 +00:00
|
|
|
public:
|
2019-03-02 11:54:46 +00:00
|
|
|
|
|
|
|
enum EFontType
|
|
|
|
{
|
|
|
|
Unknown,
|
|
|
|
Folder,
|
|
|
|
Multilump,
|
|
|
|
Fon1,
|
|
|
|
Fon2,
|
|
|
|
BMF,
|
|
|
|
Custom
|
|
|
|
};
|
|
|
|
|
2020-04-11 17:51:22 +00:00
|
|
|
FFont (const char *fontname, const char *nametemplate, const char *filetemplate, int first, int count, int base, int fdlump, int spacewidth=-1, bool notranslate = false, bool iwadonly = false, bool doomtemplate = false, GlyphSet *baseGlpyphs = nullptr);
|
2021-07-11 07:51:59 +00:00
|
|
|
FFont(int lump, FName nm = NAME_None);
|
2016-03-01 15:47:10 +00:00
|
|
|
virtual ~FFont ();
|
|
|
|
|
2021-05-24 19:24:17 +00:00
|
|
|
virtual FGameTexture *GetChar (int code, int translation, int *const width) const;
|
2016-03-01 15:47:10 +00:00
|
|
|
virtual int GetCharWidth (int code) const;
|
2023-11-09 21:55:49 +00:00
|
|
|
FTranslationID GetColorTranslation (EColorRange range, PalEntry *color = nullptr) const;
|
2016-03-01 15:47:10 +00:00
|
|
|
int GetLump() const { return Lump; }
|
|
|
|
int GetSpaceWidth () const { return SpaceWidth; }
|
|
|
|
int GetHeight () const { return FontHeight; }
|
|
|
|
int GetDefaultKerning () const { return GlobalKerning; }
|
2019-07-30 08:52:24 +00:00
|
|
|
int GetMaxAscender(const uint8_t* text) const;
|
|
|
|
int GetMaxAscender(const char* text) const { return GetMaxAscender((uint8_t*)text); }
|
|
|
|
int GetMaxAscender(const FString &text) const { return GetMaxAscender((uint8_t*)text.GetChars()); }
|
2016-03-01 15:47:10 +00:00
|
|
|
virtual void LoadTranslations();
|
2017-02-05 12:14:22 +00:00
|
|
|
FName GetName() const { return FontName; }
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-02-05 12:14:22 +00:00
|
|
|
static FFont *FindFont(FName fontname);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Return width of string in pixels (unscaled)
|
2020-04-13 10:11:14 +00:00
|
|
|
int StringWidth (const uint8_t *str, int spacing = 0) const;
|
|
|
|
inline int StringWidth (const char *str, int spacing = 0) const { return StringWidth ((const uint8_t *)str, spacing); }
|
|
|
|
inline int StringWidth (const FString &str, int spacing = 0) const { return StringWidth ((const uint8_t *)str.GetChars(), spacing); }
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2019-04-22 07:08:43 +00:00
|
|
|
// Checks if the font contains all characters to print this text.
|
|
|
|
bool CanPrint(const uint8_t *str) const;
|
|
|
|
inline bool CanPrint(const char *str) const { return CanPrint((const uint8_t *)str); }
|
|
|
|
inline bool CanPrint(const FString &str) const { return CanPrint((const uint8_t *)str.GetChars()); }
|
|
|
|
|
2021-07-11 07:51:59 +00:00
|
|
|
inline FFont* AltFont()
|
|
|
|
{
|
|
|
|
if (AltFontName != NAME_None) return V_GetFont(AltFontName.GetChars());
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
int GetCharCode(int code, bool needpic) const;
|
|
|
|
char GetCursor() const { return Cursor; }
|
|
|
|
void SetCursor(char c) { Cursor = c; }
|
2019-02-21 00:02:42 +00:00
|
|
|
void SetKerning(int c) { GlobalKerning = c; }
|
2021-07-11 07:51:59 +00:00
|
|
|
void SetHeight(int c) { FontHeight = c; }
|
|
|
|
void ClearOffsets();
|
2017-02-26 18:29:27 +00:00
|
|
|
bool NoTranslate() const { return noTranslate; }
|
2020-10-17 12:00:29 +00:00
|
|
|
virtual void RecordAllTextureColors(uint32_t *usedcolors);
|
2019-04-22 07:08:43 +00:00
|
|
|
void CheckCase();
|
2021-07-11 07:51:59 +00:00
|
|
|
void SetName(FName nm) { FontName = nm; }
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2019-07-12 18:09:15 +00:00
|
|
|
int GetDisplacement() const { return Displacement; }
|
2019-03-21 20:57:39 +00:00
|
|
|
|
2021-05-24 19:24:17 +00:00
|
|
|
static int GetLuminosity(uint32_t* colorsused, TArray<double>& Luminosity, int* minlum = nullptr, int* maxlum = nullptr);
|
2021-05-29 13:24:05 +00:00
|
|
|
EFontType GetType() const { return Type; }
|
|
|
|
|
2021-07-11 07:51:59 +00:00
|
|
|
friend void V_InitCustomFonts();
|
|
|
|
|
|
|
|
void CopyFrom(const FFont& other)
|
|
|
|
{
|
|
|
|
Type = other.Type;
|
|
|
|
FirstChar = other.FirstChar;
|
|
|
|
LastChar = other.LastChar;
|
|
|
|
SpaceWidth = other.SpaceWidth;
|
|
|
|
FontHeight = other.FontHeight;
|
|
|
|
GlobalKerning = other.GlobalKerning;
|
|
|
|
TranslationType = other.TranslationType;
|
|
|
|
Displacement = other.Displacement;
|
|
|
|
Cursor = other.Cursor;
|
|
|
|
noTranslate = other.noTranslate;
|
|
|
|
MixedCase = other.MixedCase;
|
|
|
|
forceremap = other.forceremap;
|
|
|
|
Chars = other.Chars;
|
|
|
|
Translations = other.Translations;
|
2023-02-11 11:05:45 +00:00
|
|
|
lowercaselatinonly = other.lowercaselatinonly;
|
2021-07-11 07:51:59 +00:00
|
|
|
Lump = other.Lump;
|
|
|
|
}
|
2019-03-21 20:57:39 +00:00
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
void FixXMoves();
|
|
|
|
|
2023-08-22 19:20:28 +00:00
|
|
|
void ReadSheetFont(std::vector<FileSys::FolderEntry> &folderdata, int width, int height, const DVector2 &Scale);
|
2019-02-17 18:15:57 +00:00
|
|
|
|
2019-03-02 11:54:46 +00:00
|
|
|
EFontType Type = EFontType::Unknown;
|
2021-07-11 07:51:59 +00:00
|
|
|
FName AltFontName = NAME_None;
|
2016-03-01 15:47:10 +00:00
|
|
|
int FirstChar, LastChar;
|
|
|
|
int SpaceWidth;
|
|
|
|
int FontHeight;
|
|
|
|
int GlobalKerning;
|
2019-02-17 10:43:04 +00:00
|
|
|
int TranslationType = 0;
|
2019-07-12 18:09:15 +00:00
|
|
|
int Displacement = 0;
|
2021-07-11 07:51:59 +00:00
|
|
|
int16_t MinLum = -1, MaxLum = -1;
|
2016-03-01 15:47:10 +00:00
|
|
|
char Cursor;
|
2020-05-04 18:06:54 +00:00
|
|
|
bool noTranslate = false;
|
2019-02-17 22:18:28 +00:00
|
|
|
bool MixedCase = false;
|
2019-04-21 07:51:53 +00:00
|
|
|
bool forceremap = false;
|
2023-02-11 11:05:45 +00:00
|
|
|
bool lowercaselatinonly = false;
|
2016-03-01 15:47:10 +00:00
|
|
|
struct CharData
|
|
|
|
{
|
2021-05-24 19:24:17 +00:00
|
|
|
FGameTexture *OriginalPic = nullptr;
|
2018-12-15 22:32:49 +00:00
|
|
|
int XMove = INT_MIN;
|
2018-12-15 10:55:21 +00:00
|
|
|
};
|
|
|
|
TArray<CharData> Chars;
|
2023-11-09 21:55:49 +00:00
|
|
|
TArray<FTranslationID> Translations;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
int Lump;
|
2018-08-18 23:14:15 +00:00
|
|
|
FName FontName = NAME_None;
|
2016-03-01 15:47:10 +00:00
|
|
|
FFont *Next;
|
|
|
|
|
|
|
|
static FFont *FirstFont;
|
|
|
|
friend struct FontsDeleter;
|
|
|
|
|
|
|
|
friend void V_ClearFonts();
|
2019-03-02 11:54:46 +00:00
|
|
|
friend void V_InitFonts();
|
2016-03-01 15:47:10 +00:00
|
|
|
};
|
|
|
|
|
2020-10-17 12:00:29 +00:00
|
|
|
extern FFont *SmallFont, *SmallFont2, *BigFont, *BigUpper, *ConFont, *IntermissionFont, *NewConsoleFont, *NewSmallFont, *CurrentConsoleFont, *OriginalSmallFont, *AlternativeSmallFont, *OriginalBigFont, *AlternativeBigFont;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
void V_InitFonts();
|
|
|
|
void V_ClearFonts();
|
|
|
|
EColorRange V_FindFontColor (FName name);
|
|
|
|
PalEntry V_LogColorFromColorRange (EColorRange range);
|
2017-03-08 17:47:52 +00:00
|
|
|
EColorRange V_ParseFontColor (const uint8_t *&color_value, int normalcolor, int boldcolor);
|
2016-03-01 15:47:10 +00:00
|
|
|
void V_InitFontColors();
|
2019-08-20 18:10:54 +00:00
|
|
|
char* CleanseString(char* str);
|
2023-11-09 21:55:49 +00:00
|
|
|
void V_ApplyLuminosityTranslation(const LuminosityTranslationDesc& lum, uint8_t* pixel, int size);
|
2020-05-04 18:06:54 +00:00
|
|
|
void V_LoadTranslations();
|
2021-05-24 19:24:17 +00:00
|
|
|
class FBitmap;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2019-04-09 22:45:32 +00:00
|
|
|
|