Resolves: tdf#149484 Handle <number:boolean-style> with <number:text>
Backport as the current handling when writing such format (even if it
doesn't display the text literals) is utterly broken and results in
<number:boolean-style style:name="N111">
<number:text>--</number:text>
</number:boolean-style>
so an implementation correctly reading such (e.g. now upcoming
LibreOffice 7.4) would create a format "--" and display that for any
value, true or false.
This is a combination of 3 commits.
Related: tdf#149484 Display BOOLEAN literal string text additions
xChange-Id: Ifbaf0b18178091c3a340a7c4bc66f78397aadc18
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135506
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
(cherry picked from commit 2932dc7aa0c1239d39e060e6b7627317f1305549)
Resolves: tdf#149484 Read and handle <number:text> in <number:boolean-style>
xChange-Id: I1be5f2be908eb88aa4ef7436ea7c09f35b076acf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135507
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
(cherry picked from commit 025231224b8b076e280235cd2b943addd2fb0755)
Related: tdf#149484 Write proper <number:boolean-style> with <number:text>
xChange-Id: I46b7987dde25840ae0b6e5871b14e3806c6e4ac8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135508
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
(cherry picked from commit 33a8c4bd0e8533ab42894280e7e04c13a47aefa9)
Change-Id: I1be5f2be908eb88aa4ef7436ea7c09f35b076acf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135586
Tested-by: Jenkins
Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
diff --git a/include/svl/zformat.hxx b/include/svl/zformat.hxx
index cd04f96..ae57f5c 100644
--- a/include/svl/zformat.hxx
+++ b/include/svl/zformat.hxx
@@ -696,6 +696,10 @@ private:
SVL_DLLPRIVATE static void ImpAppendEraG( OUStringBuffer& OutStringBuffer, const CalendarWrapper& rCal,
sal_Int16 nNatNum );
SVL_DLLPRIVATE bool ImpGetLogicalOutput( double fNumber,
sal_uInt16 nIx,
OUStringBuffer& OutString );
SVL_DLLPRIVATE bool ImpGetNumberOutput( double fNumber,
sal_uInt16 nIx,
OUStringBuffer& OutString );
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index 34e439e..fb9cbf5 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -2448,7 +2448,7 @@ bool SvNumberformat::GetOutputString(double fNumber,
bool bRes = false;
OutString.clear();
*ppColor = nullptr; // No color change
if (eType & SvNumFormatType::LOGICAL)
if (eType & SvNumFormatType::LOGICAL && sFormatstring == rScan.GetKeywords()[NF_KEY_BOOLEAN])
{
if (fNumber)
{
@@ -2614,6 +2614,9 @@ bool SvNumberformat::GetOutputString(double fNumber,
case SvNumFormatType::CURRENCY:
bRes |= ImpGetNumberOutput(fNumber, nIx, sBuff);
break;
case SvNumFormatType::LOGICAL:
bRes |= ImpGetLogicalOutput(fNumber, nIx, sBuff);
break;
case SvNumFormatType::FRACTION:
bRes |= ImpGetFractionOutput(fNumber, nIx, sBuff);
break;
@@ -4286,6 +4289,29 @@ bool SvNumberformat::ImpGetDateTimeOutput(double fNumber,
return bRes;
}
bool SvNumberformat::ImpGetLogicalOutput(double fNumber,
sal_uInt16 nIx,
OUStringBuffer& sStr)
{
bool bRes = false;
const ImpSvNumberformatInfo& rInfo = NumFor[nIx].Info();
const sal_uInt16 nCnt = NumFor[nIx].GetCount();
for (sal_uInt16 j = 0; j < nCnt; ++j)
{
switch (rInfo.nTypeArray[j])
{
case NF_KEY_BOOLEAN:
sStr.append( fNumber ? rScan.GetTrueString() : rScan.GetFalseString());
break;
case NF_SYMBOLTYPE_STRING:
sStr.append( rInfo.sStrArray[j]);
break;
}
}
impTransliterate(sStr, NumFor[nIx].GetNatNum());
return bRes;
}
bool SvNumberformat::ImpGetNumberOutput(double fNumber,
sal_uInt16 nIx,
OUStringBuffer& sStr)
diff --git a/xmloff/source/style/xmlnumfe.cxx b/xmloff/source/style/xmlnumfe.cxx
index 4c31353..3b68b5a 100644
--- a/xmloff/source/style/xmlnumfe.cxx
+++ b/xmloff/source/style/xmlnumfe.cxx
@@ -1253,6 +1253,37 @@ void SvXMLNumFmtExport::ExportPart_Impl( const SvNumberformat& rFormat, sal_uInt
WriteBooleanElement_Impl();
bAnyContent = true;
}
else if (eType == XML_BOOLEAN_STYLE)
{
// <number:boolean-style> may contain only <number:boolean> and
// <number:text> elements.
sal_uInt16 nPos = 0;
bool bEnd = false;
while (!bEnd)
{
const short nElemType = rFormat.GetNumForType( nPart, nPos );
switch (nElemType)
{
case 0:
bEnd = true; // end of format reached
if (bHasText && sTextContent.isEmpty())
bHasText = false; // don't write trailing empty text
break;
case NF_SYMBOLTYPE_STRING:
{
const OUString* pElemStr = rFormat.GetNumForString( nPart, nPos );
if (pElemStr)
AddToTextElement_Impl( *pElemStr );
}
break;
case NF_KEY_BOOLEAN:
WriteBooleanElement_Impl();
bAnyContent = true;
break;
}
++nPos;
}
}
else
{
// first loop to collect attributes
diff --git a/xmloff/source/style/xmlnumfi.cxx b/xmloff/source/style/xmlnumfi.cxx
index 87f6538..b21a01b 100644
--- a/xmloff/source/style/xmlnumfi.cxx
+++ b/xmloff/source/style/xmlnumfi.cxx
@@ -497,8 +497,11 @@ static bool lcl_ValidChar( sal_Unicode cChar, const SvXMLNumFormatContext& rPare
}
// see ImpSvNumberformatScan::Next_Symbol
// All format types except BOOLEAN may contain minus sign or delimiter.
if ( cChar == '-' )
return true; // all format types may content minus sign or delimiter
return nFormatType != SvXMLStylesTokens::BOOLEAN_STYLE;
if ( ( cChar == ' ' ||
cChar == '/' ||
cChar == '.' ||
@@ -528,11 +531,13 @@ static void lcl_EnquoteIfNecessary( OUStringBuffer& rContent, const SvXMLNumForm
{
bool bQuote = true;
sal_Int32 nLength = rContent.getLength();
const SvXMLStylesTokens nFormatType = rParent.GetType();
if ((nLength == 1 && lcl_ValidChar( rContent[0], rParent)) ||
(nLength == 2 &&
((rContent[0] == ' ' && rContent[1] == '-') ||
(rContent[1] == ' ' && lcl_ValidChar( rContent[0], rParent)))))
if (nFormatType != SvXMLStylesTokens::BOOLEAN_STYLE &&
((nLength == 1 && lcl_ValidChar( rContent[0], rParent)) ||
(nLength == 2 &&
((rContent[0] == ' ' && rContent[1] == '-') ||
(rContent[1] == ' ' && lcl_ValidChar( rContent[0], rParent))))))
{
// Don't quote single separator characters like space or percent,
// or separator characters followed by space (used in date formats).
@@ -541,7 +546,7 @@ static void lcl_EnquoteIfNecessary( OUStringBuffer& rContent, const SvXMLNumForm
// the difference of quotes.
bQuote = false;
}
else if ( rParent.GetType() == SvXMLStylesTokens::PERCENTAGE_STYLE && nLength > 1 )
else if ( nFormatType == SvXMLStylesTokens::PERCENTAGE_STYLE && nLength > 1 )
{
// the percent character in percentage styles must be left out of quoting
// (one occurrence is enough even if there are several percent characters in the string)
@@ -906,7 +911,7 @@ void SvXMLNumFmtElementContext::endFastElement(sal_Int32 )
}
break;
case SvXMLStyleTokens::Boolean:
// ignored - only default boolean format is supported
rParent.AddNfKeyword( NF_KEY_BOOLEAN );
break;
case SvXMLStyleTokens::Day:
@@ -1533,9 +1538,8 @@ sal_Int32 SvXMLNumFormatContext::CreateAndInsert(SvNumberFormatter* pFormatter)
nIndex = pFormatter->GetFormatIndex( NF_NUMBER_SYSTEM, nFormatLang );
}
// boolean is always the builtin boolean format
// (no other boolean formats are implemented)
if ( nType == SvXMLStylesTokens::BOOLEAN_STYLE )
if ( nType == SvXMLStylesTokens::BOOLEAN_STYLE && !bHasExtraText &&
aMyConditions.empty() && sFormat.toChar() != '[' )
nIndex = pFormatter->GetFormatIndex( NF_BOOLEAN, nFormatLang );
// check for default date formats