From db78a77bfbce2753a0cd7f8647ee54ddfca78910 Mon Sep 17 00:00:00 2001 From: 15690690116 Date: Thu, 15 May 2025 10:23:36 +0800 Subject: [PATCH 1/3] str16tostr8 --- frameworks/fontmgr/include/font_manager.h | 1 + frameworks/fontmgr/src/font_manager.cpp | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/frameworks/fontmgr/include/font_manager.h b/frameworks/fontmgr/include/font_manager.h index 504bf93..d1b6c9d 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 b86f9e1..6b538be 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); -- Gitee From 842ad6adc027fca3e1ceed75a991006516b8520e Mon Sep 17 00:00:00 2001 From: ning Date: Thu, 22 May 2025 02:02:28 +0000 Subject: [PATCH 2/3] update frameworks/fontmgr/src/font_manager.cpp. Signed-off-by: ning --- frameworks/fontmgr/src/font_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/fontmgr/src/font_manager.cpp b/frameworks/fontmgr/src/font_manager.cpp index 6b538be..e5f6cb6 100644 --- a/frameworks/fontmgr/src/font_manager.cpp +++ b/frameworks/fontmgr/src/font_manager.cpp @@ -128,7 +128,7 @@ std::vector FontManager::GetFontFullName(const int32_t &fd) } for (const auto &name : fullname) { - if (name.strData && name.strLen >0) { + 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()); -- Gitee From 61092a12f453a30290e0fd1f43d1fb1ff8a58f42 Mon Sep 17 00:00:00 2001 From: 15690690116 Date: Mon, 19 May 2025 14:20:46 +0800 Subject: [PATCH 3/3] ut fix Signed-off-by: 15690690116 --- frameworks/fontmgr/fontmgr.gni | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/fontmgr/fontmgr.gni b/frameworks/fontmgr/fontmgr.gni index 25194f6..90cf03d 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", -- Gitee