1 /*
2  * Copyright (c) 2022 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 UI_FONT_CACHE_MANAGER_H
17 #define UI_FONT_CACHE_MANAGER_H
18 
19 #include "font/glyphs_cache.h"
20 #include "font/ui_font_cache.h"
21 
22 namespace OHOS {
23 class UIFontCacheManager : public HeapBase {
24 public:
25     UIFontCacheManager(const UIFontCacheManager&) = delete;
26     UIFontCacheManager& operator=(const UIFontCacheManager&) = delete;
27     static UIFontCacheManager* GetInstance();
28     int8_t GlyphsCacheInit();
29     void ClearCacheFlag();
30     GlyphCacheNode* GetNodeFromCache(uint32_t unicode, uint16_t fontKey, uint16_t cacheType);
31     GlyphCacheNode* GetNodeCacheSpace(uint32_t unicode, uint16_t fontKey);
32     void SetBitmapCacheSize(uint32_t bitmapCacheSize);
33     void BitmapCacheInit();
34     void BitmapCacheClear();
35     /* default TextStyle is TEXT_STYLE_NORMAL. */
36     uint8_t* GetSpace(uint16_t fontKey, uint32_t unicode, uint32_t size, TextStyle textStyle);
37     void PutSpace(uint8_t* addr);
38     uint8_t* GetBitmap(uint16_t fontKey, uint32_t unicode, TextStyle textStyle);
39 
GetBitmapCache()40     UIFontCache* GetBitmapCache()
41     {
42         return bitmapCache_;
43     }
44 
45 private:
46     static constexpr uint32_t FONT_BITMAP_CACHE_SIZE = 0x64000;
47     UIFontCacheManager();
48     ~UIFontCacheManager();
49     UIFontCache* bitmapCache_;
50     GlyphsCache glyphsCache_;
51     uint32_t bitmapCacheSize_ = FONT_BITMAP_CACHE_SIZE;
52 };
53 } // namespace OHOS
54 #endif /* UI_FONT_CACHE_MANAGER_H */