1 /* 2 * Copyright (c) 2020-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_BITMAP_H 17 #define UI_FONT_BITMAP_H 18 19 #include "font/base_font.h" 20 #include "font/glyphs_manager.h" 21 #include "font/ui_font_cache.h" 22 #include "graphic_locker.h" 23 24 namespace OHOS { 25 class UIFontBitmap : public BaseFont { 26 public: 27 UIFontBitmap(); 28 virtual ~UIFontBitmap(); 29 UIFontBitmap(const UIFontBitmap&) = delete; 30 UIFontBitmap& operator=(const UIFontBitmap&) noexcept = delete; 31 bool IsVectorFont() const override; 32 uint16_t 33 GetShapingFontId(char* text, uint8_t& ttfId, uint32_t& script, uint16_t fontId, uint8_t size) const override; 34 int8_t SetFontPath(const char* path, FontType type) override; 35 uint16_t GetHeight(uint16_t fontId, uint8_t fontSize = 0) override; 36 uint16_t GetFontId(const char* ttfName, uint8_t fontSize = 0) const override; 37 int16_t GetWidth(uint32_t unicode, uint16_t fontId, uint8_t fontSize = 0) override; 38 uint8_t* GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint16_t fontId, uint8_t fontSize = 0) override; 39 int8_t GetFontHeader(FontHeader& fontHeader, uint16_t fontId, uint8_t fontSize = 0) override; 40 int8_t GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint16_t fontId, uint8_t fontSize = 0) override; 41 int8_t GetGlyphNodeFromFile(uint32_t unicode, GlyphNode& glyphNode, uint16_t fontId); 42 uint8_t GetFontWeight(uint16_t fontId) override; 43 int8_t GetFontVersion(FontType type, const char* path, char* version, uint8_t len) override; 44 int8_t SetCurrentLangId(uint8_t langId) override; 45 UITextLanguageFontParam* GetFontInfo(uint16_t fontId) const override; 46 void SetFontFileOffset(uint32_t offset) override; 47 uint16_t GetOffsetPosY(const char* text, uint16_t lineLength, bool& isEmoijLerge, 48 uint16_t fontId, uint8_t fontSize) override; 49 uint16_t GetLineMaxHeight(const char* text, uint16_t lineLength, uint16_t fontId, uint8_t fontSize, 50 uint16_t& letterIndex, SpannableString* spannableString) override; 51 bool IsEmojiFont(uint16_t fontId) override; 52 void SetPsramMemory(uintptr_t psramAddr, uint32_t psramLen) override; 53 protected: 54 int8_t GetDynamicFontBitmap(uint32_t unicode, BufferInfo& bufInfo, uint16_t fontId); 55 uint8_t* GetCacheBitmap(uint16_t fontId, uint32_t unicode); 56 void PutCacheSpace(uint8_t* addr); 57 int16_t GetDynamicFontWidth(uint32_t unicode, uint16_t fontId); 58 uint32_t offset_; 59 GraphicMutex lock_; 60 61 private: 62 uint8_t* SearchInFont(uint32_t unicode, GlyphNode& glyphNode, uint16_t fontId); 63 int16_t GetWidthInFontId(uint32_t unicode, uint16_t fontId); 64 #if defined(ENABLE_MULTI_FONT) && ENABLE_MULTI_FONT 65 int8_t GetMultiGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint16_t fontId); 66 #endif 67 void CloseFontFd(); 68 void BitmapCacheInit(); 69 static constexpr uint8_t FONT_ID_MAX = 0xFF; 70 static constexpr uint8_t TTF_NAME_LEN_MAX = 128; 71 GlyphsManager dynamicFont_; 72 Graphic::Vector<int32_t> dynamicFontFd_; 73 }; 74 } // namespce OHOS 75 #endif // UI_FONT_BITMAP_H 76