Skip to content

Commit

Permalink
use unicode compatible api to load icudtl.dat
Browse files Browse the repository at this point in the history
Change-Id: I117bdec0f17997946851719aaf7bc1032e2d06dc
Bug: https://bugs.chromium.org/p/skia/issues/detail?id=14241
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/667256
Commit-Queue: Ben Wagner <[email protected]>
Reviewed-by: Ben Wagner <[email protected]>
  • Loading branch information
ajax16384 authored and SkCQ committed Apr 10, 2023
1 parent cde087b commit cc2cb6f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Adobe Systems Incorporated <*@adobe.com>
Alexander Khovansky <[email protected]>
Amazon, Inc <*@amazon.com>
Anthony Catel <[email protected]>
Andrew Kurushin <[email protected]>
Bharat Ahuja <[email protected]>
Biswapriyo Nath <[email protected]>
Callum Moffat <[email protected]>
Expand Down
43 changes: 28 additions & 15 deletions third_party/icu/SkLoadICU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

#include "unicode/udata.h"

static void* win_mmap(const char* dataFile) {
static void* win_mmap(const wchar_t* dataFile) {
if (!dataFile) {
return nullptr;
}
struct FCloseWrapper { void operator()(FILE* f) { fclose(f); } };
std::unique_ptr<FILE, FCloseWrapper> stream(fopen(dataFile, "rb"));
std::unique_ptr<FILE, FCloseWrapper> stream(_wfopen(dataFile, L"rb"));
if (!stream) {
fprintf(stderr, "SkIcuLoader: datafile missing: %s.\n", dataFile);
fprintf(stderr, "SkIcuLoader: datafile missing: %ls.\n", dataFile);
return nullptr;
}
int fileno = _fileno(stream.get());
Expand Down Expand Up @@ -68,26 +68,39 @@ static bool init_icu(void* addr) {
return true;
}

static std::string library_directory() {
static std::wstring get_module_path(HMODULE module) {
DWORD len;
std::wstring path;
path.resize(MAX_PATH);

len = GetModuleFileNameW(module, (LPWSTR)path.data(), (DWORD)path.size());
if (len > path.size()) {
path.resize(len);
len = GetModuleFileNameW(module, (LPWSTR)path.data(), (DWORD)path.size());
}
path.resize(len);
std::size_t end = path.rfind('\\');
if (end == std::wstring::npos) {
return std::wstring();
}
path.resize(end);
return path;
}

static std::wstring library_directory() {
HMODULE hModule = NULL;
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
reinterpret_cast<LPCSTR>(&library_directory), &hModule);
char path[MAX_PATH];
GetModuleFileNameA(hModule, path, MAX_PATH);
const char* end = strrchr(path, '\\');
return end ? std::string(path, end - path) : std::string();
return get_module_path(hModule);
}

static std::string executable_directory() {
static std::wstring executable_directory() {
HMODULE hModule = GetModuleHandleA(NULL);
char path[MAX_PATH];
GetModuleFileNameA(hModule, path, MAX_PATH);
const char* end = strrchr(path, '\\');
return end ? std::string(path, end - path) : std::string();
return get_module_path(hModule);
}

static bool load_from(const std::string& dir) {
auto sPath = dir + "\\icudtl.dat";
static bool load_from(const std::wstring& dir) {
auto sPath = dir + L"\\icudtl.dat";
if (void* addr = win_mmap(sPath.c_str())) {
if (init_icu(addr)) {
return true;
Expand Down

0 comments on commit cc2cb6f

Please sign in to comment.