From 57d1a60baa9f1c493163a3012e93bee2f39930da Mon Sep 17 00:00:00 2001 From: changleipeng Date: Thu, 8 Jun 2023 19:23:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=A7=E5=93=81=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: changleipeng --- src/ports/skia_ohos/FontConfig_ohos.cpp | 70 ++++++++++++++++++++++++- src/ports/skia_ohos/FontConfig_ohos.h | 2 + 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/ports/skia_ohos/FontConfig_ohos.cpp b/src/ports/skia_ohos/FontConfig_ohos.cpp index a7caf6fee9..a76e58dd8a 100644 --- a/src/ports/skia_ohos/FontConfig_ohos.cpp +++ b/src/ports/skia_ohos/FontConfig_ohos.cpp @@ -22,6 +22,8 @@ static const char* OHOS_DEFAULT_CONFIG = "fontconfig.json"; #else static const char* OHOS_DEFAULT_CONFIG = "/system/etc/fontconfig.json"; #endif + +static const char* PRODUCT_DEFAULT_CONFIG = "/system/etc/productfontconfig.json"; /*! Constructor * \param fontScanner the scanner to get the font information from a font file * \param fname the full name of system font configuration document. @@ -30,7 +32,7 @@ static const char* OHOS_DEFAULT_CONFIG = "/system/etc/fontconfig.json"; FontConfig_OHOS::FontConfig_OHOS(const SkTypeface_FreeType::Scanner& fontScanner, const char* fname) { - int err = parseConfig(fname); + int err = checkProductFile(fname); if (err != NO_ERROR) { return; } @@ -1240,3 +1242,69 @@ int FontConfig_OHOS::logErrInfo(int err, const char* key, Json::ValueType expect } return err; } + +bool FontConfig_OHOS::judgeFileExist() +{ + bool haveFile = false; + for (unsigned int i = 0; i < fontDirSet.size(); i++) { + DIR* dir = opendir(fontDirSet[i].c_str()); + if (dir == nullptr) { + logErrInfo(ERROR_DIR_NOT_FOUND, fontDirSet[i].c_str()); + continue; + } + struct dirent* node = nullptr; +#if defined(SK_BUILD_FONT_MGR_FOR_PREVIEW_WIN) + struct stat fileStat; +#endif + while ((node = readdir(dir))) { +#if defined(SK_BUILD_FONT_MGR_FOR_PREVIEW_WIN) + stat(node->d_name, &fileStat); + if (S_ISDIR(fileStat.st_mode)) { + continue; + } +#else + if (node->d_type != DT_REG) { + continue; + } +#endif + const char* fileName = node->d_name; + int len = strlen(fileName); + int suffixLen = strlen(".ttf"); + if (len < suffixLen || (strncmp(fileName + len - suffixLen, ".ttf", suffixLen) && + strncmp(fileName + len - suffixLen, ".otf", suffixLen) && + strncmp(fileName + len - suffixLen, ".ttc", suffixLen) && + strncmp(fileName + len - suffixLen, ".otc", suffixLen))) { + continue; + } + haveFile = true; + break; + } + (void)closedir(dir); + if (haveFile) { + break; + } + } + return haveFile; +} + +int FontConfig_OHOS::checkProductFile(const char* fname) +{ + int err = parseConfig(PRODUCT_DEFAULT_CONFIG); + SkDebugf("parse productfontconfig json file err = %d", err); + if ((err != NO_ERROR) || (!judgeFileExist())) { + SkDebugf("parse productfontconfig json file error"); + fontDirSet.clear(); + fallbackForMap.reset(); + genericFamilySet.clear(); + fallbackSet.clear(); + genericNames.reset(); + fallbackNames.reset(); + errSet.clear(); + aliasMap.reset(); + adjustMap.reset(); + variationMap.reset(); + ttcIndexMap.reset(); + err = parseConfig(fname); + } + return err; +} \ No newline at end of file diff --git a/src/ports/skia_ohos/FontConfig_ohos.h b/src/ports/skia_ohos/FontConfig_ohos.h index e50b2c3d76..d23dc47c44 100644 --- a/src/ports/skia_ohos/FontConfig_ohos.h +++ b/src/ports/skia_ohos/FontConfig_ohos.h @@ -227,6 +227,8 @@ private: FontConfig_OHOS& operator = (const FontConfig_OHOS&) = delete; FontConfig_OHOS(FontConfig_OHOS&&) = delete; FontConfig_OHOS& operator = (FontConfig_OHOS&&) = delete; + int checkProductFile(const char* fname); + bool judgeFileExist(); }; #endif /* FONTCONFIG_OHOS_H */ -- Gitee