sw/inc/ndarr.hxx                             |    2 +-
 sw/source/filter/ww8/attributeoutputbase.hxx |    2 +-
 sw/source/filter/ww8/wrtw8nds.cxx            |   19 ++++++++++++++++++-
 sw/source/filter/ww8/wrtww8.cxx              |    2 +-
 4 files changed, 21 insertions(+), 4 deletions(-)

New commits:
commit 79a41e301209eb0f15af397e10ce2838965408d6
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Mon Aug 25 15:00:19 2025 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Tue Aug 26 02:45:20 2025 +0200

    tdf#104827 doc export: Keep CR when justified text before section
    
    This patch only benefits Micrsoft Word.
    MS Word has a bug where even the last line of the paragraph
    is justified when it ends with a continuous break.
    
    This change could probably be made
    for (almost) all continuous section breaks,
    but it likely has other implications or side effects,
    so just minimize the change to this one specific use-case.
    
    Change-Id: Ifd16b78a95d8cb52d37f948a6f6fe5fcdaf2a254
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190193
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/sw/inc/ndarr.hxx b/sw/inc/ndarr.hxx
index c72a6de9191f..b70f4af211f2 100644
--- a/sw/inc/ndarr.hxx
+++ b/sw/inc/ndarr.hxx
@@ -210,7 +210,7 @@ public:
                                            bool bSkipProtect = true );
     static SwContentNode* GoNextSection( SwPosition *, bool bSkipHidden  = 
true,
                                            bool bSkipProtect = true );
-    static SwContentNode* GoPrevSection( SwNodeIndex *, bool bSkipHidden  = 
true,
+    SW_DLLPUBLIC static SwContentNode* GoPrevSection( SwNodeIndex *, bool 
bSkipHidden  = true,
                                            bool bSkipProtect = true );
     static SwContentNode* GoPrevSection( SwPosition *, bool bSkipHidden  = 
true,
                                            bool bSkipProtect = true );
diff --git a/sw/source/filter/ww8/attributeoutputbase.hxx 
b/sw/source/filter/ww8/attributeoutputbase.hxx
index a05f4fe221f7..0f30865b0425 100644
--- a/sw/source/filter/ww8/attributeoutputbase.hxx
+++ b/sw/source/filter/ww8/attributeoutputbase.hxx
@@ -110,7 +110,7 @@ namespace ww8 { class Frame; }
 
 namespace msword {
     const sal_uInt8 ColumnBreak = 0xE;
-    const sal_uInt8 PageBreak   = 0xC;
+    const sal_uInt8 PageBreak = 0xC; // can indicate either a page or 
continuous break!
 }
 
 /// Type of a style in the style table.
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx 
b/sw/source/filter/ww8/wrtw8nds.cxx
index f713f4eceda6..3c9b1a30ce14 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -3444,10 +3444,27 @@ void MSWordExportBase::OutputSectionNode( const 
SwSectionNode& rSectionNode )
         const bool bInTOX = rSection.GetType() == SectionType::ToxContent || 
rSection.GetType() == SectionType::ToxHeader;
         if ( !pSet && !bInTOX )
         {
+            if (GetExportFormat() == MSWordExportBase::ExportFormat::DOC)
+            {
+                bool bJustifiedTextBeforeContinuousSectionBreak = false;
+                SwNodeIndex aDummy(rSectionNode);
+                const SwContentNode* pLastContent
+                    = SwNodes::GoPrevSection(&aDummy, /*SkipHidden*/ true, 
/*SkipProtected*/ false);
+                if (pLastContent && pLastContent->IsTextNode() && 
!pLastContent->FindTableNode())
+                {
+                    // avoid MS Word bug justifying the last line in this 
instance
+                    bJustifiedTextBeforeContinuousSectionBreak
+                        = pLastContent->GetSwAttrSet().GetAdjust().GetAdjust() 
== SvxAdjust::Block;
+                }
+                if (bJustifiedTextBeforeContinuousSectionBreak)
+                    WriteChar(msword::PageBreak); // indicates a continuous 
section break here
+                else
+                    ReplaceCr(msword::PageBreak); // indicates a continuous 
section break here
+            }
+
             // new Section with no own PageDesc/-Break
             //  -> write follow section break;
             const SwSectionFormat* pFormat = rSection.GetFormat();
-            ReplaceCr( msword::PageBreak ); // Indicator for Page/Section-Break
 
             // Get the page in use at the top of this section
             const SwPageDesc *pCurrent = SwPageDesc::GetPageDescOfNode(rNd);
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 58624c61eb5d..766f53434c1e 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -3021,7 +3021,7 @@ void MSWordExportBase::WriteText()
 
                 if (bNeedExportBreakHere)  //#120140# End of check
                 {
-                    ReplaceCr( char(0xc) ); // indicator for Page/Section-Break
+                    ReplaceCr(msword::PageBreak); // either page or continuous 
break
 
                     const SwSectionFormat* pParentFormat = 
rSect.GetFormat()->GetParent();
                     if ( !pParentFormat )

Reply via email to