summaryrefslogtreecommitdiff
path: root/vcl/source/outdev/text.cxx
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2015-03-03 15:26:10 +0100
committerMichael Stahl <mstahl@redhat.com>2015-03-31 20:08:35 +0200
commitb9782a2b59428e1bc398b5f3a895785a072c93b6 (patch)
tree11321664d97646020fb77cf161e89e20a11d68d6 /vcl/source/outdev/text.cxx
parentb7fa07b07195799f385ccba0243611f71ffe0525 (diff)
tdf#89666: vcl: speed up HbLayoutEngine with cache in SwTxtFormatInfo
When a SwTxtFormatInfo is created to format a paragraph, pre-compute the result of vcl::ScriptRun::next() and cache it for future calls to OutputDevice::GetTextBreak() and GetTextWidth(). This requires adapting a bunch of methods to pass the additional parameter, and some classes to backup and restore the cache when they replace the text of the SwTxtFormatInfo. There is some code in vcl OutputDevice::ImplPrepareLayoutArgs() to modify the passed string and replace digits depending on "meTextLanguage" member; try to set it to the correct value when creating the layout cache (unfortunately it's not possible if the user sets the CTL Numerals config to the non-default "Context" value). Another issue is the check in OutputDevice::ImplLayout() if there is a mpConversion member on the font; apparently this is used to translate between different Symbol fonts, so not very important; just ignore the cache in this case. This reduces vcl::ScriptRun::next() from 11 to 0.36 billion callgrind cycles when built with GCC 4.9.2 -m32 -Os (which is still 16% of the formatting). Change-Id: I61fb8530333f2e7a9199f767c00cf2181ba49951 Reviewed-on: https://gerrit.libreoffice.org/14732 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/source/outdev/text.cxx')
-rw-r--r--vcl/source/outdev/text.cxx53
1 files changed, 41 insertions, 12 deletions
diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx
index 06e0b4078ab5..c52cae5f858c 100644
--- a/vcl/source/outdev/text.cxx
+++ b/vcl/source/outdev/text.cxx
@@ -925,10 +925,11 @@ void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr,
mpAlphaVDev->DrawText( rStartPt, rStr, nIndex, nLen, pVector, pDisplayText );
}
-long OutputDevice::GetTextWidth( const OUString& rStr, sal_Int32 nIndex, sal_Int32 nLen ) const
+long OutputDevice::GetTextWidth( const OUString& rStr, sal_Int32 nIndex, sal_Int32 nLen,
+ vcl::TextLayoutCache const*const pLayoutCache) const
{
- long nWidth = GetTextArray( rStr, NULL, nIndex, nLen );
+ long nWidth = GetTextArray( rStr, NULL, nIndex, nLen, pLayoutCache );
return nWidth;
}
@@ -993,7 +994,8 @@ void OutputDevice::DrawTextArray( const Point& rStartPt, const OUString& rStr,
}
long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry,
- sal_Int32 nIndex, sal_Int32 nLen ) const
+ sal_Int32 nIndex, sal_Int32 nLen,
+ vcl::TextLayoutCache const*const pLayoutCache) const
{
if(nLen == 0x0FFFF)
{
@@ -1009,7 +1011,8 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry,
nLen = rStr.getLength() - nIndex;
}
// do layout
- SalLayout* pSalLayout = ImplLayout( rStr, nIndex, nLen );
+ SalLayout *const pSalLayout = ImplLayout(rStr, nIndex, nLen,
+ Point(0,0), 0, nullptr, 0, pLayoutCache);
if( !pSalLayout )
return 0;
#if VCL_FLOAT_DEVICE_PIXEL
@@ -1191,7 +1194,8 @@ void OutputDevice::DrawStretchText( const Point& rStartPt, sal_uLong nWidth,
ImplLayoutArgs OutputDevice::ImplPrepareLayoutArgs( OUString& rStr,
const sal_Int32 nMinIndex, const sal_Int32 nLen,
DeviceCoordinate nPixelWidth, const DeviceCoordinate* pDXArray,
- int nLayoutFlags ) const
+ int nLayoutFlags,
+ vcl::TextLayoutCache const*const pLayoutCache) const
{
assert(nMinIndex >= 0);
assert(nLen >= 0);
@@ -1290,7 +1294,7 @@ ImplLayoutArgs OutputDevice::ImplPrepareLayoutArgs( OUString& rStr,
nLayoutFlags |= SAL_LAYOUT_RIGHT_ALIGN;
// set layout options
- ImplLayoutArgs aLayoutArgs( rStr.getStr(), rStr.getLength(), nMinIndex, nEndIndex, nLayoutFlags, maFont.GetLanguageTag() );
+ ImplLayoutArgs aLayoutArgs( rStr.getStr(), rStr.getLength(), nMinIndex, nEndIndex, nLayoutFlags, maFont.GetLanguageTag(), pLayoutCache );
int nOrientation = mpFontEntry ? mpFontEntry->mnOrientation : 0;
aLayoutArgs.SetOrientation( nOrientation );
@@ -1304,7 +1308,8 @@ ImplLayoutArgs OutputDevice::ImplPrepareLayoutArgs( OUString& rStr,
SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr,
sal_Int32 nMinIndex, sal_Int32 nLen,
const Point& rLogicalPos, long nLogicalWidth,
- const long* pDXArray, int flags) const
+ const long* pDXArray, int flags,
+ vcl::TextLayoutCache const* pLayoutCache) const
{
// we need a graphics
if( !mpGraphics )
@@ -1333,6 +1338,7 @@ SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr,
// recode string if needed
if( mpFontEntry->mpConversion ) {
mpFontEntry->mpConversion->RecodeString( aStr, 0, aStr.getLength() );
+ pLayoutCache = nullptr; // don't use cache with modified string!
}
DeviceCoordinate nPixelWidth = (DeviceCoordinate)nLogicalWidth;
DeviceCoordinate* pDXPixelArray = NULL;
@@ -1368,7 +1374,8 @@ SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr,
}
}
- ImplLayoutArgs aLayoutArgs = ImplPrepareLayoutArgs( aStr, nMinIndex, nLen, nPixelWidth, pDXPixelArray, flags);
+ ImplLayoutArgs aLayoutArgs = ImplPrepareLayoutArgs( aStr, nMinIndex, nLen,
+ nPixelWidth, pDXPixelArray, flags, pLayoutCache);
// get matching layout object for base font
SalLayout* pSalLayout = mpGraphics->GetTextLayout( aLayoutArgs, 0 );
@@ -1407,6 +1414,24 @@ SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr,
return pSalLayout;
}
+std::shared_ptr<vcl::TextLayoutCache> OutputDevice::CreateTextLayoutCache(
+ OUString const& rString) const
+{
+ if (!mpGraphics) // can happen in e.g Insert Index/Table dialog
+ return nullptr;
+ OUString copyBecausePrepareModifiesIt(rString);
+ ImplLayoutArgs aLayoutArgs = ImplPrepareLayoutArgs(copyBecausePrepareModifiesIt,
+ 0, rString.getLength(), 0, nullptr, 0, nullptr);
+
+ SalLayout *const pSalLayout = mpGraphics->GetTextLayout( aLayoutArgs, 0 );
+ if (!pSalLayout)
+ return nullptr;
+ std::shared_ptr<vcl::TextLayoutCache> const ret(
+ pSalLayout->CreateTextLayoutCache(copyBecausePrepareModifiesIt));
+ pSalLayout->Release();
+ return ret;
+}
+
bool OutputDevice::GetTextIsRTL( const OUString& rString, sal_Int32 nIndex, sal_Int32 nLen ) const
{
OUString aStr( rString );
@@ -1420,9 +1445,11 @@ bool OutputDevice::GetTextIsRTL( const OUString& rString, sal_Int32 nIndex, sal_
sal_Int32 OutputDevice::GetTextBreak( const OUString& rStr, long nTextWidth,
sal_Int32 nIndex, sal_Int32 nLen,
- long nCharExtra ) const
+ long nCharExtra,
+ vcl::TextLayoutCache const*const pLayoutCache) const
{
- SalLayout* pSalLayout = ImplLayout( rStr, nIndex, nLen );
+ SalLayout *const pSalLayout = ImplLayout( rStr, nIndex, nLen,
+ Point(0,0), 0, nullptr, 0, pLayoutCache);
sal_Int32 nRetVal = -1;
if( pSalLayout )
{
@@ -1451,11 +1478,13 @@ sal_Int32 OutputDevice::GetTextBreak( const OUString& rStr, long nTextWidth,
sal_Int32 OutputDevice::GetTextBreak( const OUString& rStr, long nTextWidth,
sal_Unicode nHyphenChar, sal_Int32& rHyphenPos,
sal_Int32 nIndex, sal_Int32 nLen,
- long nCharExtra ) const
+ long nCharExtra,
+ vcl::TextLayoutCache const*const pLayoutCache) const
{
rHyphenPos = -1;
- SalLayout* pSalLayout = ImplLayout( rStr, nIndex, nLen );
+ SalLayout *const pSalLayout = ImplLayout( rStr, nIndex, nLen,
+ Point(0,0), 0, nullptr, 0, pLayoutCache);
sal_Int32 nRetVal = -1;
if( pSalLayout )
{