metaforce/Runtime/GuiSys/CRasterFont.hpp

98 lines
2.6 KiB
C++
Raw Normal View History

2016-03-11 00:23:16 +00:00
#ifndef __URDE_CRASTERFONT_HPP__
#define __URDE_CRASTERFONT_HPP__
2016-03-11 22:52:55 +00:00
#include "IOStreams.hpp"
2016-03-12 05:10:14 +00:00
#include "CToken.hpp"
2016-03-11 22:52:55 +00:00
2016-03-11 00:23:16 +00:00
namespace urde
{
2016-03-11 22:52:55 +00:00
class IObjectStore;
2016-03-12 05:10:14 +00:00
class CTexture;
2016-03-11 22:52:55 +00:00
class CGlyph
{
wchar_t x0_char;
s16 x2_leftPadding;
s16 x4_advance;
s16 x6_rightPadding;
float x8_startU;
float xc_startV;
float x10_endU;
float x14_endV;
s16 x18_cellWidth;
s16 x1a_cellHeight;
s16 x1c_baseline;
s16 x1e_kernStart;
s16 GetA() const { return x2_leftPadding; }
s16 GetB() const { return x4_advance; }
s16 GetC() const { return x6_rightPadding; }
float GetStartU() const { return x8_startU; }
float GetStartV() const { return xc_startV; }
float GetEndU() const { return x10_endU; }
float GetEndV() const { return x14_endV; }
2016-03-12 19:42:47 +00:00
s16 GetCellWidth() const { return x18_cellWidth; }
2016-03-11 22:52:55 +00:00
s16 GetCellHeight() const { return x1a_cellHeight; }
s16 GetBaseline() const { return x1c_baseline; }
s16 GetKernStart() const { return x1e_kernStart; }
};
struct CKernPair
{
wchar_t x0_first;
wchar_t x2_second;
s32 x4_howMuch;
wchar_t GetFirst() const { return x0_first; }
wchar_t GetSecond() const { return x2_second; }
s32 GetHowMuch() const { return x4_howMuch; }
};
2016-03-11 00:23:16 +00:00
class CRasterFont
{
2016-03-11 22:52:55 +00:00
bool x0_ = false;
2016-03-12 05:10:14 +00:00
s32 x4_monoWidth = 16;
s32 x8_monoHeight = 16;
std::unordered_map<wchar_t, CGlyph> xc_glyphs;
2016-03-11 22:52:55 +00:00
std::vector<CKernPair> x1c_kerning;
2016-03-12 05:10:14 +00:00
s32 x2c_mode;
2016-03-11 22:52:55 +00:00
s32 x30_;
2016-03-12 05:10:14 +00:00
TToken<CTexture> x80_texture;
s32 x8c_baseline;
2016-03-11 22:52:55 +00:00
s32 x90_;
2016-03-12 05:10:14 +00:00
CGlyph* InternalGetGlyph(wchar_t chr)
{
if (xc_glyphs.find(chr) == xc_glyphs.end())
return nullptr;
return &xc_glyphs[chr];
}
2016-03-11 22:52:55 +00:00
public:
CRasterFont(CInputStream& in, IObjectStore& store);
2016-03-12 05:10:14 +00:00
s32 GetMonoWidth() { return x4_monoWidth; }
s32 GetMonoHeight() { return x8_monoHeight; }
s32 GetMode() { return x2c_mode; }
s32 sub_802FFF5C() { return x90_; }
s32 GetBaseline() { return x8c_baseline; }
2016-03-11 22:52:55 +00:00
static s32 KernLookup(const std::vector<CKernPair>& kernTable, s32 kernStart, s32 chr)
{
2016-03-11 22:59:54 +00:00
auto iter = kernTable.cbegin() + kernStart;
2016-03-11 23:19:02 +00:00
for (; iter != kernTable.cend() && iter->GetFirst() == kernTable[kernStart].GetFirst() ; ++iter)
2016-03-11 22:52:55 +00:00
{
2016-03-11 23:19:02 +00:00
if (iter->GetSecond() == chr)
return iter->GetHowMuch();
2016-03-11 22:52:55 +00:00
}
return 0;
}
2016-03-11 00:23:16 +00:00
};
2016-03-12 05:10:14 +00:00
std::unique_ptr<IObj> FRasterFontFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms);
2016-03-11 00:23:16 +00:00
}
#endif // __URDE_CRASTERFONT_HPP__