Kaydet (Commit) 06d104ec authored tarafından Dennis Francis's avatar Dennis Francis

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/41252Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarDennis Francis <dennis.francis@collabora.co.uk>
üst 668ab2e7
......@@ -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();
}
......
......@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment