summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Francis <dennis.francis@collabora.co.uk>2017-08-15 11:21:04 +0530
committerDennis Francis <dennis.francis@collabora.co.uk>2017-08-20 12:48:02 +0200
commit06d104ecda085200fb6d22e0bd6d6cb89ca4f66c (patch)
treec6362ac331766b8975865d9cf0e8b2e4eba4e397
parent668ab2e739397e6b095372a1a468bd4f515927b6 (diff)
tdf#83562: Make the EditTextObject export of automatic colors...
... use the xml token "use-window-font-color" instead of "color" to encode a boolean value of whether an auto color is used or not. This is because the "auto" color is 0xffffffff and cannot be written into "color" xml field which can store only 3 byte-hexcode. This commit also adds a unit test in subsequent_export-test.cxx to ensure the correct export of automatic color. Change-Id: I42aab926f31669c1423bc09b96b45c410c9732de Reviewed-on: https://gerrit.libreoffice.org/41252 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Dennis Francis <dennis.francis@collabora.co.uk>
-rw-r--r--sc/qa/unit/subsequent_export-test.cxx67
-rw-r--r--sc/source/filter/xml/xmlexprt.cxx8
2 files changed, 73 insertions, 2 deletions
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 882dc4faea68..6d53bb5f33fd 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -26,6 +26,7 @@
#include "userdat.hxx"
#include "docsh.hxx"
#include "patattr.hxx"
+#include "docpool.hxx"
#include "scitems.hxx"
#include "document.hxx"
#include "cellform.hxx"
@@ -61,6 +62,7 @@
#include <editeng/fontitem.hxx>
#include <editeng/udlnitem.hxx>
#include <editeng/flditem.hxx>
+#include <editeng/colritem.hxx>
#include <formula/grammar.hxx>
#include <unotools/useroptions.hxx>
#include <tools/datetime.hxx>
@@ -1100,7 +1102,7 @@ void ScExportTest::testMiscRowHeightExport()
namespace {
-void setAttribute( ScFieldEditEngine& rEE, sal_Int32 nPara, sal_Int32 nStart, sal_Int32 nEnd, sal_uInt16 nType )
+void setAttribute( ScFieldEditEngine& rEE, sal_Int32 nPara, sal_Int32 nStart, sal_Int32 nEnd, sal_uInt16 nType, sal_uInt32 nColor = COL_BLACK )
{
ESelection aSel;
aSel.nStartPara = aSel.nEndPara = nPara;
@@ -1145,6 +1147,13 @@ void setAttribute( ScFieldEditEngine& rEE, sal_Int32 nPara, sal_Int32 nStart, sa
rEE.QuickSetAttribs(aItemSet, aSel);
}
break;
+ case EE_CHAR_COLOR:
+ {
+ SvxColorItem aItem(nColor, nType);
+ aItemSet.Put(aItem);
+ rEE.QuickSetAttribs(aItemSet, aSel);
+ }
+ break;
default:
;
}
@@ -1327,6 +1336,23 @@ void ScExportTest::testRichTextExportODS()
return false;
}
+ static bool isColor(const editeng::Section& rAttr, sal_uInt32 nColor)
+ {
+ if (rAttr.maAttributes.empty())
+ return false;
+
+ std::vector<const SfxPoolItem*>::const_iterator it = rAttr.maAttributes.begin(), itEnd = rAttr.maAttributes.end();
+ for (; it != itEnd; ++it)
+ {
+ const SfxPoolItem* p = *it;
+ if (p->Which() != EE_CHAR_COLOR)
+ continue;
+
+ return static_cast<const SvxColorItem*>(p)->GetValue() == nColor;
+ }
+ return false;
+ }
+
bool checkB2(const EditTextObject* pText) const
{
if (!pText)
@@ -1553,6 +1579,32 @@ void ScExportTest::testRichTextExportODS()
return true;
}
+ bool checkB10(const EditTextObject* pText) const
+ {
+ if (!pText)
+ return false;
+
+ if (pText->GetParagraphCount() != 1)
+ return false;
+
+ if (pText->GetText(0) != "BLUE AUTO")
+ return false;
+
+ std::vector<editeng::Section> aSecAttrs;
+ pText->GetAllSections(aSecAttrs);
+ if (aSecAttrs.size() != 2)
+ return false;
+
+ // auto color
+ const editeng::Section* pAttr = &aSecAttrs[1];
+ if (pAttr->mnParagraph != 0 ||pAttr->mnStart != 5 || pAttr->mnEnd != 9)
+ return false;
+
+ if (pAttr->maAttributes.size() != 1 || !isColor(*pAttr, COL_AUTO))
+ return false;
+
+ return true;
+ }
} aCheckFunc;
@@ -1654,6 +1706,17 @@ void ScExportTest::testRichTextExportODS()
pEditText = rDoc3.GetEditText(ScAddress(1,8,0));
CPPUNIT_ASSERT_MESSAGE("Incorrect B9 value.", aCheckFunc.checkB9(pEditText));
+ ScPatternAttr aCellFontColor(rDoc3.GetPool());
+ aCellFontColor.GetItemSet().Put(SvxColorItem(COL_BLUE, ATTR_FONT_COLOR));
+ // Set font color of B10 to blue.
+ rDoc3.ApplyPattern(1, 9, 0, aCellFontColor);
+ pEE->Clear();
+ pEE->SetText("BLUE AUTO");
+ // Set the color of the string "AUTO" to automatic color.
+ setAttribute(*pEE, 0, 5, 9, EE_CHAR_COLOR, COL_AUTO);
+ rDoc3.SetEditText(ScAddress(1, 9, 0), pEE->CreateTextObject());
+ pEditText = rDoc3.GetEditText(ScAddress(1, 9, 0));
+ CPPUNIT_ASSERT_MESSAGE("Incorrect B10 value.", aCheckFunc.checkB10(pEditText));
}
// Reload the doc again, and check the content of B2, B4, B6 and B7.
@@ -1673,6 +1736,8 @@ void ScExportTest::testRichTextExportODS()
CPPUNIT_ASSERT_MESSAGE("Incorrect B7 value after save and reload.", aCheckFunc.checkB7(pEditText));
pEditText = rDoc4.GetEditText(ScAddress(1,7,0));
CPPUNIT_ASSERT_MESSAGE("Incorrect B8 value after save and reload.", aCheckFunc.checkB8(pEditText));
+ pEditText = rDoc4.GetEditText(ScAddress(1,9,0));
+ CPPUNIT_ASSERT_MESSAGE("Incorrect B10 value after save and reload.", aCheckFunc.checkB10(pEditText));
xNewDocSh3->DoClose();
}
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index 8a97aa949afb..3464e0dfbd54 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -1102,7 +1102,13 @@ const SvxFieldData* toXMLPropertyStates(
if (!static_cast<const SvxColorItem*>(p)->QueryValue(aAny, pEntry->mnFlag))
continue;
- rPropStates.push_back(XMLPropertyState(nIndex, aAny));
+ sal_uInt32 nColor = 0;
+ if ( aAny >>= nColor )
+ {
+ sal_Int32 nIndexColor = ( nColor == COL_AUTO ) ? xMapper->GetEntryIndex(
+ XML_NAMESPACE_STYLE, GetXMLToken( XML_USE_WINDOW_FONT_COLOR ), 0 ) : nIndex;
+ rPropStates.push_back( XMLPropertyState( nIndexColor, aAny ) );
+ }
}
break;
case EE_CHAR_WLM: