include/svl/numformat.hxx | 2 ++ svl/source/numbers/zforlist.cxx | 8 ++++++++ sw/source/core/table/swtable.cxx | 12 +++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-)
New commits: commit 546e7d14b397cfd1210b891c8dc4a195c25f3876 Author: Justin Luth <[email protected]> AuthorDate: Wed Oct 20 18:09:46 2021 +0200 Commit: Eike Rathke <[email protected]> CommitDate: Tue Oct 26 16:04:13 2021 +0200 tdf#131025 swtable: don't apply number format to non-number text Applying a numbering style to text causes export to save that out as a number (valued as zero). That is not good because the ODF spec says that a number overrides a string. So don't accept a numbering format on non-number text. Why is this change good? -the cell previously had no direct formatting (by definition). -the cell's previous old format was text (tested). -any numbering format applied obviously isn't correct (by definition). -any previous formatting has already been overwritten with numformat. -the default numbering is appropriate for text. -empty cells still get the numbering format (tested). -odd human-designed formats are accepted as intentional (tested). What are the concerns? -the scope of this change is HUGE, way beyond this bug. -on both my dev box and patch box I saw occassional crashes. -the bug was "fixed" by a different import commit that ensured different languages were treated consistently. So this patch is no longer critical, just nice to have to avoid exporting out-of-spec content. Change-Id: Id3dc5f803c3cf4875bc0cab52d1019a18679da77 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123904 Tested-by: Jenkins Reviewed-by: Justin Luth <[email protected]> Reviewed-by: Eike Rathke <[email protected]> diff --git a/include/svl/numformat.hxx b/include/svl/numformat.hxx index 4026ff71e4a4..2cbfeb9cd171 100644 --- a/include/svl/numformat.hxx +++ b/include/svl/numformat.hxx @@ -256,6 +256,8 @@ public: /// Get return string for Calc CELL() function, "G", "D1", ... OUString GetCalcCellReturn(sal_uInt32 nFormat) const; + bool IsUserDefined(sal_uInt32 F_Index) const; + /// Check if format code string may be deleted by user bool IsUserDefined(std::u16string_view sStr, LanguageType eLnge = LANGUAGE_DONTKNOW); diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx index d2340bf2d968..3969f1885199 100644 --- a/svl/source/numbers/zforlist.cxx +++ b/svl/source/numbers/zforlist.cxx @@ -3351,6 +3351,14 @@ OUString SvNumberFormatter::GenerateFormat(sal_uInt32 nIndex, return sString.makeStringAndClear(); } +bool SvNumberFormatter::IsUserDefined(sal_uInt32 F_Index) const +{ + ::osl::MutexGuard aGuard( GetInstanceMutex() ); + const SvNumberformat* pFormat = GetFormatEntry(F_Index); + + return pFormat && (pFormat->GetType() & SvNumFormatType::DEFINED); +} + bool SvNumberFormatter::IsUserDefined(std::u16string_view sStr, LanguageType eLnge) { diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx index a67b05a48e2f..9f68ca5203ff 100644 --- a/sw/source/core/table/swtable.cxx +++ b/sw/source/core/table/swtable.cxx @@ -2318,6 +2318,7 @@ void SwTableBoxFormat::BoxAttributeChanged(SwTableBox& rBox, const SwTableBoxNum // format contents with the new value assigned and write to paragraph const Color* pCol = nullptr; OUString sNewText; + bool bChangeFormat = true; if(DBL_MAX == fVal) { sNewText = SwViewShell::GetShellRes()->aCalc_Error; @@ -2342,6 +2343,14 @@ void SwTableBoxFormat::BoxAttributeChanged(SwTableBox& rBox, const SwTableBoxNum #else sNewText = aOrigText; #endif + // Remove the newly assigned numbering format as well if text actually exists. + // Exception: assume user-defined formats are always intentional. + if (bChgText && pNumFormatr->IsTextFormat(nOldFormat) + && !pNumFormatr->IsUserDefined(nNewFormat)) + { + rBox.GetFrameFormat()->ResetFormatAttr(RES_BOXATR_FORMAT); + bChangeFormat = false; + } } if(!bChgText) @@ -2349,7 +2358,8 @@ void SwTableBoxFormat::BoxAttributeChanged(SwTableBox& rBox, const SwTableBoxNum } // across all boxes - ChgTextToNum(rBox, sNewText, pCol, GetDoc()->IsInsTableAlignNum()); + if (bChangeFormat) + ChgTextToNum(rBox, sNewText, pCol, GetDoc()->IsInsTableAlignNum()); } else if(bNewIsTextFormat && nOldFormat != nNewFormat)
