Skip to content
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/new_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,4 @@ Once a release cycle:

- Check that completions are still working with `fish` and `zsh` when tab is pressed
- Check that F3D is added for extensions on a fresh Windows installation
- Check that the font scale has been scaled correctly when using a HiDPI screen (only supported on Windows)
5 changes: 4 additions & 1 deletion application/F3DStarter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,10 @@ class F3DStarter::F3DInternals
f3d::window& window = this->Engine->getWindow();
if (this->AppOptions.Resolution.size() == 2)
{
window.setSize(this->AppOptions.Resolution[0], this->AppOptions.Resolution[1]);
double dpiScale = f3d::utils::getDPIScale();

window.setSize(static_cast<int>(this->AppOptions.Resolution[0] * dpiScale),
static_cast<int>(this->AppOptions.Resolution[1] * dpiScale));
}
else if (!this->AppOptions.Resolution.empty())
{
Expand Down
4 changes: 4 additions & 0 deletions doc/user/11-DESKTOP_INTEGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ cd C:\path\to\f3d\bin\
regsvr32 /u F3DShellExtension.dll
```

On Windows platforms where screen DPI detection is supported, the F3D window resolution and fonts are scaled by the display scaling factor.

For example, if you specify `--resolution=800,600` in the CLI options and the system display scale is set to `150%`, the effective window resolution becomes `1200×900`.

## MacOS

There is no support for thumbnails on MacOS, the .dmg binary release provides automatic file openings.
Expand Down
7 changes: 7 additions & 0 deletions library/public/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ class F3D_EXPORT utils
*/
[[nodiscard]] static std::string globToRegex(std::string_view glob, char pathSeparator = '/');

/**
* Get the primary monitor system zoom scale base on DPI.
* Currently only supported on Windows platform.
* Return a hardcoded 1.f on other platform.
*/
[[nodiscard]] static double getDPIScale();

/**
* Get an environment variable value, returns std::nullopt if not set
*/
Expand Down
7 changes: 7 additions & 0 deletions library/src/utils.cxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "utils.h"

#include "F3DUtils.h"
#include "levenshtein.h"
#include "log.h"

Expand Down Expand Up @@ -331,6 +332,12 @@ std::string utils::globToRegex(std::string_view glob, char pathSeparator)
return result;
}

//----------------------------------------------------------------------------
double utils::getDPIScale()
{
return F3DUtils::getDPIScale();
}

//----------------------------------------------------------------------------
std::optional<std::string> utils::getEnv(const std::string& env)
{
Expand Down
1 change: 1 addition & 0 deletions python/F3DPythonBindings.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ PYBIND11_MODULE(pyf3d, module)
.def_static("tokenize", &f3d::utils::tokenize, py::arg("str"), py::arg("keep_comments") = true)
.def_static(
"glob_to_regex", &f3d::utils::globToRegex, py::arg("glob"), py::arg("path_separator") = '/')
.def_static("get_dpi_scale", &f3d::utils::getDPIScale)
.def_static("get_env", &f3d::utils::getEnv)
.def_static("get_known_folder", &f3d::utils::getKnownFolder);

Expand Down
4 changes: 2 additions & 2 deletions testing/baselines/TestFontScale2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions testing/baselines/TestFontScale3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions vtkext/private/module/vtkF3DImguiActor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -328,17 +328,17 @@ void vtkF3DImguiActor::Initialize(vtkOpenGLRenderWindow* renWin)
// ImGui API is not very helpful with this
fontConfig.FontDataOwnedByAtlas = false;
font = io.Fonts->AddFontFromMemoryTTF(
const_cast<void*>(reinterpret_cast<const void*>(F3DFontBuffer)), sizeof(F3DFontBuffer), 18,
&fontConfig, ranges.Data);
const_cast<void*>(reinterpret_cast<const void*>(F3DFontBuffer)), sizeof(F3DFontBuffer),
18 * this->FontScale, &fontConfig, ranges.Data);
}
else
{
font = io.Fonts->AddFontFromFileTTF(this->FontFile.c_str(), 18, &fontConfig, ranges.Data);
font = io.Fonts->AddFontFromFileTTF(
this->FontFile.c_str(), 18 * this->FontScale, &fontConfig, ranges.Data);
}

io.Fonts->Build();
io.FontDefault = font;
io.FontGlobalScale = this->FontScale;

ImVec4 colTransparent = ImVec4(0.0f, 0.0f, 0.0f, 0.0f); // #000000

Expand All @@ -352,6 +352,7 @@ void vtkF3DImguiActor::Initialize(vtkOpenGLRenderWindow* renWin)
style->WindowBorderSize = 0.f;
style->WindowPadding = ImVec2(10, 10);
style->WindowRounding = 8.f;
style->ScaleAllSizes(this->FontScale);
style->Colors[ImGuiCol_Text] = F3DStyle::imgui::GetTextColor();
style->Colors[ImGuiCol_WindowBg] = F3DStyle::imgui::GetBackgroundColor();
style->Colors[ImGuiCol_FrameBg] = colTransparent;
Expand Down
3 changes: 2 additions & 1 deletion vtkext/private/module/vtkF3DRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "F3DColoringInfoHandler.h"
#include "F3DDefaultHDRI.h"
#include "F3DLog.h"
#include "F3DUtils.h"
#include "vtkF3DCachedLUTTexture.h"
#include "vtkF3DCachedSpecularTexture.h"
#include "vtkF3DInteractorStyle.h"
Expand Down Expand Up @@ -1345,7 +1346,7 @@ void vtkF3DRenderer::ConfigureTextActors()
}
}

this->UIActor->SetFontScale(this->FontScale);
this->UIActor->SetFontScale(this->FontScale * F3DUtils::getDPIScale());

this->TextActorsConfigured = true;
}
Expand Down
14 changes: 14 additions & 0 deletions vtkext/public/module/F3DUtils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <vtkObject.h>
#include <vtkSetGet.h>
#include <vtkWindows.h>

#include <charconv>
#include <stdexcept>
Expand Down Expand Up @@ -53,3 +54,16 @@ int F3DUtils::ParseToInt(const std::string& str, int def, const std::string& nam
}
return value;
}

//----------------------------------------------------------------------------
double F3DUtils::getDPIScale()
{
double dpiScale = 1.0;

#ifdef _WIN32
int dpi = GetDeviceCaps(wglGetCurrentDC(), LOGPIXELSY); // Default return 96
dpiScale = static_cast<double>(dpi) / 96;
#endif

return dpiScale;
}
7 changes: 7 additions & 0 deletions vtkext/public/module/F3DUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ VTKEXT_EXPORT double ParseToDouble(
* Use nameError in the log for easier debugging.
*/
VTKEXT_EXPORT int ParseToInt(const std::string& str, int def, const std::string& nameError);

/*
* Get the primary monitor system zoom scale base on DPI.
* Currently only supported on Windows platform.
* Return a hardcoded 1.f on other platform.
*/
VTKEXT_EXPORT double getDPIScale();
};

#endif