oox/source/vml/vmlshape.cxx                                  |   17 +++++++-
 sw/qa/extras/ooxmlexport/data/tdf160049_anchorMargin15.docx  |binary
 sw/qa/extras/ooxmlexport/data/tdf160049_anchorMarginVML.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport21.cxx                   |   21 +++++++++++
 sw/qa/extras/ww8export/data/tdf160049_anchorMargin.doc       |binary
 sw/qa/extras/ww8export/ww8export4.cxx                        |   10 +++++
 sw/source/filter/ww8/ww8graf.cxx                             |    6 +++
 writerfilter/source/dmapper/GraphicImport.cxx                |   10 +++++
 8 files changed, 61 insertions(+), 3 deletions(-)

New commits:
commit 8dcc7c73999727a5a5e5577d6d48f43f403e2995
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Tue Mar 5 19:43:51 2024 -0500
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Mar 11 09:44:45 2024 +0100

    tdf#160049 doc import: use margins with left/right HoriOrientRelation
    
    No interesting existing unit tests.
    
    make CppunitTest_sw_ww8export4 \
        CPPUNIT_TEST_NAME=testTdf160049_anchorMargin
    
    Change-Id: Ib855d9f35db9e0f47aff18400b69a990cd1ad5ca
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164444
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164583
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/sw/qa/extras/ww8export/data/tdf160049_anchorMargin.doc 
b/sw/qa/extras/ww8export/data/tdf160049_anchorMargin.doc
new file mode 100644
index 000000000000..d1082515fd9c
Binary files /dev/null and 
b/sw/qa/extras/ww8export/data/tdf160049_anchorMargin.doc differ
diff --git a/sw/qa/extras/ww8export/ww8export4.cxx 
b/sw/qa/extras/ww8export/ww8export4.cxx
index d31bf17a31f6..e297ac949afe 100644
--- a/sw/qa/extras/ww8export/ww8export4.cxx
+++ b/sw/qa/extras/ww8export/ww8export4.cxx
@@ -49,6 +49,16 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf77964)
     CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AS_CHARACTER, 
getProperty<text::TextContentAnchorType>(getShapeByName(u"Image2"), 
"AnchorType"));
 }
 
+DECLARE_WW8EXPORT_TEST(testTdf160049_anchorMargin, 
"tdf160049_anchorMargin.doc")
+{
+    // given a document with a LEFT "column/text" anchored image
+
+    // The image takes into account the margin, so it looks like it is in the 
middle of the doc,
+    // which is "Paragraph text area"/PRINT_AREA/1, not "Entire paragraph 
area"/FRAME/0
+    CPPUNIT_ASSERT_EQUAL(css::text::RelOrientation::PRINT_AREA,
+                         getProperty<sal_Int16>(getShape(1), 
"HoriOrientRelation"));
+}
+
 DECLARE_WW8EXPORT_TEST(testTdf150197_anlv2ListFormat, 
"tdf150197_anlv2ListFormat.doc")
 {
     CPPUNIT_ASSERT_EQUAL(OUString("1."), 
getProperty<OUString>(getParagraph(2), "ListLabelString"));
diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx
index 8a9dd1197129..7d486f471e1f 100644
--- a/sw/source/filter/ww8/ww8graf.cxx
+++ b/sw/source/filter/ww8/ww8graf.cxx
@@ -2400,6 +2400,12 @@ RndStdIds 
SwWW8ImplReader::ProcessEscherAlign(SvxMSDffImportRec& rRecord, WW8_FS
         rFSPA.nXaLeft = 0;
         rFSPA.nXaRight = nWidth;
     }
+    else if ((eHoriOri == text::HoriOrientation::LEFT || eHoriOri == 
text::HoriOrientation::RIGHT)
+             && eHoriRel == text::RelOrientation::FRAME)
+    {
+        // relative left/right honors paragraph margins, but not with center 
or none/absolute offset
+        eHoriRel = text::RelOrientation::PRINT_AREA;
+    }
 
     // #i24255# - position of floating screen objects in
     // R2L layout are given in L2R layout, thus convert them of all
commit bb6fa9b093e857c7d34eb161ff4c6692f09f7b9e
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Tue Mar 5 19:22:34 2024 -0500
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Mar 11 09:44:39 2024 +0100

    tdf#160049 dml import: use margins with left/right HoriOrientRelation
    
    I'm really surprised this wasn't found much earlier.
    Even DOC format isn't handling this.
    
    compat15 gets rid of this inconsistency.
    
    Surprisingly, there were no interesting unit tests matching this.
    
    make CppunitTest_sw_ooxmlexport21 \
        CPPUNIT_TEST_NAME=testTdf160049_anchorMarginVML
    
    make CppunitTest_sw_ooxmlexport21 \
        CPPUNIT_TEST_NAME=testTdf160049_anchorMargin15
    
    Change-Id: Ic5c316569ad3640ba0e786d39a6e5c006c74d665
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164443
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164582
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf160049_anchorMargin15.docx 
b/sw/qa/extras/ooxmlexport/data/tdf160049_anchorMargin15.docx
new file mode 100755
index 000000000000..0b80c9652fbe
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf160049_anchorMargin15.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
index 339e54784843..d57c94835e4b 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
@@ -295,14 +295,22 @@ DECLARE_OOXMLEXPORT_TEST(testTdf160049_anchorMarginVML, 
"tdf160049_anchorMarginV
 {
     // given a VML (Word 2003) document with a LEFT "column/text" anchored 
image
     // (which will import as DML compat12 on the round-trip)
-    if (isExported())
-        return;
+
     // The image takes into account the margin, so it looks like it is in the 
middle of the doc,
     // which is "Paragraph text area"/PRINT_AREA/1, not "Entire paragraph 
area"/FRAME/0
     CPPUNIT_ASSERT_EQUAL(css::text::RelOrientation::PRINT_AREA,
                          getProperty<sal_Int16>(getShape(1), 
"HoriOrientRelation"));
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf160049_anchorMargin15, 
"tdf160049_anchorMargin15.docx")
+{
+    // given a DML compat15 (Word 2013) document with a LEFT "column/text" 
anchored image
+
+    // The image ignores the margin, so it is at the left for compat15 (but 
middle-ish for compat14)
+    CPPUNIT_ASSERT_EQUAL(css::text::RelOrientation::FRAME,
+                         getProperty<sal_Int16>(getShape(1), 
"HoriOrientRelation"));
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf153909_followTextFlow, 
"tdf153909_followTextFlow.docx")
 {
     // Although MSO's UI reports "layoutInCell" for the rectangle, it isn't 
specified or honored
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx 
b/writerfilter/source/dmapper/GraphicImport.cxx
index dc2a7935eba0..3e5d6d87b267 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -1817,6 +1817,16 @@ uno::Reference<text::XTextContent> 
GraphicImport::createGraphicObject(uno::Refer
             sal_Int32 nWidth = - m_pImpl->m_nLeftPosition;
             if (m_pImpl->m_rGraphicImportType == IMPORT_AS_DETECTED_ANCHOR)
             {
+                if (m_pImpl->m_nHoriRelation == text::RelOrientation::FRAME
+                    && m_pImpl->m_nHoriOrient > text::HoriOrientation::NONE
+                    && m_pImpl->m_nHoriOrient != text::HoriOrientation::CENTER
+                    && m_pImpl->m_nHoriOrient < text::HoriOrientation::FULL)
+                {
+                    // before compat15, relative left/right/inside/outside 
honored margins.
+                    if 
(m_pImpl->m_rDomainMapper.GetSettingsTable()->GetWordCompatibilityMode() < 15)
+                        m_pImpl->m_nHoriRelation = 
text::RelOrientation::PRINT_AREA;
+                }
+
                 //adjust margins
                 if( (m_pImpl->m_nHoriOrient == text::HoriOrientation::LEFT &&
                     (m_pImpl->m_nHoriRelation == 
text::RelOrientation::PAGE_PRINT_AREA ||
commit 22adb6942a081aaadfcb04adb2bd3746d4034a68
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Tue Mar 5 19:05:29 2024 -0500
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Mar 11 09:44:33 2024 +0100

    tdf#160049 oox import: use margins with left/right HoriOrientRelation
    
    I'm really surprised this wasn't found much earlier.
    Even DOC format isn't handling this.
    
    make CppunitTest_sw_ooxmlexport21 \
        CPPUNIT_TEST_NAME=testTdf160049_anchorMarginVML
    
    Change-Id: I92ee8eceb6c6bab5f027663bae94d7acdf01be3d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164442
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164581
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/oox/source/vml/vmlshape.cxx b/oox/source/vml/vmlshape.cxx
index 5284de176839..8f16c6267211 100644
--- a/oox/source/vml/vmlshape.cxx
+++ b/oox/source/vml/vmlshape.cxx
@@ -647,8 +647,13 @@ static void lcl_SetAnchorType(PropertySet& rPropSet, const 
ShapeTypeModel& rType
         rPropSet.setAnyProperty(PROP_VertOrient, 
Any(text::VertOrientation::TOP));
     }
 
+    // if the anchor is not inline, and is relative to left or right, then 
apply the margins
+    bool bHonorMargins = rTypeModel.maPosition == "relative" || 
rTypeModel.maPosition == "absolute";
     if ( rTypeModel.maPositionHorizontal == "center" )
+    {
         rPropSet.setAnyProperty(PROP_HoriOrient, 
Any(text::HoriOrientation::CENTER));
+        bHonorMargins = false;
+    }
     else if ( rTypeModel.maPositionHorizontal == "left" )
         rPropSet.setAnyProperty(PROP_HoriOrient, 
Any(text::HoriOrientation::LEFT));
     else if ( rTypeModel.maPositionHorizontal == "right" )
@@ -663,6 +668,8 @@ static void lcl_SetAnchorType(PropertySet& rPropSet, const 
ShapeTypeModel& rType
         rPropSet.setAnyProperty(PROP_HoriOrient, 
Any(text::HoriOrientation::RIGHT));
         rPropSet.setAnyProperty(PROP_PageToggle, Any(true));
     }
+    else
+        bHonorMargins = false;
 
     if ( rTypeModel.maPositionHorizontalRelative == "page" )
         rPropSet.setAnyProperty(PROP_HoriOrientRelation, 
Any(text::RelOrientation::PAGE_FRAME));
@@ -674,9 +681,13 @@ static void lcl_SetAnchorType(PropertySet& rPropSet, const 
ShapeTypeModel& rType
     else if (rTypeModel.maPositionHorizontalRelative == "left-margin-area" ||
              rTypeModel.maPositionHorizontalRelative == "outer-margin-area")
         rPropSet.setProperty(PROP_HoriOrientRelation, 
text::RelOrientation::PAGE_LEFT);
-    else if ( rTypeModel.maPositionHorizontalRelative == "text" )
-        rPropSet.setProperty(PROP_HoriOrientRelation, 
text::RelOrientation::FRAME);
-
+    else // "text"
+    {
+        if (bHonorMargins)
+            rPropSet.setProperty(PROP_HoriOrientRelation, 
text::RelOrientation::PRINT_AREA);
+        else
+            rPropSet.setProperty(PROP_HoriOrientRelation, 
text::RelOrientation::FRAME);
+    }
     if ( rTypeModel.maPositionVertical == "center" )
         rPropSet.setAnyProperty(PROP_VertOrient, 
Any(text::VertOrientation::CENTER));
     else if ( rTypeModel.maPositionVertical == "top" )
diff --git a/sw/qa/extras/ooxmlexport/data/tdf160049_anchorMarginVML.docx 
b/sw/qa/extras/ooxmlexport/data/tdf160049_anchorMarginVML.docx
new file mode 100644
index 000000000000..f8cb262f53c8
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf160049_anchorMarginVML.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
index 7080199c75f5..339e54784843 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport21.cxx
@@ -13,6 +13,7 @@
 #include <com/sun/star/awt/Gradient2.hpp>
 #include <com/sun/star/beans/XPropertyState.hpp>
 #include <com/sun/star/drawing/FillStyle.hpp>
+#include <com/sun/star/text/RelOrientation.hpp>
 #include <com/sun/star/text/XDocumentIndex.hpp>
 #include <com/sun/star/text/XTextTable.hpp>
 #include <com/sun/star/style/LineSpacing.hpp>
@@ -290,6 +291,18 @@ DECLARE_OOXMLEXPORT_TEST(testTdf158597, "tdf158597.docx")
     }
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf160049_anchorMarginVML, 
"tdf160049_anchorMarginVML.docx")
+{
+    // given a VML (Word 2003) document with a LEFT "column/text" anchored 
image
+    // (which will import as DML compat12 on the round-trip)
+    if (isExported())
+        return;
+    // The image takes into account the margin, so it looks like it is in the 
middle of the doc,
+    // which is "Paragraph text area"/PRINT_AREA/1, not "Entire paragraph 
area"/FRAME/0
+    CPPUNIT_ASSERT_EQUAL(css::text::RelOrientation::PRINT_AREA,
+                         getProperty<sal_Int16>(getShape(1), 
"HoriOrientRelation"));
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf153909_followTextFlow, 
"tdf153909_followTextFlow.docx")
 {
     // Although MSO's UI reports "layoutInCell" for the rectangle, it isn't 
specified or honored

Reply via email to