FIX: add log for load font

jira: none
Change-Id: I30d652525bb2f6917a2ed6b59408fe93459ad4bf
This commit is contained in:
zhimin.zeng 2024-05-16 15:18:27 +08:00 committed by Lane.Wei
parent a89df79068
commit 92e6de4961
2 changed files with 28 additions and 4 deletions

View File

@ -45,6 +45,8 @@ std::vector<std::string> init_face_names()
wxArrayString facenames = wxFontEnumerator::GetFacenames(font_encoding);
std::vector<wxString> 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<std::string> init_face_names()
return false;
return true;
};
};
std::sort(facenames.begin(), facenames.end());
for (const wxString &name : facenames) {
@ -83,6 +85,8 @@ std::vector<std::string> 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;
}

View File

@ -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<LPTSTR>(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<FontFile> 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<LPTSTR>(lpMsgBuf);
return nullptr;
}