From a6107139b627f1a3277c707f873106ca4c882f9d Mon Sep 17 00:00:00 2001 From: halx99 Date: Wed, 13 Dec 2023 01:56:53 +0800 Subject: [PATCH] Fix Device::getPixelRatio for win32,android --- .appveyor.yml | 5 +++++ core/2d/FontAtlas.cpp | 2 +- core/2d/FontFreeType.h | 2 +- core/2d/Label.h | 4 ++-- core/platform/Device.h | 1 + .../android/java/src/org/axmol/lib/AxmolEngine.java | 7 +------ core/platform/win32/Device-win32.cpp | 7 +++++-- core/platform/winrt/xaml/AxmolRenderer.cpp | 2 +- 8 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index cfdd9b2441..ce68c5adb1 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -6,6 +6,11 @@ version: 2.1.0.{build} install: - git submodule update --init --recursive +skip_commits: + files: + - docs/* + - '**/*.md' + build_script: - pwsh: .\build.ps1 -p wasm -xb '--target','cpp-tests','--config','Release' -xc '-DAX_ENABLE_EXT_EFFEKSEER=ON','-DAX_WASM_THREADS=8' - pwsh: .\build.ps1 -p wasm -xb '--target','fairygui-tests','--config','Release' -xc '-DAX_ENABLE_EXT_EFFEKSEER=ON','-DAX_WASM_THREADS=8' diff --git a/core/2d/FontAtlas.cpp b/core/2d/FontAtlas.cpp index 202e6a92c3..107b1c5056 100644 --- a/core/2d/FontAtlas.cpp +++ b/core/2d/FontAtlas.cpp @@ -64,7 +64,7 @@ void FontAtlas::loadFontAtlas(std::string_view fontatlasFile, hlookup::string_ma std::string_view type = settings["type"]; if (type != "fontatlas") { - ax::print("Load fontatlas %s fail, invalid asset type: ", fontatlasFile.data(), type.data()); + ax::print("Load fontatlas %s fail, invalid asset type: %s", fontatlasFile.data(), type.data()); return; } diff --git a/core/2d/FontFreeType.h b/core/2d/FontFreeType.h index d0124ff9f7..4ac63f34c9 100644 --- a/core/2d/FontFreeType.h +++ b/core/2d/FontFreeType.h @@ -70,7 +70,7 @@ public: static void setMissingGlyphCharacter(char32_t charCode) { _mssingGlyphCharacter = charCode; }; /** - * @brief Whether enable SDF font rendering globally, by default: disabled, since axmol-2.0.1 + * @brief Whether enable SDF font rendering globally, by default: disabled, since axmol-2.1.0 * * @param enabled */ diff --git a/core/2d/Label.h b/core/2d/Label.h index 2453464518..d3aeeaf2a1 100644 --- a/core/2d/Label.h +++ b/core/2d/Label.h @@ -550,11 +550,11 @@ public: /** * Set the ttf/ttc font face size to determine how big to generate SDF bitmap - * since axmol-2.0.1 + * since axmol-2.1.0 */ void setTTFFaceSize(int faceSize); - /** Gets ttf/ttc font face size, since axmol-2.0.1 */ + /** Gets ttf/ttc font face size, since axmol-2.1.0 */ int getTTFFaceSize() const; /** diff --git a/core/platform/Device.h b/core/platform/Device.h index 3205336332..334e971404 100644 --- a/core/platform/Device.h +++ b/core/platform/Device.h @@ -86,6 +86,7 @@ public: /** * Gets the device pixel ratio + * @since axmol-2.1.0 */ static float getPixelRatio(); diff --git a/core/platform/android/java/src/org/axmol/lib/AxmolEngine.java b/core/platform/android/java/src/org/axmol/lib/AxmolEngine.java index f9125776a8..79389f5d58 100644 --- a/core/platform/android/java/src/org/axmol/lib/AxmolEngine.java +++ b/core/platform/android/java/src/org/axmol/lib/AxmolEngine.java @@ -404,12 +404,7 @@ public class AxmolEngine { private static int displayMetricsToDPI(DisplayMetrics metrics) { - if(metrics.xdpi != metrics.ydpi) { - Log.w(AxmolEngine.TAG, "xdpi != ydpi, use (xdpi + ydpi)/2 instead."); - return (int) ((metrics.xdpi + metrics.ydpi) / 2.0); - } else { - return (int)metrics.xdpi; - } + return metrics.densityDpi; } public static int getDPI() diff --git a/core/platform/win32/Device-win32.cpp b/core/platform/win32/Device-win32.cpp index 18a91d3063..c10e405d5b 100644 --- a/core/platform/win32/Device-win32.cpp +++ b/core/platform/win32/Device-win32.cpp @@ -46,9 +46,12 @@ int Device::getDPI() return dpi; } -float Device::getPixelRatio() +float Device::getPixelRatio() { - return Device::getDPI() / 96.0f; + const HDC dc = GetDC(NULL); + const auto xdpi = GetDeviceCaps(dc, LOGPIXELSX); + ReleaseDC(nullptr, dc); + return xdpi / 96.0f; } void Device::setAccelerometerEnabled(bool isEnabled) {} diff --git a/core/platform/winrt/xaml/AxmolRenderer.cpp b/core/platform/winrt/xaml/AxmolRenderer.cpp index d6710b52e8..6fba34e640 100644 --- a/core/platform/winrt/xaml/AxmolRenderer.cpp +++ b/core/platform/winrt/xaml/AxmolRenderer.cpp @@ -59,7 +59,7 @@ void AxmolRenderer::Resume() if (!glview) { GLViewImpl* glview = GLViewImpl::createWithRect( - "AXMOL10", ax::Rect{0, 0, static_cast(m_width), static_cast(m_height)}); + "axmol2", ax::Rect{0, 0, static_cast(m_width), static_cast(m_height)}); glview->UpdateOrientation(m_orientation); glview->SetDPI(m_dpi); glview->setDispatcher(m_dispatcher);