未验证 提交 9e45d1be 编写于 作者: O openharmony_ci 提交者: Gitee

!857 矢量字体性能优化

Merge pull request !857 from Lizhiqi/font_opt
......@@ -17,7 +17,7 @@
#include "gfx_utils/graphic_log.h"
#include "securec.h"
namespace OHOS {
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
SpannableString::~SpannableString()
{
if (text_ != nullptr) {
......
......@@ -40,7 +40,7 @@ Text::Text()
horizontalAlign_(TEXT_ALIGNMENT_LEFT),
verticalAlign_(TEXT_ALIGNMENT_TOP)
{
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
textStyles_ = nullptr;
#endif
SetFont(DEFAULT_VECTOR_FONT_FILENAME, DEFAULT_VECTOR_FONT_SIZE);
......@@ -52,7 +52,7 @@ Text::~Text()
UIFree(text_);
text_ = nullptr;
}
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
if (textStyles_ != nullptr) {
UIFree(textStyles_);
textStyles_ = nullptr;
......@@ -73,7 +73,7 @@ Text::~Text()
}
}
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
void Text::SetSpannableString(const SpannableString* spannableString)
{
SetText(spannableString->text_);
......@@ -130,7 +130,7 @@ void Text::SetText(const char* text)
text_ = nullptr;
return;
}
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
if (textStyles_ != nullptr) {
UIFree(textStyles_);
textStyles_ = nullptr;
......@@ -334,7 +334,7 @@ void Text::Draw(BufferInfo& gfxDstBuffer,
0, opa, style, &text_[lineBegin], textLine_[i].lineBytes,
lineBegin, fontId_, fontSize_, 0, static_cast<UITextLanguageDirect>(direct_),
nullptr, baseLine_,
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
textStyles_,
#endif
&backgroundColor_, &foregroundColor_, &linebackgroundColor_, sizeSpans_, 0};
......
......@@ -183,7 +183,7 @@ void UILabel::SetText(const char* text)
}
}
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
void UILabel::SetText(const SpannableString* text)
{
InitLabelText();
......
......@@ -57,7 +57,7 @@ uint16_t DrawLabel::DrawTextOneLine(BufferInfo& gfxDstBuffer, const LabelLineInf
ColorType foregroundColor = labelLine.style.textColor_;
GetForegroundColor(letterIndex, labelLine.foregroundColor, foregroundColor);
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
TextStyle textStyle = TEXT_STYLE_NORMAL;
if (labelLine.textStyles) {
textStyle = labelLine.textStyles[letterIndex];
......@@ -74,7 +74,7 @@ uint16_t DrawLabel::DrawTextOneLine(BufferInfo& gfxDstBuffer, const LabelLineInf
fontId,
0,
fontSize,
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
textStyle,
#endif
labelLine.baseLine,
......@@ -82,7 +82,7 @@ uint16_t DrawLabel::DrawTextOneLine(BufferInfo& gfxDstBuffer, const LabelLineInf
labelLine.style.lineSpace_,
havebackgroundColor,
backgroundColor};
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
glyphNode.textStyle = letterInfo.textStyle;
#endif
glyphNode.advance = 0;
......@@ -217,7 +217,7 @@ void DrawLabel::DrawLetterWithRotate(BufferInfo& gfxDstBuffer,
UIFont* fontEngine = UIFont::GetInstance();
FontHeader head;
GlyphNode node;
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
node.textStyle = TEXT_STYLE_NORMAL;
#endif
if (fontEngine->GetFontHeader(head, fontId, fontSize) != 0) {
......
......@@ -74,7 +74,7 @@ struct LabelLineInfo {
UITextLanguageDirect direct;
uint32_t* codePoints;
bool baseLine;
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
TextStyle* textStyles;
#endif
List<BackgroundColor>* backgroundColor;
......@@ -97,7 +97,7 @@ struct LabelLetterInfo {
uint16_t fontId;
uint8_t shapingId;
uint8_t fontSize;
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
TextStyle textStyle;
#endif
bool baseLine;
......
......@@ -67,7 +67,7 @@ GlyphNode* GlyphsCache::GetNodeFromCache(uint32_t unicode, uint16_t fontId)
{
GlyphNode* node = nullptr;
uint8_t font = fontId & FONT_HASH_MASK;
uint8_t font = (fontId | unicode) & FONT_HASH_MASK;
uint8_t uc = unicode & UNICODE_HASH_MASK;
for (uint8_t i = 0; i < NODE_HASH_NR; i++) {
GlyphNode* p = &((*nodeCache_)[font][uc][i]);
......@@ -81,7 +81,7 @@ GlyphNode* GlyphsCache::GetNodeFromCache(uint32_t unicode, uint16_t fontId)
GlyphNode* GlyphsCache::GetNodeCacheSpace(uint32_t unicode, uint16_t fontId)
{
uint8_t font = fontId & FONT_HASH_MASK;
uint8_t font = (fontId | unicode) & FONT_HASH_MASK;
uint8_t uc = unicode & UNICODE_HASH_MASK;
uint8_t i = (*cacheStatus_)[font][uc];
GlyphNode* node = &((*nodeCache_)[font][uc][i]);
......
......@@ -39,7 +39,11 @@ public:
GlyphNode* GetNodeCacheSpace(uint32_t unicode, uint16_t fontId);
private:
#if (defined(ENABLE_MIX_FONT) && (ENABLE_MIX_FONT ==1))
static constexpr uint8_t FONT_HASH_SHIFT = 1;
#else
static constexpr uint8_t FONT_HASH_SHIFT = 3;
#endif
static constexpr uint8_t FONT_HASH_NR = 1 << FONT_HASH_SHIFT;
static constexpr uint32_t FONT_HASH_MASK = FONT_HASH_NR - 1;
static constexpr uint8_t UNICODE_HASH_SHIFT = 6;
......
......@@ -73,7 +73,7 @@ uint8_t* UIFontCache::GetSpace(uint32_t fontId, uint32_t unicode, uint32_t size,
bitmap->fontId = fontId;
bitmap->unicode = unicode;
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
bitmap->textStyle = textStyle;
#endif
......@@ -101,7 +101,7 @@ uint8_t* UIFontCache::GetBitmap(uint32_t fontId, uint32_t unicode, TextStyle tex
bitmap = reinterpret_cast<struct Bitmap*>(reinterpret_cast<uint8_t*>(node) -
offsetof(struct Bitmap, hashHead));
if ((bitmap->fontId == fontId) &&
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
(bitmap->textStyle == textStyle) &&
#endif
(bitmap->unicode == unicode)) {
......
......@@ -54,7 +54,7 @@ public:
ListHead lruHead;
uint32_t fontId; // bitmap font: fontId vector font: fontKey ttfId + fontsize
uint32_t unicode;
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
TextStyle textStyle;
#endif
uint8_t data[];
......
......@@ -580,28 +580,12 @@ int16_t UIFontVector::GetWidth(uint32_t unicode, uint16_t fontId, uint8_t fontSi
return INVALID_RET_VALUE;
}
if (!freeTypeInited_ || (bitmapCache_ == nullptr)) {
return INVALID_RET_VALUE;
}
FaceInfo faceInfo = {};
faceInfo.key = GetKey(fontId, fontSize);
uint8_t* bitmap = bitmapCache_->GetBitmap(faceInfo.key, unicode);
if (bitmap != nullptr) {
return reinterpret_cast<Metric*>(bitmap)->advance;
}
int8_t ret = GetFaceInfo(fontId, fontSize, faceInfo);
if ((ret != RET_VALUE_OK) || (faceInfo.face == nullptr)) {
return INVALID_RET_VALUE;
}
int8_t error = LoadGlyphIntoFace(fontId, unicode);
if (error != RET_VALUE_OK) {
GlyphNode node;
int8_t ret = GetGlyphNode(unicode, node, fontId, fontSize);
if (ret != RET_VALUE_OK) {
return INVALID_RET_VALUE;
}
SetFace(faceInfo, unicode);
return static_cast<uint16_t>(faceInfo.face->glyph->advance.x / FONT_PIXEL_IN_POINT);
return node.advance;
}
int8_t UIFontVector::GetFontHeader(FontHeader& fontHeader, uint16_t fontId, uint8_t fontSize)
......@@ -621,20 +605,39 @@ int8_t UIFontVector::GetFontHeader(FontHeader& fontHeader, uint16_t fontId, uint
return RET_VALUE_OK;
}
void UIFontVector::SaveGlyphNode(uint32_t unicode, uint32_t fontKey, Metric *metric)
{
GlyphNode *node = glyphsCache_.GetNodeCacheSpace(unicode, fontKey);
if (node == nullptr) {
return;
}
node->left = metric->left;
node->top = metric->top;
node->cols = metric->cols;
node->rows = metric->rows;
node->advance = metric->advance;
node->unicode = unicode;
node->fontId = fontKey;
}
int8_t UIFontVector::GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint16_t fontId, uint8_t fontSize)
{
FaceInfo faceInfo;
int8_t ret = GetFaceInfo(fontId, fontSize, faceInfo);
if (ret != RET_VALUE_OK) {
return INVALID_RET_VALUE;
// get glyph from glyph cache
uint32_t fontKey = GetKey(fontId, fontSize);
GlyphNode* node = glyphsCache_.GetNodeFromCache(unicode, fontKey);
if (node != nullptr) {
glyphNode = *node;
return RET_VALUE_OK;
}
if (!freeTypeInited_ || (faceInfo.face == nullptr) || (bitmapCache_ == nullptr)) {
// get glyph from bitmap cache
if (bitmapCache_ == nullptr) {
return INVALID_RET_VALUE;
}
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
uint8_t* bitmap = bitmapCache_->GetBitmap(faceInfo.key, unicode, glyphNode.textStyle);
#if defined(ENABLE_SPANNALBE_STRING) && ENABLE_SPANNALBE_STRING
uint8_t* bitmap = bitmapCache_->GetBitmap(fontKey, unicode, glyphNode.textStyle);
#else
uint8_t* bitmap = bitmapCache_->GetBitmap(faceInfo.key, unicode);
uint8_t* bitmap = bitmapCache_->GetBitmap(fontKey, unicode);
#endif
if (bitmap != nullptr) {
Metric* f = reinterpret_cast<Metric*>(bitmap);
......@@ -644,45 +647,69 @@ int8_t UIFontVector::GetGlyphNode(uint32_t unicode, GlyphNode& glyphNode, uint16
glyphNode.rows = f->rows;
glyphNode.advance = f->advance;
glyphNode.fontId = fontId;
SaveGlyphNode(unicode, fontKey, f);
return RET_VALUE_OK;
}
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
int8_t error = LoadGlyphIntoFace(fontId, unicode, faceInfo.face, glyphNode.textStyle);
#else
int8_t error = LoadGlyphIntoFace(fontId, unicode);
#endif
FaceInfo faceInfo;
int8_t ret = GetFaceInfo(fontId, fontSize, faceInfo);
if (ret != RET_VALUE_OK) {
return INVALID_RET_VALUE;
}
if (faceInfo.face == nullptr) {
return INVALID_RET_VALUE;
}
int8_t error = LoadGlyphIntoFace(fontId, fontSize, unicode, glyphNode);
if (error != RET_VALUE_OK) {
return INVALID_RET_VALUE;
}
glyphNode.left = faceInfo.face->glyph->bitmap_left;
glyphNode.top = faceInfo.face->glyph->bitmap_top;
glyphNode.cols = faceInfo.face->glyph->bitmap.width;
glyphNode.rows = faceInfo.face->glyph->bitmap.rows;
glyphNode.advance = static_cast<uint16_t>(faceInfo.face->glyph->advance.x / FONT_PIXEL_IN_POINT);
glyphNode.fontId = fontId;
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
SetFace(faceInfo, unicode, glyphNode.textStyle);
#else
SetFace(faceInfo, unicode);
#endif
return RET_VALUE_OK;
}
uint8_t* UIFontVector::GetBitmap(uint32_t unicode, GlyphNode& glyphNode, uint16_t fontId, uint8_t fontSize)
{
if (GetGlyphNode(unicode, glyphNode, fontId, fontSize) != RET_VALUE_OK) {
if (bitmapCache_ == nullptr) {
return nullptr;
}
uint32_t fontKey = GetKey(fontId, fontSize);
#if ENABLE_SPANNALBE_STRING
uint8_t* bitmap = bitmapCache_->GetBitmap(fontKey, unicode, glyphNode.textStyle);
#else
uint8_t* bitmap = bitmapCache_->GetBitmap(fontKey, unicode);
#endif
if (bitmap != nullptr) {
Metric* f = reinterpret_cast<Metric*>(bitmap);
glyphNode.left = f->left;
glyphNode.top = f->top;
glyphNode.cols = f->cols;
glyphNode.rows = f->rows;
glyphNode.advance = f->advance;
glyphNode.fontId = fontId;
SaveGlyphNode(unicode, fontKey, f);
return bitmap + sizeof(Metric);
}
FaceInfo faceInfo;
int8_t ret = GetFaceInfo(fontId, fontSize, faceInfo);
if (ret != RET_VALUE_OK) {
return nullptr;
}
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
uint8_t* bitmap = bitmapCache_->GetBitmap(faceInfo.key, unicode, glyphNode.textStyle);
if (faceInfo.face == nullptr) {
return nullptr;
}
int8_t error = LoadGlyphIntoFace(fontId, fontSize, unicode, glyphNode);
if (error != RET_VALUE_OK) {
return nullptr;
}
#if defined(ENABLE_SPANNALBE_STRING) && ENABLE_SPANNALBE_STRING
bitmap = bitmapCache_->GetBitmap(fontKey, unicode, glyphNode.textStyle);
#else
uint8_t* bitmap = bitmapCache_->GetBitmap(faceInfo.key, unicode);
bitmap = bitmapCache_->GetBitmap(fontKey, unicode);
#endif
if (bitmap != nullptr) {
return bitmap + sizeof(Metric);
......@@ -699,7 +726,7 @@ bool UIFontVector::IsEmojiFont(uint16_t fontId)
return (fontInfo_[fontId].fontWeight >= 16); // 16: rgb color font
}
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNALBE_STRING) && ENABLE_SPANNALBE_STRING
void UIFontVector::SetItaly(FT_GlyphSlot slot)
{
if (slot->format != FT_GLYPH_FORMAT_OUTLINE) {
......@@ -742,15 +769,14 @@ void UIFontVector::SetBold(uint16_t fontId)
}
#endif
int8_t UIFontVector::LoadGlyphIntoFace(uint16_t& fontId, uint32_t unicode)
int8_t UIFontVector::LoadGlyphIntoFace(uint16_t& fontId, uint8_t fontSize, uint32_t unicode, GlyphNode& glyphNode)
{
int32_t error;
if (IsGlyphFont(unicode) != 0) {
if (fontId != GetFontId(unicode)) {
return INVALID_RET_VALUE;
}
unicode = unicode & (0xFFFFFF); // Whether 0 ~24 bit storage is unicode
error = FT_Load_Glyph(ftFaces_[fontId], unicode, FT_LOAD_RENDER);
error = FT_Load_Glyph(ftFaces_[fontId], unicode & (0xFFFFFF), FT_LOAD_RENDER);
} else {
if (IsEmojiFont(fontId)) {
error = FT_Load_Char(ftFaces_[fontId], unicode, FT_LOAD_COLOR);
......@@ -761,10 +787,27 @@ int8_t UIFontVector::LoadGlyphIntoFace(uint16_t& fontId, uint32_t unicode)
if ((error != 0) || (ftFaces_[fontId]->glyph->glyph_index == 0)) {
return INVALID_RET_VALUE;
}
FaceInfo faceInfo;
faceInfo.key = GetKey(fontId, fontSize);
faceInfo.face = ftFaces_[fontId];
glyphNode.left = faceInfo.face->glyph->bitmap_left;
glyphNode.top = faceInfo.face->glyph->bitmap_top;
glyphNode.cols = faceInfo.face->glyph->bitmap.width;
glyphNode.rows = faceInfo.face->glyph->bitmap.rows;
glyphNode.advance = static_cast<uint16_t>(faceInfo.face->glyph->advance.x / FONT_PIXEL_IN_POINT);
glyphNode.fontId = fontId;
#if defined(ENABLE_SPANNALBE_STRING) && ENABLE_SPANNALBE_STRING
SetFace(faceInfo, unicode, glyphNode.textStyle);
#else
SetFace(faceInfo, unicode);
#endif
return RET_VALUE_OK;
}
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
int8_t UIFontVector::LoadGlyphIntoFace(uint16_t& fontId, uint32_t unicode, FT_Face face, TextStyle textStyle)
{
int32_t error;
......@@ -814,7 +857,7 @@ uint8_t UIFontVector::IsGlyphFont(uint32_t unicode)
void UIFontVector::SetFace(FaceInfo& faceInfo, uint32_t unicode)
{
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNALBE_STRING) && ENABLE_SPANNALBE_STRING
SetFace(faceInfo, unicode, TEXT_STYLE_NORMAL);
#else
Metric f;
......@@ -824,17 +867,24 @@ void UIFontVector::SetFace(FaceInfo& faceInfo, uint32_t unicode)
f.cols = faceInfo.face->glyph->bitmap.width;
f.rows = faceInfo.face->glyph->bitmap.rows;
// cache glyph
SaveGlyphNode(unicode, faceInfo.key, &f);
int16_t pixSize = 1;
if (faceInfo.face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_BGRA) {
pixSize = 0x04; // 4 Byte
}
uint32_t bitmapSize = faceInfo.face->glyph->bitmap.width * faceInfo.face->glyph->bitmap.rows * pixSize;
// cache bitmap
uint8_t* bitmap = bitmapCache_->GetSpace(faceInfo.key, unicode, bitmapSize + sizeof(Metric));
if (bitmap != nullptr) {
if (memcpy_s(bitmap, sizeof(Metric), &f, sizeof(Metric)) != EOK) {
bitmapCache_->PutSpace(bitmap);
return;
}
if (memcpy_s(bitmap + sizeof(Metric), bitmapSize, faceInfo.face->glyph->bitmap.buffer, bitmapSize) != EOK) {
if ((faceInfo.face->glyph->bitmap.buffer != nullptr) &&
(memcpy_s(bitmap + sizeof(Metric), bitmapSize, faceInfo.face->glyph->bitmap.buffer, bitmapSize) != EOK)) {
bitmapCache_->PutSpace(bitmap);
return;
}
ClearFontGlyph(faceInfo.face);
......@@ -842,7 +892,7 @@ void UIFontVector::SetFace(FaceInfo& faceInfo, uint32_t unicode)
#endif
}
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNALBE_STRING) && ENABLE_SPANNALBE_STRING
void UIFontVector::SetFace(FaceInfo& faceInfo, uint32_t unicode, TextStyle textStyle)
{
Metric f;
......@@ -852,17 +902,23 @@ void UIFontVector::SetFace(FaceInfo& faceInfo, uint32_t unicode, TextStyle textS
f.cols = faceInfo.face->glyph->bitmap.width;
f.rows = faceInfo.face->glyph->bitmap.rows;
// cache glyph
SaveGlyphNode(unicode, faceInfo.key, &f);
int16_t pixSize = 1;
if (faceInfo.face->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_BGRA) {
pixSize = 0x04; // 4 Byte
}
uint32_t bitmapSize = faceInfo.face->glyph->bitmap.width * faceInfo.face->glyph->bitmap.rows * pixSize;
// cache bitmap
uint8_t* bitmap = bitmapCache_->GetSpace(faceInfo.key, unicode, bitmapSize + sizeof(Metric), textStyle);
if (bitmap != nullptr) {
if (memcpy_s(bitmap, sizeof(Metric), &f, sizeof(Metric)) != EOK) {
bitmapCache_->PutSpace(bitmap);
return;
}
if (memcpy_s(bitmap + sizeof(Metric), bitmapSize, faceInfo.face->glyph->bitmap.buffer, bitmapSize) != EOK) {
bitmapCache_->PutSpace(bitmap);
return;
}
ClearFontGlyph(faceInfo.face);
......@@ -1014,26 +1070,31 @@ void UIFontVector::SetPsramMemory(uintptr_t psramAddr, uint32_t psramLen)
{
BaseFont::SetPsramMemory(psramAddr, psramLen);
FontRamAllocator::GetInstance().SetRamAddr(psramAddr, psramLen);
BitmapCacheInit();
FontCacheInit();
}
void UIFontVector::BitmapCacheInit()
void UIFontVector::FontCacheInit()
{
if (bitmapCache_ != nullptr) {
// glyph cache
if (glyphsCache_.CacheInit() != RET_VALUE_OK) {
GRAPHIC_LOGE("UIFontVector::FontCacheInit glyphs cache init failed");
return;
}
// bitmap cache
if (bitmapCache_ != nullptr) {
return;
}
#if (defined(ENABLE_MIX_FONT) && (ENABLE_MIX_FONT == 1))
uint32_t cacheSize = FONT_BITMAP_CACHE_SIZE;
uint32_t bitmapCacheSize = FONT_BITMAP_CACHE_SIZE;
#else
uint32_t cacheSize = GetRamLen();
uint32_t bitmapCacheSize = GetRamLen() - FontRamAllocator::GetInstance().GetRamUsedLen();
#endif
uint8_t* bitmapCacheAddr = reinterpret_cast<uint8_t*>(FontRamAllocator::GetInstance().Allocate(cacheSize));
uint8_t* bitmapCacheAddr = reinterpret_cast<uint8_t*>(FontRamAllocator::GetInstance().Allocate(bitmapCacheSize));
if (bitmapCacheAddr == nullptr) {
GRAPHIC_LOGE("UIFontVector::BitmapCacheInit allocate failed");
GRAPHIC_LOGE("UIFontVector::FontCacheInit allocate failed");
return;
}
bitmapCache_ = new UIFontCache(bitmapCacheAddr, FONT_BITMAP_CACHE_SIZE);
bitmapCache_ = new UIFontCache(bitmapCacheAddr, bitmapCacheSize);
}
} // namespace OHOS
......@@ -20,6 +20,7 @@
#include "ft2build.h"
#include "freetype/freetype.h"
#include "freetype/tttables.h"
#include "font/glyphs_cache.h"
#include "font/ui_font_cache.h"
#include <memory>
......@@ -72,6 +73,7 @@ private:
uint8_t currentFontInfoNum_ = 0;
bool freeTypeInited_;
UIFontCache* bitmapCache_;
GlyphsCache glyphsCache_;
struct FaceInfo {
FT_Face face;
uint32_t key;
......@@ -90,17 +92,18 @@ private:
};
TtcInfo ttcInfos_[FONT_TTC_MAX] = {};
void SetFace(FaceInfo& faceInfo, uint32_t unicode);
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
void SetFace(FaceInfo& faceInfo, uint32_t unicode, TextStyle textStyle);
#endif
uint16_t GetFontId(uint32_t unicode) const;
uint32_t GetKey(uint16_t fontId, uint32_t size);
int8_t LoadGlyphIntoFace(uint16_t& fontId, uint32_t unicode);
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
int8_t LoadGlyphIntoFace(uint16_t& fontId, uint8_t fontSize, uint32_t unicode, GlyphNode& glyphNode);
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
int8_t LoadGlyphIntoFace(uint16_t& fontId, uint32_t unicode, FT_Face face, TextStyle textStyle);
#endif
void SaveGlyphNode(uint32_t unicode, uint32_t fontKey, Metric *metric);
uint8_t IsGlyphFont(uint32_t unicode);
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
void SetItaly(FT_GlyphSlot slot);
void SetBold(uint16_t fontId);
#endif
......@@ -114,7 +117,7 @@ private:
uint32_t ttfBufferSize,
TtfHeader& ttfHeader,
UITextLanguageFontParam fontInfo);
void BitmapCacheInit();
void FontCacheInit();
void ClearFontGlyph(FT_Face face);
};
} // namespace OHOS
......
......@@ -18,7 +18,7 @@
#include "gfx_utils/list.h"
#include "font/ui_font_header.h"
namespace OHOS {
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
class StyleSpan : public HeapBase {
public:
StyleSpan() {};
......
......@@ -43,7 +43,7 @@
#include "gfx_utils/vector.h"
#include "engines/gfx/gfx_engine_manager.h"
#include "font/ui_font_header.h"
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
#include "common/spannable_string.h"
#endif
......@@ -164,7 +164,7 @@ public:
*/
virtual void SetText(const char* text);
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
/**
* @brief Sets the SpannableString for this text.
*
......@@ -515,8 +515,9 @@ protected:
SizeSpan* sizeSpans);
uint8_t GetSpanFontIdBySize(uint8_t size);
void InitSizeSpans();
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
TextStyle* textStyles_;
#endif
char* text_;
uint16_t fontId_;
uint8_t fontSize_; // Only the vector font library has a valid value.
......
......@@ -38,7 +38,7 @@
#include "animator/animator.h"
#include "common/text.h"
#include "components/ui_view.h"
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
#include "common/spannable_string.h"
#endif
......@@ -188,7 +188,7 @@ public:
*/
void SetText(const char* text);
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
/**
* @brief Sets the SpannableString content for this label.
*
......
......@@ -290,7 +290,7 @@ struct GlyphNode {
uint16_t kernSize; // GLYPH_KERN_SIZE_OFFSET
uint16_t fontId; // GLYPH_FONT_ID
uint16_t dataFlag; // GLYPH_DATA_HEAD_FLAG
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
TextStyle textStyle; // GLYPH_TEXT_STYLE
#endif
};
......
......@@ -75,7 +75,7 @@ void UITestVectorFont::InnerTestTitle(const char* title)
const UIView* UITestVectorFont::GetTestView()
{
#if ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
TestDrawTextITALYBOLD();
#endif
FontFontEngineVectorTestCHLang001();
......@@ -340,7 +340,7 @@ void UITestVectorFont::FontFontEngineMultiLanguageTestROLang001()
}
}
#endif
#if ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
void UITestVectorFont::TestDrawTextITALYBOLD()
{
if (container_ != nullptr) {
......
......@@ -74,7 +74,7 @@ public:
void FontFontEngineMultiLanguageTestROLang001();
#endif
#if ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
void TestDrawTextITALYBOLD();
#endif
private:
......
......@@ -185,7 +185,7 @@ HWTEST_F(TextTest, TextSetRelativeSpan_001, TestSize.Level1)
text = nullptr;
}
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
HWTEST_F(TextTest, TextSetStyleSpan_001, TestSize.Level1)
{
SpannableString spannableString("图形子系统测试正常粗体斜体粗斜体");
......
......@@ -263,7 +263,7 @@ HWTEST_F(UILabelTest, UILabelOnPreDraw_001, TestSize.Level1)
invalidatedArea = nullptr;
}
#if defined(ENABLE_VECTOR_FONT) && ENABLE_VECTOR_FONT
#if defined(ENABLE_SPANNABLE_STRING) && ENABLE_SPANNABLE_STRING
/**
* @tc.name: UILabelSetText_002
* @tc.desc: Verify SetText function.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册