diff --git a/frameworks/fontmgr/fontmgr.gni b/frameworks/fontmgr/fontmgr.gni index 25194f6ea2023486ce1359780d354b3c1621552d..eab720de36fd4de538a5ca92d863fbc0f11e7e36 100644 --- a/frameworks/fontmgr/fontmgr.gni +++ b/frameworks/fontmgr/fontmgr.gni @@ -28,6 +28,7 @@ fontmgr_src = [ fontmgr_external_deps = [ "ability_base:want", + "c_utils:utils", "cJSON:cjson", "common_event_service:cesfwk_innerkits", "hilog:libhilog", diff --git a/frameworks/fontmgr/include/font_manager.h b/frameworks/fontmgr/include/font_manager.h index 504bf93e14e0e9acfc86df3587b4c78f4ad66c7d..d1b6c9d8bc07d2eef17df93d25f1dfd2c0476dd3 100644 --- a/frameworks/fontmgr/include/font_manager.h +++ b/frameworks/fontmgr/include/font_manager.h @@ -30,6 +30,7 @@ public: private: bool CheckInstallPath(); bool CheckFontConfigPath(); + std::string Utf16BEToUtf8(const uint8_t* data, size_t byteLen); std::vector GetFontFullName(const int32_t &fd); std::string GetFormatFullName(const std::vector &fullNameVector); std::string CopyFile(const std::string &fontPath, const int32_t &fd); diff --git a/frameworks/fontmgr/src/font_manager.cpp b/frameworks/fontmgr/src/font_manager.cpp index b86f9e1ecd52874798c19bcb35cd57f601541f51..bcd6990245802475be401f878ee3c0f865d95d3e 100644 --- a/frameworks/fontmgr/src/font_manager.cpp +++ b/frameworks/fontmgr/src/font_manager.cpp @@ -15,6 +15,7 @@ #include "font_manager.h" +#include #include "font_hilog.h" #include "font_event_publish.h" #include "font_config.h" @@ -28,6 +29,7 @@ static const std::string INSTALL_PATH = "/data/service/el1/public/for-all-app/fo static const std::string FONT_CONFIG_FILE = INSTALL_PATH + "install_fontconfig.json"; static const std::string FONTS_TEMP_PATH = "/data/service/el1/public/for-all-app/fonts/temp/"; static constexpr int32_t MAX_INSTALL_NUM = 200; +static constexpr int32_t NUM_TWO = 2; FontManager::FontManager() { } @@ -126,15 +128,26 @@ std::vector FontManager::GetFontFullName(const int32_t &fd) } for (const auto &name : fullname) { - std::string fullnameStr; - fullnameStr.assign((char *)name.strData.get(), name.strLen); - fullnameStr.erase(std::remove(fullnameStr.begin(), fullnameStr.end(), '\0'), fullnameStr.end()); - FONT_LOGI("GetFontFullname, fullnameStr:%{public}s", fullnameStr.c_str()); - fullNameVector.emplace_back(std::move(fullnameStr)); + if (name.strData && name.strLen > 0) { + std::string fullnameStr = Utf16BEToUtf8(name.strData.get(), name.strLen); + fullNameVector.emplace_back(std::move(fullnameStr)); + FONT_LOGI("GetFontFullname, fullnameStr:%{public}s", fullnameStr.c_str()); + } } return fullNameVector; } +std::string FontManager::Utf16BEToUtf8(const uint8_t* data, size_t byteLen) +{ + std::u16string utf16Str; + for (size_t i = 0; i + 1 < byteLen; i += NUM_TWO) { + uint16_t ch = (data[i] << 8) | data[i + 1]; + utf16Str.push_back(static_cast(ch)); + } + // Convert to UTF-8 + return Str16ToStr8(utf16Str); +} + std::string FontManager::CopyFile(const std::string &sourcePath, const int32_t &fd) { std::string fileName = FileUtils::GetFileName(sourcePath);