From b147e47856b8e0e6b3a4cbbbb3e13ff5a73f4083 Mon Sep 17 00:00:00 2001 From: "Marco Antonio J. Costa" Date: Wed, 22 Jul 2026 13:19:25 -0300 Subject: [PATCH] let the text drawing path take a string it will not write to DrawTextToScreen takes STR16, a mutable wchar_t*, for a string it only measures and prints. Quest Debug System.cpp picks its text with a conditional: DrawTextToScreen( gubFact[ usLoop1 ] ? L"True" : L"False", ... ); which has type const wchar_t*. clang-cl's MSVC compatibility lets a bare string literal decay to wchar_t*, but not a const wchar_t* expression, so it reports error: no matching function for call to 'DrawTextToScreen' note: candidate function not viable: 1st argument ('const wchar_t *') would lose const qualifier The parameter is const-correct in every function DrawTextToScreen hands the string on to, so the change follows the string down the call chain rather than stopping at the top: DrawTextToScreen, ShadowText Utils/WordWrap.h WFStringPixLength Utils/Font Control.h mprintf, StringPixLength, sgp/Font.h VarFindFontCenterCoordinates, VarFindFontRightCoordinates WinFontStringPixLength sgp/WinFont.h gprintfdirty TileEngine/Render Dirty.h The varargs members of that list copy the format string into a local buffer before doing anything with it, and the measuring ones walk it and return a width; none of the nine assigns through the parameter. Where StringPixLength casts the string to UINT16* to walk it, the cast and the local now carry the const rather than dropping it. Callers are unaffected: every one already passes something that converts to const CHAR16*. Both configurations build with no new diagnostics, and the parse sweep drops from 9 error sites in 7 files to 5 in 3. To check the claim that nothing writes through these parameters, read the nine bodies; each is short. --- TileEngine/Render Dirty.cpp | 2 +- TileEngine/Render Dirty.h | 2 +- Utils/Font Control.cpp | 2 +- Utils/Font Control.h | 2 +- Utils/WordWrap.cpp | 4 ++-- Utils/WordWrap.h | 4 ++-- sgp/Font.cpp | 13 +++++++------ sgp/Font.h | 8 ++++---- sgp/WinFont.cpp | 4 ++-- sgp/WinFont.h | 2 +- 10 files changed, 22 insertions(+), 21 deletions(-) diff --git a/TileEngine/Render Dirty.cpp b/TileEngine/Render Dirty.cpp index 0b7be536a..864e1b80e 100644 --- a/TileEngine/Render Dirty.cpp +++ b/TileEngine/Render Dirty.cpp @@ -717,7 +717,7 @@ BOOLEAN CopyExternBackgroundRect( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 s // to the video buffer. // //***************************************************************************** -UINT16 gprintfdirty(INT16 x, INT16 y, STR16 pFontString, ...) +UINT16 gprintfdirty(INT16 x, INT16 y, const CHAR16* pFontString, ...) { va_list argptr; CHAR16 string[512]; diff --git a/TileEngine/Render Dirty.h b/TileEngine/Render Dirty.h index 113f0766f..8a7578924 100644 --- a/TileEngine/Render Dirty.h +++ b/TileEngine/Render Dirty.h @@ -127,7 +127,7 @@ BOOLEAN EmptyBackgroundRects( void ); // GPRINTF DIRTY STUFF -UINT16 gprintfdirty(INT16 x, INT16 y, STR16 pFontString, ...); +UINT16 gprintfdirty(INT16 x, INT16 y, const CHAR16* pFontString, ...); UINT16 gprintfinvalidate(INT16 x, INT16 y, STR16 pFontString, ...); UINT16 gprintfRestore(INT16 x, INT16 y, STR16 pFontString, ...); diff --git a/Utils/Font Control.cpp b/Utils/Font Control.cpp index 5c652b23a..b36ad776e 100644 --- a/Utils/Font Control.cpp +++ b/Utils/Font Control.cpp @@ -347,7 +347,7 @@ UINT16 WFGetFontHeight( INT32 FontNum ) } -INT16 WFStringPixLength( STR16 string,INT32 UseFont ) +INT16 WFStringPixLength( const CHAR16* string,INT32 UseFont ) { return( StringPixLength( string, UseFont ) ); } diff --git a/Utils/Font Control.h b/Utils/Font Control.h index 45ff67f4c..368de6de1 100644 --- a/Utils/Font Control.h +++ b/Utils/Font Control.h @@ -16,7 +16,7 @@ extern INT32 giCurWinFont; // ATE: A few winfont wrappers.. UINT16 WFGetFontHeight( INT32 FontNum ); -INT16 WFStringPixLength( STR16 string,INT32 UseFont ); +INT16 WFStringPixLength( const CHAR16* string,INT32 UseFont ); diff --git a/Utils/WordWrap.cpp b/Utils/WordWrap.cpp index b171aa154..c6c8b12ec 100644 --- a/Utils/WordWrap.cpp +++ b/Utils/WordWrap.cpp @@ -497,7 +497,7 @@ UINT16 DeleteWrappedString(WRAPPED_STRING *pWrappedString) // do you want to display it using dirty rects, TRUE or FALSE // flags for either LEFT_JUSTIFIED, CENTER_JUSTIFIED, RIGHT_JUSTIFIED -BOOLEAN DrawTextToScreen(STR16 pStr, UINT16 usLocX, UINT16 usLocY, UINT16 usWidth, INT32 iFont, UINT8 ubColor, UINT8 ubBackGroundColor, BOOLEAN fDirty, UINT32 ulFlags) +BOOLEAN DrawTextToScreen(const CHAR16* pStr, UINT16 usLocX, UINT16 usLocY, UINT16 usWidth, INT32 iFont, UINT8 ubColor, UINT8 ubBackGroundColor, BOOLEAN fDirty, UINT32 ulFlags) { UINT16 usPosX = 0, usPosY = 0; UINT16 usFontHeight=0; @@ -1874,7 +1874,7 @@ INT32 GetNewTotalYPositionOfThisString( INT32 iTotalYPosition, INT32 iPageSize, return( iNewYPosition ); } -void ShadowText(UINT32 uiDestVSurface, STR16 pString, INT32 iFont, UINT16 usPosX, UINT16 usPosY ) +void ShadowText(UINT32 uiDestVSurface, const CHAR16* pString, INT32 iFont, UINT16 usPosX, UINT16 usPosY ) { UINT32 uiLength = StringPixLength( pString, iFont); UINT16 usFontHeight = WFGetFontHeight( iFont ); diff --git a/Utils/WordWrap.h b/Utils/WordWrap.h index 50e2a4740..316ef3b01 100644 --- a/Utils/WordWrap.h +++ b/Utils/WordWrap.h @@ -50,7 +50,7 @@ void CleanOutControlCodesFromString(STR16 pSourceString, STR16 pDestString); INT16 IanDisplayWrappedStringToPages(UINT16 usPosX, UINT16 usPosY, UINT16 usWidth, UINT16 usPageHeight, UINT16 usTotalHeight, UINT16 usPageNumber,UINT8 ubGap, INT32 iFont, UINT8 ubColor, STR16 pString, UINT8 ubBackGroundColor, BOOLEAN fDirty, UINT32 uiFlags, BOOLEAN *fOnLastPageFlag); -BOOLEAN DrawTextToScreen(STR16 pStr, UINT16 LocX, UINT16 LocY, UINT16 usWidth, INT32 iFont, UINT8 ubColor, UINT8 ubBackGroundColor, BOOLEAN fDirty, UINT32 FLAGS); +BOOLEAN DrawTextToScreen(const CHAR16* pStr, UINT16 LocX, UINT16 LocY, UINT16 usWidth, INT32 iFont, UINT8 ubColor, UINT8 ubBackGroundColor, BOOLEAN fDirty, UINT32 FLAGS); UINT16 IanWrappedStringHeight(UINT16 usPosX, UINT16 usPosY, UINT16 usWidth, UINT8 ubGap, INT32 iFont, UINT8 ubColor, STR16 pString, UINT8 ubBackGroundColor, BOOLEAN fDirty, UINT32 uiFlags); @@ -62,7 +62,7 @@ RecordPtr GetFirstRecordOnThisPage( RecordPtr RecordList, INT32 iFont, UINT16 us FileStringPtr GetFirstStringOnThisPage( FileStringPtr RecordList, INT32 iFont, UINT16 usWidth, UINT8 ubGap, INT32 iPage, INT32 iPageSize, FileRecordWidthPtr iWidthArray ); // Places a shadow the width an height of the string, to PosX, posY -void ShadowText(UINT32 uiDestVSurface, STR16 pString, INT32 iFont, UINT16 usPosX, UINT16 usPosY ); +void ShadowText(UINT32 uiDestVSurface, const CHAR16* pString, INT32 iFont, UINT16 usPosX, UINT16 usPosY ); BOOLEAN ReduceStringLength( STR16 pString, UINT32 uiWidthToFitIn, INT32 iFont ); diff --git a/sgp/Font.cpp b/sgp/Font.cpp index 15d00bdba..0778c9d99 100644 --- a/sgp/Font.cpp +++ b/sgp/Font.cpp @@ -584,10 +584,11 @@ INT16 StringNPixLength(STR16 string, UINT32 uiMaxCount, INT32 UseFont) // Returns the length of a string in pixels, depending on the font given. // //***************************************************************************** -INT16 StringPixLength(const STR16 string, INT32 UseFont) +INT16 StringPixLength(const CHAR16* string, INT32 UseFont) { UINT32 Cur; - UINT16 *curletter,transletter; + const UINT16 *curletter; + UINT16 transletter; if ( iUseWinFonts ) { INT32 MapFont; MapFont = WinFontMap[UseFont]; @@ -602,7 +603,7 @@ INT16 StringPixLength(const STR16 string, INT32 UseFont) } Cur=0; - curletter = (UINT16 *)string; + curletter = (const UINT16 *)string; while((*curletter) != L'\0') { @@ -813,7 +814,7 @@ BOOLEAN SetFontDestBuffer(UINT32 DestBuffer, INT32 x1, INT32 y1, INT32 x2, INT32 // the parameters are identical to printf. The resulting string may be no longer // than 512 word-characters. Uses monochrome font color settings //***************************************************************************** -UINT32 mprintf(INT32 x, INT32 y, const STR16 pFontString, ...) +UINT32 mprintf(INT32 x, INT32 y, const CHAR16* pFontString, ...) { INT32 destx, desty; CHAR16 *curletter, transletter; @@ -864,7 +865,7 @@ UINT8 *pDestBuf; return(0); } -void VarFindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const STR16 pFontString, ... ) +void VarFindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const CHAR16* pFontString, ... ) { CHAR16 string[512]; va_list argptr; @@ -876,7 +877,7 @@ void VarFindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 s FindFontRightCoordinates( sLeft, sTop, sWidth, sHeight, string, iFontIndex, psNewX, psNewY ); } -void VarFindFontCenterCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const STR16 pFontString, ... ) +void VarFindFontCenterCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const CHAR16* pFontString, ... ) { CHAR16 string[512]; va_list argptr; diff --git a/sgp/Font.h b/sgp/Font.h index a48ff41ba..b28610f80 100644 --- a/sgp/Font.h +++ b/sgp/Font.h @@ -104,7 +104,7 @@ extern BOOLEAN IsFontLoaded(INT32 iFont); extern HVOBJECT GetFontObject(INT32 iFont); extern UINT32 gprintf(INT32 x, INT32 y, const STR16 pFontString, ...); extern UINT32 gprintfDirty(INT32 x, INT32 y, const STR16 pFontString, ...); -extern UINT32 mprintf(INT32 x, INT32 y, const STR16 pFontString, ...); +extern UINT32 mprintf(INT32 x, INT32 y, const CHAR16* pFontString, ...); extern UINT32 gprintf_buffer( UINT8 *pDestBuf, UINT32 uiDestPitchBYTES, UINT32 FontType, INT32 x, INT32 y, const STR16 pFontString, ...); extern UINT32 mprintf_buffer( UINT8 *pDestBuf, UINT32 uiDestPitchBYTES, UINT32 FontType, INT32 x, INT32 y, const STR16 pFontString, ...); @@ -132,15 +132,15 @@ extern UINT32 GetWidth(HVOBJECT hSrcVObject, INT16 ssIndex); extern INT16 StringPixLengthArgFastHelp( INT32 usUseFont, INT32 usBoldFont, UINT32 uiCharCount, STR16 pFontString ); extern INT16 StringPixLengthArg(INT32 usUseFont, UINT32 uiCharCount, STR16 pFontString, ...); -extern INT16 StringPixLength(const STR16 string,INT32 UseFont); +extern INT16 StringPixLength(const CHAR16* string,INT32 UseFont); extern INT16 SubstringPixLength(STR16 string, UINT32 iStart, UINT32 iEnd, INT32 UseFont); extern INT16 StringNPixLength(STR16 string, UINT32 uiMaxCount, INT32 UseFont); extern void SaveFontSettings(void); extern void RestoreFontSettings(void); -void VarFindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const STR16 pFontString, ... ); +void VarFindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const CHAR16* pFontString, ... ); -void VarFindFontCenterCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const STR16 pFontString, ... ); +void VarFindFontCenterCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY, const CHAR16* pFontString, ... ); void FindFontRightCoordinates( INT16 sLeft, INT16 sTop, INT16 sWidth, INT16 sHeight, const STR16 pStr, INT32 iFontIndex, INT16 *psNewX, INT16 *psNewY ); diff --git a/sgp/WinFont.cpp b/sgp/WinFont.cpp index 8836519a3..1d4b2aa85 100644 --- a/sgp/WinFont.cpp +++ b/sgp/WinFont.cpp @@ -461,7 +461,7 @@ void PrintWinFont( UINT32 uiDestBuf, INT32 iFont, INT32 x, INT32 y, STR16 pFontS } -INT16 WinFontStringPixLength( STR16 string2, INT32 iFont ) +INT16 WinFontStringPixLength( const CHAR16* string2, INT32 iFont ) { HWINFONT *pWinFont; pWinFont = GetWinFont( iFont ); @@ -469,7 +469,7 @@ INT16 WinFontStringPixLength( STR16 string2, INT32 iFont ) if (pWinFont == NULL) return(0); if(g_lang == i18n::Lang::zh) { - wchar_t *p=string2; + const wchar_t *p=string2; UINT32 size = 0; while (*p!=0) { diff --git a/sgp/WinFont.h b/sgp/WinFont.h index 751e42e37..3497b50fd 100644 --- a/sgp/WinFont.h +++ b/sgp/WinFont.h @@ -16,7 +16,7 @@ void SetWinFontForeColor( INT32 iFont, COLORVAL *pColor ); void PrintWinFont( UINT32 uiDestBuf, INT32 iFont, INT32 x, INT32 y, STR16 pFontString, ...); -INT16 WinFontStringPixLength( STR16 string, INT32 iFont ); +INT16 WinFontStringPixLength( const CHAR16* string, INT32 iFont ); INT16 GetWinFontHeight( INT32 iFont ); //if you cahnge this enum, you must change FontInfo struct in WinFont.cpp too.