summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorLaurent Balland-Poirier <laurent.balland-poirier@laposte.net>2017-03-16 23:45:13 +0100
committerAndras Timar <andras.timar@collabora.com>2017-04-08 18:09:06 +0200
commit5314bc77e0b6c596170ee142a514c0c390d8c2e7 (patch)
treeed9a1da020d72bf4691000fad1e2d3a361c4faf8 /svl
parent8cea1db917b44ffe731af84b90c3470553d91adc (diff)
tdf#106190 Fix (again) left alignment of denominator
Instead of moving spaces from left to right, like it was done previously, this patch insert spaces directly on right when in denominator This avoid complex calculation when user enter such (stupid) format: # ?/ ??? or # ?/" hello world "??? In SvNumberformat::ImpNumberFill, for NF_SYMBOLTYPE_FRAC_FDIV you need at least to move in sBuf, to insert text at the expected place for (stupid) format like # ?/ 100 or # ?/" hello world "100 All these formats works, but are stored in ODF with text after fraction Change-Id: I296e60643e93242b8006848a643135219ad4ad0c Reviewed-on: https://gerrit.libreoffice.org/35320 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Eike Rathke <erack@redhat.com> (cherry picked from commit 2fd110a78d03510d031c4c6cf6ad380d82899df8) Reviewed-on: https://gerrit.libreoffice.org/36232 (cherry picked from commit 693c929c1a475e6b4bd737e50d09d6f390700812)
Diffstat (limited to 'svl')
-rw-r--r--svl/source/numbers/zformat.cxx29
1 files changed, 11 insertions, 18 deletions
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index ac622bf4cc45..2c018f662784 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -2212,7 +2212,8 @@ OUString lcl_GetDenominatorString(const ImpSvNumberformatInfo &rInfo, sal_uInt16
{
if( rInfo.nTypeArray[i] == NF_SYMBOLTYPE_FRAC )
{
- while ( ( ++i < nAnz ) && rInfo.nTypeArray[i] == NF_SYMBOLTYPE_STRING );
+ while ( ( ++i < nAnz ) && rInfo.nTypeArray[i] != NF_SYMBOLTYPE_FRAC_FDIV
+ && rInfo.nTypeArray[i] != NF_SYMBOLTYPE_DIGIT );
for( ; i < nAnz; i++ )
{
if( rInfo.nTypeArray[i] == NF_SYMBOLTYPE_FRAC_FDIV || rInfo.nTypeArray[i] == NF_SYMBOLTYPE_DIGIT )
@@ -2815,21 +2816,7 @@ bool SvNumberformat::ImpGetFractionOutput(double fNumber,
sal_uInt16 j = nAnz-1; // Last symbol -> backwards
sal_Int32 k; // Denominator
- bRes |= ImpNumberFill(sDiv, fNumber, k, j, nIx, NF_SYMBOLTYPE_FRAC);
- if ( !bHideFraction && sDenominatorFormat.getLength() > 0 )
- {
- // Guard against a (theoretical?) endless loop of blanks only.
- sal_Int32 n = sDiv.getLength();
- sal_Int32 nDenominatorLen = sDenominatorFormat.getLength();
- while ( n-- > 0 && sDiv[0] == ' ' ) // left align denominator
- {
- if (sDiv.getLength() <= nDenominatorLen)
- sDiv.append(" ");
- else
- sDiv.insert( nDenominatorLen, " " );
- sDiv.remove( 0, 1 );
- }
- }
+ bRes |= ImpNumberFill(sDiv, fNumber, k, j, nIx, NF_SYMBOLTYPE_FRAC, true);
bool bCont = true;
if (rInfo.nTypeArray[j] == NF_SYMBOLTYPE_FRAC)
@@ -4484,7 +4471,8 @@ bool SvNumberformat::ImpNumberFill( OUStringBuffer& sBuff, // number string
sal_Int32& k, // position within string
sal_uInt16& j, // symbol index within format code
sal_uInt16 nIx, // subformat index
- short eSymbolType ) // type of stop condition
+ short eSymbolType, // type of stop condition
+ bool bInsertRightBlank)// insert blank on right for denominator (default = false)
{
bool bRes = false;
bool bStop = false;
@@ -4536,6 +4524,7 @@ bool SvNumberformat::ImpNumberFill( OUStringBuffer& sBuff, // number string
case NF_SYMBOLTYPE_DIGIT:
{
bFoundNumber = true;
+ sal_uInt16 nPosInsertBlank = bInsertRightBlank ? k : 0; // left alignment of denominator
const OUString& rStr = rInfo.sStrArray[j];
const sal_Unicode* p1 = rStr.getStr();
const sal_Unicode* p = p1 + rStr.getLength();
@@ -4553,7 +4542,7 @@ bool SvNumberformat::ImpNumberFill( OUStringBuffer& sBuff, // number string
sBuff.insert(0, '0');
break;
case '?':
- sBuff.insert(0, ' ');
+ sBuff.insert(nPosInsertBlank, ' ');
break;
}
}
@@ -4573,6 +4562,10 @@ bool SvNumberformat::ImpNumberFill( OUStringBuffer& sBuff, // number string
}
break;
case NF_SYMBOLTYPE_FRAC_FDIV: // Do Nothing
+ if (k > 0)
+ {
+ k--;
+ }
break;
default: