include/svl/zformat.hxx        |    3 ++-
 svl/source/numbers/zformat.cxx |   29 +++++++++++------------------
 2 files changed, 13 insertions(+), 19 deletions(-)

New commits:
commit 2fd110a78d03510d031c4c6cf6ad380d82899df8
Author: Laurent Balland-Poirier <laurent.balland-poir...@laposte.net>
Date:   Thu Mar 16 23:45:13 2017 +0100

    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 <c...@libreoffice.org>
    Reviewed-by: Eike Rathke <er...@redhat.com>

diff --git a/include/svl/zformat.hxx b/include/svl/zformat.hxx
index 9bee5ca38370..d5086d7a7fc2 100644
--- a/include/svl/zformat.hxx
+++ b/include/svl/zformat.hxx
@@ -571,7 +571,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 3b85e192adfa..505e3c06df9a 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -2211,7 +2211,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 )
@@ -2835,21 +2836,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)
@@ -4504,7 +4491,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;
@@ -4556,6 +4544,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();
@@ -4573,7 +4562,7 @@ bool SvNumberformat::ImpNumberFill( OUStringBuffer& 
sBuff, // number string
                         sBuff.insert(0, '0');
                         break;
                     case '?':
-                        sBuff.insert(0, ' ');
+                        sBuff.insert(nPosInsertBlank, ' ');
                         break;
                     }
                 }
@@ -4593,6 +4582,10 @@ bool SvNumberformat::ImpNumberFill( OUStringBuffer& 
sBuff, // number string
         }
         break;
         case NF_SYMBOLTYPE_FRAC_FDIV: // Do Nothing
+            if (k > 0)
+            {
+                k--;
+            }
             break;
 
         default:
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to