66
77#include " ui_local.h"
88
9+ #include < algorithm>
910#include < filesystem>
1011#include < fstream>
1112#include < zlib.h>
@@ -799,10 +800,11 @@ static int l_SetViewport(lua_State* L)
799800 for (int i = 1 ; i <= 4 ; i++) {
800801 ui->LAssert (L, lua_isnumber (L, i), " SetViewport() argument %d: expected number, got %s" , i, luaL_typename (L, i));
801802 }
802- ui->renderer ->SetViewport ((int )(lua_tointeger (L, 1 ) * dpiScale),
803- (int )(lua_tointeger (L, 2 ) * dpiScale),
804- (int )(lua_tointeger (L, 3 ) * dpiScale),
805- (int )(lua_tointeger (L, 4 ) * dpiScale));
803+ int vpX = (int )std::lround (lua_tonumber (L, 1 ) * dpiScale);
804+ int vpY = (int )std::lround (lua_tonumber (L, 2 ) * dpiScale);
805+ int vpWidth = (int )std::ceil (lua_tonumber (L, 3 ) * dpiScale);
806+ int vpHeight = (int )std::ceil (lua_tonumber (L, 4 ) * dpiScale);
807+ ui->renderer ->SetViewport (vpX, vpY, vpWidth, vpHeight);
806808 }
807809 else {
808810 ui->renderer ->SetViewport ();
@@ -1071,14 +1073,21 @@ static int l_DrawString(lua_State* L)
10711073 const float dpiScale = ui->renderer ->VirtualScreenScaleFactor ();
10721074 const float left = lua_tonumber (L, 1 ) * dpiScale;
10731075 const float top = lua_tonumber (L, 2 ) * dpiScale;
1074- const int scaledHeight = (int )std::lround ((double )lua_tointeger (L, 4 ) * (double )dpiScale);
1076+ const lua_Number logicalHeight = lua_tonumber (L, 4 );
1077+ int scaledHeight = (int )std::lround (logicalHeight * dpiScale);
1078+ if (scaledHeight <= 1 ) {
1079+ scaledHeight = std::max (1 , scaledHeight);
1080+ }
1081+ else {
1082+ scaledHeight = (scaledHeight + 1 ) & ~1 ;
1083+ }
10751084 ui->renderer ->DrawString (
10761085 left,
10771086 top,
10781087 luaL_checkoption (L, 3 , " LEFT" , alignMap),
10791088 scaledHeight,
1080- NULL ,
1081- luaL_checkoption (L, 5 , " FIXED" , fontMap),
1089+ NULL ,
1090+ luaL_checkoption (L, 5 , " FIXED" , fontMap),
10821091 lua_tostring (L, 6 )
10831092 );
10841093 return 0 ;
@@ -1097,7 +1106,13 @@ static int l_DrawStringWidth(lua_State* L)
10971106 const float dpiScale = ui->renderer ->VirtualScreenScaleFactor ();
10981107 const lua_Number logicalHeight = lua_tonumber (L, 1 );
10991108 int scaledHeight = (int )std::lround (logicalHeight * dpiScale);
1100- double const physicalWidth = (double )ui->renderer ->DrawStringWidth (
1109+ if (scaledHeight <= 1 ) {
1110+ scaledHeight = std::max (1 , scaledHeight);
1111+ }
1112+ else {
1113+ scaledHeight = (scaledHeight + 1 ) & ~1 ;
1114+ }
1115+ double const physicalWidth = ui->renderer ->DrawStringWidth (
11011116 scaledHeight,
11021117 luaL_checkoption (L, 2 , " FIXED" , fontMap),
11031118 lua_tostring (L, 3 ));
@@ -1121,7 +1136,13 @@ static int l_DrawStringCursorIndex(lua_State* L)
11211136 const lua_Number logicalHeight = lua_tonumber (L, 1 );
11221137 const lua_Number logicalCursorX = lua_tonumber (L, 4 );
11231138 const lua_Number logicalCursorY = lua_tonumber (L, 5 );
1124- const int scaledHeight = (int )std::lround (logicalHeight * dpiScale);
1139+ int scaledHeight = (int )std::lround (logicalHeight * dpiScale);
1140+ if (scaledHeight <= 1 ) {
1141+ scaledHeight = std::max (1 , scaledHeight);
1142+ }
1143+ else {
1144+ scaledHeight = (scaledHeight + 1 ) & ~1 ;
1145+ }
11251146 const int scaledCursorX = (int )std::lround (logicalCursorX * dpiScale);
11261147 const int scaledCursorY = (int )std::lround (logicalCursorY * dpiScale);
11271148 lua_pushinteger (L, ui->renderer ->DrawStringCursorIndex (
0 commit comments