Files
SatyandClaude Opus 5.5 860511ea4d Gxu: port the font and light TUs
GxuFontMain.cpp (0x6BCD60-0x6BF370), GxuFontUtil.cpp, GxuFontFont.cpp,
GxuFontFace.cpp, GxuFontString.cpp, GxuFontMiscClasses.cpp,
GxuFontTextureCache.cpp and IGxuFontGlyph.cpp, named after the 12340 and
Mac 13682 source file strings; CGxFont moves from Gx to Gxu.
GxuLight.cpp (0x6BB510-0x6BCD60): the light grid behind the GxuLight*
function-pointer table at 0xAD9834.

Gxu links FreeType 2.0.1. Shared additions: GxBufDestroy, GxFormatColor,
CGxVertexPC/PCT, CMath fint_n/fuint_pi/CeilToInt64, C3Vector::SquaredMag,
HASHKEY_DWORD and the template instances in stpl.h.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
2026-09-27 00:15:42 +02:00

112 lines
2.7 KiB
C++

#include <cstddef>
#include <cstdint>
#include "Engine/Source/Gxu/GxuFontFace.h"
#include "Engine/Source/BlizzardCore/SFile2-Core.h"
#include "Engine/Source/Storm/H/storm.h"
// STATIC: 0x00C7D2FC
TSHashTable<FACEDATA, HASHKEY_STRI> s_faceHash;
// VERIFY: e0237d01 auto
// OFFSET: 0x006C8080
FT_Face FontFaceGetFace(HFACE handle) {
if (!handle) {
SErrSetLastError(STORM_ERROR_INVALID_PARAMETER);
return nullptr;
}
return reinterpret_cast<FACEDATA*>(handle)->m_face;
}
// VERIFY: 5082eae0 auto
// OFFSET: 0x006C80A0
void FontFaceCloseHandle(HFACE handle) {
if (!handle) {
SErrSetLastError(STORM_ERROR_INVALID_PARAMETER);
return;
}
FACEDATA* face = reinterpret_cast<FACEDATA*>(handle);
HandleClose(reinterpret_cast<HOBJECT>(handle));
if (face->m_refcount <= 1) {
HOBJECT selfReference = face->m_selfReference;
face->m_selfReference = nullptr;
HandleClose(selfReference);
}
}
// VERIFY: c0728d10 auto
// OFFSET: 0x006C80E0
const char* FontFaceGetFontName(HFACE handle) {
if (!handle) {
SErrSetLastError(STORM_ERROR_INVALID_PARAMETER);
return nullptr;
}
return reinterpret_cast<FACEDATA*>(handle)->m_key.m_str;
}
// VERIFY: 63774048 manual
// OFFSET: 0x006C8190
FACEDATA::FACEDATA() {
this->m_data = nullptr;
this->m_face = nullptr;
}
// VERIFY: 263b0e27 manual
// OFFSET: 0x006C81C0
FACEDATA::~FACEDATA() {
if (this->m_face) {
FT_Done_Face(this->m_face);
}
if (this->m_data) {
SFile::Unload(this->m_data);
}
}
// VERIFY: 45a8d799 auto
// OFFSET: 0x006C8AE0
HFACE FontFaceGetHandle(const char* fileName, FT_Library library) {
if (!library || !fileName || !*fileName) {
return nullptr;
}
FACEDATA* existing = s_faceHash.Ptr(fileName);
if (existing) {
return reinterpret_cast<HFACE>(HandleDuplicate(existing->m_selfReference));
}
HFACE handle = nullptr;
void* data = nullptr;
uint32_t size;
if (SFile::ReadFile(nullptr, fileName, &data, &size, 0, 3, nullptr)) {
if (!data) {
return handle;
}
FT_Face ftFace;
if (!FT_New_Memory_Face(library, static_cast<FT_Byte*>(data), size, 0, &ftFace) && ftFace && !FT_Select_Charmap(ftFace, ft_encoding_unicode)) {
FACEDATA* face = new ("HFACE", SLOG_OBJECT) FACEDATA;
face->m_data = data;
face->m_face = ftFace;
s_faceHash.Insert(face, fileName);
data = nullptr;
ftFace = nullptr;
face->m_selfReference = HandleCreate(face, "HFACE");
handle = reinterpret_cast<HFACE>(HandleDuplicate(face->m_selfReference));
}
}
if (data) {
SFile::Unload(data);
}
return handle;
}