diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2021-03-18 17:39:01 +0100 |
---|---|---|
committer | Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de> | 2021-03-25 09:53:50 +0100 |
commit | e9c6fd6b4d09ee59b6a86942cbf001f2ba9782e6 (patch) | |
tree | 9cfece98c8b202cdddb77406ff29b8db5223bd57 /xmloff | |
parent | 56d8007a197b095b09423c691a51515567648e80 (diff) |
tdf#134734 xmloff: ODF import compatibility for BackgroundFullSize
This is annoyingly complex because LO 6.3 changed the way backgrounds
are painted in an inconsistent way.
Use the generator version to guess what the document should look like,
which of course will give the wrong result if it was created before LO
6.3 and then round-tripped with LO 6.3.
Since LO 7.0 at least a hard-coded draw:background-size was written.
Change-Id: If9c5d2b32bfa50cbe4fb166132f7223763af850f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112770
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/qa/unit/uxmloff.cxx | 3 | ||||
-rw-r--r-- | xmloff/source/core/xmlimp.cxx | 11 | ||||
-rw-r--r-- | xmloff/source/style/PageMasterImportContext.cxx | 78 |
3 files changed, 85 insertions, 7 deletions
diff --git a/xmloff/qa/unit/uxmloff.cxx b/xmloff/qa/unit/uxmloff.cxx index b5aff93d02be..1efd05dacafe 100644 --- a/xmloff/qa/unit/uxmloff.cxx +++ b/xmloff/qa/unit/uxmloff.cxx @@ -197,6 +197,9 @@ void Test::testMetaGenerator() { "Collabora_Office/5.3.10.27$Linux_X86_64 LibreOffice_project/7a5a5378661e338a44666c08773cc796b8d1c84a", ";531027", SvXMLImport::LO_5x }, { "LibreOfficeDev/5.4.7.0.0$Linux_X86_64 LibreOffice_project/ba7461fc88c08e75e315f786020a2946e56166c9", ";54700", SvXMLImport::LO_5x }, { "LibreOfficeDev/6.0.3.0.0$Linux_X86_64 LibreOffice_project/34442b85bfb0c451738b4db023345a7484463321", ";60300", SvXMLImport::LO_6x }, + { "LibreOffice_powered_by_CIBDev/6.3.9.0.0$Linux_X86_64 LibreOffice_project/c87f331d2900eab70ac3021cbe530926efa6499f", ";63900", SvXMLImport::LO_63x }, + { "LibreOffice_powered_by_CIBDev/6.4.0.0.0$Linux_X86_64 LibreOffice_project/e29e100174c133d27e953934311d68602c4515b7", ";64000", SvXMLImport::LO_63x }, + { "LibreOfficeDev/7.0.6.0.0$Linux_X86_64 LibreOffice_project/dfc40e2292c6e19e285c10ed8c8044d9454107d0", ";70600", SvXMLImport::LO_7x }, }; for (size_t i = 0; i < SAL_N_ELEMENTS(tests); ++i) diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx index 6d7b0805ddfb..7e904af3e7dc 100644 --- a/xmloff/source/core/xmlimp.cxx +++ b/xmloff/source/core/xmlimp.cxx @@ -195,7 +195,16 @@ public: } else if ('6' == loVersion[0]) { - mnGeneratorVersion = SvXMLImport::LO_6x; + if (loVersion.getLength() > 1 + && (loVersion[1] == '0' || loVersion[1] == '1' + || loVersion[1] == '2')) + { + mnGeneratorVersion = SvXMLImport::LO_6x; // 6.0/6.1/6.2 + } + else + { + mnGeneratorVersion = SvXMLImport::LO_63x; // 6.3/6.4 + } } else if ('7' == loVersion[0]) { diff --git a/xmloff/source/style/PageMasterImportContext.cxx b/xmloff/source/style/PageMasterImportContext.cxx index 17d9bf7986da..685d82b9091a 100644 --- a/xmloff/source/style/PageMasterImportContext.cxx +++ b/xmloff/source/style/PageMasterImportContext.cxx @@ -33,6 +33,8 @@ // #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <com/sun/star/drawing/FillStyle.hpp> +#include <com/sun/star/drawing/BitmapMode.hpp> #include <xmloff/xmlerror.hxx> #include <xmloff/XMLTextMasterPageContext.hxx> @@ -158,7 +160,7 @@ void PageStyleContext::FillPropertySet(const uno::Reference<beans::XPropertySet } void PageStyleContext::FillPropertySet_PageStyle( - const uno::Reference<beans::XPropertySet> & rPropSet, + const uno::Reference<beans::XPropertySet> & xPropSet, XMLPropStyleContext *const pDrawingPageStyle) { // need to filter out old fill definitions when the new ones are used. The new @@ -229,7 +231,7 @@ void PageStyleContext::FillPropertySet_PageStyle( }; // Fill PropertySet, but let it handle special properties not itself - xImpPrMap->FillPropertySet(GetProperties(), rPropSet, aContextIDs); + xImpPrMap->FillPropertySet(GetProperties(), xPropSet, aContextIDs); // get property set mapper const rtl::Reference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper(); @@ -273,12 +275,12 @@ void PageStyleContext::FillPropertySet_PageStyle( if(!xInfo.is()) { - xInfo = rPropSet->getPropertySetInfo(); + xInfo = xPropSet->getPropertySetInfo(); } if(xInfo->hasPropertyByName(rPropertyName)) { - rPropSet->setPropertyValue(rPropertyName,Any(sStyleName)); + xPropSet->setPropertyValue(rPropertyName,Any(sStyleName)); } } catch(css::lang::IllegalArgumentException& e) @@ -302,7 +304,71 @@ void PageStyleContext::FillPropertySet_PageStyle( // pDrawingPageStyle overrides this if (pDrawingPageStyle) { - pDrawingPageStyle->FillPropertySet(rPropSet); + pDrawingPageStyle->FillPropertySet(xPropSet); + } + // horrible heuristic to guess BackgroundFullSize for Writer < 7.0 + else if (!IsDefaultStyle() // ignore pool default, only fix existing styles + && (GetImport().isGeneratorVersionOlderThan(SvXMLImport::AOO_4x, SvXMLImport::LO_7x) + // also for AOO 4.x, assume there won't ever be a 4.2 + || GetImport().getGeneratorVersion() == SvXMLImport::AOO_4x)) + { + bool isFullSize(true); // default is current LO default + drawing::FillStyle fillStyle{drawing::FillStyle_NONE}; + xPropSet->getPropertyValue("FillStyle") >>= fillStyle; + if (GetImport().isGeneratorVersionOlderThan(SvXMLImport::AOO_4x, SvXMLImport::LO_63x) + // also for AOO 4.x, assume there won't ever be a 4.2 + || GetImport().getGeneratorVersion() == SvXMLImport::AOO_4x) + { + // before LO 6.3, always inside the margins (but ignore it if NONE) + if (fillStyle != drawing::FillStyle_NONE) + { + isFullSize = false; + } + } + else + { + // LO 6.3/6.4: guess depending on fill style/bitmap mode + // this should work even if the document doesn't contain fill style + // but only old background attributes + // (can't use the aContextIDs stuff above because that requires + // re-routing through handleSpecialItem()) + switch (fillStyle) + { + case drawing::FillStyle_NONE: + break; + case drawing::FillStyle_SOLID: + case drawing::FillStyle_GRADIENT: + case drawing::FillStyle_HATCH: + isFullSize = true; + break; + case drawing::FillStyle_BITMAP: + { + drawing::BitmapMode bitmapMode{}; + xPropSet->getPropertyValue("FillBitmapMode") >>= bitmapMode; + switch (bitmapMode) + { + case drawing::BitmapMode_REPEAT: + isFullSize = true; + break; + case drawing::BitmapMode_STRETCH: + case drawing::BitmapMode_NO_REPEAT: + isFullSize = false; + break; + default: + assert(false); + } + } + break; + default: + assert(false); + } + } + // set it explicitly if it's not the default + if (!isFullSize) + { + SAL_INFO("xmloff.style", "FillPropertySet_PageStyle: Heuristically resetting BackgroundFullSize"); + xPropSet->setPropertyValue("BackgroundFullSize", uno::makeAny(isFullSize)); + } } // old code, replaced by above stuff @@ -313,7 +379,7 @@ void PageStyleContext::FillPropertySet_PageStyle( uno::Any aPageUsage; XMLPMPropHdl_PageStyleLayout aPageUsageHdl; if (aPageUsageHdl.importXML(sPageUsage, aPageUsage, GetImport().GetMM100UnitConverter())) - rPropSet->setPropertyValue("PageStyleLayout", aPageUsage); + xPropSet->setPropertyValue("PageStyleLayout", aPageUsage); } } |