5252// -----------------------------------------------------------------------------
5353#include " PreRTS.h"
5454
55+ #include " Common/AddonCompat.h"
5556#include " Common/FileSystem.h"
5657#include " Common/INI.h"
5758#include " Common/Registry.h"
6465// -----------------------------------------------------------------------------
6566GlobalLanguage *TheGlobalLanguageData = NULL ; // /< The global language singalton
6667
68+ static const LookupListRec ResolutionFontSizeMethodNames[] =
69+ {
70+ { " CLASSIC" , GlobalLanguage::ResolutionFontSizeMethod_Classic },
71+ { " STRICT" , GlobalLanguage::ResolutionFontSizeMethod_Strict },
72+ { " BALANCED" , GlobalLanguage::ResolutionFontSizeMethod_Balanced },
73+ { NULL , 0 }
74+ };
75+
6776static const FieldParse TheGlobalLanguageDataFieldParseTable[] =
6877{
6978 { " UnicodeFontName" , INI::parseAsciiString,NULL , offsetof ( GlobalLanguage, m_unicodeFontName ) },
@@ -72,7 +81,7 @@ static const FieldParse TheGlobalLanguageDataFieldParseTable[] =
7281 { " MilitaryCaptionSpeed" , INI::parseInt, NULL , offsetof ( GlobalLanguage, m_militaryCaptionSpeed ) },
7382 { " UseHardWordWrap" , INI::parseBool, NULL , offsetof ( GlobalLanguage, m_useHardWrap) },
7483 { " ResolutionFontAdjustment" , INI::parseReal, NULL , offsetof ( GlobalLanguage, m_resolutionFontSizeAdjustment) },
75-
84+ { " ResolutionFontSizeMethod " , INI::parseLookupList, ResolutionFontSizeMethodNames, offsetof ( GlobalLanguage, m_resolutionFontSizeMethod) },
7685 { " CopyrightFont" , GlobalLanguage::parseFontDesc, NULL , offsetof ( GlobalLanguage, m_copyrightFont ) },
7786 { " MessageFont" , GlobalLanguage::parseFontDesc, NULL , offsetof ( GlobalLanguage, m_messageFont) },
7887 { " MilitaryCaptionTitleFont" , GlobalLanguage::parseFontDesc, NULL , offsetof ( GlobalLanguage, m_militaryCaptionTitleFont) },
@@ -119,6 +128,7 @@ GlobalLanguage::GlobalLanguage()
119128 m_militaryCaptionSpeed = 0 ;
120129 m_useHardWrap = FALSE ;
121130 m_resolutionFontSizeAdjustment = 0 .7f ;
131+ m_resolutionFontSizeMethod = ResolutionFontSizeMethod_Balanced;
122132 m_militaryCaptionDelayMS = 750 ;
123133 // End Add
124134}
@@ -193,38 +203,76 @@ void GlobalLanguage::parseFontFileName( INI *ini, void * instance, void *store,
193203
194204Int GlobalLanguage::adjustFontSize (Int theFontSize)
195205{
196- // TheSuperHackers @tweak xezon 16/08/2025 The size adjustment now also weighs in
197- // the display height for a balanced rescale on non 4:3 resolutions.
198- // The aspect ratio scaling is clamped between 1 and 2 to avoid oversizing.
199- // The scaler no longer clamps at max 2, which makes it work properly for
200- // 4k Resolutions and beyond.
201-
202- Real w = TheDisplay->getWidth ();
203- Real h = TheDisplay->getHeight ();
204- const Real aspect = w / h;
205- Real wScale = w / (Real)DEFAULT_DISPLAY_WIDTH;
206- Real hScale = h / (Real)DEFAULT_DISPLAY_HEIGHT;
207-
208- if (aspect > 2 .0f )
206+ Real adjustFactor;
207+
208+ switch (m_resolutionFontSizeMethod)
209209 {
210- // Recompute width at aspect=2
211- w = 2 .0f * h;
212- wScale = w / (Real)DEFAULT_DISPLAY_WIDTH;
210+ default :
211+ case ResolutionFontSizeMethod_Classic:
212+ {
213+ // TheSuperHackers @info The original font scaling for this game.
214+ // Can be useful for not breaking legacy Addons and Mods but scales poorly.
215+ adjustFactor = TheDisplay->getWidth () / (Real)DEFAULT_DISPLAY_WIDTH;
216+ adjustFactor = 1 .0f + (adjustFactor - 1 .0f ) * m_resolutionFontSizeAdjustment;
217+ if (adjustFactor > 2 .0f )
218+ adjustFactor = 2 .0f ;
219+ break ;
213220 }
214- else if (aspect < 1 . 0f )
221+ case ResolutionFontSizeMethod_Strict:
215222 {
216- // Recompute height at aspect=1
217- h = 1 .0f * w;
218- hScale = h / (Real)DEFAULT_DISPLAY_HEIGHT;
223+ // TheSuperHackers @feature The strict method scales fonts based on the smallest screen
224+ // dimension so they scale independent of aspect ratio.
225+ const Real wScale = TheDisplay->getWidth () / (Real)DEFAULT_DISPLAY_WIDTH;
226+ const Real hScale = TheDisplay->getHeight () / (Real)DEFAULT_DISPLAY_HEIGHT;
227+ adjustFactor = min (wScale, hScale);
228+ adjustFactor = 1 .0f + (adjustFactor - 1 .0f ) * m_resolutionFontSizeAdjustment;
229+ break ;
219230 }
231+ case ResolutionFontSizeMethod_Balanced:
232+ {
233+ // TheSuperHackers @feature The balanced method evenly weighs the display width and height
234+ // for a balanced rescale on non 4:3 resolutions. The aspect ratio scaling is clamped
235+ // between 1 and 2 to avoid oversizing.
236+ Real w = TheDisplay->getWidth ();
237+ Real h = TheDisplay->getHeight ();
238+ const Real aspect = w / h;
239+ Real wScale = w / (Real)DEFAULT_DISPLAY_WIDTH;
240+ Real hScale = h / (Real)DEFAULT_DISPLAY_HEIGHT;
220241
221- Real adjustFactor = (wScale + hScale) * 0 .5f ;
222- adjustFactor = 1 .0f + (adjustFactor-1 .0f ) * m_resolutionFontSizeAdjustment;
223- if (adjustFactor < 1 .0f ) adjustFactor = 1 .0f ;
242+ if (aspect > 2 .0f )
243+ {
244+ // Recompute width at aspect=2
245+ w = 2 .0f * h;
246+ wScale = w / (Real)DEFAULT_DISPLAY_WIDTH;
247+ }
248+ else if (aspect < 1 .0f )
249+ {
250+ // Recompute height at aspect=1
251+ h = 1 .0f * w;
252+ hScale = h / (Real)DEFAULT_DISPLAY_HEIGHT;
253+ }
254+ adjustFactor = (wScale + hScale) * 0 .5f ;
255+ adjustFactor = 1 .0f + (adjustFactor - 1 .0f ) * m_resolutionFontSizeAdjustment;
256+ break ;
257+ }
258+ }
259+
260+ if (adjustFactor < 1 .0f )
261+ adjustFactor = 1 .0f ;
224262 Int pointSize = REAL_TO_INT_FLOOR (theFontSize*adjustFactor);
225263 return pointSize;
226264}
227265
266+ void GlobalLanguage::parseCustomDefinition ()
267+ {
268+ if (addon::HasFullviewportDat ())
269+ {
270+ // TheSuperHackers @tweak xezon 19/08/2025 Force the classic font size adjustment for the old
271+ // 'Control Bar Pro' Addons because they use manual font upscaling in higher resolution packages.
272+ m_resolutionFontSizeMethod = ResolutionFontSizeMethod_Classic;
273+ }
274+ }
275+
228276FontDesc::FontDesc (void )
229277{
230278 name = " Arial Unicode MS" ; // /<name of font
0 commit comments