From 02a0e304b7b9e7c22e488775dacae6850034c948 Mon Sep 17 00:00:00 2001 From: Sungyeon Woo Date: Thu, 4 Apr 2013 23:09:46 +0900 Subject: [PATCH] applied bidi cache Change-Id: I85c1819ede2d8f13e168ad88c2bceeae116dcb05 Signed-off-by: Sungyeon Woo --- src/graphics/FGrp_Font.cpp | 10 +---- src/graphics/FGrp_FontCache.cpp | 18 ++++---- src/graphics/FGrp_FontCache.h | 6 +-- src/graphics/FGrp_FontFt2.cpp | 81 +++++++++++++++++------------------ src/graphics/FGrp_FontFt2.h | 6 +-- src/graphics/FGrp_FontRsrcManager.cpp | 4 +- src/graphics/FGrp_IFont.h | 4 +- 7 files changed, 61 insertions(+), 68 deletions(-) diff --git a/src/graphics/FGrp_Font.cpp b/src/graphics/FGrp_Font.cpp index cdb6357..35d29a2 100644 --- a/src/graphics/FGrp_Font.cpp +++ b/src/graphics/FGrp_Font.cpp @@ -1410,10 +1410,7 @@ _Font::__GetTextExtentList(_TextBidiPropertyWithReorder& bidiProperty, _Util::Ac _IFont::Glyph* pGlyph; pEnum->GetCurrent(pGlyph); - delete[] (char*) pGlyph; - - // bidi cache underdevelop - //pBaseFont->UnloadGlyph(&pGlyph); + pBaseFont->UnloadGlyph(&pGlyph); } delete pEnum; @@ -1768,10 +1765,7 @@ _Font::__DrawText(_Canvas& canvas, const Point& point, const Tizen::Base::String _IFont::Glyph* pGlyph; pEnum->GetCurrent(pGlyph); - delete[] (char*) pGlyph; - - // bidi cache underdevelop - //pBaseFont->UnloadGlyph(&pGlyph); + pBaseFont->UnloadGlyph(&pGlyph); } delete pEnum; diff --git a/src/graphics/FGrp_FontCache.cpp b/src/graphics/FGrp_FontCache.cpp index 3e37520..21a4e8e 100644 --- a/src/graphics/FGrp_FontCache.cpp +++ b/src/graphics/FGrp_FontCache.cpp @@ -39,16 +39,16 @@ namespace // unnamed { inline bool -_MakeId(unsigned long character, Tizen::Graphics::_Util::FixedPoint26_6 size, int style, unsigned long& out) +_MakeId(unsigned long glyphIndex, Tizen::Graphics::_Util::FixedPoint26_6 size, int style, unsigned long& out) { int fixedSize = size >> 5; - if (((character >> 22) > 0) || ((fixedSize >> 8) > 0) || ((style >> 2) > 0)) + if (((glyphIndex >> 22) > 0) || ((fixedSize >> 8) > 0) || ((style >> 2) > 0)) { return false; } - out = (character << 10) | ((fixedSize & 0xFF) << 2) | (style & 0x3); + out = (glyphIndex << 10) | ((fixedSize & 0xFF) << 2) | (style & 0x3); return true; } @@ -277,10 +277,10 @@ _FontCache::IsValid(void) const } bool -_FontCache::Find(unsigned long character, _Util::FixedPoint26_6 size, int style, _IFont::Glyph** pOut) +_FontCache::Find(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, _IFont::Glyph** pOut) { unsigned long id = 0; - bool rtn = _MakeId(character, size, style, id); + bool rtn = _MakeId(glyphIndex, size, style, id); if (!rtn) { @@ -301,11 +301,11 @@ _FontCache::Find(unsigned long character, _Util::FixedPoint26_6 size, int style, } bool -_FontCache::Add(unsigned long character, _Util::FixedPoint26_6 size, int style, _IFont::Glyph* pGlyph) +_FontCache::Add(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, _IFont::Glyph* pGlyph) { unsigned long bufferSize = 0; unsigned long id = 0; - bool rtn = _MakeId(character, size, style, id); + bool rtn = _MakeId(glyphIndex, size, style, id); if (!rtn) { // Requested glyph is not cachable @@ -348,10 +348,10 @@ _FontCache::Add(unsigned long character, _Util::FixedPoint26_6 size, int style, } void -_FontCache::Remove(unsigned long character, _Util::FixedPoint26_6 size, int style) +_FontCache::Remove(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style) { unsigned long id = 0; - bool rtn = _MakeId(character, size, style, id); + bool rtn = _MakeId(glyphIndex, size, style, id); if (!rtn) { return; diff --git a/src/graphics/FGrp_FontCache.h b/src/graphics/FGrp_FontCache.h index 3185b66..e55f2b4 100644 --- a/src/graphics/FGrp_FontCache.h +++ b/src/graphics/FGrp_FontCache.h @@ -43,9 +43,9 @@ public: bool IsValid(void) const; - bool Find(unsigned long character, _Util::FixedPoint26_6 size, int style, _IFont::Glyph** pOut); - bool Add(unsigned long character, _Util::FixedPoint26_6 size, int style, _IFont::Glyph* pGlyph); - void Remove(unsigned long character, _Util::FixedPoint26_6 size, int style); + bool Find(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, _IFont::Glyph** pOut); + bool Add(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, _IFont::Glyph* pGlyph); + void Remove(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style); void RemoveFirst(void); bool IsEmpty(void); diff --git a/src/graphics/FGrp_FontFt2.cpp b/src/graphics/FGrp_FontFt2.cpp index 42dc20c..509321e 100644 --- a/src/graphics/FGrp_FontFt2.cpp +++ b/src/graphics/FGrp_FontFt2.cpp @@ -461,15 +461,15 @@ _FontFt2::Destroy(void) } bool -_FontFt2::FindCache(unsigned long character, _Util::FixedPoint26_6 size, int style, Glyph** pOut) +_FontFt2::FindCache(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, Glyph** pOut) { - return (__fontCache.get()) ? __fontCache->Find(character, __fontAttrib.size, __fontAttrib.style, pOut) : false; + return (__fontCache.get()) ? __fontCache->Find(glyphIndex, __fontAttrib.size, __fontAttrib.style, pOut) : false; } bool -_FontFt2::AddCache(unsigned long character, _Util::FixedPoint26_6 size, int style, Glyph* pGlyph) +_FontFt2::AddCache(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, Glyph* pGlyph) { - return (__fontCache.get()) ? __fontCache->Add(character, size, style, pGlyph) : false; + return (__fontCache.get()) ? __fontCache->Add(glyphIndex, size, style, pGlyph) : false; } bool @@ -564,8 +564,8 @@ _FontFt2::GetKerning(unsigned long character1, unsigned long character2, long& x } pFace = FT_Face(__pFontFace); - index1 = __GetCharIndex(character1); - index2 = __GetCharIndex(character2); + index1 = __GetGlyphIndex(character1); + index2 = __GetGlyphIndex(character2); bool hasKerning = false; @@ -611,7 +611,9 @@ _FontFt2::LoadGlyph(unsigned long character, Glyph** ppFontGlyphData) CHECK_NULL_PARAM(__pFontFace); CHECK_NULL_PARAM(ppFontGlyphData); - bool rtn = FindCache(character, __fontAttrib.size, __fontAttrib.style, ppFontGlyphData); + FT_UInt glyphIndex = __GetGlyphIndex(character); + + bool rtn = FindCache(glyphIndex, __fontAttrib.size, __fontAttrib.style, ppFontGlyphData); if (rtn) { @@ -621,7 +623,6 @@ _FontFt2::LoadGlyph(unsigned long character, Glyph** ppFontGlyphData) *ppFontGlyphData = null; FT_Face pFace = null; - FT_UInt ixCurr = character; pFace = FT_Face(__pFontFace); @@ -630,9 +631,6 @@ _FontFt2::LoadGlyph(unsigned long character, Glyph** ppFontGlyphData) SysLog(NID_GRP, "[] FT_IS_SCALABLE has been failed"); } - // retrieve glyph index from character code - ixCurr = __GetCharIndex(character); - // set transformation FT_Matrix matrix; FT_Vector pen = {0, 0}; @@ -649,12 +647,12 @@ _FontFt2::LoadGlyph(unsigned long character, Glyph** ppFontGlyphData) if (isSynthetic) { - errCode = FT_Load_Glyph(pFace, ixCurr, FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP); + errCode = FT_Load_Glyph(pFace, glyphIndex, FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP); } else { - //errCode = FT_Load_Glyph(pFace, ixCurr, FT_LOAD_RENDER); - errCode = FT_Load_Glyph(pFace, ixCurr, FT_LOAD_DEFAULT); + //errCode = FT_Load_Glyph(pFace, glyphIndex, FT_LOAD_RENDER); + errCode = FT_Load_Glyph(pFace, glyphIndex, FT_LOAD_DEFAULT); } if (errCode) // 0: success @@ -676,7 +674,7 @@ _FontFt2::LoadGlyph(unsigned long character, Glyph** ppFontGlyphData) //TODO sunmi557.shin, will not support FT_Error errCode = 1; - errCode = FT_Load_Glyph(pFace, ixCurr, FT_LOAD_RENDER | FT_LOAD_MONOCHROME); + errCode = FT_Load_Glyph(pFace, glyphIndex, FT_LOAD_RENDER | FT_LOAD_MONOCHROME); if (errCode) { @@ -696,7 +694,7 @@ _FontFt2::LoadGlyph(unsigned long character, Glyph** ppFontGlyphData) if (__isLoadGlyph) { - rtn = AddCache(character, __fontAttrib.size, __fontAttrib.style, *ppFontGlyphData); + rtn = AddCache(glyphIndex, __fontAttrib.size, __fontAttrib.style, *ppFontGlyphData); } if (*ppFontGlyphData != null) @@ -733,7 +731,7 @@ _FontFt2::UnloadGlyph(Glyph** ppFontGlyphData) unsigned long _FontFt2::CheckGlyph(unsigned long character) { - return __GetCharIndex(character); + return __GetGlyphIndex(character); } bool @@ -918,37 +916,38 @@ _FontFt2::GetGlyphList(const _Util::String& reorderedText, Tizen::Base::Collecti if (!auxInfo.isAvailable) { - char* pFontGlyphData = new (std::nothrow) char[sizeof(_IFont::Glyph)]; + _IFont::Glyph* pFontGlyphData = (_IFont::Glyph*) new (std::nothrow) char[sizeof(_IFont::Glyph)]; if (pFontGlyphData) { memset(pFontGlyphData, 0, sizeof(_IFont::Glyph)); - out.Add((_IFont::Glyph*) pFontGlyphData); + pFontGlyphData->hasOwnerShip = 1; + out.Add(pFontGlyphData); } continue; } - FT_UInt glyph_index = auxInfo.glyphIndex; + FT_UInt glyphIndex = auxInfo.glyphIndex; // bidi cache underdevelop - //_IFont::Glyph *pFontGlyphData; - // - //bool rtn = FindCache(glyph_index, __fontAttrib.size, __fontAttrib.style, &pFontGlyphData); - // - //if (rtn) - //{ - // out.Add(pFontGlyphData); - // continue; - //} + _IFont::Glyph* pFontGlyphData; + + bool rtn = FindCache(glyphIndex, __fontAttrib.size, __fontAttrib.style, &pFontGlyphData); + + if (rtn) + { + out.Add(pFontGlyphData); + continue; + } if (isSynthetic) { - error = FT_Load_Glyph(pFace, glyph_index, FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP); + error = FT_Load_Glyph(pFace, glyphIndex, FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP); } else { - error = FT_Load_Glyph(pFace, glyph_index, /*FT_LOAD_RENDER*/FT_LOAD_DEFAULT/* | FT_LOAD_NO_BITMAP*/); + error = FT_Load_Glyph(pFace, glyphIndex, /*FT_LOAD_RENDER*/FT_LOAD_DEFAULT/* | FT_LOAD_NO_BITMAP*/); } if (error) @@ -989,7 +988,7 @@ _FontFt2::GetGlyphList(const _Util::String& reorderedText, Tizen::Base::Collecti image.bytesPerLine = pSlot->bitmap.pitch; image.pBitmap = pSlot->bitmap.buffer; - _IFont::Glyph *pFontGlyphData = (_IFont::Glyph*) new (std::nothrow) char[sizeof(_IFont::Glyph) + (image.bytesPerLine * image.height)]; + pFontGlyphData = (_IFont::Glyph*) new (std::nothrow) char[sizeof(_IFont::Glyph) + (image.bytesPerLine * image.height)]; if (pFontGlyphData == null) { @@ -1019,12 +1018,12 @@ _FontFt2::GetGlyphList(const _Util::String& reorderedText, Tizen::Base::Collecti out.Add(pFontGlyphData); // bidi cache underdevelop - //AddCache(glyph_index, __fontAttrib.size, __fontAttrib.style, pFontGlyphData); - // - //if (pFontGlyphData != null) - //{ - // pFontGlyphData->hasOwnerShip = 1; - //} + AddCache(glyphIndex, __fontAttrib.size, __fontAttrib.style, pFontGlyphData); + + if (pFontGlyphData != null) + { + pFontGlyphData->hasOwnerShip = 1; + } } return true; @@ -1055,7 +1054,7 @@ _FontFt2::__CleanUp() } unsigned long -_FontFt2::__GetCharIndex(unsigned long character) const +_FontFt2::__GetGlyphIndex(unsigned long character) const { if (!__isValid) { @@ -1071,9 +1070,9 @@ _FontFt2::__GetCharIndex(unsigned long character) const if (pFace->charmap != null) { - unsigned long ixCurr = FT_Get_Char_Index(pFace, character); + unsigned long glyphIndex = FT_Get_Char_Index(pFace, character); - return ixCurr; + return glyphIndex; } return character; diff --git a/src/graphics/FGrp_FontFt2.h b/src/graphics/FGrp_FontFt2.h index 217728c..32a864c 100644 --- a/src/graphics/FGrp_FontFt2.h +++ b/src/graphics/FGrp_FontFt2.h @@ -64,8 +64,8 @@ protected: virtual bool Reload(const void* pBuffer, long bufSize, long face = 0); virtual bool Reload(const char* filePath, long face = 0); virtual void Destroy(void); - virtual bool FindCache(unsigned long character, _Util::FixedPoint26_6 size, int style, Glyph** pOut); - virtual bool AddCache(unsigned long character, _Util::FixedPoint26_6 size, int style, Glyph* pGlyph); + virtual bool FindCache(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, Glyph** pOut); + virtual bool AddCache(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, Glyph* pGlyph); virtual bool CleanCache(void); private: @@ -76,7 +76,7 @@ private: void __CleanUp(); // return internal index for wide character - unsigned long __GetCharIndex(unsigned long character) const; + unsigned long __GetGlyphIndex(unsigned long character) const; // convert the glyph of FreeType2 to _IFont::Glyph information bool __ConvertPrivateToImage(void* pData1, _IFont::Glyph** ppFontGlyphData); diff --git a/src/graphics/FGrp_FontRsrcManager.cpp b/src/graphics/FGrp_FontRsrcManager.cpp index 0f865de..01045b4 100644 --- a/src/graphics/FGrp_FontRsrcManager.cpp +++ b/src/graphics/FGrp_FontRsrcManager.cpp @@ -160,12 +160,12 @@ protected: virtual void Destroy(void) {} - virtual bool FindCache(unsigned long character, _Util::FixedPoint26_6 size, int style, Glyph** pOut) + virtual bool FindCache(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, Glyph** pOut) { return false; } - virtual bool AddCache(unsigned long character, _Util::FixedPoint26_6 size, int style, Glyph* pGlyph) + virtual bool AddCache(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, Glyph* pGlyph) { return false; } diff --git a/src/graphics/FGrp_IFont.h b/src/graphics/FGrp_IFont.h index 3e74751..8d43068 100644 --- a/src/graphics/FGrp_IFont.h +++ b/src/graphics/FGrp_IFont.h @@ -188,9 +188,9 @@ protected: //! Destroys the instance. virtual void Destroy(void) = 0; //! Finds glyph in the cache - virtual bool FindCache(unsigned long character, _Util::FixedPoint26_6 size, int style, Glyph** pOut) = 0; + virtual bool FindCache(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, Glyph** pOut) = 0; //! Adds glyph in the cache - virtual bool AddCache(unsigned long character, _Util::FixedPoint26_6 size, int style, Glyph* pGlyph) = 0; + virtual bool AddCache(unsigned long glyphIndex, _Util::FixedPoint26_6 size, int style, Glyph* pGlyph) = 0; //! Clean cache virtual bool CleanCache(void) = 0; -- 2.7.4