1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FONT_ROSEN_FONT_COLLECTION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FONT_ROSEN_FONT_COLLECTION_H 18 19 #include <future> 20 #include <vector> 21 #include <unordered_set> 22 23 #ifndef USE_GRAPHIC_TEXT_GINE 24 #include "txt/font_collection.h" 25 #else 26 #include "rosen_text/font_collection.h" 27 #endif 28 29 #include "core/components/font/font_collection.h" 30 31 namespace OHOS::Ace { 32 33 class ACE_EXPORT RosenFontCollection : public FontCollection { 34 public: 35 static RosenFontCollection& GetInstance(); 36 37 #ifndef USE_GRAPHIC_TEXT_GINE 38 std::shared_ptr<txt::FontCollection> GetFontCollection() override; 39 #else 40 std::shared_ptr<Rosen::FontCollection> GetFontCollection() override; 41 #endif 42 43 void LoadFontFromList(const uint8_t* fontData, size_t length, std::string familyName); 44 45 void LoadFontFamily(const char* fontFamily, const char* familySrc); 46 47 void VaryFontCollectionWithFontWeightScale(float fontWeightScale); 48 49 void LoadSystemFont(); 50 51 void SetIsZawgyiMyanmar(bool isZawgyiMyanmar); 52 53 #ifndef USE_GRAPHIC_TEXT_GINE 54 #ifndef USE_ROSEN_DRAWING 55 sk_sp<txt::DynamicFontManager> GetDynamicFontManager(); 56 #else 57 std::shared_ptr<RSFontMgr> GetDynamicFontManager(); 58 #endif 59 #endif 60 61 private: 62 void LoadThemeFont(const char* fontFamily, std::unique_ptr<char[]> buffer, size_t size); 63 64 void InitializeFontCollection(); 65 66 bool StdFilesystemExists(const std::string &path); 67 68 #ifndef USE_GRAPHIC_TEXT_GINE 69 std::shared_ptr<txt::FontCollection> fontCollection_; 70 #ifndef USE_ROSEN_DRAWING 71 sk_sp<txt::DynamicFontManager> dynamicFontManager_; 72 #else 73 std::shared_ptr<RSFontMgr> dynamicFontManager_; 74 #endif 75 #else 76 std::shared_ptr<Rosen::FontCollection> fontCollection_; 77 #endif 78 std::unordered_set<std::string> families_; 79 80 std::string currentFamily_; 81 82 bool isZawgyiMyanmar_ = false; 83 std::once_flag fontFlag_; 84 85 static RosenFontCollection instance; 86 }; 87 88 } // namespace OHOS::Ace 89 90 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FONT_ROSEN_FONT_COLLECTION_H 91