-
Notifications
You must be signed in to change notification settings - Fork 118
tweak(font): Redesign and fix the font scaling for large resolutions and non 4:3 aspect ratios #1466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
tweak(font): Redesign and fix the font scaling for large resolutions and non 4:3 aspect ratios #1466
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| ** Command & Conquer Generals Zero Hour(tm) | ||
| ** Copyright 2025 TheSuperHackers | ||
| ** | ||
| ** This program is free software: you can redistribute it and/or modify | ||
| ** it under the terms of the GNU General Public License as published by | ||
| ** the Free Software Foundation, either version 3 of the License, or | ||
| ** (at your option) any later version. | ||
| ** | ||
| ** This program is distributed in the hope that it will be useful, | ||
| ** but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| ** GNU General Public License for more details. | ||
| ** | ||
| ** You should have received a copy of the GNU General Public License | ||
| ** along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| namespace addon | ||
| { | ||
| extern Bool HasFullviewportDat(); | ||
|
|
||
| } // namespace addon |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| ** Command & Conquer Generals Zero Hour(tm) | ||
| ** Copyright 2025 TheSuperHackers | ||
| ** | ||
| ** This program is free software: you can redistribute it and/or modify | ||
| ** it under the terms of the GNU General Public License as published by | ||
| ** the Free Software Foundation, either version 3 of the License, or | ||
| ** (at your option) any later version. | ||
| ** | ||
| ** This program is distributed in the hope that it will be useful, | ||
| ** but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| ** GNU General Public License for more details. | ||
| ** | ||
| ** You should have received a copy of the GNU General Public License | ||
| ** along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #include "PreRTS.h" | ||
|
|
||
| #include "Common/AddonCompat.h" | ||
| #include "Common/FileSystem.h" | ||
|
|
||
| namespace addon | ||
| { | ||
| Bool HasFullviewportDat() | ||
| { | ||
| Char value = '0'; | ||
| if (File* file = TheFileSystem->openFile("GenTool/fullviewport.dat", File::READ | File::BINARY)) | ||
| { | ||
| file->read(&value, 1); | ||
| } | ||
| return value != '0'; | ||
| } | ||
|
|
||
| } // namespace addon |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,16 +52,27 @@ | |
| //----------------------------------------------------------------------------- | ||
| #include "PreRTS.h" | ||
|
|
||
| #include "Common/AddonCompat.h" | ||
| #include "Common/FileSystem.h" | ||
| #include "Common/INI.h" | ||
| #include "Common/Registry.h" | ||
|
|
||
| #include "GameClient/Display.h" | ||
| #include "GameClient/GlobalLanguage.h" | ||
| #include "Common/FileSystem.h" | ||
|
|
||
| //----------------------------------------------------------------------------- | ||
| // DEFINES //////////////////////////////////////////////////////////////////// | ||
| //----------------------------------------------------------------------------- | ||
| GlobalLanguage *TheGlobalLanguageData = NULL; ///< The global language singalton | ||
|
|
||
| static const LookupListRec ResolutionFontSizeMethodNames[] = | ||
| { | ||
| { "CLASSIC", GlobalLanguage::ResolutionFontSizeMethod_Classic }, | ||
| { "STRICT", GlobalLanguage::ResolutionFontSizeMethod_Strict }, | ||
| { "BALANCED", GlobalLanguage::ResolutionFontSizeMethod_Balanced }, | ||
| { NULL, 0 } | ||
| }; | ||
|
|
||
| static const FieldParse TheGlobalLanguageDataFieldParseTable[] = | ||
| { | ||
| { "UnicodeFontName", INI::parseAsciiString,NULL, offsetof( GlobalLanguage, m_unicodeFontName ) }, | ||
|
|
@@ -70,7 +81,7 @@ static const FieldParse TheGlobalLanguageDataFieldParseTable[] = | |
| { "MilitaryCaptionSpeed", INI::parseInt, NULL, offsetof( GlobalLanguage, m_militaryCaptionSpeed ) }, | ||
| { "UseHardWordWrap", INI::parseBool, NULL, offsetof( GlobalLanguage, m_useHardWrap) }, | ||
| { "ResolutionFontAdjustment", INI::parseReal, NULL, offsetof( GlobalLanguage, m_resolutionFontSizeAdjustment) }, | ||
|
|
||
| { "ResolutionFontSizeMethod", INI::parseLookupList, ResolutionFontSizeMethodNames, offsetof( GlobalLanguage, m_resolutionFontSizeMethod) }, | ||
| { "CopyrightFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_copyrightFont ) }, | ||
| { "MessageFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_messageFont) }, | ||
| { "MilitaryCaptionTitleFont", GlobalLanguage::parseFontDesc, NULL, offsetof( GlobalLanguage, m_militaryCaptionTitleFont) }, | ||
|
|
@@ -117,6 +128,7 @@ GlobalLanguage::GlobalLanguage() | |
| m_militaryCaptionSpeed = 0; | ||
| m_useHardWrap = FALSE; | ||
| m_resolutionFontSizeAdjustment = 0.7f; | ||
| m_resolutionFontSizeMethod = ResolutionFontSizeMethod_Balanced; | ||
| m_militaryCaptionDelayMS = 750; | ||
| //End Add | ||
| } | ||
|
|
@@ -191,14 +203,76 @@ void GlobalLanguage::parseFontFileName( INI *ini, void * instance, void *store, | |
|
|
||
| Int GlobalLanguage::adjustFontSize(Int theFontSize) | ||
| { | ||
| Real adjustFactor = TheGlobalData->m_xResolution / (Real)DEFAULT_DISPLAY_WIDTH; | ||
| adjustFactor = 1.0f + (adjustFactor-1.0f) * m_resolutionFontSizeAdjustment; | ||
| if (adjustFactor<1.0f) adjustFactor = 1.0f; | ||
| if (adjustFactor>2.0f) adjustFactor = 2.0f; | ||
|
||
| Real adjustFactor; | ||
|
|
||
| switch (m_resolutionFontSizeMethod) | ||
| { | ||
| default: | ||
| case ResolutionFontSizeMethod_Classic: | ||
| { | ||
| // TheSuperHackers @info The original font scaling for this game. | ||
| // Can be useful for not breaking legacy Addons and Mods but scales poorly. | ||
| adjustFactor = TheDisplay->getWidth() / (Real)DEFAULT_DISPLAY_WIDTH; | ||
| adjustFactor = 1.0f + (adjustFactor - 1.0f) * m_resolutionFontSizeAdjustment; | ||
| if (adjustFactor > 2.0f) | ||
| adjustFactor = 2.0f; | ||
| break; | ||
| } | ||
| case ResolutionFontSizeMethod_Strict: | ||
| { | ||
| // TheSuperHackers @feature The strict method scales fonts based on the smallest screen | ||
| // dimension so they scale independent of aspect ratio. | ||
| const Real wScale = TheDisplay->getWidth() / (Real)DEFAULT_DISPLAY_WIDTH; | ||
| const Real hScale = TheDisplay->getHeight() / (Real)DEFAULT_DISPLAY_HEIGHT; | ||
| adjustFactor = min(wScale, hScale); | ||
| adjustFactor = 1.0f + (adjustFactor - 1.0f) * m_resolutionFontSizeAdjustment; | ||
| break; | ||
| } | ||
| case ResolutionFontSizeMethod_Balanced: | ||
| { | ||
| // TheSuperHackers @feature The balanced method evenly weighs the display width and height | ||
| // for a balanced rescale on non 4:3 resolutions. The aspect ratio scaling is clamped | ||
| // between 1 and 2 to avoid oversizing. | ||
| Real w = TheDisplay->getWidth(); | ||
| Real h = TheDisplay->getHeight(); | ||
| const Real aspect = w / h; | ||
| Real wScale = w / (Real)DEFAULT_DISPLAY_WIDTH; | ||
| Real hScale = h / (Real)DEFAULT_DISPLAY_HEIGHT; | ||
|
|
||
| if (aspect > 2.0f) | ||
| { | ||
| // Recompute width at aspect=2 | ||
| w = 2.0f * h; | ||
| wScale = w / (Real)DEFAULT_DISPLAY_WIDTH; | ||
| } | ||
| else if (aspect < 1.0f) | ||
| { | ||
| // Recompute height at aspect=1 | ||
| h = 1.0f * w; | ||
| hScale = h / (Real)DEFAULT_DISPLAY_HEIGHT; | ||
| } | ||
| adjustFactor = (wScale + hScale) * 0.5f; | ||
| adjustFactor = 1.0f + (adjustFactor - 1.0f) * m_resolutionFontSizeAdjustment; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (adjustFactor < 1.0f) | ||
| adjustFactor = 1.0f; | ||
| Int pointSize = REAL_TO_INT_FLOOR(theFontSize*adjustFactor); | ||
| return pointSize; | ||
| } | ||
|
|
||
| void GlobalLanguage::parseCustomDefinition() | ||
| { | ||
| if (addon::HasFullviewportDat()) | ||
| { | ||
| // TheSuperHackers @tweak xezon 19/08/2025 Force the classic font size adjustment for the old | ||
| // 'Control Bar Pro' Addons because they use manual font upscaling in higher resolution packages. | ||
| m_resolutionFontSizeMethod = ResolutionFontSizeMethod_Classic; | ||
| } | ||
| } | ||
|
|
||
| FontDesc::FontDesc(void) | ||
| { | ||
| name = "Arial Unicode MS"; ///<name of font | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this better default to
ResolutionFontSizeMethod_ClassicNoCap, where the classic scaling no longer caps at 2x. This way for users the default optics do not change, but it will still work for >1920x1080 resolutions.