From 952ec8267898d72b4d032ca40010f9dd278b66f5 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 10 Dec 2013 22:59:45 -0800 Subject: [PATCH 1/2] Detect bad fonts ascenders and workaround. Fixes #4765 with the fonts that come with PPSSPP. --- Core/Font/PGF.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Core/Font/PGF.cpp b/Core/Font/PGF.cpp index c1a987b157..9d7810d4f8 100644 --- a/Core/Font/PGF.cpp +++ b/Core/Font/PGF.cpp @@ -30,7 +30,7 @@ // These fonts, created by ttf2pgf, don't have complete glyph info and need to be identified. static bool isJPCSPFont(const char *fontName) { - return !strcmp(fontName, "Liberation") || !strcmp(fontName, "Sazanami") || !strcmp(fontName, "UnDotum"); + return !strcmp(fontName, "Liberation Sans") || !strcmp(fontName, "Liberation Serif") || !strcmp(fontName, "Sazanami") || !strcmp(fontName, "UnDotum") || !strcmp(fontName, "Microsoft YaHei"); } // Gets a number of bits from an offset. @@ -181,6 +181,8 @@ void PGF::ReadPtr(const u8 *ptr, size_t dataSize) { memcpy(&header, ptr, sizeof(header)); ptr += sizeof(header); + fileName = header.fontName; + if (header.revision == 3) { memcpy(&rev3extra, ptr, sizeof(rev3extra)); rev3extra.compCharMapLength1 &= 0xFFFF; From 916768d93822921876cb7341a43fec31c41b8989 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 10 Dec 2013 23:19:25 -0800 Subject: [PATCH 2/2] Kill the "packagedFont" hack, correctly fixed now. --- Core/Font/PGF.cpp | 6 +----- Core/Font/PGF.h | 2 +- Core/HLE/sceFont.cpp | 10 ++-------- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/Core/Font/PGF.cpp b/Core/Font/PGF.cpp index 9d7810d4f8..86015781cc 100644 --- a/Core/Font/PGF.cpp +++ b/Core/Font/PGF.cpp @@ -516,7 +516,7 @@ bool PGF::GetCharGlyph(int charCode, int glyphType, Glyph &glyph) { return true; } -void PGF::DrawCharacter(const GlyphImage *image, int clipX, int clipY, int clipWidth, int clipHeight, int charCode, int altCharCode, int glyphType, bool packagedFont) { +void PGF::DrawCharacter(const GlyphImage *image, int clipX, int clipY, int clipWidth, int clipHeight, int charCode, int altCharCode, int glyphType) { Glyph glyph; if (!GetCharGlyph(charCode, glyphType, glyph)) { // No Glyph available for this charCode, try to use the alternate char. @@ -572,10 +572,6 @@ void PGF::DrawCharacter(const GlyphImage *image, int clipX, int clipY, int clipW int pixelX = x + xx; int pixelY = y + yy; - // Apply offset by 1px for our packaged PSP fonts - if (packagedFont) - pixelX += 1; - if (pixelX >= clipX && pixelX < clipX + clipWidth && pixelY >= clipY && pixelY < clipY + clipHeight) { // 4-bit color value int pixelColor = value; diff --git a/Core/Font/PGF.h b/Core/Font/PGF.h index a0f4f6954c..20848983dd 100644 --- a/Core/Font/PGF.h +++ b/Core/Font/PGF.h @@ -266,7 +266,7 @@ public: bool GetCharInfo(int charCode, PGFCharInfo *ci, int altCharCode); void GetFontInfo(PGFFontInfo *fi); - void DrawCharacter(const GlyphImage *image, int clipX, int clipY, int clipWidth, int clipHeight, int charCode, int altCharCode, int glyphType, bool packagedFont); + void DrawCharacter(const GlyphImage *image, int clipX, int clipY, int clipWidth, int clipHeight, int charCode, int altCharCode, int glyphType); void DoState(PointerWrap &p); diff --git a/Core/HLE/sceFont.cpp b/Core/HLE/sceFont.cpp index 0f5a71ed6f..a015d37fe6 100644 --- a/Core/HLE/sceFont.cpp +++ b/Core/HLE/sceFont.cpp @@ -104,7 +104,6 @@ class LoadedFont; class FontLib; class Font; int GetInternalFontIndex(Font *font); -bool packagedFont; // These should not need to be state saved. static std::vector internalFonts; @@ -519,11 +518,6 @@ void __LoadInternalFonts() { if (pspFileSystem.ReadEntireFile(fontFilename, buffer) < 0) { ERROR_LOG(SCEFONT, "Failed opening font"); continue; - } - // Our provided font of jpn0.pgf has size 4367080 bytes - // This is an ugly hack to workaround incorrect metrics in it. - if (std::string(entry.fileName) == "jpn0.pgf" && (int)info.size == 4367080) { - packagedFont = true; } internalFonts.push_back(new Font(buffer, entry)); @@ -885,7 +879,7 @@ int sceFontGetCharGlyphImage(u32 fontHandle, u32 charCode, u32 glyphImagePtr) { DEBUG_LOG(SCEFONT, "sceFontGetCharGlyphImage(%x, %x, %x)", fontHandle, charCode, glyphImagePtr); auto glyph = Memory::GetStruct(glyphImagePtr); int altCharCode = font->GetFontLib()->GetAltCharCode(); - font->GetPGF()->DrawCharacter(glyph, 0, 0, 8192, 8192, charCode, altCharCode, FONT_PGF_CHARGLYPH, packagedFont); + font->GetPGF()->DrawCharacter(glyph, 0, 0, 8192, 8192, charCode, altCharCode, FONT_PGF_CHARGLYPH); return 0; } @@ -903,7 +897,7 @@ int sceFontGetCharGlyphImage_Clip(u32 fontHandle, u32 charCode, u32 glyphImagePt INFO_LOG(SCEFONT, "sceFontGetCharGlyphImage_Clip(%08x, %i, %08x, %i, %i, %i, %i)", fontHandle, charCode, glyphImagePtr, clipXPos, clipYPos, clipWidth, clipHeight); auto glyph = Memory::GetStruct(glyphImagePtr); int altCharCode = font->GetFontLib()->GetAltCharCode(); - font->GetPGF()->DrawCharacter(glyph, clipXPos, clipYPos, clipXPos + clipWidth, clipYPos + clipHeight, charCode, altCharCode, FONT_PGF_CHARGLYPH, packagedFont); + font->GetPGF()->DrawCharacter(glyph, clipXPos, clipYPos, clipXPos + clipWidth, clipYPos + clipHeight, charCode, altCharCode, FONT_PGF_CHARGLYPH); return 0; }