Correct clipping in sceFontGetCharGlyphImage_Clip.

It was not clipping completely, and didn't handle negative clip w/h.
Also, reduce to debug log (seems to work fine now and has been working
fine in most games.)
This commit is contained in:
Unknown W. Brackets 2014-02-27 00:19:40 -08:00
parent 056968129c
commit ab6b998710
3 changed files with 18 additions and 12 deletions

View File

@ -323,7 +323,7 @@ int PGF::GetCharIndex(int charCode, const std::vector<int> &charmapCompressed) {
return -1;
}
bool PGF::GetCharInfo(int charCode, PGFCharInfo *charInfo, int altCharCode) {
bool PGF::GetCharInfo(int charCode, PGFCharInfo *charInfo, int altCharCode) const {
Glyph glyph;
memset(charInfo, 0, sizeof(*charInfo));
@ -357,7 +357,7 @@ bool PGF::GetCharInfo(int charCode, PGFCharInfo *charInfo, int altCharCode) {
return true;
}
void PGF::GetFontInfo(PGFFontInfo *fi) {
void PGF::GetFontInfo(PGFFontInfo *fi) const {
fi->maxGlyphWidthI = header.maxSize[0];
fi->maxGlyphHeightI = header.maxSize[1];
fi->maxGlyphAscenderI = header.maxAscender;
@ -511,7 +511,7 @@ bool PGF::GetGlyph(const u8 *fontdata, size_t charPtr, int glyphType, Glyph &gly
return true;
}
bool PGF::GetCharGlyph(int charCode, int glyphType, Glyph &glyph) {
bool PGF::GetCharGlyph(int charCode, int glyphType, Glyph &glyph) const {
if (charCode < firstGlyph)
return false;
charCode -= firstGlyph;
@ -530,7 +530,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) {
void PGF::DrawCharacter(const GlyphImage *image, int clipX, int clipY, int clipWidth, int clipHeight, int charCode, int altCharCode, int glyphType) const {
Glyph glyph;
if (!GetCharGlyph(charCode, glyphType, glyph)) {
// No Glyph available for this charCode, try to use the alternate char.
@ -556,6 +556,12 @@ void PGF::DrawCharacter(const GlyphImage *image, int clipX, int clipY, int clipW
int x = image->xPos64 >> 6;
int y = image->yPos64 >> 6;
// Negative means don't clip on that side.
if (clipWidth < 0)
clipWidth = glyph.w;
if (clipHeight < 0)
clipHeight = glyph.h;
while (pixelIndex < numberPixels && bitPtr + 8 < fontDataSize * 8) {
// This is some kind of nibble based RLE compression.
int nibble = consumeBits(4, fontData, bitPtr);
@ -624,7 +630,7 @@ void PGF::DrawCharacter(const GlyphImage *image, int clipX, int clipY, int clipW
gpu->InvalidateCache(image->bufferPtr, image->bytesPerLine * image->bufHeight, GPU_INVALIDATE_SAFE);
}
void PGF::SetFontPixel(u32 base, int bpl, int bufWidth, int bufHeight, int x, int y, int pixelColor, int pixelformat) {
void PGF::SetFontPixel(u32 base, int bpl, int bufWidth, int bufHeight, int x, int y, int pixelColor, int pixelformat) const {
if (x < 0 || x >= bufWidth || y < 0 || y >= bufHeight) {
return;
}

View File

@ -264,9 +264,9 @@ public:
bool ReadPtr(const u8 *ptr, size_t dataSize);
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 GetCharInfo(int charCode, PGFCharInfo *ci, int altCharCode) const;
void GetFontInfo(PGFFontInfo *fi) const;
void DrawCharacter(const GlyphImage *image, int clipX, int clipY, int clipWidth, int clipHeight, int charCode, int altCharCode, int glyphType) const;
void DoState(PointerWrap &p);
@ -274,12 +274,12 @@ public:
private:
bool GetGlyph(const u8 *fontdata, size_t charPtr, int glyphType, Glyph &glyph);
bool GetCharGlyph(int charCode, int glyphType, Glyph &glyph);
bool GetCharGlyph(int charCode, int glyphType, Glyph &glyph) const;
// Unused
int GetCharIndex(int charCode, const std::vector<int> &charmapCompressed);
void SetFontPixel(u32 base, int bpl, int bufWidth, int bufHeight, int x, int y, int pixelColor, int pixelformat);
void SetFontPixel(u32 base, int bpl, int bufWidth, int bufHeight, int x, int y, int pixelColor, int pixelformat) const;
PGFHeaderRev3Extra rev3extra;

View File

@ -1074,10 +1074,10 @@ int sceFontGetCharGlyphImage_Clip(u32 fontHandle, u32 charCode, u32 glyphImagePt
return ERROR_FONT_INVALID_PARAMETER;
}
INFO_LOG(SCEFONT, "sceFontGetCharGlyphImage_Clip(%08x, %i, %08x, %i, %i, %i, %i)", fontHandle, charCode, glyphImagePtr, clipXPos, clipYPos, clipWidth, clipHeight);
DEBUG_LOG(SCEFONT, "sceFontGetCharGlyphImage_Clip(%08x, %i, %08x, %i, %i, %i, %i)", fontHandle, charCode, glyphImagePtr, clipXPos, clipYPos, clipWidth, clipHeight);
auto glyph = Memory::GetStruct<const GlyphImage>(glyphImagePtr);
int altCharCode = font->GetFontLib()->GetAltCharCode();
font->GetPGF()->DrawCharacter(glyph, clipXPos, clipYPos, clipXPos + clipWidth, clipYPos + clipHeight, charCode, altCharCode, FONT_PGF_CHARGLYPH);
font->GetPGF()->DrawCharacter(glyph, clipXPos, clipYPos, clipWidth, clipHeight, charCode, altCharCode, FONT_PGF_CHARGLYPH);
return 0;
}