diff --git a/Core/Font/PGF.cpp b/Core/Font/PGF.cpp index 23db5391ea..4095d70479 100644 --- a/Core/Font/PGF.cpp +++ b/Core/Font/PGF.cpp @@ -276,7 +276,7 @@ bool PGF::ReadPtr(const u8 *ptr, size_t dataSize) { int charmap_compr_len = header.revision == 3 ? 7 : 1; charmap_compr.resize(charmap_compr_len * 4); glyphs.resize(header.charPointerLength); - shadowGlyphs.resize(header.shadowMapLength); + shadowGlyphs.resize(header.charPointerLength); firstGlyph = header.firstGlyph; // Parse out the char map (array where each entry is an irregular number of bits) @@ -289,7 +289,7 @@ bool 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()); + std::vector shadowMap = getTable(shadowCharMap, header.shadowMapBpe, (s32)header.shadowMapLength); // Pregenerate glyphs. for (size_t i = 0; i < glyphs.size(); i++) { @@ -299,11 +299,11 @@ bool PGF::ReadPtr(const u8 *ptr, size_t dataSize) { // And shadow glyphs. for (size_t i = 0; i < glyphs.size(); i++) { size_t shadowId = glyphs[i].shadowID; - if ((shadowId < shadowMap.size()) && (shadowId < shadowGlyphs.size())) { + if (shadowId < shadowMap.size()) { size_t charId = shadowMap[shadowId]; - if (charId < glyphs.size()) { + if (charId < shadowGlyphs.size()) { // TODO: check for pre existing shadow glyph - GetGlyph(fontData, charPointers[charId] * 4 * 8 /* ??? */, FONT_PGF_SHADOWGLYPH, shadowGlyphs[shadowId]); + GetGlyph(fontData, charPointers[charId] * 4 * 8 /* ??? */, FONT_PGF_SHADOWGLYPH, shadowGlyphs[charId]); } } } diff --git a/Core/HLE/sceFont.cpp b/Core/HLE/sceFont.cpp index 96a263af2f..ac2974cd80 100644 --- a/Core/HLE/sceFont.cpp +++ b/Core/HLE/sceFont.cpp @@ -1059,7 +1059,7 @@ int sceFontGetCharGlyphImage(u32 fontHandle, u32 charCode, u32 glyphImagePtr) { DEBUG_LOG(SCEFONT, "sceFontGetCharGlyphImage(%x, %x, %x)", fontHandle, charCode, glyphImagePtr); auto glyph = PSPPointer::Create(glyphImagePtr); int altCharCode = font->GetFontLib()->GetAltCharCode(); - font->GetPGF()->DrawCharacter(glyph, 0, 0, 8192, 8192, charCode, altCharCode, FONT_PGF_CHARGLYPH); + font->GetPGF()->DrawCharacter(glyph, -1, -1, -1, -1, charCode, altCharCode, FONT_PGF_CHARGLYPH); return 0; } @@ -1175,13 +1175,39 @@ int sceFontCalcMemorySize() { return 0; } -int sceFontGetShadowGlyphImage() { - ERROR_LOG_REPORT(SCEFONT, "UNIMPL sceFontGetShadowGlyphImage()"); +int sceFontGetShadowGlyphImage(u32 fontHandle, u32 charCode, u32 glyphImagePtr) { + if (!Memory::IsValidAddress(glyphImagePtr)) { + ERROR_LOG(SCEFONT, "sceFontGetShadowGlyphImage(%x, %x, %x): bad glyphImage pointer", fontHandle, charCode, glyphImagePtr); + return ERROR_FONT_INVALID_PARAMETER; + } + LoadedFont *font = GetLoadedFont(fontHandle, true); + if (!font) { + ERROR_LOG_REPORT(SCEFONT, "sceFontGetShadowGlyphImage(%x, %x, %x): bad font", fontHandle, charCode, glyphImagePtr); + return ERROR_FONT_INVALID_PARAMETER; + } + + DEBUG_LOG(SCEFONT, "sceFontGetShadowGlyphImage(%x, %x, %x)", fontHandle, charCode, glyphImagePtr); + auto glyph = PSPPointer::Create(glyphImagePtr); + int altCharCode = font->GetFontLib()->GetAltCharCode(); + font->GetPGF()->DrawCharacter(glyph, -1, -1, -1, -1, charCode, altCharCode, FONT_PGF_SHADOWGLYPH); return 0; } -int sceFontGetShadowGlyphImage_Clip() { - ERROR_LOG_REPORT(SCEFONT, "UNIMPL sceFontGetShadowGlyphImage_Clip()"); +int sceFontGetShadowGlyphImage_Clip(u32 fontHandle, u32 charCode, u32 glyphImagePtr, int clipXPos, int clipYPos, int clipWidth, int clipHeight) { + if (!Memory::IsValidAddress(glyphImagePtr)) { + ERROR_LOG(SCEFONT, "sceFontGetShadowGlyphImage_Clip(%08x, %i, %08x, %i, %i, %i, %i): bad glyphImage pointer", fontHandle, charCode, glyphImagePtr, clipXPos, clipYPos, clipWidth, clipHeight); + return ERROR_FONT_INVALID_PARAMETER; + } + LoadedFont *font = GetLoadedFont(fontHandle, true); + if (!font) { + ERROR_LOG_REPORT(SCEFONT, "sceFontGetShadowGlyphImage_Clip(%08x, %i, %08x, %i, %i, %i, %i): bad font", fontHandle, charCode, glyphImagePtr, clipXPos, clipYPos, clipWidth, clipHeight); + return ERROR_FONT_INVALID_PARAMETER; + } + + DEBUG_LOG(SCEFONT, "sceFontGetShadowGlyphImage_Clip(%08x, %i, %08x, %i, %i, %i, %i)", fontHandle, charCode, glyphImagePtr, clipXPos, clipYPos, clipWidth, clipHeight); + auto glyph = PSPPointer::Create(glyphImagePtr); + int altCharCode = font->GetFontLib()->GetAltCharCode(); + font->GetPGF()->DrawCharacter(glyph, clipXPos, clipYPos, clipWidth, clipHeight, charCode, altCharCode, FONT_PGF_SHADOWGLYPH); return 0; } @@ -1211,8 +1237,8 @@ const HLEFunction sceLibFont[] = { {0x472694cd, WrapF_IFU, "sceFontPointToPixelH"}, {0x3c4b7e82, WrapF_IFU, "sceFontPointToPixelV"}, {0xee232411, WrapI_UU, "sceFontSetAltCharacterCode"}, - {0x568be516, WrapI_V, "sceFontGetShadowGlyphImage"}, - {0x5dcf6858, WrapI_V, "sceFontGetShadowGlyphImage_Clip"}, + {0x568be516, WrapI_UUU, "sceFontGetShadowGlyphImage"}, + {0x5dcf6858, WrapI_UUUIIII, "sceFontGetShadowGlyphImage_Clip"}, {0x02d7f94b, WrapI_U, "sceFontFlush"}, };