1 /* 2 * Copyright 2018 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 #ifndef load_icu_DEFINED 8 #define load_icu_DEFINED 9 10 #include "SkTypes.h" 11 12 #ifdef SK_BUILD_FOR_WIN 13 14 #include "../private/SkLeanWindows.h" 15 16 #include "unicode/uvernum.h" 17 #include "unicode/udata.h" 18 19 #define ICU_UTIL_DATA_SYMBOL "icudt" U_ICU_VERSION_SHORT "_dat" 20 #define ICU_UTIL_DATA_SHARED_MODULE_NAME "icudt.dll" 21 SkLoadICU()22inline void SkLoadICU() { 23 HMODULE module = LoadLibraryA(ICU_UTIL_DATA_SHARED_MODULE_NAME); 24 if (!module) { 25 SK_ABORT("Failed to load " ICU_UTIL_DATA_SHARED_MODULE_NAME "\n"); 26 } 27 FARPROC addr = GetProcAddress(module, ICU_UTIL_DATA_SYMBOL); 28 if (!addr) { 29 SK_ABORT("Symbol " ICU_UTIL_DATA_SYMBOL " missing in " 30 ICU_UTIL_DATA_SHARED_MODULE_NAME ".\n"); 31 } 32 UErrorCode err = U_ZERO_ERROR; 33 udata_setCommonData(reinterpret_cast<void*>(addr), &err); 34 if (err != U_ZERO_ERROR) { 35 SkDebugf("udata_setCommonData() returned %d.\n", (int)err); 36 SK_ABORT(""); 37 } 38 udata_setFileAccess(UDATA_ONLY_PACKAGES, &err); 39 if (err != U_ZERO_ERROR) { 40 SkDebugf("udata_setFileAccess() returned %d.\n", (int)err); 41 SK_ABORT(""); 42 } 43 } 44 45 #undef ICU_UTIL_DATA_SHARED_MODULE_NAME 46 #undef ICU_UTIL_DATA_SYMBOL 47 48 #else SkLoadICU()49inline void SkLoadICU() {} 50 #endif // SK_BUILD_FOR_WIN 51 #endif // load_icu_DEFINED 52 53