sw/qa/extras/ooxmlexport/data/tdf154129_framePr1.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport18.cxx            |   14 ++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx     |   29 +++++++++++++++---
 3 files changed, 39 insertions(+), 4 deletions(-)

New commits:
commit 1519ae101abf32187db983c8a08f7bf1899d5d22
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Sat Mar 11 11:36:59 2023 -0500
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Mar 13 07:43:12 2023 +0000

    tdf#154129 writerfilter framePr: check whole style inheritance: HAnchor
    
    A style can inherit its properties from another style,
    but the code was naively just checking the first paragraph style,
    and not any of the parents.
    
    I'm going to onboard these one at a time.
    
    make CppunitTest_sw_ooxmlexport18 CPPUNIT_TEST_NAME=testTdf154129_framePr1
    
    Change-Id: I32eabc6c1090dbc2c467da74fe32c6377e9a3875
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148686
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf154129_framePr1.docx 
b/sw/qa/extras/ooxmlexport/data/tdf154129_framePr1.docx
new file mode 100644
index 000000000000..27ba6055c287
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf154129_framePr1.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
index 9e637fb937e7..3c8950162648 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -16,6 +16,7 @@
 #include <com/sun/star/drawing/XShapes.hpp>
 #include <com/sun/star/frame/XStorable.hpp>
 #include <com/sun/star/text/GraphicCrop.hpp>
+#include <com/sun/star/text/RelOrientation.hpp>
 #include <com/sun/star/text/WritingMode2.hpp>
 #include <com/sun/star/text/XFootnotesSupplier.hpp>
 #include <com/sun/star/text/XTextDocument.hpp>
@@ -134,6 +135,19 @@ DECLARE_OOXMLEXPORT_TEST(testTdf104394_lostTextbox, 
"tdf104394_lostTextbox.docx"
     CPPUNIT_ASSERT_EQUAL(2, getPages());
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf154129_framePr1, "tdf154129_framePr1.docx")
+{
+    for (size_t i = 1; i < 4; ++i)
+    {
+        uno::Reference<drawing::XShape> xTextFrame = getShape(i);
+        // The anchor is defined in the style, and only the first style was 
checked, not the parents
+        auto nAnchor = getProperty<sal_Int16>(xTextFrame, 
"HoriOrientRelation");
+        CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, nAnchor);
+        //nAnchor = getProperty<sal_Int16>(xTextFrame, "VertOrientRelation");
+        //CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, nAnchor);
+    }
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf153613_anchoredAfterPgBreak, 
"tdf153613_anchoredAfterPgBreak.docx")
 {
     const auto& pLayout = parseLayoutDump();
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 68f2511358b8..f8cbc3c7f3f5 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1603,6 +1603,21 @@ void 
DomainMapper_Impl::CheckUnregisteredFrameConversion( )
         StyleSheetEntryPtr pParaStyle =
             
GetStyleSheetTable()->FindStyleSheetByConvertedStyleName(rAppendContext.pLastParagraphProperties->GetParaStyleName());
 
+        // A paragraph's properties come from direct formatting or somewhere 
in the style hierarchy
+        std::vector<const ParagraphProperties*> vProps;
+        vProps.emplace_back(rAppendContext.pLastParagraphProperties.get());
+        sal_Int8 nSafetyLimit = 16;
+        StyleSheetEntryPtr pStyle = 
GetStyleSheetTable()->FindStyleSheetByConvertedStyleName(
+            rAppendContext.pLastParagraphProperties->GetParaStyleName());
+        while (--nSafetyLimit && pStyle && pStyle->m_pProperties)
+        {
+            vProps.emplace_back(&pStyle->m_pProperties->props());
+            assert(pStyle->m_sBaseStyleIdentifier != pStyle->m_sStyleName);
+            if (pStyle->m_sBaseStyleIdentifier.isEmpty())
+                break;
+            pStyle = 
GetStyleSheetTable()->FindStyleSheetByISTD(pStyle->m_sBaseStyleIdentifier);
+        }
+
         std::vector<beans::PropertyValue> aFrameProperties;
 
         if ( pParaStyle )
@@ -1665,10 +1680,16 @@ void 
DomainMapper_Impl::CheckUnregisteredFrameConversion( )
                         ? pStyleProperties->props().Getx() : DEFAULT_VALUE));
 
             //Default the anchor in case FramePr_hAnchor is missing ECMA 
17.3.1.11
-            
aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_HORI_ORIENT_RELATION),
 sal_Int16(
-                rAppendContext.pLastParagraphProperties->GethAnchor() >= 0 ?
-                    rAppendContext.pLastParagraphProperties->GethAnchor() :
-                pStyleProperties->props().GethAnchor() >=0 ? 
pStyleProperties->props().GethAnchor() : text::RelOrientation::FRAME )));
+            sal_Int16 nHAnchor = text::RelOrientation::FRAME;
+            for (const auto pProp : vProps)
+            {
+                if (pProp->GethAnchor() < 0)
+                    continue;
+                nHAnchor = pProp->GethAnchor();
+                break;
+            }
+            aFrameProperties.push_back(comphelper::makePropertyValue(
+                getPropertyName(PROP_HORI_ORIENT_RELATION), nHAnchor));
 
             sal_Int16 nVertOrient = sal_Int16(
                 rAppendContext.pLastParagraphProperties->GetyAlign() >= 0 ?

Reply via email to