/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_ROSEN_FONT_DESCRIPTOR_CACHE_H #define OHOS_ROSEN_FONT_DESCRIPTOR_CACHE_H #include #include #include #include #include #include "font_parser.h" namespace OHOS::Rosen { using FontDescSharedPtr = std::shared_ptr; class FontDescriptorCache { public: FontDescriptorCache(); ~FontDescriptorCache(); void ParserSystemFonts(); void ParserStylishFonts(); void MatchFromFontDescriptor(FontDescSharedPtr desc, std::set& result); void ClearFontFileCache(); void Dump(); void GetFontDescSharedPtrByFullName(const std::string& fullName, const int32_t& systemFontType, FontDescSharedPtr& result); void GetSystemFontFullNamesByType(const int32_t& systemFontType, std::unordered_set& fontList); private: void FontDescriptorScatter(FontDescSharedPtr desc); void ParserInstallFonts(); bool ParseInstalledConfigFile(const std::string& fontPath, std::vector& fontPathList); bool ProcessInstalledFontPath(const std::string& path); bool ProcessSystemFontType(const int32_t& systemFontType, int32_t& fontType); bool ParseInstallFontDescSharedPtrByName(const std::string& fullName, FontDescSharedPtr& result); std::unordered_set GetInstallFontList(); std::unordered_set GetStylishFontList(); std::unordered_set GetGenericFontList(); bool HandleMapIntersection(std::set& finishRet, const std::string& name, std::unordered_map>& map); bool FilterBoldCache(int weight, std::set& finishRet); bool FilterWidthCache(int width, std::set& finishRet); bool FilterItalicCache(int italic, std::set& finishRet); bool FilterMonoSpaceCache(bool monoSpace, std::set& finishRet); bool FilterSymbolicCache(bool symbolic, std::set& finishRet); bool IsDefault(FontDescSharedPtr desc); private: TextEngine::FontParser parser_; struct FontDescriptorEqual { bool operator()(const FontDescSharedPtr& lhs, const FontDescSharedPtr& rhs) const { if (lhs->fontFamily == rhs->fontFamily) { return lhs->fullName < rhs->fullName; } return lhs->fontFamily < rhs->fontFamily; } }; std::set allFontDescriptor_; std::unordered_map> fontFamilyMap_; std::unordered_map> fullNameMap_; std::unordered_map> postScriptNameMap_; std::unordered_map> fontSubfamilyNameMap_; std::set boldCache_; std::set italicCache_; std::set monoSpaceCache_; std::set symbolicCache_; std::unordered_map> installPathMap_; std::unordered_map> stylishFullNameMap_; }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_FONT_DESCRIPTOR_CACHE_H