52
52
// -----------------------------------------------------------------------------
53
53
#include " PreRTS.h"
54
54
55
+ #include " Common/AddonCompat.h"
55
56
#include " Common/FileSystem.h"
56
57
#include " Common/INI.h"
57
58
#include " Common/Registry.h"
64
65
// -----------------------------------------------------------------------------
65
66
GlobalLanguage *TheGlobalLanguageData = NULL ; // /< The global language singalton
66
67
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
+
67
76
static const FieldParse TheGlobalLanguageDataFieldParseTable[] =
68
77
{
69
78
{ " UnicodeFontName" , INI::parseAsciiString,NULL , offsetof ( GlobalLanguage, m_unicodeFontName ) },
@@ -72,7 +81,7 @@ static const FieldParse TheGlobalLanguageDataFieldParseTable[] =
72
81
{ " MilitaryCaptionSpeed" , INI::parseInt, NULL , offsetof ( GlobalLanguage, m_militaryCaptionSpeed ) },
73
82
{ " UseHardWordWrap" , INI::parseBool, NULL , offsetof ( GlobalLanguage, m_useHardWrap) },
74
83
{ " ResolutionFontAdjustment" , INI::parseReal, NULL , offsetof ( GlobalLanguage, m_resolutionFontSizeAdjustment) },
75
-
84
+ { " ResolutionFontSizeMethod " , INI::parseLookupList, ResolutionFontSizeMethodNames, offsetof ( GlobalLanguage, m_resolutionFontSizeMethod) },
76
85
{ " CopyrightFont" , GlobalLanguage::parseFontDesc, NULL , offsetof ( GlobalLanguage, m_copyrightFont ) },
77
86
{ " MessageFont" , GlobalLanguage::parseFontDesc, NULL , offsetof ( GlobalLanguage, m_messageFont) },
78
87
{ " MilitaryCaptionTitleFont" , GlobalLanguage::parseFontDesc, NULL , offsetof ( GlobalLanguage, m_militaryCaptionTitleFont) },
@@ -119,6 +128,7 @@ GlobalLanguage::GlobalLanguage()
119
128
m_militaryCaptionSpeed = 0 ;
120
129
m_useHardWrap = FALSE ;
121
130
m_resolutionFontSizeAdjustment = 0 .7f ;
131
+ m_resolutionFontSizeMethod = ResolutionFontSizeMethod_Balanced;
122
132
m_militaryCaptionDelayMS = 750 ;
123
133
// End Add
124
134
}
@@ -193,38 +203,76 @@ void GlobalLanguage::parseFontFileName( INI *ini, void * instance, void *store,
193
203
194
204
Int GlobalLanguage::adjustFontSize (Int theFontSize)
195
205
{
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)
209
209
{
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 ;
213
220
}
214
- else if (aspect < 1 . 0f )
221
+ case ResolutionFontSizeMethod_Strict:
215
222
{
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 ;
219
230
}
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;
220
241
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 ;
224
262
Int pointSize = REAL_TO_INT_FLOOR (theFontSize*adjustFactor);
225
263
return pointSize;
226
264
}
227
265
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
+
228
276
FontDesc::FontDesc (void )
229
277
{
230
278
name = " Arial Unicode MS" ; // /<name of font
0 commit comments