This is an automated email from the ASF dual-hosted git repository.

jimjag pushed a commit to branch odf13-devel
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit dec5ba502c9a5ece89247564a378245fb9dfd6a6
Author: Jim Jagielski <[email protected]>
AuthorDate: Fri Oct 30 12:58:03 2026 -0400

    xmloff: Write number:min-decimal-places in the ODF 1.3 modes
---
 main/xmloff/inc/xmloff/xmlnumfe.hxx   |  5 ++--
 main/xmloff/source/style/xmlnumfe.cxx | 45 +++++++++++++++++++++++++++++++----
 2 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/main/xmloff/inc/xmloff/xmlnumfe.hxx 
b/main/xmloff/inc/xmloff/xmlnumfe.hxx
index 344afa5544..2fffb94f9e 100644
--- a/main/xmloff/inc/xmloff/xmlnumfe.hxx
+++ b/main/xmloff/inc/xmloff/xmlnumfe.hxx
@@ -67,9 +67,10 @@ private:
        SAL_DLLPRIVATE void WriteNumberElement_Impl( sal_Int32 nDecimals, 
sal_Int32 nInteger,
                                                                                
const ::rtl::OUString& rDashStr, sal_Bool bVarDecimals,
                                                                                
sal_Bool bGrouping, sal_Int32 nTrailingThousands,
-                                                                               
const SvXMLEmbeddedTextEntryArr& rEmbeddedEntries );
+                                                                               
const SvXMLEmbeddedTextEntryArr& rEmbeddedEntries,
+                                                                               
sal_Int32 nMinDecimals = -1 );
        SAL_DLLPRIVATE void WriteScientificElement_Impl( sal_Int32 nDecimals, 
sal_Int32 nInteger,
-                                                                               
sal_Bool bGrouping, sal_Int32 nExp );
+                                                                               
sal_Bool bGrouping, sal_Int32 nExp, sal_Int32 nMinDecimals = -1 );
        SAL_DLLPRIVATE void WriteFractionElement_Impl( sal_Int32 nInteger, 
sal_Bool bGrouping,
                                                                                
sal_Int32 nNumerator, sal_Int32 nDenominator );
        SAL_DLLPRIVATE void WriteCurrencyElement_Impl( const ::rtl::OUString& 
rString,
diff --git a/main/xmloff/source/style/xmlnumfe.cxx 
b/main/xmloff/source/style/xmlnumfe.cxx
index 5ee83aab12..487535f3a9 100644
--- a/main/xmloff/source/style/xmlnumfe.cxx
+++ b/main/xmloff/source/style/xmlnumfe.cxx
@@ -579,7 +579,8 @@ void SvXMLNumFmtExport::WriteNumberElement_Impl(
                                                        sal_Int32 nDecimals, 
sal_Int32 nInteger,
                                                        const OUString& 
rDashStr, sal_Bool bVarDecimals,
                                                        sal_Bool bGrouping, 
sal_Int32 nTrailingThousands,
-                                                       const 
SvXMLEmbeddedTextEntryArr& rEmbeddedEntries )
+                                                       const 
SvXMLEmbeddedTextEntryArr& rEmbeddedEntries,
+                                                       sal_Int32 nMinDecimals )
 {
        FinishTextElement_Impl();
 
@@ -590,6 +591,13 @@ void SvXMLNumFmtExport::WriteNumberElement_Impl(
                               OUString::valueOf( nDecimals ) );
        }
 
+       //      minimum decimals (ODF 1.3), if some of the decimals are optional
+       if ( nMinDecimals > 0 && nMinDecimals < nDecimals )
+       {
+               rExport.AddAttribute( XML_NAMESPACE_NUMBER, 
XML_MIN_DECIMAL_PLACES,
+                              OUString::valueOf( nMinDecimals ) );
+       }
+
        //      integer digits
        if ( nInteger >= 0 )    // negative = automatic
        {
@@ -654,7 +662,7 @@ void SvXMLNumFmtExport::WriteNumberElement_Impl(
 
 void SvXMLNumFmtExport::WriteScientificElement_Impl(
                                                        sal_Int32 nDecimals, 
sal_Int32 nInteger,
-                                                       sal_Bool bGrouping, 
sal_Int32 nExp )
+                                                       sal_Bool bGrouping, 
sal_Int32 nExp, sal_Int32 nMinDecimals )
 {
        FinishTextElement_Impl();
 
@@ -665,6 +673,13 @@ void SvXMLNumFmtExport::WriteScientificElement_Impl(
                               OUString::valueOf( nDecimals ) );
        }
 
+       //      minimum decimals (ODF 1.3); without it all decimals are 
mandatory
+       if ( nMinDecimals >= 0 && nMinDecimals < nDecimals )
+       {
+               rExport.AddAttribute( XML_NAMESPACE_NUMBER, 
XML_MIN_DECIMAL_PLACES,
+                              OUString::valueOf( nMinDecimals ) );
+       }
+
        //      integer digits
        if ( nInteger >= 0 )    // negative = automatic
        {
@@ -1173,6 +1188,9 @@ void SvXMLNumFmtExport::ExportPart_Impl( const 
SvNumberformat& rFormat, sal_uInt
                sal_Bool bInInteger  = sal_True;
                sal_Int32 nExpDigits = 0;
                sal_Int32 nIntegerSymbols = 0;                  // for 
embedded-text, including "#"
+               sal_Int32 nDecZeros = 0;                                // 
mandatory decimals: '0's before the first '#'
+               sal_Bool bDecHash = sal_False;                  // a '#' was 
found in the decimals
+               sal_Bool bDecIrregular = sal_False;             // decimals 
other than 0... followed by #...
                sal_Int32 nTrailingThousands = 0;               // 
thousands-separators after all digits
                OUString sCurrExt;
                OUString aCalendar;
@@ -1199,6 +1217,19 @@ void SvXMLNumFmtExport::ExportPart_Impl( const 
SvNumberformat& rFormat, sal_uInt
                                                //      decimals is assumed 
(for 0.###, but not 0.0##).
                                                bVarDecimals = sal_True;
                                        }
+                                       if ( !bExpFound && !bInInteger && 
!bDecDashes && pElemStr && pElemStr->GetChar(0) != '-' )
+                                       {
+                                               for ( xub_StrLen nDec = 0; nDec 
< pElemStr->Len(); nDec++ )
+                                               {
+                                                       sal_Unicode cDec = 
pElemStr->GetChar( nDec );
+                                                       if ( cDec == '0' && 
!bDecHash )
+                                                               nDecZeros++;
+                                                       else if ( cDec == '#' )
+                                                               bDecHash = 
sal_True;
+                                                       else
+                                                               bDecIrregular = 
sal_True;
+                                               }
+                                       }
                                        if ( bInInteger && pElemStr )
                                                nIntegerSymbols += 
pElemStr->Len();
                                        nTrailingThousands = 0;
@@ -1380,6 +1411,12 @@ void SvXMLNumFmtExport::ExportPart_Impl( const 
SvNumberformat& rFormat, sal_uInt
                                case NF_SYMBOLTYPE_DIGIT:
                                        if (!bNumWritten)                       
// write number part
                                        {
+                                               //      only ODF 1.3 can 
express mandatory decimals followed by optional ones
+                                               sal_Int32 nMinDecimals = -1;
+                                               if ( 
rExport.getDefaultVersion() >= SvtSaveOptions::ODFVER_013 &&
+                                                               bDecHash && 
!bDecIrregular && !bDecDashes )
+                                                       nMinDecimals = 
nDecZeros;
+
                                                switch ( nFmtType )
                                                {
                                                        // for type 0 (not 
recognized as a special type),
@@ -1413,7 +1450,7 @@ void SvXMLNumFmtExport::ExportPart_Impl( const 
SvNumberformat& rFormat, sal_uInt
                                                                                
sDashStr.Fill( nPrecision, '-' );
 
                                                                        
WriteNumberElement_Impl( nDecimals, nInteger, sDashStr, bVarDecimals,
-                                                                               
                                bThousand, nTrailingThousands, aEmbeddedEntries 
);
+                                                                               
                                bThousand, nTrailingThousands, 
aEmbeddedEntries, nMinDecimals );
                                                                        
bAnyContent = sal_True;
                                                                }
                                                                break;
@@ -1421,7 +1458,7 @@ void SvXMLNumFmtExport::ExportPart_Impl( const 
SvNumberformat& rFormat, sal_uInt
                                 // #i43959# for scientific numbers, count all 
integer symbols ("0" and "#")
                                 // as integer digits: use nIntegerSymbols 
instead of nLeading
                                 // (use of '#' to select multiples in exponent 
might be added later)
-                                WriteScientificElement_Impl( nPrecision, 
nIntegerSymbols, bThousand, nExpDigits );
+                                WriteScientificElement_Impl( nPrecision, 
nIntegerSymbols, bThousand, nExpDigits, nMinDecimals );
                                                                bAnyContent = 
sal_True;
                                                                break;
                                                        case 
NUMBERFORMAT_FRACTION:

Reply via email to