tdf#159158 writerfilter: duplicate relativeHeights? last one wins #2

Revert the previous solution and replace it with this simpler one.

This version of the patch is riskier, but from what I can see
last one always wins for GraphicImport.
I assume that Miklos just limited it to a certain situation
as a sanity check to try to avoid causing regressions
outside of the scope he was working on.

The fact that all DOCX and RTF unit tests pass is a good sign.

The only way I would expect this to cause problems is
if z-index somehow can come into play with a GraphicImport
(since both z-index and relativeHeight feed into zOrder).
However, an assert didn't turn up any instances where
applyZOrder was called without a relativeHeight being set.
assert(m_rDomainMapper.IsRTFImport() || bOldStyle || UsedRelativeHeight);

Change-Id: I28e8acd5997eed0e82d5853c85b672c62b21afe5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162036
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
diff --git a/writerfilter/inc/dmapper/GraphicZOrderHelper.hxx b/writerfilter/inc/dmapper/GraphicZOrderHelper.hxx
index 2ad71c4..c6a308d 100644
--- a/writerfilter/inc/dmapper/GraphicZOrderHelper.hxx
+++ b/writerfilter/inc/dmapper/GraphicZOrderHelper.hxx
@@ -19,7 +19,6 @@ public:
    void addItem(css::uno::Reference<css::beans::XPropertySet> const& props,
                 sal_Int32 relativeHeight);
    sal_Int32 findZOrder(sal_Int32 relativeHeight, bool bOldStyle = false);
    bool hasZOrder(sal_Int32 relativeHeight) { return m_items.count(relativeHeight) != 0; }

private:
    using Items = std::map<sal_Int32, css::uno::Reference<css::beans::XPropertySet>>;
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index 6fbc172..45d0462 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -396,10 +396,13 @@ public:
            // tdf#120760 Send objects with behinddoc=true to the back.
            if (m_bBehindDoc && m_rDomainMapper.IsInHeaderFooter())
                nZOrder -= SAL_MAX_INT32;

            // TODO: it is possible that RTF has been wrong all along as well. Always true here?
            const bool bLastDuplicateWins(!m_rDomainMapper.IsRTFImport()
                || m_rGraphicImportType == GraphicImportType::IMPORT_AS_DETECTED_INLINE);
            GraphicZOrderHelper* pZOrderHelper = m_rDomainMapper.graphicZOrderHelper();
            bool const bOldStyle(m_rGraphicImportType == GraphicImportType::IMPORT_AS_DETECTED_INLINE);
            xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_Z_ORDER),
                uno::Any(pZOrderHelper->findZOrder(nZOrder, bOldStyle)));
                uno::Any(pZOrderHelper->findZOrder(nZOrder, bLastDuplicateWins)));
            pZOrderHelper->addItem(xGraphicObjectProperties, nZOrder);
        }
    }
@@ -737,14 +740,6 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
        case NS_ooxml::LN_CT_Anchor_relativeHeight:
        {
            m_pImpl->m_zOrder = nIntValue;

            // Last one defined must win - opposite to what the existing code (for z-Index?) does.
            GraphicZOrderHelper* pZOrderHelper = m_pImpl->m_rDomainMapper.graphicZOrderHelper();
            if (pZOrderHelper->hasZOrder(m_pImpl->m_zOrder)
                && m_pImpl->m_rGraphicImportType != GraphicImportType::IMPORT_AS_DETECTED_INLINE)
            {
                ++m_pImpl->m_zOrder;
            }
        }
        break;
        case NS_ooxml::LN_CT_Anchor_behindDoc: