From 92e6de4961c0c44ba2d558acb07be603d09f0bee Mon Sep 17 00:00:00 2001 From: "zhimin.zeng" Date: Thu, 16 May 2024 15:18:27 +0800 Subject: [PATCH] FIX: add log for load font jira: none Change-Id: I30d652525bb2f6917a2ed6b59408fe93459ad4bf --- src/slic3r/GUI/Gizmos/GLGizmoText.cpp | 6 +++++- src/slic3r/Utils/FontUtils.cpp | 26 +++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoText.cpp b/src/slic3r/GUI/Gizmos/GLGizmoText.cpp index 47e3231a9..aee2d1432 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoText.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoText.cpp @@ -45,6 +45,8 @@ std::vector init_face_names() wxArrayString facenames = wxFontEnumerator::GetFacenames(font_encoding); std::vector bad_fonts; + BOOST_LOG_TRIVIAL(info) << "init_fonts_names start"; + // validation lambda auto is_valid_font = [coding = font_encoding, bad = bad_fonts](const wxString &name) { if (name.empty()) @@ -70,7 +72,7 @@ std::vector init_face_names() return false; return true; - }; + }; std::sort(facenames.begin(), facenames.end()); for (const wxString &name : facenames) { @@ -83,6 +85,8 @@ std::vector init_face_names() } assert(std::is_sorted(bad_fonts.begin(), bad_fonts.end())); + BOOST_LOG_TRIVIAL(info) << "init_fonts_names end"; + return valid_font_names; } diff --git a/src/slic3r/Utils/FontUtils.cpp b/src/slic3r/Utils/FontUtils.cpp index 15b274491..e7bc0c0e7 100644 --- a/src/slic3r/Utils/FontUtils.cpp +++ b/src/slic3r/Utils/FontUtils.cpp @@ -160,7 +160,16 @@ bool load_hfont(void *hfont, DWORD &dwTable, DWORD &dwOffset, size_t &size, HDC if (hdc == nullptr) { del_hdc = true; hdc = ::CreateCompatibleDC(NULL); - if (hdc == NULL) return false; + if (hdc == NULL) { + DWORD errorCode = GetLastError(); + LPVOID lpMsgBuf; + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &lpMsgBuf, 0, NULL); + + BOOST_LOG_TRIVIAL(error) << "CreateCompatibleDC failed in load_hfont : " + << "Error: " << reinterpret_cast(lpMsgBuf); + return false; + } } // To retrieve the data from the beginning of the file for TrueType @@ -177,9 +186,14 @@ bool load_hfont(void *hfont, DWORD &dwTable, DWORD &dwOffset, size_t &size, HDC } if (size == 0 || size == GDI_ERROR) { - if (del_hdc) ::DeleteDC(hdc); + if (del_hdc) + ::DeleteDC(hdc); return false; } + + if (del_hdc) + ::DeleteDC(hdc); + return true; } @@ -188,7 +202,13 @@ std::unique_ptr create_font_file(void *hfont) HDC hdc = ::CreateCompatibleDC(NULL); if (hdc == NULL) { assert(false); - BOOST_LOG_TRIVIAL(error) << "Can't create HDC by CreateCompatibleDC(NULL)."; + DWORD errorCode = GetLastError(); + LPVOID lpMsgBuf; + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL); + + BOOST_LOG_TRIVIAL(error) << "CreateCompatibleDC failed in create_font_file : " + << "Error: " << reinterpret_cast(lpMsgBuf); return nullptr; }