From 29948a230b193e1b188156ebf76c102324153243 Mon Sep 17 00:00:00 2001 From: rarified Date: Thu, 9 Sep 2021 21:13:23 -0600 Subject: [PATCH] Refactor font index changes; VS2010 can't handle multiple array refs in the single block. --- Sources/Plasma/PubUtilLib/plGImage/plFont.cpp | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp b/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp index b89020a5..cdc47362 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plFont.cpp @@ -288,15 +288,16 @@ void plFont::IRenderString( plMipmap *mip, UInt16 x, UInt16 y, const wchar_t *st if( justCalc ) { - plCharacter& ch = fCharacters[(UInt16)L' ' - fFirstChar]; + UInt16 ixFC = (UInt16)L' ' - fFirstChar; if (fCharacters.Count() <= ((UInt16)string[0] - fFirstChar)) { - UInt16 w = wctob(string[0]); - if (w != EOF && (w - fFirstChar) <= fCharacters.Count()) - ch = (fCharacters[w - fFirstChar]); + UInt16 w = wctob((UInt16)string[0]); + if ((w != EOF) && (fCharacters.Count() > (w - fFirstChar))) + ixFC = w - fFirstChar; } else { - ch = (fCharacters[(UInt16)string[0] - fFirstChar]); + ixFC = (UInt16)string[0] - fFirstChar; } + plCharacter &ch = fCharacters[ixFC]; fRenderInfo.fX = fRenderInfo.fFarthestX = x - (Int16)ch.fLeftKern; if( fRenderInfo.fX < 0 ) fRenderInfo.fX = 0; @@ -395,15 +396,17 @@ void plFont::IRenderString( plMipmap *mip, UInt16 x, UInt16 y, const wchar_t *st // Just calculating, no wrapping, so the max is as far as we can go // Note: 32767 isn't quite right, since we'll be adding the left kern in before we // calc the first character, so adjust so we make sure we don't underflow - plCharacter& ch = fCharacters[(UInt16)L' ' - fFirstChar]; + UInt16 ixFC = (UInt16)L' ' - fFirstChar; if (fCharacters.Count() <= ((UInt16)string[0] - fFirstChar)) { - UInt16 w = wctob(string[0]); - if (w != EOF && (w - fFirstChar) <= fCharacters.Count()) - ch = (fCharacters[w - fFirstChar]); + UInt16 w = wctob((UInt16)string[0]); + if ((w != EOF) && (fCharacters.Count() > (w - fFirstChar))) + ixFC = w - fFirstChar; } else { - ch = (fCharacters[(UInt16)string[0] - fFirstChar]); + ixFC = (UInt16)string[0] - fFirstChar; } + plCharacter &ch = fCharacters[ixFC]; + fRenderInfo.fMaxHeight = (Int16)fMaxCharHeight; fRenderInfo.fMaxWidth = (Int16)32767 + (Int16)ch.fLeftKern; } @@ -466,14 +469,16 @@ void plFont::IRenderString( plMipmap *mip, UInt16 x, UInt16 y, const wchar_t *st } // handle invalid chars discretely - plCharacter* charToDraw = &(fCharacters[(UInt16)L' ' - fFirstChar]); + UInt16 ixFC = (UInt16)L' ' - fFirstChar; if (fCharacters.Count() <= ((UInt16)string[i] - fFirstChar)) { - UInt16 w = wctob(string[i]); - if (w != EOF && (w - fFirstChar) <= fCharacters.Count()) - charToDraw = &(fCharacters[w - fFirstChar]); + UInt16 w = wctob((UInt16)string[i]); + if ((w != EOF) && (fCharacters.Count() > (w - fFirstChar))) + ixFC = w - fFirstChar; } else { - charToDraw = &(fCharacters[(UInt16)string[i] - fFirstChar]); + ixFC = (UInt16)string[i] - fFirstChar; } + + plCharacter* charToDraw = &(fCharacters[ixFC]); Int16 leftKern = (Int16)charToDraw->fLeftKern; if( fRenderInfo.fFlags & kRenderScaleAA ) @@ -603,14 +608,16 @@ void plFont::IRenderString( plMipmap *mip, UInt16 x, UInt16 y, const wchar_t *st { Int16 baseX = fRenderInfo.fX; - plCharacter& ch = fCharacters[(UInt16)L' ' - fFirstChar]; + UInt16 ixFC = (UInt16)L' ' - fFirstChar; if (fCharacters.Count() <= ((UInt16)string[0] - fFirstChar)) { - UInt16 w = wctob(string[0]); - if (w != EOF && (w - fFirstChar) <= fCharacters.Count()) - ch = (fCharacters[w - fFirstChar]); + UInt16 w = wctob((UInt16)string[0]); + if ((w != EOF) && (fCharacters.Count() > (w - fFirstChar))) + ixFC = w - fFirstChar; } else { - ch = (fCharacters[(UInt16)string[0] - fFirstChar]); + ixFC = (UInt16)string[0] - fFirstChar; } + + plCharacter &ch = fCharacters[ixFC]; fRenderInfo.fX -= (Int16)ch.fLeftKern; fRenderInfo.fDestPtr -= (Int16)ch.fLeftKern * fRenderInfo.fDestBPP;