diff --git a/Common/ChunkFile.h b/Common/ChunkFile.h index 8bf1c82232..982d854680 100644 --- a/Common/ChunkFile.h +++ b/Common/ChunkFile.h @@ -84,7 +84,7 @@ class PointerWrap static void DoArray(PointerWrap *p, T *x, int count) { for (int i = 0; i < count; ++i) - p->DoClass(x[i]); + p->Do(x[i]); } static void Do(PointerWrap *p, T &x) diff --git a/Core/Font/PGF.cpp b/Core/Font/PGF.cpp index 635d1021f0..eca139eb35 100644 --- a/Core/Font/PGF.cpp +++ b/Core/Font/PGF.cpp @@ -23,6 +23,7 @@ #include "Common/CommonTypes.h" #include "Core/MemMap.h" #include "Core/Font/PGF.h" +#include "Core/HLE/HLE.h" // These fonts, created by ttf2pgf, don't have complete glyph info and need to be identified. static bool isJPCSPFont(const char *fontName) { @@ -50,19 +51,48 @@ static std::vector getTable(const u8 *buf, int bpe, int length) { } PGF::PGF() - : fontData(0), charMap(0), shadowCharMap(0), charPointerTable(0) { + : fontData(0) { } PGF::~PGF() { - delete [] fontData; - delete [] charMap; - delete [] shadowCharMap; - delete [] charPointerTable; + if (fontData) { + delete [] fontData; + } } void PGF::DoState(PointerWrap &p) { - // TODO! + p.Do(header); + p.Do(rev3extra); + + p.Do(fontDataSize); + if (p.mode == p.MODE_READ) { + if (fontData) { + delete [] fontData; + } + if (fontDataSize) { + fontData = new u8[fontDataSize]; + p.DoArray(fontData, fontDataSize); + } + } else if (fontDataSize) { + p.DoArray(fontData, fontDataSize); + } + p.Do(fileName); + + p.DoArray(dimensionTable, ARRAY_SIZE(dimensionTable)); + p.DoArray(xAdjustTable, ARRAY_SIZE(xAdjustTable)); + p.DoArray(yAdjustTable, ARRAY_SIZE(yAdjustTable)); + p.DoArray(advanceTable, ARRAY_SIZE(advanceTable)); + p.DoArray(charmapCompressionTable1, ARRAY_SIZE(charmapCompressionTable1)); + p.DoArray(charmapCompressionTable2, ARRAY_SIZE(charmapCompressionTable2)); + + p.Do(charmap_compr); + p.Do(charmap); + p.Do(glyphs); + p.Do(shadowGlyphs); + p.Do(firstGlyph); + + p.DoMarker("PGF"); } void PGF::ReadPtr(const u8 *ptr, size_t dataSize) { @@ -111,7 +141,7 @@ void PGF::ReadPtr(const u8 *ptr, size_t dataSize) { const u8 *uptr = (const u8 *)wptr; int shadowCharMapSize = ((header.shadowMapLength * header.shadowMapBpe + 31) & ~31) / 8; - shadowCharMap = new u8[shadowCharMapSize]; + u8 *shadowCharMap = new u8[shadowCharMapSize]; for (int i = 0; i < shadowCharMapSize; i++) { shadowCharMap[i] = *uptr++; } @@ -137,13 +167,13 @@ void PGF::ReadPtr(const u8 *ptr, size_t dataSize) { int charMapSize = ((header.charMapLength * header.charMapBpe + 31) & ~31) / 8; - charMap = new u8[charMapSize]; + u8 *charMap = new u8[charMapSize]; for (int i = 0; i < charMapSize; i++) { charMap[i] = *uptr++; } int charPointerSize = (((header.charPointerLength * header.charPointerBpe + 31) & ~31) / 8); - charPointerTable = new u8[charPointerSize]; + u8 *charPointerTable = new u8[charPointerSize]; for (int i = 0; i < charPointerSize; i++) { charPointerTable[i] = *uptr++; } @@ -175,6 +205,10 @@ void PGF::ReadPtr(const u8 *ptr, size_t dataSize) { std::vector charPointers = getTable(charPointerTable, header.charPointerBpe, glyphs.size()); std::vector shadowMap = getTable(shadowCharMap, header.shadowMapBpe, shadowGlyphs.size()); + delete [] charMap; + delete [] shadowCharMap; + delete [] charPointerTable; + // Pregenerate glyphs. for (size_t i = 0; i < glyphs.size(); i++) { GetGlyph(fontData, charPointers[i] * 4 * 8 /* ??? */, FONT_PGF_CHARGLYPH, glyphs[i]); diff --git a/Core/Font/PGF.h b/Core/Font/PGF.h index bba9f29d3d..3a133394ed 100644 --- a/Core/Font/PGF.h +++ b/Core/Font/PGF.h @@ -91,8 +91,7 @@ struct PGFFontStyle { }; -class Glyph { -public: +struct Glyph { int x; int y; int w; @@ -276,10 +275,6 @@ private: std::vector charmapCompressionTable1[2]; std::vector charmapCompressionTable2[2]; - u8 *charMap; - u8 *shadowCharMap; - u8 *charPointerTable; - std::vector charmap_compr; std::vector charmap; diff --git a/Core/HLE/sceFont.cpp b/Core/HLE/sceFont.cpp index 9f6118cfe3..12bf74fe01 100644 --- a/Core/HLE/sceFont.cpp +++ b/Core/HLE/sceFont.cpp @@ -183,7 +183,7 @@ private: class LoadedFont { public: // For savestates only. - LoadedFont() { + LoadedFont() : font_(NULL) { } LoadedFont(Font *font, u32 fontLibID, u32 handle)