summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasily Melenchuk <vasily.melenchuk@cib.de>2022-03-22 14:02:35 +0300
committerAndras Timar <andras.timar@collabora.com>2022-03-25 15:55:11 +0100
commit2723eea9f498586b74671ab10683ae1818b9919b (patch)
tree50f799705aeaa153838c9133957f22574fac9be5
parent6c90a4f35b6655b382e4e5a4400fce318870b9fa (diff)
tdf#111851: rtf import: fifty shades of grey
Unlike in DOCX in RTF token \clshdngN can represent much more transitional cell shade values from 0 (white) to 10000 (black). So we should not match these values strictly but use ranges instead. Change-Id: I4e0066e2b79e73cf6fbc3dd773047be8dab2b907 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131931 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131962
-rw-r--r--sw/qa/extras/rtfexport/data/tdf111851.rtf17
-rw-r--r--sw/qa/extras/rtfexport/rtfexport4.cxx36
-rw-r--r--writerfilter/source/rtftok/rtfdispatchvalue.cxx136
3 files changed, 111 insertions, 78 deletions
diff --git a/sw/qa/extras/rtfexport/data/tdf111851.rtf b/sw/qa/extras/rtfexport/data/tdf111851.rtf
new file mode 100644
index 000000000000..242354364e76
--- /dev/null
+++ b/sw/qa/extras/rtfexport/data/tdf111851.rtf
@@ -0,0 +1,17 @@
+{\rtf
+
+\trowd
+\clshdng-20000\cellx200
+\clshdng0\cellx400
+\clshdng666\cellx600
+\clshdng3275\cellx800
+\clshdng10000\cellx1000
+\clshdng20000\cellx1200
+\intbl a\cell
+\intbl b\cell
+\intbl c\cell
+\intbl d\cell
+\intbl e\cell
+\intbl f\cell
+\row
+} \ No newline at end of file
diff --git a/sw/qa/extras/rtfexport/rtfexport4.cxx b/sw/qa/extras/rtfexport/rtfexport4.cxx
index 1b29939ac4fc..55ae121a695b 100644
--- a/sw/qa/extras/rtfexport/rtfexport4.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport4.cxx
@@ -431,6 +431,42 @@ CPPUNIT_TEST_FIXTURE(Test, testGutterTop)
CPPUNIT_ASSERT(bGutterAtTop);
}
+DECLARE_RTFEXPORT_TEST(testTdf111851, "tdf111851.rtf")
+{
+ uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), uno::UNO_QUERY);
+
+ // No shading
+ uno::Reference<text::XTextRange> xCell1(xTable->getCellByName("A1"), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(OUString("a"), xCell1->getString());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty<sal_Int32>(xCell1, "BackColor"));
+
+ uno::Reference<text::XTextRange> xCell2(xTable->getCellByName("B1"), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(OUString("b"), xCell2->getString());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty<sal_Int32>(xCell2, "BackColor"));
+
+ // Check some random not standard shading values and ensure some non-white background color
+ uno::Reference<text::XTextRange> xCell3(xTable->getCellByName("C1"), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(OUString("c"), xCell3->getString());
+ sal_Int32 nShadingColor3 = getProperty<sal_Int32>(xCell3, "BackColor");
+ CPPUNIT_ASSERT(0x00FFFFFF > nShadingColor3);
+ CPPUNIT_ASSERT(0 < nShadingColor3);
+
+ uno::Reference<text::XTextRange> xCell4(xTable->getCellByName("D1"), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(OUString("d"), xCell4->getString());
+ sal_Int32 nShadingColor4 = getProperty<sal_Int32>(xCell4, "BackColor");
+ CPPUNIT_ASSERT(0x00FFFFFF > nShadingColor4);
+ CPPUNIT_ASSERT(0 < nShadingColor4);
+
+ // Values 10000 and more - black
+ uno::Reference<text::XTextRange> xCell5(xTable->getCellByName("E1"), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(OUString("e"), xCell5->getString());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xCell5, "BackColor"));
+
+ uno::Reference<text::XTextRange> xCell6(xTable->getCellByName("F1"), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(OUString("f"), xCell6->getString());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xCell6, "BackColor"));
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
index 14d0b3993a54..d78f087d76e3 100644
--- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
@@ -485,84 +485,64 @@ bool RTFDocumentImpl::dispatchTableValue(RTFKeyword nKeyword, int nParam)
case RTFKeyword::CLSHDNG:
{
int nValue = -1;
- switch (nParam)
- {
- case 500:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct5;
- break;
- case 1000:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct10;
- break;
- case 1200:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct12;
- break;
- case 1500:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct15;
- break;
- case 2000:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct20;
- break;
- case 2500:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct25;
- break;
- case 3000:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct30;
- break;
- case 3500:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct35;
- break;
- case 3700:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct37;
- break;
- case 4000:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct40;
- break;
- case 4500:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct45;
- break;
- case 5000:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct50;
- break;
- case 5500:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct55;
- break;
- case 6000:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct60;
- break;
- case 6200:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct62;
- break;
- case 6500:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct65;
- break;
- case 7000:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct70;
- break;
- case 7500:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct75;
- break;
- case 8000:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct80;
- break;
- case 8500:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct85;
- break;
- case 8700:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct87;
- break;
- case 9000:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct90;
- break;
- case 9500:
- nValue = NS_ooxml::LN_Value_ST_Shd_pct95;
- break;
- default:
- break;
- }
- if (nValue != -1)
- putNestedAttribute(m_aStates.top().getTableCellSprms(),
- NS_ooxml::LN_CT_TcPrBase_shd, NS_ooxml::LN_CT_Shd_val,
- new RTFValue(nValue));
+
+ if (nParam < 1)
+ nValue = NS_ooxml::LN_Value_ST_Shd_clear;
+ else if (nParam < 750)
+ // Values in between 1 and 250 visually closer to 0% shading (white)
+ // But this will mean "no shading" while cell actually have some.
+ // So lets use minimal available value.
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct5;
+ else if (nParam < 1100)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct10;
+ else if (nParam < 1350)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct12;
+ else if (nParam < 1750)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct15;
+ else if (nParam < 2250)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct20;
+ else if (nParam < 2750)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct25;
+ else if (nParam < 3250)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct30;
+ else if (nParam < 3600)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct35;
+ else if (nParam < 3850)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct37;
+ else if (nParam < 4250)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct40;
+ else if (nParam < 4750)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct45;
+ else if (nParam < 5250)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct50;
+ else if (nParam < 5750)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct55;
+ else if (nParam < 6100)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct60;
+ else if (nParam < 6350)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct62;
+ else if (nParam < 6750)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct65;
+ else if (nParam < 7250)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct70;
+ else if (nParam < 7750)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct75;
+ else if (nParam < 8250)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct80;
+ else if (nParam < 8600)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct85;
+ else if (nParam < 8850)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct87;
+ else if (nParam < 9250)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct90;
+ else if (nParam < 9750)
+ nValue = NS_ooxml::LN_Value_ST_Shd_pct95;
+ else
+ // Solid fill
+ nValue = NS_ooxml::LN_Value_ST_Shd_solid;
+
+ putNestedAttribute(m_aStates.top().getTableCellSprms(), NS_ooxml::LN_CT_TcPrBase_shd,
+ NS_ooxml::LN_CT_Shd_val, new RTFValue(nValue));
return true;
}
break;