5252// -----------------------------------------------------------------------------
5353#include " PreRTS.h"
5454
55+ #include " Common/AddonCompat.h"
5556#include " Common/INI.h"
5657#include " Common/Registry.h"
5758#include " Common/FileSystem.h"
5859#include " Common/UserPreferences.h"
5960
61+ #include " GameClient/Display.h"
6062#include " GameClient/GlobalLanguage.h"
6163
6264// -----------------------------------------------------------------------------
6365// DEFINES ////////////////////////////////////////////////////////////////////
6466// -----------------------------------------------------------------------------
65- GlobalLanguage *TheGlobalLanguageData = NULL ; // /< The global language singalton
67+ GlobalLanguage *TheGlobalLanguageData = NULL ; // /< The global language singleton
68+
69+ static const LookupListRec ResolutionFontSizeMethodNames[] =
70+ {
71+ { " CLASSIC" , GlobalLanguage::ResolutionFontSizeMethod_Classic },
72+ { " CLASSIC_NO_CEILING" , GlobalLanguage::ResolutionFontSizeMethod_ClassicNoCeiling },
73+ { " STRICT" , GlobalLanguage::ResolutionFontSizeMethod_Strict },
74+ { " BALANCED" , GlobalLanguage::ResolutionFontSizeMethod_Balanced },
75+ { NULL , 0 }
76+ };
6677
6778static const FieldParse TheGlobalLanguageDataFieldParseTable[] =
6879{
@@ -72,7 +83,7 @@ static const FieldParse TheGlobalLanguageDataFieldParseTable[] =
7283 { " MilitaryCaptionSpeed" , INI::parseInt, NULL , offsetof ( GlobalLanguage, m_militaryCaptionSpeed ) },
7384 { " UseHardWordWrap" , INI::parseBool, NULL , offsetof ( GlobalLanguage, m_useHardWrap) },
7485 { " ResolutionFontAdjustment" , INI::parseReal, NULL , offsetof ( GlobalLanguage, m_resolutionFontSizeAdjustment) },
75-
86+ { " ResolutionFontSizeMethod " , INI::parseLookupList, ResolutionFontSizeMethodNames, offsetof ( GlobalLanguage, m_resolutionFontSizeMethod) },
7687 { " CopyrightFont" , GlobalLanguage::parseFontDesc, NULL , offsetof ( GlobalLanguage, m_copyrightFont ) },
7788 { " MessageFont" , GlobalLanguage::parseFontDesc, NULL , offsetof ( GlobalLanguage, m_messageFont) },
7889 { " MilitaryCaptionTitleFont" , GlobalLanguage::parseFontDesc, NULL , offsetof ( GlobalLanguage, m_militaryCaptionTitleFont) },
@@ -118,6 +129,7 @@ GlobalLanguage::GlobalLanguage()
118129 m_militaryCaptionSpeed = 0 ;
119130 m_useHardWrap = FALSE ;
120131 m_resolutionFontSizeAdjustment = 0 .7f ;
132+ m_resolutionFontSizeMethod = ResolutionFontSizeMethod_Default;
121133 // End Add
122134
123135 m_userResolutionFontSizeAdjustment = -1 .0f ;
@@ -193,14 +205,88 @@ float GlobalLanguage::getResolutionFontSizeAdjustment( void ) const
193205
194206Int GlobalLanguage::adjustFontSize (Int theFontSize)
195207{
196- Real adjustFactor = TheGlobalData->m_xResolution / (Real)DEFAULT_DISPLAY_WIDTH;
197- adjustFactor = 1 .0f + (adjustFactor-1 .0f ) * getResolutionFontSizeAdjustment ();
198- if (adjustFactor<1 .0f ) adjustFactor = 1 .0f ;
199- if (adjustFactor>2 .0f ) adjustFactor = 2 .0f ;
208+ // TheSuperHackers @todo This function is called very often.
209+ // Therefore cache the adjustFactor on resolution change to not recompute it on every call.
210+ Real adjustFactor;
211+
212+ switch (m_resolutionFontSizeMethod)
213+ {
214+ default :
215+ case ResolutionFontSizeMethod_Classic:
216+ {
217+ // TheSuperHackers @info The original font scaling for this game.
218+ // Useful for not breaking legacy Addons and Mods. Scales poorly with large resolutions.
219+ adjustFactor = TheDisplay->getWidth () / (Real)DEFAULT_DISPLAY_WIDTH;
220+ adjustFactor = 1 .0f + (adjustFactor - 1 .0f ) * getResolutionFontSizeAdjustment ();
221+ if (adjustFactor > 2 .0f )
222+ adjustFactor = 2 .0f ;
223+ break ;
224+ }
225+ case ResolutionFontSizeMethod_ClassicNoCeiling:
226+ {
227+ // TheSuperHackers @feature The original font scaling, but without ceiling.
228+ // Useful for not changing the original look of the game. Scales alright with large resolutions.
229+ adjustFactor = TheDisplay->getWidth () / (Real)DEFAULT_DISPLAY_WIDTH;
230+ adjustFactor = 1 .0f + (adjustFactor - 1 .0f ) * getResolutionFontSizeAdjustment ();
231+ break ;
232+ }
233+ case ResolutionFontSizeMethod_Strict:
234+ {
235+ // TheSuperHackers @feature The strict method scales fonts based on the smallest screen
236+ // dimension so they scale independent of aspect ratio.
237+ const Real wScale = TheDisplay->getWidth () / (Real)DEFAULT_DISPLAY_WIDTH;
238+ const Real hScale = TheDisplay->getHeight () / (Real)DEFAULT_DISPLAY_HEIGHT;
239+ adjustFactor = min (wScale, hScale);
240+ adjustFactor = 1 .0f + (adjustFactor - 1 .0f ) * getResolutionFontSizeAdjustment ();
241+ break ;
242+ }
243+ case ResolutionFontSizeMethod_Balanced:
244+ {
245+ // TheSuperHackers @feature The balanced method evenly weighs the display width and height
246+ // for a balanced rescale on non 4:3 resolutions. The aspect ratio scaling is clamped to
247+ // prevent oversizing.
248+ constexpr const Real maxAspect = 1 .8f ;
249+ constexpr const Real minAspect = 1 .0f ;
250+ Real w = TheDisplay->getWidth ();
251+ Real h = TheDisplay->getHeight ();
252+ const Real aspect = w / h;
253+ Real wScale = w / (Real)DEFAULT_DISPLAY_WIDTH;
254+ Real hScale = h / (Real)DEFAULT_DISPLAY_HEIGHT;
255+
256+ if (aspect > maxAspect)
257+ {
258+ // Recompute width at max aspect
259+ w = maxAspect * h;
260+ wScale = w / (Real)DEFAULT_DISPLAY_WIDTH;
261+ }
262+ else if (aspect < minAspect)
263+ {
264+ // Recompute height at min aspect
265+ h = minAspect * w;
266+ hScale = h / (Real)DEFAULT_DISPLAY_HEIGHT;
267+ }
268+ adjustFactor = (wScale + hScale) * 0 .5f ;
269+ adjustFactor = 1 .0f + (adjustFactor - 1 .0f ) * getResolutionFontSizeAdjustment ();
270+ break ;
271+ }
272+ }
273+
274+ if (adjustFactor < 1 .0f )
275+ adjustFactor = 1 .0f ;
200276 Int pointSize = REAL_TO_INT_FLOOR (theFontSize*adjustFactor);
201277 return pointSize;
202278}
203279
280+ void GlobalLanguage::parseCustomDefinition ()
281+ {
282+ if (addon::HasFullviewportDat ())
283+ {
284+ // TheSuperHackers @tweak xezon 19/08/2025 Force the classic font size adjustment for the old
285+ // 'Control Bar Pro' Addons because they use manual font upscaling in higher resolution packages.
286+ m_resolutionFontSizeMethod = ResolutionFontSizeMethod_Classic;
287+ }
288+ }
289+
204290FontDesc::FontDesc (void )
205291{
206292 name = " Arial Unicode MS" ; // /<name of font
0 commit comments