From 693c929c1a475e6b4bd737e50d09d6f390700812 Mon Sep 17 00:00:00 2001 From: Laurent Balland-Poirier Date: Thu, 16 Mar 2017 23:45:13 +0100 Subject: 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 Reviewed-by: Eike Rathke (cherry picked from commit 2fd110a78d03510d031c4c6cf6ad380d82899df8) Reviewed-on: https://gerrit.libreoffice.org/36232 --- include/svl/zformat.hxx | 3 ++- svl/source/numbers/zformat.cxx | 29 +++++++++++------------------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/include/svl/zformat.hxx b/include/svl/zformat.hxx index ce632ae04920..ceba6a4993ca 100644 --- a/include/svl/zformat.hxx +++ b/include/svl/zformat.hxx @@ -553,7 +553,8 @@ private: sal_Int32& k, sal_uInt16& j, sal_uInt16 nIx, - short eSymbolType ); + short eSymbolType, + bool bInsertRightBlank = false ); // Helper function to fill in the integer part and the group (AKA thousand) separators SVL_DLLPRIVATE bool ImpNumberFillWithThousands( OUStringBuffer& sStr, 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: -- cgit v1.2.3