Kaydet (Commit) 92cb21eb authored tarafından Michael Stahl's avatar Michael Stahl

fdo#75872: ODF import: fix up graphics defaults stroke/fill colors

These have changed a few times, notably in LO 4.0 with commit
89589056 and AOO 4.0 with commit
c0eb5e77; unfortunately historic OOo and
current AOO do not write the values into ODF files, whereas LO 4.x does
(probably by accident, since 45d3577b
by design).

Try to set the defaults depending on the generator; since the defaults
are not specified by ODF they are implementation defined anyway so this
should be OK.

Change-Id: I1270d6e0cdeea5cb493724a0998f661a0cf644f1
üst 7225de6c
...@@ -428,9 +428,14 @@ public: ...@@ -428,9 +428,14 @@ public:
static const sal_uInt16 OOo_32x = 32; static const sal_uInt16 OOo_32x = 32;
static const sal_uInt16 OOo_33x = 33; static const sal_uInt16 OOo_33x = 33;
static const sal_uInt16 OOo_34x = 34; static const sal_uInt16 OOo_34x = 34;
// for AOO, no release overlaps with OOo, so continue OOo version numbers
static const sal_uInt16 AOO_40x = 40;
static const sal_uInt16 AOO_4x = 41;
static const sal_uInt16 LO_flag = 0x100; static const sal_uInt16 LO_flag = 0x100;
static const sal_uInt16 LO_3x = 30 | LO_flag; static const sal_uInt16 LO_3x = 30 | LO_flag;
static const sal_uInt16 LO_4x = 40 | LO_flag; static const sal_uInt16 LO_41x = 41 | LO_flag;
static const sal_uInt16 LO_42x = 42 | LO_flag;
static const sal_uInt16 LO_4x = 43 | LO_flag;
static const sal_uInt16 ProductVersionUnknown = SAL_MAX_UINT16; static const sal_uInt16 ProductVersionUnknown = SAL_MAX_UINT16;
/** depending on whether the generator version indicates LO, compare /** depending on whether the generator version indicates LO, compare
......
...@@ -279,6 +279,26 @@ DECLARE_ODFIMPORT_TEST(testFdo56272, "fdo56272.odt") ...@@ -279,6 +279,26 @@ DECLARE_ODFIMPORT_TEST(testFdo56272, "fdo56272.odt")
CPPUNIT_ASSERT_EQUAL(sal_Int32(422), xShape->getPosition().Y); // Was -2371 CPPUNIT_ASSERT_EQUAL(sal_Int32(422), xShape->getPosition().Y); // Was -2371
} }
DECLARE_ODFIMPORT_TEST(testFdo75872_ooo33, "fdo75872_ooo33.odt")
{
// graphics default style: line color and fill color changed
uno::Reference<drawing::XShape> xShape = getShape(1);
CPPUNIT_ASSERT_EQUAL(sal_Int32(COL_BLACK),
getProperty<sal_Int32>(xShape, "LineColor"));
CPPUNIT_ASSERT_EQUAL(sal_Int32(RGB_COLORDATA(153, 204, 255)),
getProperty<sal_Int32>(xShape, "FillColor"));
}
DECLARE_ODFIMPORT_TEST(testFdo75872_aoo40, "fdo75872_aoo40.odt")
{
// graphics default style: line color and fill color changed
uno::Reference<drawing::XShape> xShape = getShape(1);
CPPUNIT_ASSERT_EQUAL(sal_Int32(RGB_COLORDATA(128, 128, 128)),
getProperty<sal_Int32>(xShape, "LineColor"));
CPPUNIT_ASSERT_EQUAL(sal_Int32(RGB_COLORDATA(0xCF, 0xE7, 0xF5)),
getProperty<sal_Int32>(xShape, "FillColor"));
}
DECLARE_ODFIMPORT_TEST(testFdo55814, "fdo55814.odt") DECLARE_ODFIMPORT_TEST(testFdo55814, "fdo55814.odt")
{ {
uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
......
...@@ -194,7 +194,20 @@ getBuildIdsProperty(uno::Reference<beans::XPropertySet> const& xImportInfo) ...@@ -194,7 +194,20 @@ getBuildIdsProperty(uno::Reference<beans::XPropertySet> const& xImportInfo)
else else
{ {
SAL_INFO_IF('4' != loVersion[0], "xmloff.core", "unknown LO version: " << loVersion); SAL_INFO_IF('4' != loVersion[0], "xmloff.core", "unknown LO version: " << loVersion);
mnGeneratorVersion = SvXMLImport::LO_4x; if ('4' == loVersion[0] && loVersion.getLength() > 1
&& (loVersion[1] == '0' || loVersion[1] == '1'))
{
mnGeneratorVersion = SvXMLImport::LO_41x; // 4.0/4.1
}
else if ('4' == loVersion[0]
&& loVersion.getLength() > 1 && loVersion[1] == '2')
{
mnGeneratorVersion = SvXMLImport::LO_42x; // 4.2
}
else
{
mnGeneratorVersion = SvXMLImport::LO_4x;
}
} }
return; // ignore buildIds return; // ignore buildIds
} }
...@@ -231,6 +244,16 @@ getBuildIdsProperty(uno::Reference<beans::XPropertySet> const& xImportInfo) ...@@ -231,6 +244,16 @@ getBuildIdsProperty(uno::Reference<beans::XPropertySet> const& xImportInfo)
{ {
mnGeneratorVersion = SvXMLImport::OOo_34x; mnGeneratorVersion = SvXMLImport::OOo_34x;
} }
else if (nUPD == 400)
{
mnGeneratorVersion = SvXMLImport::AOO_40x;
}
else if (nUPD >= 410)
{
// effectively this means "latest", see use
// in XMLGraphicsDefaultStyle::SetDefaults()!
mnGeneratorVersion = SvXMLImport::AOO_4x;
}
} }
} }
......
...@@ -17,7 +17,12 @@ ...@@ -17,7 +17,12 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <xmloff/XMLGraphicsDefaultStyle.hxx>
#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <tools/color.hxx>
#include <xmloff/xmlimp.hxx> #include <xmloff/xmlimp.hxx>
#include <xmloff/nmspmap.hxx> #include <xmloff/nmspmap.hxx>
#include <xmloff/xmlnmspe.hxx> #include <xmloff/xmlnmspe.hxx>
...@@ -25,7 +30,6 @@ ...@@ -25,7 +30,6 @@
#include <xmloff/families.hxx> #include <xmloff/families.hxx>
#include "XMLShapePropertySetContext.hxx" #include "XMLShapePropertySetContext.hxx"
#include <xmloff/XMLGraphicsDefaultStyle.hxx>
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
...@@ -76,6 +80,14 @@ SvXMLImportContext *XMLGraphicsDefaultStyle::CreateChildContext( sal_uInt16 nPre ...@@ -76,6 +80,14 @@ SvXMLImportContext *XMLGraphicsDefaultStyle::CreateChildContext( sal_uInt16 nPre
return pContext; return pContext;
} }
struct XMLPropertyByIndex {
sal_Int32 const m_nIndex;
XMLPropertyByIndex(sal_Int32 const nIndex) : m_nIndex(nIndex) {}
bool operator()(XMLPropertyState const& rProp) {
return m_nIndex == rProp.mnIndex;
}
};
// This method is called for every default style // This method is called for every default style
void XMLGraphicsDefaultStyle::SetDefaults() void XMLGraphicsDefaultStyle::SetDefaults()
{ {
...@@ -113,6 +125,51 @@ void XMLGraphicsDefaultStyle::SetDefaults() ...@@ -113,6 +125,51 @@ void XMLGraphicsDefaultStyle::SetDefaults()
xDefaults->setPropertyValue("IsFollowingTextFlow", uno::makeAny(true)); xDefaults->setPropertyValue("IsFollowingTextFlow", uno::makeAny(true));
} }
bool const bIsAOO4(
GetImport().getGeneratorVersion() >= SvXMLImport::AOO_40x
&& GetImport().getGeneratorVersion() <= SvXMLImport::AOO_4x);
// fdo#75872: backward compatibility for pool defaults change
if (GetImport().isGeneratorVersionOlderThan(
SvXMLImport::AOO_40x, SvXMLImport::LO_42x)
// argh... it turns out that LO has also changed defaults for these
// since LO 4.0, and so even the _new_ AOO 4.0+ default needs
// special handling since AOO still does _not_ write it into the file
|| bIsAOO4)
{
UniReference<XMLPropertySetMapper> const pImpPrMap(
GetStyles()->GetImportPropertyMapper(GetFamily())
->getPropertySetMapper());
sal_Int32 const nStrokeIndex(
pImpPrMap->GetEntryIndex(XML_NAMESPACE_SVG, "stroke-color", 0));
if (std::find_if(GetProperties().begin(), GetProperties().end(),
XMLPropertyByIndex(nStrokeIndex)) == GetProperties().end())
{
sal_Int32 const nStroke(
(bIsAOO4) ? RGB_COLORDATA(128, 128, 128) : COL_BLACK);
xDefaults->setPropertyValue("LineColor", makeAny(nStroke));
}
sal_Int32 const nFillColor( (bIsAOO4)
? RGB_COLORDATA(0xCF, 0xE7, 0xF5) : RGB_COLORDATA(153, 204, 255));
sal_Int32 const nFillIndex(
pImpPrMap->GetEntryIndex(XML_NAMESPACE_DRAW, "fill-color", 0));
if (std::find_if(GetProperties().begin(), GetProperties().end(),
XMLPropertyByIndex(nFillIndex)) == GetProperties().end())
{
xDefaults->setPropertyValue("FillColor", makeAny(nFillColor));
}
if (xInfo->hasPropertyByName("FillColor2"))
{
sal_Int32 const nFill2Index(pImpPrMap->GetEntryIndex(
XML_NAMESPACE_DRAW, "secondary-fill-color", 0));
if (std::find_if(GetProperties().begin(), GetProperties().end(),
XMLPropertyByIndex(nFill2Index)) == GetProperties().end())
{
xDefaults->setPropertyValue("FillColor2", makeAny(nFillColor));
}
}
}
FillPropertySet( xDefaults ); FillPropertySet( xDefaults );
} }
......
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