From 68af1ea6f8e53ab26bf0d7343493eb280ab322c7 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 16 Nov 2013 18:32:06 -0800 Subject: [PATCH 01/10] Flip the descender in char info. This makes it close to the value from a PSP (just rounded to 64...) --- Core/Font/PGF.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/Font/PGF.cpp b/Core/Font/PGF.cpp index c7f8689070..01f26808f9 100644 --- a/Core/Font/PGF.cpp +++ b/Core/Font/PGF.cpp @@ -263,7 +263,8 @@ bool PGF::GetCharInfo(int charCode, PGFCharInfo *charInfo) { charInfo->sfp26Width = glyph.dimensionWidth; charInfo->sfp26Height = glyph.dimensionHeight; charInfo->sfp26Ascender = glyph.top << 6; - charInfo->sfp26Descender = (glyph.h - glyph.top) << 6; + // Font y goes upwards. If top is 10 and height is 11, the descender is approx. -1 (below 0.) + charInfo->sfp26Descender = (glyph.top - glyph.h) << 6; charInfo->sfp26BearingHX = glyph.xAdjustH; charInfo->sfp26BearingHY = glyph.yAdjustH; charInfo->sfp26BearingVX = glyph.xAdjustV; From 2d7741a433efdbeadf6c83e447b28046250a5cad Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 16 Nov 2013 18:33:10 -0800 Subject: [PATCH 02/10] Return # of glyphs, not charmaps, in font info. This makes it match the value from the PSP, and seems logical (the charmap value is hardly useful, and might lead me to overallocate space for the glyph bitmaps...) --- Core/Font/PGF.cpp | 2 +- Core/Font/PGF.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/Font/PGF.cpp b/Core/Font/PGF.cpp index 01f26808f9..1a7da774a0 100644 --- a/Core/Font/PGF.cpp +++ b/Core/Font/PGF.cpp @@ -298,7 +298,7 @@ void PGF::GetFontInfo(PGFFontInfo *fi) { fi->maxGlyphWidth = header.maxGlyphWidth; fi->maxGlyphHeight = header.maxGlyphHeight; - fi->charMapLength = header.charMapLength; + fi->numGlyphs = header.charPointerLength; fi->shadowMapLength = 0; // header.shadowMapLength; TODO fi->BPP = header.bpp; diff --git a/Core/Font/PGF.h b/Core/Font/PGF.h index 127e2f2b46..32ba766278 100644 --- a/Core/Font/PGF.h +++ b/Core/Font/PGF.h @@ -242,7 +242,7 @@ struct PGFFontInfo { // Bitmap dimensions. s16_le maxGlyphWidth; s16_le maxGlyphHeight; - s32_le charMapLength; // Number of elements in the font's charmap. + s32_le numGlyphs; s32_le shadowMapLength; // Number of elements in the font's shadow charmap. // Font style (used by font comparison functions). From e77b8bc5b56909b5e2b875e3b5fbbb0ef7b17547 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 16 Nov 2013 18:35:15 -0800 Subject: [PATCH 03/10] Check for non-indexed glyph advance values. This change from JPCSP: http://code.google.com/p/jpcsp/source/detail?r=3350 --- Core/Font/PGF.cpp | 22 ++++++++++++++++------ Core/Font/PGF.h | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Core/Font/PGF.cpp b/Core/Font/PGF.cpp index 1a7da774a0..211ce65d1a 100644 --- a/Core/Font/PGF.cpp +++ b/Core/Font/PGF.cpp @@ -335,7 +335,7 @@ bool PGF::GetGlyph(const u8 *fontdata, size_t charPtr, int glyphType, Glyph &gly glyph.flags = getBits(6, fontdata, charPtr); charPtr += 6; - if (glyph.flags & FONT_PGF_CHARGLYPH) { + if (glyphType == FONT_PGF_CHARGLYPH) { // Skip magic number charPtr += 7; @@ -419,12 +419,22 @@ bool PGF::GetGlyph(const u8 *fontdata, size_t charPtr, int glyphType, Glyph &gly charPtr += 32; } - int advanceIndex = getBits(8, fontdata, charPtr); - charPtr += 8; + if ((glyph.flags & FONT_PGF_METRIC_ADVANCE_INDEX) == FONT_PGF_METRIC_ADVANCE_INDEX) + { + int advanceIndex = getBits(8, fontdata, charPtr); + charPtr += 8; - if (advanceIndex < header.advanceTableLength) { - glyph.advanceH = advanceTable[0][advanceIndex]; - glyph.advanceV = advanceTable[1][advanceIndex]; + if (advanceIndex < header.advanceTableLength) { + glyph.advanceH = advanceTable[0][advanceIndex]; + glyph.advanceV = advanceTable[1][advanceIndex]; + } + } + else + { + glyph.advanceH = getBits(32, fontdata, charPtr); + charPtr += 32; + glyph.advanceV = getBits(32, fontdata, charPtr); + charPtr += 32; } } else { glyph.shadowID = 65535; diff --git a/Core/Font/PGF.h b/Core/Font/PGF.h index 32ba766278..9bec8293f6 100644 --- a/Core/Font/PGF.h +++ b/Core/Font/PGF.h @@ -39,6 +39,7 @@ enum { FONT_PGF_METRIC_DIMENSION_INDEX = 0x04, FONT_PGF_METRIC_BEARING_X_INDEX = 0x08, FONT_PGF_METRIC_BEARING_Y_INDEX = 0x10, + FONT_PGF_METRIC_ADVANCE_INDEX = 0x20, FONT_PGF_CHARGLYPH = 0x20, FONT_PGF_SHADOWGLYPH = 0x40, }; From d446659b2ab17dcf94098a4d194d44d3180955c1 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 16 Nov 2013 19:10:21 -0800 Subject: [PATCH 04/10] Improve the performance of getBits(). Well, it's not used much, although it's much faster now, heh. --- Core/Font/PGF.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Core/Font/PGF.cpp b/Core/Font/PGF.cpp index 211ce65d1a..ddb6818ee0 100644 --- a/Core/Font/PGF.cpp +++ b/Core/Font/PGF.cpp @@ -34,14 +34,26 @@ static bool isJPCSPFont(const char *fontName) { } // Gets a number of bits from an offset. -// TODO: Make more efficient. static int getBits(int numBits, const u8 *buf, size_t pos) { - int v = 0; - for (int i = 0; i < numBits; i++) { - v = v | (((buf[pos >> 3] >> (pos & 7)) & 1) << i); - pos++; + _dbg_assert_msg_(SCEFONT, numBits <= 32, "Unable to return more than 32 bits, %d requested", numBits); + + const size_t wordpos = pos >> 5; + const u32 *wordbuf = (const u32 *)buf; + const u8 bitoff = pos & 31; + + // Might just be in one, has to be within two. + if (bitoff + numBits < 32) { + const u32 mask = (1 << numBits) - 1; + return (wordbuf[wordpos] >> bitoff) & mask; + } else { + int v = wordbuf[wordpos] >> bitoff; + + const u8 done = 32 - bitoff; + const u8 remaining = numBits - done; + const u32 mask = (1 << remaining) - 1; + v |= (wordbuf[wordpos + 1] & mask) << done; + return v; } - return v; } static std::vector getTable(const u8 *buf, int bpe, size_t length) { From bb94f31ec75ae7206f51833ce3181a7514f5efbc Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 16 Nov 2013 19:44:33 -0800 Subject: [PATCH 05/10] Simplify GetGlyph() and getBits() usage a bit. --- Core/Font/PGF.cpp | 73 +++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 44 deletions(-) diff --git a/Core/Font/PGF.cpp b/Core/Font/PGF.cpp index ddb6818ee0..6af919a29c 100644 --- a/Core/Font/PGF.cpp +++ b/Core/Font/PGF.cpp @@ -56,6 +56,12 @@ static int getBits(int numBits, const u8 *buf, size_t pos) { } } +static inline int consumeBits(int numBits, const u8 *buf, size_t &pos) { + int v = getBits(numBits, buf, pos); + pos += numBits; + return v; +} + static std::vector getTable(const u8 *buf, int bpe, size_t length) { std::vector vec; vec.resize(length); @@ -324,40 +330,33 @@ bool PGF::GetGlyph(const u8 *fontdata, size_t charPtr, int glyphType, Glyph &gly if (charPtr + 96 > fontDataSize * 8) return false; } + // Skip size. charPtr += 14; - glyph.w = getBits(7, fontdata, charPtr); - charPtr += 7; + glyph.w = consumeBits(7, fontdata, charPtr); + glyph.h = consumeBits(7, fontdata, charPtr); - glyph.h = getBits(7, fontdata, charPtr); - charPtr += 7; - - glyph.left = getBits(7, fontdata, charPtr); - charPtr += 7; + glyph.left = consumeBits(7, fontdata, charPtr); if (glyph.left >= 64) { glyph.left -= 128; } - glyph.top = getBits(7, fontdata, charPtr); - charPtr += 7; + glyph.top = consumeBits(7, fontdata, charPtr); if (glyph.top >= 64) { glyph.top -= 128; } - glyph.flags = getBits(6, fontdata, charPtr); - charPtr += 6; + glyph.flags = consumeBits(6, fontdata, charPtr); if (glyphType == FONT_PGF_CHARGLYPH) { - // Skip magic number + // Skip magic number (seems to differ, what sort of magic is this?) charPtr += 7; - glyph.shadowID = getBits(9, fontdata, charPtr); - charPtr += 9; + glyph.shadowID = consumeBits(9, fontdata, charPtr); if ((glyph.flags & FONT_PGF_METRIC_DIMENSION_INDEX) == FONT_PGF_METRIC_DIMENSION_INDEX) { - int dimensionIndex = getBits(8, fontdata, charPtr); - charPtr += 8; + int dimensionIndex = consumeBits(8, fontdata, charPtr); if (dimensionIndex < header.dimTableLength) { glyph.dimensionWidth = dimensionTable[0][dimensionIndex]; @@ -373,16 +372,13 @@ bool PGF::GetGlyph(const u8 *fontdata, size_t charPtr, int glyphType, Glyph &gly } else { - glyph.dimensionWidth = getBits(32, fontdata, charPtr); - charPtr += 32; - glyph.dimensionHeight = getBits(32, fontdata, charPtr); - charPtr += 32; + glyph.dimensionWidth = consumeBits(32, fontdata, charPtr); + glyph.dimensionHeight = consumeBits(32, fontdata, charPtr); } if ((glyph.flags & FONT_PGF_METRIC_BEARING_X_INDEX) == FONT_PGF_METRIC_BEARING_X_INDEX) { - int xAdjustIndex = getBits(8, fontdata, charPtr); - charPtr += 8; + int xAdjustIndex = consumeBits(8, fontdata, charPtr); if (xAdjustIndex < header.xAdjustTableLength) { glyph.xAdjustH = xAdjustTable[0][xAdjustIndex]; @@ -399,16 +395,13 @@ bool PGF::GetGlyph(const u8 *fontdata, size_t charPtr, int glyphType, Glyph &gly } else { - glyph.xAdjustH = getBits(32, fontdata, charPtr); - charPtr += 32; - glyph.xAdjustV = getBits(32, fontdata, charPtr); - charPtr += 32; + glyph.xAdjustH = consumeBits(32, fontdata, charPtr); + glyph.xAdjustV = consumeBits(32, fontdata, charPtr); } if ((glyph.flags & FONT_PGF_METRIC_BEARING_Y_INDEX) == FONT_PGF_METRIC_BEARING_Y_INDEX) { - int yAdjustIndex = getBits(8, fontdata, charPtr); - charPtr += 8; + int yAdjustIndex = consumeBits(8, fontdata, charPtr); if (yAdjustIndex < header.xAdjustTableLength) { glyph.yAdjustH = yAdjustTable[0][yAdjustIndex]; @@ -425,16 +418,13 @@ bool PGF::GetGlyph(const u8 *fontdata, size_t charPtr, int glyphType, Glyph &gly } else { - glyph.yAdjustH = getBits(32, fontdata, charPtr); - charPtr += 32; - glyph.yAdjustV = getBits(32, fontdata, charPtr); - charPtr += 32; + glyph.yAdjustH = consumeBits(32, fontdata, charPtr); + glyph.yAdjustV = consumeBits(32, fontdata, charPtr); } if ((glyph.flags & FONT_PGF_METRIC_ADVANCE_INDEX) == FONT_PGF_METRIC_ADVANCE_INDEX) { - int advanceIndex = getBits(8, fontdata, charPtr); - charPtr += 8; + int advanceIndex = consumeBits(8, fontdata, charPtr); if (advanceIndex < header.advanceTableLength) { glyph.advanceH = advanceTable[0][advanceIndex]; @@ -443,10 +433,8 @@ bool PGF::GetGlyph(const u8 *fontdata, size_t charPtr, int glyphType, Glyph &gly } else { - glyph.advanceH = getBits(32, fontdata, charPtr); - charPtr += 32; - glyph.advanceV = getBits(32, fontdata, charPtr); - charPtr += 32; + glyph.advanceH = consumeBits(32, fontdata, charPtr); + glyph.advanceV = consumeBits(32, fontdata, charPtr); } } else { glyph.shadowID = 65535; @@ -504,14 +492,12 @@ void PGF::DrawCharacter(const GlyphImage *image, int clipX, int clipY, int clipW while (pixelIndex < numberPixels && bitPtr + 8 < fontDataSize * 8) { // This is some kind of nibble based RLE compression. - int nibble = getBits(4, fontData, bitPtr); - bitPtr += 4; + int nibble = consumeBits(4, fontData, bitPtr); int count; int value = 0; if (nibble < 8) { - value = getBits(4, fontData, bitPtr); - bitPtr += 4; + value = consumeBits(4, fontData, bitPtr); count = nibble + 1; } else { count = 16 - nibble; @@ -519,8 +505,7 @@ void PGF::DrawCharacter(const GlyphImage *image, int clipX, int clipY, int clipW for (int i = 0; i < count && pixelIndex < numberPixels; i++) { if (nibble >= 8) { - value = getBits(4, fontData, bitPtr); - bitPtr += 4; + value = consumeBits(4, fontData, bitPtr); } int xx, yy; From 4505cb4b3ad06844ecaf23ac729c5a2876b68923 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 16 Nov 2013 20:35:50 -0800 Subject: [PATCH 06/10] Match ascender/descender values per character. This makes sense, and matches the ascender/descender for my fonts. However, it could be wrong for vertical fonts... not sure. --- Core/Font/PGF.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/Font/PGF.cpp b/Core/Font/PGF.cpp index 6af919a29c..e8e00f901c 100644 --- a/Core/Font/PGF.cpp +++ b/Core/Font/PGF.cpp @@ -280,9 +280,9 @@ bool PGF::GetCharInfo(int charCode, PGFCharInfo *charInfo) { charInfo->bitmapTop = glyph.top; charInfo->sfp26Width = glyph.dimensionWidth; charInfo->sfp26Height = glyph.dimensionHeight; - charInfo->sfp26Ascender = glyph.top << 6; + charInfo->sfp26Ascender = glyph.yAdjustH; // Font y goes upwards. If top is 10 and height is 11, the descender is approx. -1 (below 0.) - charInfo->sfp26Descender = (glyph.top - glyph.h) << 6; + charInfo->sfp26Descender = charInfo->sfp26Ascender - charInfo->sfp26Height; charInfo->sfp26BearingHX = glyph.xAdjustH; charInfo->sfp26BearingHY = glyph.yAdjustH; charInfo->sfp26BearingVX = glyph.xAdjustV; From 769ffbd33b1d565a1fdc82893a7c644fc309d3a2 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 16 Nov 2013 21:08:12 -0800 Subject: [PATCH 07/10] Read in the shadow flags and give them to the game. Yay, now this struct seems to match the PSP. --- Core/Font/PGF.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++---- Core/Font/PGF.h | 6 ++--- 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/Core/Font/PGF.cpp b/Core/Font/PGF.cpp index e8e00f901c..d9db3b9de2 100644 --- a/Core/Font/PGF.cpp +++ b/Core/Font/PGF.cpp @@ -82,8 +82,47 @@ PGF::~PGF() { } } +struct GlyphFromPGF1State { + int x; + int y; + int w; + int h; + int left; + int top; + int flags; + int shadowID; + int advanceH; + int advanceV; + int dimensionWidth, dimensionHeight; + int xAdjustH, xAdjustV; + int yAdjustH, yAdjustV; + u32 ptr; + + operator Glyph() { + Glyph ret; + ret.w = w; + ret.h = h; + ret.left = left; + ret.top = top; + ret.flags = flags; + // Wasn't read before. + ret.shadowFlags = 0; + ret.shadowID = shadowID; + ret.advanceH = advanceH; + ret.advanceV = advanceV; + ret.dimensionWidth = dimensionWidth; + ret.dimensionHeight = dimensionHeight; + ret.xAdjustH = xAdjustH; + ret.xAdjustV = xAdjustV; + ret.yAdjustH = yAdjustH; + ret.yAdjustV = yAdjustV; + ret.ptr = ptr; + return ret; + } +}; + void PGF::DoState(PointerWrap &p) { - auto s = p.Section("PGF", 1); + auto s = p.Section("PGF", 1, 2); if (!s) return; @@ -116,8 +155,22 @@ void PGF::DoState(PointerWrap &p) { p.Do(charmap_compr); p.Do(charmap); - p.Do(glyphs); - p.Do(shadowGlyphs); + if (s == 1) { + std::vector oldGlyphs; + p.Do(oldGlyphs); + glyphs.resize(oldGlyphs.size()); + for (size_t i = 0; i < oldGlyphs.size(); ++i) { + glyphs[i] = oldGlyphs[i]; + } + p.Do(oldGlyphs); + shadowGlyphs.resize(oldGlyphs.size()); + for (size_t i = 0; i < oldGlyphs.size(); ++i) { + shadowGlyphs[i] = oldGlyphs[i]; + } + } else { + p.Do(glyphs); + p.Do(shadowGlyphs); + } p.Do(firstGlyph); } @@ -289,6 +342,8 @@ bool PGF::GetCharInfo(int charCode, PGFCharInfo *charInfo) { charInfo->sfp26BearingVY = glyph.yAdjustV; charInfo->sfp26AdvanceH = glyph.advanceH; charInfo->sfp26AdvanceV = glyph.advanceV; + charInfo->shadowFlags = glyph.shadowFlags; + charInfo->shadowId = glyph.shadowID; return true; } @@ -349,8 +404,9 @@ bool PGF::GetGlyph(const u8 *fontdata, size_t charPtr, int glyphType, Glyph &gly glyph.flags = consumeBits(6, fontdata, charPtr); if (glyphType == FONT_PGF_CHARGLYPH) { - // Skip magic number (seems to differ, what sort of magic is this?) - charPtr += 7; + glyph.shadowFlags = consumeBits(2, fontdata, charPtr) << (2 + 3); + glyph.shadowFlags |= consumeBits(2, fontdata, charPtr) << 3; + glyph.shadowFlags |= consumeBits(3, fontdata, charPtr); glyph.shadowID = consumeBits(9, fontdata, charPtr); diff --git a/Core/Font/PGF.h b/Core/Font/PGF.h index 9bec8293f6..5ccaf01581 100644 --- a/Core/Font/PGF.h +++ b/Core/Font/PGF.h @@ -94,13 +94,12 @@ struct PGFFontStyle { struct Glyph { - int x; - int y; int w; int h; int left; int top; int flags; + int shadowFlags; int shadowID; int advanceH; int advanceV; @@ -212,7 +211,8 @@ struct PGFCharInfo { s32_le sfp26BearingVY; s32_le sfp26AdvanceH; s32_le sfp26AdvanceV; - u8 pad[4]; + s16_le shadowFlags; + s16_le shadowId; }; struct PGFFontInfo { From d955d9b303bb86066cb979f18618ffc580707023 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 16 Nov 2013 22:53:05 -0800 Subject: [PATCH 08/10] Cut down on unnecessary allocs in font loading. --- Core/Font/PGF.cpp | 23 ++++++----------------- Core/Font/PGF.h | 2 ++ 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/Core/Font/PGF.cpp b/Core/Font/PGF.cpp index d9db3b9de2..c97d60bc26 100644 --- a/Core/Font/PGF.cpp +++ b/Core/Font/PGF.cpp @@ -220,10 +220,8 @@ void PGF::ReadPtr(const u8 *ptr, size_t dataSize) { const u8 *uptr = (const u8 *)wptr; int shadowCharMapSize = ((header.shadowMapLength * header.shadowMapBpe + 31) & ~31) / 8; - u8 *shadowCharMap = new u8[shadowCharMapSize]; - for (int i = 0; i < shadowCharMapSize; i++) { - shadowCharMap[i] = *uptr++; - } + const u8 *shadowCharMap = uptr; + uptr += shadowCharMapSize; const u16_le *sptr = (const u16_le *)uptr; if (header.revision == 3) { @@ -245,17 +243,12 @@ void PGF::ReadPtr(const u8 *ptr, size_t dataSize) { uptr = (const u8 *)sptr; int charMapSize = ((header.charMapLength * header.charMapBpe + 31) & ~31) / 8; - - u8 *charMap = new u8[charMapSize]; - for (int i = 0; i < charMapSize; i++) { - charMap[i] = *uptr++; - } + const u8 *charMap = uptr; + uptr += charMapSize; int charPointerSize = (((header.charPointerLength * header.charPointerBpe + 31) & ~31) / 8); - u8 *charPointerTable = new u8[charPointerSize]; - for (int i = 0; i < charPointerSize; i++) { - charPointerTable[i] = *uptr++; - } + const u8 *charPointerTable = uptr; + uptr += charPointerSize; // PGF Fontdata. u32 fontDataOffset = (u32)(uptr - startPtr); @@ -284,10 +277,6 @@ 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 5ccaf01581..721f0ed586 100644 --- a/Core/Font/PGF.h +++ b/Core/Font/PGF.h @@ -142,6 +142,7 @@ struct PGFHeader s32_le charMapBpe; s32_le charPointerBpe; + // TODO: This has values in it (0404)... u8 pad1[2]; u8 bpp; u8 pad2[1]; @@ -159,6 +160,7 @@ struct PGFHeader u16_le firstGlyph; u16_le lastGlyph; + // TODO: This has a few 01s in it in the official fonts. u8 pad5[26]; s32_le maxAscender; From 8f6315e3750c765575b6004d553014c5f8c22bf4 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 16 Nov 2013 23:11:13 -0800 Subject: [PATCH 09/10] Support replacement chars in sceFontGetCharInfo(). --- Core/Font/PGF.cpp | 11 ++++++++--- Core/Font/PGF.h | 2 +- Core/HLE/sceFont.cpp | 11 ++++++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Core/Font/PGF.cpp b/Core/Font/PGF.cpp index c97d60bc26..8a076bd1df 100644 --- a/Core/Font/PGF.cpp +++ b/Core/Font/PGF.cpp @@ -307,13 +307,18 @@ int PGF::GetCharIndex(int charCode, const std::vector &charmapCompressed) { return -1; } -bool PGF::GetCharInfo(int charCode, PGFCharInfo *charInfo) { +bool PGF::GetCharInfo(int charCode, PGFCharInfo *charInfo, int altCharCode) { Glyph glyph; memset(charInfo, 0, sizeof(*charInfo)); if (!GetCharGlyph(charCode, FONT_PGF_CHARGLYPH, glyph)) { - // Character not in font, return zeroed charInfo as on real PSP. - return false; + if (charCode < firstGlyph) { + // Character not in font, return zeroed charInfo as on real PSP. + return false; + } + if (!GetCharGlyph(altCharCode, FONT_PGF_CHARGLYPH, glyph)) { + return false; + } } charInfo->bitmapWidth = glyph.w; diff --git a/Core/Font/PGF.h b/Core/Font/PGF.h index 721f0ed586..bc5b429aac 100644 --- a/Core/Font/PGF.h +++ b/Core/Font/PGF.h @@ -263,7 +263,7 @@ public: void ReadPtr(const u8 *ptr, size_t dataSize); - bool GetCharInfo(int charCode, PGFCharInfo *ci); + 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); diff --git a/Core/HLE/sceFont.cpp b/Core/HLE/sceFont.cpp index 9d23192f21..a12a41a621 100644 --- a/Core/HLE/sceFont.cpp +++ b/Core/HLE/sceFont.cpp @@ -338,6 +338,7 @@ public: } } u32 args[2] = { params_.userDataAddr, (u32)handle_ }; + // TODO: The return value of this is leaking. __KernelDirectMipsCall(params_.freeFuncAddr, 0, args, 2, false); handle_ = 0; fonts_.clear(); @@ -825,8 +826,10 @@ int sceFontGetCharInfo(u32 fontHandle, u32 charCode, u32 charInfoPtr) { } DEBUG_LOG(SCEFONT, "sceFontGetCharInfo(%08x, %i, %08x)", fontHandle, charCode, charInfoPtr); + auto fontLib = font->GetFontLib(); + int altCharCode = fontLib == NULL ? -1 : fontLib->GetAltCharCode(); auto charInfo = Memory::GetStruct(charInfoPtr); - font->GetPGF()->GetCharInfo(charCode, charInfo); + font->GetPGF()->GetCharInfo(charCode, charInfo, altCharCode); return 0; } @@ -842,11 +845,13 @@ int sceFontGetCharImageRect(u32 fontHandle, u32 charCode, u32 charRectPtr) { DEBUG_LOG(SCEFONT, "sceFontGetCharImageRect(%08x, %i, %08x)", fontHandle, charCode, charRectPtr); if (!Memory::IsValidAddress(charRectPtr)) return -1; - + PGFCharInfo charInfo; LoadedFont *font = GetLoadedFont(fontHandle, false); + auto fontLib = font->GetFontLib(); + int altCharCode = fontLib == NULL ? -1 : fontLib->GetAltCharCode(); if (font) { - font->GetPGF()->GetCharInfo(charCode, &charInfo); + font->GetPGF()->GetCharInfo(charCode, &charInfo, altCharCode); Memory::Write_U16(charInfo.bitmapWidth, charRectPtr); // character bitmap width in pixels Memory::Write_U16(charInfo.bitmapHeight, charRectPtr + 2); // character bitmap height in pixels } else { From 0bd7d7ad196c87be8aa4962c0052d23f0702644b Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 16 Nov 2013 23:39:19 -0800 Subject: [PATCH 10/10] Minor correctness: don't zero extend bpp bits. --- Core/Font/PGF.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/Font/PGF.h b/Core/Font/PGF.h index bc5b429aac..a0f4f6954c 100644 --- a/Core/Font/PGF.h +++ b/Core/Font/PGF.h @@ -251,7 +251,8 @@ struct PGFFontInfo { // Font style (used by font comparison functions). PGFFontStyle fontStyle; - s32_le BPP; // Font's BPP. + u8 BPP; // Font's BPP. + u8 pad[3]; }; #pragma pack(pop)