mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-10 21:16:24 +02:00
Merge pull request #4789 from unknownbrackets/font-tweak
Detect bad fonts' ascenders and workaround
This commit is contained in:
commit
2bd314a4bc
3 files changed
+7
-15
No files matched your search
+4
-6
@@ -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;
|
||||
@@ -514,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.
|
||||
@@ -570,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;
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
|
||||
@@ -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<Font *> 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<const GlyphImage>(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<const GlyphImage>(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;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user