From 0acc22214b6ff61fd465ab02b04441abd27807c5 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Mon, 2 Sep 2024 22:08:19 +0000 Subject: [PATCH] Read scaling filter for fonts from config --- client/renderSDL/CBitmapFont.cpp | 15 +++++++++++---- config/schemas/settings.json | 6 ++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/client/renderSDL/CBitmapFont.cpp b/client/renderSDL/CBitmapFont.cpp index 4e6575593..7f30d75db 100644 --- a/client/renderSDL/CBitmapFont.cpp +++ b/client/renderSDL/CBitmapFont.cpp @@ -16,13 +16,14 @@ #include "../render/Colors.h" #include "../render/IScreenHandler.h" +#include "../../lib/CConfigHandler.h" #include "../../lib/Rect.h" +#include "../../lib/VCMI_Lib.h" #include "../../lib/filesystem/Filesystem.h" #include "../../lib/modding/CModHandler.h" #include "../../lib/texts/Languages.h" #include "../../lib/texts/TextOperations.h" #include "../../lib/vcmi_endian.h" -#include "../../lib/VCMI_Lib.h" #include #include @@ -200,9 +201,15 @@ CBitmapFont::CBitmapFont(const std::string & filename): if (GH.screenHandler().getScalingFactor() != 1) { - // scale using nearest neighbour - looks way better with H3 fonts than more high-quality xBRZ - // TODO: make configurable? - auto scaledSurface = CSDL_Ext::scaleSurfaceIntegerFactor(atlasImage, GH.screenHandler().getScalingFactor(), EScalingAlgorithm::NEAREST); + static const std::map filterNameToEnum = { + { "nearest", EScalingAlgorithm::NEAREST}, + { "bilinear", EScalingAlgorithm::BILINEAR}, + { "xbrz", EScalingAlgorithm::XBRZ} + }; + + auto filterName = settings["video"]["fontUpscalingFilter"].String(); + EScalingAlgorithm algorithm = filterNameToEnum.at(filterName); + auto scaledSurface = CSDL_Ext::scaleSurfaceIntegerFactor(atlasImage, GH.screenHandler().getScalingFactor(), algorithm); SDL_FreeSurface(atlasImage); atlasImage = scaledSurface; } diff --git a/config/schemas/settings.json b/config/schemas/settings.json index d1e70bc4f..7f08a6844 100644 --- a/config/schemas/settings.json +++ b/config/schemas/settings.json @@ -167,6 +167,7 @@ "targetfps", "vsync", "upscalingFilter", + "fontUpscalingFilter", "downscalingFilter" ], "properties" : { @@ -231,6 +232,11 @@ "type" : "boolean", "default" : true }, + "fontUpscalingFilter" : { + "type" : "string", + "enum" : [ "nearest", "bilinear", "xbrz" ], + "default" : "nearest" + }, "upscalingFilter" : { "type" : "string", "enum" : [ "auto", "none", "xbrz2", "xbrz3", "xbrz4" ],