summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2023-09-28 21:14:15 +1000
committerTomaž Vajngerl <quikee@gmail.com>2023-10-27 05:48:33 +0200
commitadba3022f14d28090a668da10fc3311633535ae8 (patch)
treeada8517f3b862217f4c30d20116be8034df01713
parent7ac066438f6d029fd0be2f0c72207805b0ca8153 (diff)
vcl: flatten TextLayoutCommon::GetEllipsisString()
Change-Id: I04a5eed7a6fbd2d4c7f31006c73729cf79a2ed02 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157367 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--vcl/source/gdi/textlayout.cxx182
1 files changed, 96 insertions, 86 deletions
diff --git a/vcl/source/gdi/textlayout.cxx b/vcl/source/gdi/textlayout.cxx
index 2eaf5746f30b..a1597c69793e 100644
--- a/vcl/source/gdi/textlayout.cxx
+++ b/vcl/source/gdi/textlayout.cxx
@@ -75,117 +75,127 @@ namespace vcl
OUString aStr = rOrigStr;
sal_Int32 nIndex = GetTextBreak( aStr, nMaxWidth, 0, aStr.getLength() );
- if ( nIndex != -1 )
+ if (nIndex == -1)
+ return aStr;
+
+ if( (nStyle & DrawTextFlags::CenterEllipsis) == DrawTextFlags::CenterEllipsis )
{
- if( (nStyle & DrawTextFlags::CenterEllipsis) == DrawTextFlags::CenterEllipsis )
+ OUStringBuffer aTmpStr( aStr );
+ // speed it up by removing all but 1.33x as many as the break pos.
+ sal_Int32 nEraseChars = std::max<sal_Int32>(4, aStr.getLength() - (nIndex*4)/3);
+ while( nEraseChars < aStr.getLength() && GetTextWidth( aTmpStr.toString(), 0, aTmpStr.getLength() ) > nMaxWidth )
{
- OUStringBuffer aTmpStr( aStr );
- // speed it up by removing all but 1.33x as many as the break pos.
- sal_Int32 nEraseChars = std::max<sal_Int32>(4, aStr.getLength() - (nIndex*4)/3);
- while( nEraseChars < aStr.getLength() && GetTextWidth( aTmpStr.toString(), 0, aTmpStr.getLength() ) > nMaxWidth )
- {
- aTmpStr = aStr;
- sal_Int32 i = (aTmpStr.getLength() - nEraseChars)/2;
- aTmpStr.remove(i, nEraseChars++);
- aTmpStr.insert(i, "...");
- }
- aStr = aTmpStr.makeStringAndClear();
+ aTmpStr = aStr;
+ sal_Int32 i = (aTmpStr.getLength() - nEraseChars)/2;
+ aTmpStr.remove(i, nEraseChars++);
+ aTmpStr.insert(i, "...");
}
- else if ( nStyle & DrawTextFlags::EndEllipsis )
+ aStr = aTmpStr.makeStringAndClear();
+ }
+ else if ( nStyle & DrawTextFlags::EndEllipsis )
+ {
+ aStr = aStr.copy(0, nIndex);
+ if ( nIndex > 1 )
{
- aStr = aStr.copy(0, nIndex);
- if ( nIndex > 1 )
+ aStr += "...";
+ while ( !aStr.isEmpty() && ( GetTextWidth( aStr, 0, aStr.getLength() ) > nMaxWidth) )
{
- aStr += "...";
- while ( !aStr.isEmpty() && ( GetTextWidth( aStr, 0, aStr.getLength() ) > nMaxWidth) )
- {
- if ( (nIndex > 1) || (nIndex == aStr.getLength()) )
- nIndex--;
- aStr = aStr.replaceAt( nIndex, 1, u"");
- }
+ if ( (nIndex > 1) || (nIndex == aStr.getLength()) )
+ nIndex--;
+ aStr = aStr.replaceAt( nIndex, 1, u"");
}
+ }
- if ( aStr.isEmpty() && (nStyle & DrawTextFlags::Clip) )
- aStr += OUStringChar(rOrigStr[ 0 ]);
+ if ( aStr.isEmpty() && (nStyle & DrawTextFlags::Clip) )
+ aStr += OUStringChar(rOrigStr[ 0 ]);
+ }
+ else if ( nStyle & DrawTextFlags::PathEllipsis )
+ {
+ OUString aPath( rOrigStr );
+ OUString aAbbreviatedPath;
+ osl_abbreviateSystemPath( aPath.pData, &aAbbreviatedPath.pData, nIndex, nullptr );
+ aStr = aAbbreviatedPath;
+ }
+ else if ( nStyle & DrawTextFlags::NewsEllipsis )
+ {
+ static char const pSepChars[] = ".";
+ // Determine last section
+ sal_Int32 nLastContent = aStr.getLength();
+ while ( nLastContent )
+ {
+ nLastContent--;
+ if ( ImplIsCharIn( aStr[ nLastContent ], pSepChars ) )
+ break;
}
- else if ( nStyle & DrawTextFlags::PathEllipsis )
+ while ( nLastContent &&
+ ImplIsCharIn( aStr[ nLastContent-1 ], pSepChars ) )
+ nLastContent--;
+
+ OUString aLastStr = aStr.copy(nLastContent);
+ OUString aTempLastStr1 = "..." + aLastStr;
+ if ( GetTextWidth( aTempLastStr1, 0, aTempLastStr1.getLength() ) > nMaxWidth )
{
- OUString aPath( rOrigStr );
- OUString aAbbreviatedPath;
- osl_abbreviateSystemPath( aPath.pData, &aAbbreviatedPath.pData, nIndex, nullptr );
- aStr = aAbbreviatedPath;
+ aStr = GetEllipsisString( aStr, nMaxWidth, nStyle | DrawTextFlags::EndEllipsis );
}
- else if ( nStyle & DrawTextFlags::NewsEllipsis )
+ else
{
- static char const pSepChars[] = ".";
- // Determine last section
- sal_Int32 nLastContent = aStr.getLength();
- while ( nLastContent )
+ sal_Int32 nFirstContent = 0;
+ while ( nFirstContent < nLastContent )
{
- nLastContent--;
- if ( ImplIsCharIn( aStr[ nLastContent ], pSepChars ) )
+ nFirstContent++;
+ if ( ImplIsCharIn( aStr[ nFirstContent ], pSepChars ) )
break;
}
- while ( nLastContent &&
- ImplIsCharIn( aStr[ nLastContent-1 ], pSepChars ) )
- nLastContent--;
- OUString aLastStr = aStr.copy(nLastContent);
- OUString aTempLastStr1 = "..." + aLastStr;
- if ( GetTextWidth( aTempLastStr1, 0, aTempLastStr1.getLength() ) > nMaxWidth )
+ while ( (nFirstContent < nLastContent) &&
+ ImplIsCharIn( aStr[ nFirstContent ], pSepChars ) )
+ {
+ nFirstContent++;
+ }
+
+ // MEM continue here
+ if ( nFirstContent >= nLastContent )
+ {
aStr = GetEllipsisString( aStr, nMaxWidth, nStyle | DrawTextFlags::EndEllipsis );
+ }
else
{
- sal_Int32 nFirstContent = 0;
- while ( nFirstContent < nLastContent )
- {
- nFirstContent++;
- if ( ImplIsCharIn( aStr[ nFirstContent ], pSepChars ) )
- break;
- }
- while ( (nFirstContent < nLastContent) &&
- ImplIsCharIn( aStr[ nFirstContent ], pSepChars ) )
- nFirstContent++;
- // MEM continue here
- if ( nFirstContent >= nLastContent )
+ if ( nFirstContent > 4 )
+ nFirstContent = 4;
+ OUString aFirstStr = OUString::Concat(aStr.subView( 0, nFirstContent )) + "...";
+ OUString aTempStr = aFirstStr + aLastStr;
+ if ( GetTextWidth( aTempStr, 0, aTempStr.getLength() ) > nMaxWidth )
aStr = GetEllipsisString( aStr, nMaxWidth, nStyle | DrawTextFlags::EndEllipsis );
else
{
- if ( nFirstContent > 4 )
- nFirstContent = 4;
- OUString aFirstStr = OUString::Concat(aStr.subView( 0, nFirstContent )) + "...";
- OUString aTempStr = aFirstStr + aLastStr;
- if ( GetTextWidth( aTempStr, 0, aTempStr.getLength() ) > nMaxWidth )
- aStr = GetEllipsisString( aStr, nMaxWidth, nStyle | DrawTextFlags::EndEllipsis );
- else
+ do
{
- do
+ aStr = aTempStr;
+ if( nLastContent > aStr.getLength() )
+ nLastContent = aStr.getLength();
+ while ( nFirstContent < nLastContent )
{
- aStr = aTempStr;
- if( nLastContent > aStr.getLength() )
- nLastContent = aStr.getLength();
- while ( nFirstContent < nLastContent )
- {
- nLastContent--;
- if ( ImplIsCharIn( aStr[ nLastContent ], pSepChars ) )
- break;
-
- }
- while ( (nFirstContent < nLastContent) &&
- ImplIsCharIn( aStr[ nLastContent-1 ], pSepChars ) )
- nLastContent--;
-
- if ( nFirstContent < nLastContent )
- {
- std::u16string_view aTempLastStr = aStr.subView( nLastContent );
- aTempStr = aFirstStr + aTempLastStr;
-
- if ( GetTextWidth( aTempStr, 0, aTempStr.getLength() ) > nMaxWidth )
- break;
- }
+ nLastContent--;
+ if ( ImplIsCharIn( aStr[ nLastContent ], pSepChars ) )
+ break;
+
+ }
+ while ( (nFirstContent < nLastContent) &&
+ ImplIsCharIn( aStr[ nLastContent-1 ], pSepChars ) )
+ {
+ nLastContent--;
+ }
+
+ if ( nFirstContent < nLastContent )
+ {
+ std::u16string_view aTempLastStr = aStr.subView( nLastContent );
+ aTempStr = aFirstStr + aTempLastStr;
+
+ if ( GetTextWidth( aTempStr, 0, aTempStr.getLength() ) > nMaxWidth )
+ break;
}
- while ( nFirstContent < nLastContent );
}
+ while ( nFirstContent < nLastContent );
}
}
}