summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Luth <justin_luth@sil.org>2017-01-11 14:33:39 +0300
committerJustin Luth <justin_luth@sil.org>2017-06-07 06:53:41 +0200
commit9d6bf9d45d43a00f6dc87b9c83d28b93450ec51d (patch)
tree0833d8e1def19688ff89abefa218aaad83f206ac
parentd4721434d83852102ac10ab33fae26a69eb3b1c3 (diff)
tdf#74177 writer: ignoring comment allows number recognition
The presence of an annotation anchor was causing number recognition to fail in Writer's table cells. Formulas accessing the cell read a value of zero. Annotation anchors are only used in SW right now, so SVL didn't want the overhead in their code. So this wrapper function should be called first to cleanup SW specific things that interfere with number recognition. Specifically known to be needed in cellfml.cxx, but converted everywhere for consistency. The formula in older documents is not "fixed" during document loading since the table/formulas are not refreshed at load time. Only documents saved with incorrect results will notice this, and any cursor access inside the table will cause a refresh. Printing also causes a refresh (but not print preview or PDF export). So this patch only fixes document creation or modification, which should be adequate for this bug. Change-Id: Ib46f2b7899ae9a0fdc3aae5887bb2d61535d29f3 Reviewed-on: https://gerrit.libreoffice.org/32909 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Justin Luth <justin_luth@sil.org>
-rw-r--r--sw/inc/doc.hxx2
-rw-r--r--sw/source/core/docnode/ndtbl.cxx17
-rw-r--r--sw/source/core/edit/edtab.cxx2
-rw-r--r--sw/source/core/fields/cellfml.cxx4
-rw-r--r--sw/source/core/fields/fldbas.cxx4
-rw-r--r--sw/source/core/fields/usrfld.cxx4
-rw-r--r--sw/source/core/table/swtable.cxx10
-rw-r--r--sw/source/core/txtnode/fmtatr2.cxx5
-rw-r--r--sw/source/core/unocore/unotbl.cxx2
9 files changed, 31 insertions, 19 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 08c590a81024..e63fb0c7dd03 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1252,6 +1252,8 @@ public:
SwTableBoxFormat* MakeTableBoxFormat();
SwTableLineFormat* MakeTableLineFormat();
+ // helper function: cleanup before checking number value
+ bool IsNumberFormat( const OUString& rString, sal_uInt32& F_Index, double& fOutNumber);
// Check if box has numerical value. Change format of box if required.
void ChkBoxNumFormat( SwTableBox& rAktBox, bool bCallUpdate );
void SetTableBoxFormulaAttrs( SwTableBox& rBox, const SfxItemSet& rSet );
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 9d427e613372..d5c9d5357a06 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -4032,6 +4032,23 @@ bool SwDoc::SetColRowWidthHeight( SwTableBox& rAktBox, TableChgWidthHeightType e
return bRet;
}
+bool SwDoc::IsNumberFormat( const OUString& rString, sal_uInt32& F_Index, double& fOutNumber )
+{
+ if( rString.getLength() > 308 ) // optimization matches svl:IsNumberFormat arbitrary value
+ return false;
+
+ // remove any comment anchor marks
+ OUStringBuffer sStringBuffer(rString);
+ sal_Int32 nCommentPosition = sStringBuffer.indexOf( CH_TXTATR_INWORD );
+ while( nCommentPosition != -1 )
+ {
+ sStringBuffer.remove( nCommentPosition, 1 );
+ nCommentPosition = sStringBuffer.indexOf( CH_TXTATR_INWORD, nCommentPosition );
+ }
+
+ return GetNumberFormatter()->IsNumberFormat( sStringBuffer.makeStringAndClear(), F_Index, fOutNumber );
+}
+
void SwDoc::ChkBoxNumFormat( SwTableBox& rBox, bool bCallUpdate )
{
// Optimization: If the Box says it's Text, it remains Text
diff --git a/sw/source/core/edit/edtab.cxx b/sw/source/core/edit/edtab.cxx
index e547f40ba83e..af961388cba9 100644
--- a/sw/source/core/edit/edtab.cxx
+++ b/sw/source/core/edit/edtab.cxx
@@ -400,7 +400,7 @@ bool SwEditShell::IsTableBoxTextFormat() const
return false;
double fVal;
- return !GetDoc()->GetNumberFormatter()->IsNumberFormat( rText, nFormat, fVal );
+ return !GetDoc()->IsNumberFormat( rText, nFormat, fVal );
}
OUString SwEditShell::GetTableBoxText() const
diff --git a/sw/source/core/fields/cellfml.cxx b/sw/source/core/fields/cellfml.cxx
index c0655b2de3f7..1be01755be5a 100644
--- a/sw/source/core/fields/cellfml.cxx
+++ b/sw/source/core/fields/cellfml.cxx
@@ -224,12 +224,12 @@ double SwTableBox::GetValue( SwTableCalcPara& rCalcPara ) const
css::util::NumberFormat::PERCENT == pNumFormatr->GetType( nFormatIndex ))
{
sal_uInt32 nTmpFormat = 0;
- if( pNumFormatr->IsNumberFormat( sText, nTmpFormat, aNum ) &&
+ if( pDoc->IsNumberFormat( sText, nTmpFormat, aNum ) &&
css::util::NumberFormat::NUMBER == pNumFormatr->GetType( nTmpFormat ))
sText += "%";
}
- if( pNumFormatr->IsNumberFormat( sText, nFormatIndex, aNum ))
+ if( pDoc->IsNumberFormat( sText, nFormatIndex, aNum ))
nRet = aNum;
}
// ?? otherwise it is an error
diff --git a/sw/source/core/fields/fldbas.cxx b/sw/source/core/fields/fldbas.cxx
index 1bd796bb66f0..0eca840c2311 100644
--- a/sw/source/core/fields/fldbas.cxx
+++ b/sw/source/core/fields/fldbas.cxx
@@ -702,9 +702,7 @@ void SwFormulaField::SetExpandedFormula( const OUString& rStr )
{
double fTmpValue;
- SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
-
- if (pFormatter->IsNumberFormat(rStr, nFormat, fTmpValue))
+ if (GetDoc()->IsNumberFormat(rStr, nFormat, fTmpValue))
{
SwValueField::SetValue(fTmpValue);
diff --git a/sw/source/core/fields/usrfld.cxx b/sw/source/core/fields/usrfld.cxx
index 080dcfc77bd1..845d02de6582 100644
--- a/sw/source/core/fields/usrfld.cxx
+++ b/sw/source/core/fields/usrfld.cxx
@@ -259,9 +259,7 @@ void SwUserFieldType::SetContent( const OUString& rStr, sal_uInt32 nFormat )
{
double fValue;
- SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
-
- if (pFormatter->IsNumberFormat(rStr, nFormat, fValue))
+ if (GetDoc()->IsNumberFormat(rStr, nFormat, fValue))
{
SetValue(fValue);
aContent = DoubleToString(fValue, nFormat);
diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx
index ca0efb0f9353..281249f700f7 100644
--- a/sw/source/core/table/swtable.cxx
+++ b/sw/source/core/table/swtable.cxx
@@ -2293,19 +2293,19 @@ void SwTableBoxFormat::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew
pNumFormatr->GetType( nNewFormat ))
{
sal_uInt32 nTmpFormat = 0;
- if( pNumFormatr->IsNumberFormat(
+ if( GetDoc()->IsNumberFormat(
aText, nTmpFormat, fVal ))
{
if( css::util::NumberFormat::NUMBER ==
pNumFormatr->GetType( nTmpFormat ))
aText += "%";
- bIsNumFormat = pNumFormatr->IsNumberFormat(
+ bIsNumFormat = GetDoc()->IsNumberFormat(
aText, nTmpFormatIdx, fVal );
}
}
else
- bIsNumFormat = pNumFormatr->IsNumberFormat(
+ bIsNumFormat = GetDoc()->IsNumberFormat(
aText, nTmpFormatIdx, fVal );
if( bIsNumFormat )
@@ -2393,7 +2393,7 @@ bool SwTableBox::HasNumContent( double& rNum, sal_uInt32& rFormatIndex,
if( !rIsEmptyTextNd && css::util::NumberFormat::PERCENT == pNumFormatr->GetType( rFormatIndex ))
{
sal_uInt32 nTmpFormat = 0;
- if( pNumFormatr->IsNumberFormat( aText, nTmpFormat, rNum ) &&
+ if( GetFrameFormat()->GetDoc()->IsNumberFormat( aText, nTmpFormat, rNum ) &&
css::util::NumberFormat::NUMBER == pNumFormatr->GetType( nTmpFormat ))
aText += "%";
}
@@ -2401,7 +2401,7 @@ bool SwTableBox::HasNumContent( double& rNum, sal_uInt32& rFormatIndex,
else
rFormatIndex = 0;
- bRet = pNumFormatr->IsNumberFormat( aText, rFormatIndex, rNum );
+ bRet = GetFrameFormat()->GetDoc()->IsNumberFormat( aText, rFormatIndex, rNum );
}
else
rIsEmptyTextNd = false;
diff --git a/sw/source/core/txtnode/fmtatr2.cxx b/sw/source/core/txtnode/fmtatr2.cxx
index f8ef2b31698b..d26594caf222 100644
--- a/sw/source/core/txtnode/fmtatr2.cxx
+++ b/sw/source/core/txtnode/fmtatr2.cxx
@@ -754,11 +754,8 @@ sal_uInt32 MetaField::GetNumberFormat(OUString const & rContent) const
SwTextNode * const pTextNode( GetTextNode() );
if (pTextNode)
{
- SvNumberFormatter *const pNumberFormatter(
- pTextNode->GetDoc()->GetNumberFormatter() );
double number;
- (void) pNumberFormatter->IsNumberFormat(
- rContent, nNumberFormat, number );
+ (void) pTextNode->GetDoc()->IsNumberFormat( rContent, nNumberFormat, number );
}
return nNumberFormat;
}
diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx
index 4754febbc808..1c00d99e4461 100644
--- a/sw/source/core/unocore/unotbl.cxx
+++ b/sw/source/core/unocore/unotbl.cxx
@@ -1238,7 +1238,7 @@ double SwXCell::GetForcedNumericalValue() const
nFIndex = pNumFormatter->GetStandardIndex( eLang );
}
double fTmp;
- if (!pNumFormatter->IsNumberFormat(const_cast<SwXCell*>(this)->getString(), nFIndex, fTmp))
+ if (!const_cast<SwDoc*>(GetDoc())->IsNumberFormat(const_cast<SwXCell*>(this)->getString(), nFIndex, fTmp))
::rtl::math::setNan(&fTmp);
return fTmp;
}