From 9eaced3877cceb64a303fd79e2af23deb32bb5fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Tue, 12 Feb 2013 14:51:58 +0000 Subject: [PATCH] doesn't help one bit Change-Id: I6741cce6f752c3cd635d5594166f7cb13d53269a --- vcl/generic/glyphs/gcach_layout.cxx | 89 ++++++++++++++++++++++++++++++++++--- 1 file changed, 83 insertions(+), 6 deletions(-) diff --git a/vcl/generic/glyphs/gcach_layout.cxx b/vcl/generic/glyphs/gcach_layout.cxx index a9f373e..9e5d269 100644 --- a/vcl/generic/glyphs/gcach_layout.cxx +++ b/vcl/generic/glyphs/gcach_layout.cxx @@ -260,6 +260,59 @@ le_bool IcuFontFromServerFont::getGlyphPoint( LEGlyphID, // ======================================================================= +struct layoutCharsArgs +{ + const sal_Unicode *m_pChars; + le_int32 m_nOffset; + le_int32 m_nCount; + le_int32 m_nMax; + le_bool m_bRightToLeft; + float m_nX; + float m_nY; + layoutCharsArgs() + : m_pChars(NULL) + , m_nOffset(0) + , m_nCount(0) + , m_nMax(0) + , m_bRightToLeft(false) + , m_nX(0.0) + , m_nY(0.0) + { + } + layoutCharsArgs(const sal_Unicode *chars, le_int32 offset, + le_int32 count, le_int32 max, le_bool rightToLeft, float x, float y) + : m_pChars(chars) + , m_nOffset(offset) + , m_nCount(count) + , m_nMax(max) + , m_bRightToLeft(rightToLeft) + , m_nX(x) + , m_nY(y) + { + } + bool operator==(const layoutCharsArgs& rOther) const + { + return (m_pChars == rOther.m_pChars && + m_nOffset == rOther.m_nOffset && + m_nCount == rOther.m_nCount && + m_nMax == rOther.m_nMax && + m_bRightToLeft == rOther.m_bRightToLeft && + m_nX == rOther.m_nX && + m_nY == rOther.m_nY); + } +}; + +struct layoutCharsCache +{ + layoutCharsArgs m_aArgs; + le_int32 m_nRawRunGlyphCount; + LEErrorCode m_nErrorCode; + void clear() + { + m_aArgs = layoutCharsArgs(); + } +}; + class IcuLayoutEngine : public ServerFontLayoutEngine { private: @@ -269,6 +322,8 @@ private: le_int32 mnLayoutFlags; LayoutEngine* mpIcuLE; + layoutCharsCache maCache; + public: IcuLayoutEngine( ServerFont& ); virtual ~IcuLayoutEngine(); @@ -385,6 +440,7 @@ bool IcuLayoutEngine::layout(ServerFontLayout& rLayout, ImplLayoutArgs& rArgs) { // TODO: cache multiple layout engines when multiple scripts are used delete mpIcuLE; + maCache.clear(); meScriptCode = eScriptCode; mnLayoutFlags = nLayoutFlags; le_int32 eLangCode = 0; // TODO: get better value @@ -400,11 +456,33 @@ bool IcuLayoutEngine::layout(ServerFontLayout& rLayout, ImplLayoutArgs& rArgs) if( !mpIcuLE ) break; - // run ICU layout engine - // TODO: get enough context, remove extra glyps below - int nRawRunGlyphCount = mpIcuLE->layoutChars( pIcuChars, - nMinRunPos, nEndRunPos - nMinRunPos, rArgs.mnLength, - bRightToLeft, aNewPos.X(), aNewPos.Y(), rcIcu ); + int nRawRunGlyphCount; + + layoutCharsArgs aArgs(rArgs.mpStr, nMinRunPos, nEndRunPos - nMinRunPos, rArgs.mnLength, + bRightToLeft, aNewPos.X(), aNewPos.Y()); + + if (aArgs == maCache.m_aArgs) + { + nRawRunGlyphCount = maCache.m_nRawRunGlyphCount; + rcIcu = maCache.m_nErrorCode; + } + else + { + mpIcuLE->reset(); // frees the glyph, character index and position arrays + // so that the LayoutEngine can be reused to layout a + // different characer array + + // run ICU layout engine + // TODO: get enough context, remove extra glyphs below + nRawRunGlyphCount = mpIcuLE->layoutChars(pIcuChars, + aArgs.m_nOffset, aArgs.m_nCount, aArgs.m_nMax, + aArgs.m_bRightToLeft, aArgs.m_nX, aArgs.m_nY, rcIcu ); + + maCache.m_aArgs = aArgs; + maCache.m_nRawRunGlyphCount = nRawRunGlyphCount; + maCache.m_nErrorCode = rcIcu; + } + if( LE_FAILURE(rcIcu) ) return false; @@ -412,7 +490,6 @@ bool IcuLayoutEngine::layout(ServerFontLayout& rLayout, ImplLayoutArgs& rArgs) mpIcuLE->getGlyphs( pIcuGlyphs, rcIcu ); mpIcuLE->getCharIndices( pCharIndices, rcIcu ); mpIcuLE->getGlyphPositions( &pGlyphPositions->fX, rcIcu ); - mpIcuLE->reset(); // TODO: get rid of this, PROBLEM: crash at exit when removed if( LE_FAILURE(rcIcu) ) return false; -- 1.8.1.2