sw/qa/extras/layout/data/s4_min2.fodt                   |  360 ++++++++++++++++
 sw/qa/extras/layout/data/tdf150606-1-min.odt            |binary
 sw/qa/extras/layout/data/tdf152983-1-min.docx           |binary
 sw/qa/extras/layout/layout.cxx                          |   86 +++
 sw/source/core/doc/DocumentContentOperationsManager.cxx |    2 
 sw/source/core/layout/flowfrm.cxx                       |    2 
 sw/source/core/layout/fly.cxx                           |    6 
 sw/source/core/layout/newfrm.cxx                        |    5 
 sw/source/core/layout/wsfrm.cxx                         |    8 
 9 files changed, 463 insertions(+), 6 deletions(-)

New commits:
commit b1707fea5936557688864124654ef6eeb5c0beb4
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sun May 7 17:11:21 2023 +0300
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Mon Jul 17 11:52:17 2023 +0200

    tdf#137972: when correcting PaMs, move them to the end
    
    The cursor position is pushed in SwView::ExecSpellPopup, and popped
    in the end, to restore the changed position e.g. when the action is
    cancelled.
    
    In the replacement, the PaM of the pushed cursor is updated in
    DocumentContentOperationsManager::ReplaceRangeImpl, likely to avoid
    several updates during the further processing. The stated goal is
    to move all PaMs out of the deleted range, but the direction is not
    stated explicitly.
    
    If this correction is removed, the cursor PaM gets corrected anyway,
    and arrives at the end of the replaced text. So, to fix the bug, and
    to be compliant with the default case, let's correct to the end of
    the range, instead of the random direction (GetPoint() may return a
    position at either end, depending how PaM was created).
    
    Change-Id: I83bcf01bcc0bf7277a9a34263b524b1212785814
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151462
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit 4f93995f2262cde0b16bacc83f4ba3c6161ada7f)

diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx 
b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index 315cf5cdeefa..975a35965d17 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -4317,7 +4317,7 @@ bool DocumentContentOperationsManager::ReplaceRangeImpl( 
SwPaM& rPam, const OUSt
         // the other views out of the deletion range.
         // Except for itself!
         SwPaM aDelPam( *rPam.GetMark(), *rPam.GetPoint() );
-        ::PaMCorrAbs( aDelPam, *aDelPam.GetPoint() );
+        ::PaMCorrAbs( aDelPam, *aDelPam.End() );
 
         SwPosition *pStt = aDelPam.Start(),
                    *pEnd = aDelPam.End();
commit d87c3775acdd0bf9b08444069b51e350a5d91359
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Wed Jun 28 17:19:02 2023 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Mon Jul 17 11:52:17 2023 +0200

    tdf#156077 sw: layout: call AssertFlyPages() in Init()
    
    The bugdoc has 3 pages, and there are at-page flys anchored to the 3rd
    page, and these are not displayed - simply missing from the layout.
    
    In LO 6.1, this worked because the layout-cache was read from the file,
    and 3 pages were created in SwRootFrame::Init() calling InsertCnt_().
    
    But now this creates only 2 pages, and later SwLayAction creates the 2nd
    page between the existing ones on some MoveFwd(), but despite page nr 2
    becoming page nr 3 nothing attaches the at-page flys to the now-page-3.
    
    If a document is loaded containing at-page flys, then all pages that
    have flys anchored to them should be created in SwRootFrame::Init()
    already.
    
    (regression from commit 7e8b4756d95057f069467b34e7849f9354856578)
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153720
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit ff8ec4cfe5df1e15c3e9f6adc843dfe31358e097)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153699
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    (cherry picked from commit c34e72ff817b07403f908a9098dd513b96c30ad1)
    
    Change-Id: I4792c483a7620efd81211e6ad0d9220152367d68

diff --git a/sw/qa/extras/layout/data/s4_min2.fodt 
b/sw/qa/extras/layout/data/s4_min2.fodt
new file mode 100644
index 000000000000..e1317de597d8
--- /dev/null
+++ b/sw/qa/extras/layout/data/s4_min2.fodt
@@ -0,0 +1,360 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<office:document 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:dc="http://purl.org/dc/elements/1.1/"; 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" 
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:config="urn:oas
 is:names:tc:opendocument:xmlns:config:1.0" 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:xforms="http://www.w3.org/2002/xforms"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; 
xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:formx="urn:openoffice:names:
 experimental:ooxml-odf-interop:xmlns:form:1.0" 
xmlns:css3t="http://www.w3.org/TR/css3-text/"; office:version="1.2" 
office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:meta><meta:generator>CIB_OfficeDev/6.1.7.41$Linux_X86_64 
LibreOffice_project/1df0ab666a1bb346850daa72aaa2e29a697a252c</meta:generator><meta:creation-date>2023-06-26T22:28:03.054604345</meta:creation-date><dc:language>de-DE</dc:language><meta:editing-cycles>11</meta:editing-cycles><meta:editing-duration>PT14M3S</meta:editing-duration><dc:date>2023-06-26T23:06:43.147312212</dc:date><meta:document-statistic
 meta:table-count="1" meta:image-count="0" meta:object-count="0" 
meta:page-count="3" meta:paragraph-count="14" meta:word-count="247" 
meta:character-count="1680"/><meta:user-defined meta:name="Info 
1"/><meta:user-defined meta:name="Info 2"/><meta:user-defined meta:name="Info 
3"/><meta:user-defined meta:name="Info 4"/></office:meta>
+ <office:font-face-decls>
+  <style:font-face style:name="Arial" svg:font-family="Arial" 
style:font-pitch="variable"/>
+  <style:font-face style:name="Arial Unicode MS" svg:font-family="'Arial 
Unicode MS'" style:font-pitch="variable"/>
+  <style:font-face style:name="HG Mincho Light J" svg:font-family="'HG Mincho 
Light J'" style:font-pitch="variable"/>
+  <style:font-face style:name="Times New Roman" svg:font-family="'Times New 
Roman'" style:font-pitch="variable"/>
+  <style:font-face style:name="Thorndale" svg:font-family="Thorndale" 
style:font-family-generic="roman" style:font-pitch="variable"/>
+ </office:font-face-decls>
+ <office:styles>
+  <style:default-style style:family="graphic">
+   <style:graphic-properties svg:stroke-color="#808080" 
draw:fill-color="#cfe7f5" fo:wrap-option="no-wrap" draw:shadow-offset-x="0.3cm" 
draw:shadow-offset-y="0.3cm" draw:start-line-spacing-horizontal="0.283cm" 
draw:start-line-spacing-vertical="0.283cm" 
draw:end-line-spacing-horizontal="0.283cm" 
draw:end-line-spacing-vertical="0.283cm" style:flow-with-text="true"/>
+   <style:paragraph-properties style:text-autospace="ideograph-alpha" 
style:line-break="strict" style:font-independent-line-spacing="false">
+    <style:tab-stops/>
+   </style:paragraph-properties>
+   <style:text-properties fo:color="#000000" style:font-name="Thorndale" 
fo:font-size="12pt" fo:language="de" fo:country="DE" style:font-name-asian="HG 
Mincho Light J" style:font-size-asian="12pt" style:language-asian="zxx" 
style:country-asian="none" style:font-name-complex="Arial Unicode MS" 
style:font-size-complex="12pt" style:language-complex="zxx" 
style:country-complex="none"/>
+  </style:default-style>
+  <style:default-style style:family="paragraph">
+   <style:paragraph-properties fo:hyphenation-ladder-count="no-limit" 
style:text-autospace="ideograph-alpha" style:punctuation-wrap="hanging" 
style:line-break="strict" style:tab-stop-distance="2cm" 
style:writing-mode="lr-tb"/>
+   <style:text-properties fo:color="#000000" style:font-name="Thorndale" 
fo:font-size="12pt" fo:language="de" fo:country="DE" style:font-name-asian="HG 
Mincho Light J" style:font-size-asian="12pt" style:language-asian="zxx" 
style:country-asian="none" style:font-name-complex="Arial Unicode MS" 
style:font-size-complex="12pt" style:language-complex="zxx" 
style:country-complex="none" fo:hyphenate="false" 
fo:hyphenation-remain-char-count="2" fo:hyphenation-push-char-count="2"/>
+  </style:default-style>
+  <style:default-style style:family="table">
+   <style:table-properties table:border-model="separating"/>
+  </style:default-style>
+  <style:default-style style:family="table-row">
+   <style:table-row-properties fo:keep-together="always"/>
+  </style:default-style>
+  <style:style style:name="Standard" style:family="paragraph" 
style:class="text">
+   <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0cm" 
loext:contextual-spacing="false" fo:hyphenation-ladder-count="no-limit"/>
+   <style:text-properties style:font-name="Arial" fo:font-family="Arial" 
style:font-pitch="variable" fo:hyphenate="true" 
fo:hyphenation-remain-char-count="4" fo:hyphenation-push-char-count="4"/>
+  </style:style>
+  <style:style style:name="Text_20_body" style:display-name="Text body" 
style:family="paragraph" style:parent-style-name="Standard" style:class="text">
+   <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0cm" 
loext:contextual-spacing="false" fo:hyphenation-ladder-count="no-limit"/>
+   <style:text-properties style:font-name="Arial" fo:font-family="Arial" 
style:font-pitch="variable" fo:hyphenate="true" 
fo:hyphenation-remain-char-count="4" fo:hyphenation-push-char-count="4"/>
+  </style:style>
+  <style:style style:name="Footer" style:family="paragraph" 
style:parent-style-name="Standard" style:class="extra">
+   <style:paragraph-properties>
+    <style:tab-stops>
+     <style:tab-stop style:position="8.5cm" style:type="center"/>
+     <style:tab-stop style:position="17.002cm" style:type="right"/>
+    </style:tab-stops>
+   </style:paragraph-properties>
+  </style:style>
+  <style:style style:name="Table_20_Contents" style:display-name="Table 
Contents" style:family="paragraph" style:parent-style-name="Text_20_body" 
style:class="extra"/>
+  <style:style style:name="Frame_20_contents" style:display-name="Frame 
contents" style:family="paragraph" style:parent-style-name="Text_20_body" 
style:class="extra"/>
+  <style:style style:name="Arial_5f_12_5f_Links" 
style:display-name="Arial_12_Links" style:family="paragraph" 
style:parent-style-name="Standard">
+   <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0cm" 
loext:contextual-spacing="false" fo:hyphenation-ladder-count="no-limit"/>
+   <style:text-properties style:font-name="Arial" fo:font-family="Arial" 
style:font-pitch="variable" fo:font-weight="350" fo:hyphenate="false" 
fo:hyphenation-remain-char-count="4" fo:hyphenation-push-char-count="4"/>
+  </style:style>
+  <style:style style:name="TVS_20_Standard" style:display-name="TVS Standard" 
style:family="paragraph" style:master-page-name="">
+   <style:paragraph-properties fo:hyphenation-ladder-count="no-limit" 
style:page-number="auto"/>
+   <style:text-properties style:font-name="Arial" fo:font-family="Arial" 
style:font-pitch="variable" fo:hyphenate="true" 
fo:hyphenation-remain-char-count="4" fo:hyphenation-push-char-count="4"/>
+  </style:style>
+  <style:style style:name="TVS_20_KopfzeileFKB_5f_S2" style:display-name="TVS 
KopfzeileFKB_S2" style:family="paragraph" 
style:parent-style-name="TVS_20_Standard">
+   <style:paragraph-properties fo:text-align="center" 
style:justify-single-word="false"/>
+   <style:text-properties fo:font-size="8pt"/>
+  </style:style>
+  <style:style style:name="TVS_20_FußzeileFKB" style:display-name="TVS 
FußzeileFKB" style:family="paragraph" style:parent-style-name="TVS_20_Standard" 
style:master-page-name="">
+   <style:paragraph-properties fo:text-align="center" 
style:justify-single-word="false" style:page-number="auto" 
style:vertical-align="middle"/>
+   <style:text-properties style:font-name="Times New Roman" 
fo:font-family="'Times New Roman'" style:font-pitch="variable" 
fo:font-size="8pt"/>
+  </style:style>
+  <style:style style:name="TVS_20_Adressfeld" style:display-name="TVS 
Adressfeld" style:family="paragraph" style:parent-style-name="TVS_20_Standard" 
style:master-page-name="">
+   <style:paragraph-properties style:page-number="auto"/>
+   <style:text-properties fo:language="zxx" fo:country="none"/>
+  </style:style>
+  <style:style style:name="TVS_20_Unsichtbar" style:display-name="TVS 
Unsichtbar" style:family="paragraph" style:parent-style-name="TVS_20_Standard" 
style:master-page-name="">
+   <style:paragraph-properties style:page-number="auto"/>
+   <style:text-properties fo:font-size="2pt"/>
+  </style:style>
+  <style:style style:name="TVS_20_Mehrfertigung" style:display-name="TVS 
Mehrfertigung" style:family="paragraph" 
style:parent-style-name="TVS_20_Standard" style:master-page-name="">
+   <style:paragraph-properties fo:text-align="center" 
style:justify-single-word="false" style:page-number="auto"/>
+   <style:text-properties fo:font-weight="bold"/>
+  </style:style>
+  <style:style style:name="TVS_20_Absender" style:display-name="TVS Absender" 
style:family="paragraph" style:parent-style-name="TVS_20_Standard" 
style:master-page-name="">
+   <style:paragraph-properties style:page-number="auto"/>
+   <style:text-properties style:font-name="Times New Roman" 
fo:font-family="'Times New Roman'" style:font-pitch="variable" 
fo:font-size="8pt"/>
+  </style:style>
+  <style:style style:name="TVS_20_Anrede" style:display-name="TVS Anrede" 
style:family="paragraph" style:parent-style-name="TVS_20_Standard" 
style:next-style-name="TVS_20_Freitext">
+   <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0.42cm" 
loext:contextual-spacing="false"/>
+  </style:style>
+  <style:style style:name="TVS_20_Freitext" style:display-name="TVS Freitext" 
style:family="paragraph" style:parent-style-name="TVS_20_Standard">
+   <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0.42cm" 
loext:contextual-spacing="false"/>
+  </style:style>
+  <style:style style:name="Footnote_20_Symbol" style:display-name="Footnote 
Symbol" style:family="text"/>
+  <style:style style:name="Endnote_20_Symbol" style:display-name="Endnote 
Symbol" style:family="text"/>
+  <style:style style:name="TVS_20_Fett" style:display-name="TVS Fett" 
style:family="text">
+   <style:text-properties fo:font-weight="bold"/>
+  </style:style>
+  <style:style style:name="Footnote_20_anchor" style:display-name="Footnote 
anchor" style:family="text">
+   <style:text-properties style:text-position="super 58%"/>
+  </style:style>
+  <style:style style:name="Endnote_20_anchor" style:display-name="Endnote 
anchor" style:family="text">
+   <style:text-properties style:text-position="super 58%"/>
+  </style:style>
+  <style:style style:name="Frame" style:family="graphic">
+   <style:graphic-properties svg:width="7.696cm" fo:min-height="3.519cm" 
text:anchor-type="page" style:wrap="parallel" 
style:number-wrapped-paragraphs="no-limit" style:wrap-contour="false">
+    <style:columns fo:column-count="1" fo:column-gap="0cm"/>
+   </style:graphic-properties>
+  </style:style>
+  <text:outline-style style:name="Outline">
+   <text:outline-level-style text:level="1" style:num-format="">
+    <style:list-level-properties/>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="2" style:num-format="">
+    <style:list-level-properties/>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="3" style:num-format="">
+    <style:list-level-properties/>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="4" style:num-format="">
+    <style:list-level-properties/>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="5" style:num-format="">
+    <style:list-level-properties/>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="6" style:num-format="">
+    <style:list-level-properties/>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="7" style:num-format="">
+    <style:list-level-properties/>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="8" style:num-format="">
+    <style:list-level-properties/>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="9" style:num-format="">
+    <style:list-level-properties/>
+   </text:outline-level-style>
+   <text:outline-level-style text:level="10" style:num-format="">
+    <style:list-level-properties/>
+   </text:outline-level-style>
+  </text:outline-style>
+  <text:notes-configuration text:note-class="footnote" 
text:citation-style-name="Footnote_20_Symbol" 
text:citation-body-style-name="Footnote_20_anchor" 
text:master-page-name="Standard" style:num-format="1" text:start-value="0" 
text:footnotes-position="page" text:start-numbering-at="document"/>
+  <text:notes-configuration text:note-class="endnote" 
text:citation-style-name="Endnote_20_Symbol" 
text:citation-body-style-name="Endnote_20_anchor" 
text:master-page-name="Endnote" style:num-format="1" text:start-value="0"/>
+  <text:linenumbering-configuration text:number-lines="false" 
text:offset="0.499cm" style:num-format="1" text:number-position="left" 
text:increment="5"/>
+ </office:styles>
+ <office:automatic-styles>
+  <style:style style:name="Tabelle1" style:family="table">
+   <style:table-properties style:width="16.574cm" table:align="margins"/>
+  </style:style>
+  <style:style style:name="Tabelle1.A" style:family="table-column">
+   <style:table-column-properties style:column-width="16.574cm" 
style:rel-column-width="65535*"/>
+  </style:style>
+  <style:style style:name="Tabelle1.A1" style:family="table-cell">
+   <style:table-cell-properties fo:padding="0.097cm" fo:border="none"/>
+  </style:style>
+  <style:style style:name="P1" style:family="paragraph" 
style:parent-style-name="Standard">
+   <style:paragraph-properties fo:text-align="center" 
style:justify-single-word="false"/>
+   <style:text-properties fo:font-size="2pt" fo:font-weight="bold"/>
+  </style:style>
+  <style:style style:name="P2" style:family="paragraph" 
style:parent-style-name="Standard">
+   <style:paragraph-properties fo:text-align="center" 
style:justify-single-word="false"/>
+   <style:text-properties fo:font-size="14pt" fo:font-weight="bold"/>
+  </style:style>
+  <style:style style:name="P3" style:family="paragraph" 
style:parent-style-name="Standard">
+   <style:paragraph-properties fo:text-align="center" 
style:justify-single-word="false"/>
+   <style:text-properties fo:font-size="10pt" fo:font-weight="normal"/>
+  </style:style>
+  <style:style style:name="P4" style:family="paragraph" 
style:parent-style-name="Standard">
+   <style:text-properties/>
+  </style:style>
+  <style:style style:name="P5" style:family="paragraph" 
style:parent-style-name="TVS_20_Adressfeld">
+   <style:text-properties fo:font-size="10pt"/>
+  </style:style>
+  <style:style style:name="P6" style:family="paragraph" 
style:parent-style-name="Table_20_Contents">
+   <style:text-properties fo:font-size="12pt" style:font-size-asian="12pt" 
style:font-size-complex="12pt"/>
+  </style:style>
+  <style:style style:name="P7" style:family="paragraph" 
style:parent-style-name="Arial_5f_12_5f_Links">
+   <style:text-properties/>
+  </style:style>
+  <style:style style:name="P8" style:family="paragraph" 
style:parent-style-name="Standard" style:master-page-name="Standard2">
+   <style:paragraph-properties fo:margin-left="0cm" fo:margin-right="0cm" 
fo:margin-top="0cm" fo:margin-bottom="0cm" loext:contextual-spacing="false" 
fo:text-indent="0cm" style:auto-text-indent="false" style:page-number="auto"/>
+   <style:text-properties style:font-name="Arial" fo:font-size="12pt" 
fo:font-style="normal" style:text-underline-style="none" fo:font-weight="bold" 
style:font-size-asian="12pt" style:font-weight-asian="normal" 
style:font-size-complex="12pt" style:font-weight-complex="normal"/>
+  </style:style>
+  <style:style style:name="P9" style:family="paragraph" 
style:parent-style-name="TVS_20_Anrede" style:master-page-name="FABrief_5f_S1">
+   <style:paragraph-properties style:page-number="auto"/>
+  </style:style>
+  <style:style style:name="fr1" style:family="graphic" 
style:parent-style-name="Frame">
+   <style:graphic-properties style:protect="size position" 
style:vertical-pos="from-top" style:vertical-rel="paragraph" 
style:horizontal-pos="from-left" style:horizontal-rel="paragraph" 
fo:padding="0cm" fo:border="none" style:shadow="none" 
draw:shadow-opacity="100%"/>
+  </style:style>
+  <style:style style:name="fr2" style:family="graphic" 
style:parent-style-name="Frame">
+   <style:graphic-properties fo:margin-left="0cm" fo:margin-right="0cm" 
fo:margin-top="0cm" fo:margin-bottom="0cm" style:protect="content size 
position" style:vertical-pos="middle" style:vertical-rel="page" 
style:horizontal-pos="from-left" style:horizontal-rel="paragraph" 
fo:padding="0cm" fo:border-left="none" fo:border-right="none" 
fo:border-top="0.51pt solid #000000" fo:border-bottom="none"/>
+  </style:style>
+  <style:style style:name="fr3" style:family="graphic" 
style:parent-style-name="Frame">
+   <style:graphic-properties style:protect="size position" 
style:wrap="parallel" style:number-wrapped-paragraphs="no-limit" 
style:vertical-pos="from-top" style:vertical-rel="page" 
style:horizontal-pos="from-left" style:horizontal-rel="page" fo:padding="0cm" 
fo:border="none">
+    <style:columns fo:column-count="1" fo:column-gap="0cm"/>
+   </style:graphic-properties>
+  </style:style>
+  <style:style style:name="fr4" style:family="graphic" 
style:parent-style-name="Frame">
+   <style:graphic-properties style:protect="size position" 
style:wrap="parallel" style:number-wrapped-paragraphs="no-limit" 
style:vertical-pos="from-top" style:vertical-rel="page" 
style:horizontal-pos="from-left" style:horizontal-rel="page" 
fo:background-color="transparent" draw:fill="none" draw:fill-color="#ffffff" 
fo:padding="0cm" fo:border-left="none" fo:border-right="none" 
fo:border-top="none" fo:border-bottom="0.51pt solid #000000"/>
+  </style:style>
+  <style:style style:name="fr5" style:family="graphic" 
style:parent-style-name="Frame">
+   <style:graphic-properties style:protect="size position" 
style:wrap="parallel" style:number-wrapped-paragraphs="no-limit" 
style:vertical-pos="from-top" style:vertical-rel="page" 
style:horizontal-pos="from-left" style:horizontal-rel="page" 
style:shadow="none" draw:shadow-opacity="100%"/>
+  </style:style>
+  <style:style style:name="fr6" style:family="graphic" 
style:parent-style-name="Frame">
+   <style:graphic-properties style:protect="size position" 
style:wrap="parallel" style:number-wrapped-paragraphs="no-limit" 
style:vertical-pos="from-top" style:vertical-rel="page" 
style:horizontal-pos="from-left" style:horizontal-rel="paragraph" 
fo:padding="0cm" fo:border="none">
+    <style:columns fo:column-count="1" fo:column-gap="0cm"/>
+   </style:graphic-properties>
+  </style:style>
+  <style:style style:name="fr7" style:family="graphic" 
style:parent-style-name="Frame">
+   <style:graphic-properties style:protect="position" style:wrap="parallel" 
style:number-wrapped-paragraphs="no-limit" style:vertical-pos="from-top" 
style:vertical-rel="page" style:horizontal-pos="from-left" 
style:horizontal-rel="page">
+    <style:columns fo:column-count="1" fo:column-gap="0cm"/>
+   </style:graphic-properties>
+  </style:style>
+  <style:style style:name="Sect1" style:family="section">
+   <style:section-properties style:editable="false">
+    <style:columns fo:column-count="1" fo:column-gap="0cm"/>
+   </style:section-properties>
+  </style:style>
+  <style:page-layout style:name="pm1">
+   <style:page-layout-properties fo:page-width="21.001cm" 
fo:page-height="29.7cm" style:num-format="1" style:paper-tray-name="[From 
printer settings]" style:print-orientation="portrait" fo:margin-top="2cm" 
fo:margin-bottom="2cm" fo:margin-left="2cm" fo:margin-right="2cm" 
fo:border="none" fo:padding="0cm" style:shadow="none" 
fo:background-color="transparent" style:writing-mode="lr-tb" 
style:layout-grid-color="#c0c0c0" style:layout-grid-lines="20" 
style:layout-grid-base-height="0.706cm" style:layout-grid-ruby-height="0.353cm" 
style:layout-grid-mode="none" style:layout-grid-ruby-below="false" 
style:layout-grid-print="true" style:layout-grid-display="true" 
draw:fill="none" draw:fill-color="#cfe7f5" style:footnote-max-height="0cm">
+    <style:columns fo:column-count="1" fo:column-gap="0cm"/>
+    <style:footnote-sep style:width="0.018cm" 
style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" 
style:line-style="none" style:adjustment="left" style:rel-width="25%" 
style:color="#000000"/>
+   </style:page-layout-properties>
+   <style:header-style/>
+   <style:footer-style/>
+  </style:page-layout>
+  <style:page-layout style:name="pm2" style:page-usage="mirrored">
+   <style:page-layout-properties fo:page-width="21.001cm" 
fo:page-height="29.7cm" style:num-format="1" style:paper-tray-name="[From 
printer settings]" style:print-orientation="portrait" fo:margin-top="1.3cm" 
fo:margin-bottom="1.799cm" fo:margin-left="2.9cm" fo:margin-right="1.799cm" 
fo:border="none" fo:padding="0cm" style:shadow="none" 
fo:background-color="transparent" style:writing-mode="lr-tb" 
style:layout-grid-color="#c0c0c0" style:layout-grid-lines="20" 
style:layout-grid-base-height="0.706cm" style:layout-grid-ruby-height="0.353cm" 
style:layout-grid-mode="none" style:layout-grid-ruby-below="false" 
style:layout-grid-print="true" style:layout-grid-display="true" 
draw:fill="none" draw:fill-color="#cfe7f5" style:footnote-max-height="0cm">
+    <style:columns fo:column-count="1" fo:column-gap="0cm"/>
+    <style:footnote-sep style:width="0.018cm" 
style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" 
style:line-style="none" style:adjustment="left" style:rel-width="25%" 
style:color="#000000"/>
+   </style:page-layout-properties>
+   <style:header-style>
+    <style:header-footer-properties svg:height="1.9cm" fo:margin-left="0cm" 
fo:margin-right="0cm" fo:margin-bottom="1.401cm" fo:border="none" 
fo:padding="0cm" style:shadow="none" fo:background-color="transparent" 
style:dynamic-spacing="false" draw:fill="none" draw:fill-color="#cfe7f5"/>
+   </style:header-style>
+   <style:footer-style/>
+  </style:page-layout>
+  <style:page-layout style:name="pm3">
+   <style:page-layout-properties fo:page-width="21.001cm" 
fo:page-height="29.7cm" style:num-format="1" style:print-orientation="portrait" 
fo:margin-top="8.7cm" fo:margin-bottom="1.799cm" fo:margin-left="2.193cm" 
fo:margin-right="1.799cm" fo:background-color="transparent" 
style:writing-mode="lr-tb" style:layout-grid-color="#c0c0c0" 
style:layout-grid-lines="20" style:layout-grid-base-height="0.706cm" 
style:layout-grid-ruby-height="0.353cm" style:layout-grid-mode="none" 
style:layout-grid-ruby-below="false" style:layout-grid-print="false" 
style:layout-grid-display="false" draw:fill="none" draw:fill-color="#cfe7f5" 
style:footnote-max-height="0cm">
+    <style:columns fo:column-count="1" fo:column-gap="0cm"/>
+    <style:footnote-sep style:width="0.018cm" 
style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" 
style:line-style="none" style:adjustment="left" style:rel-width="25%" 
style:color="#000000"/>
+   </style:page-layout-properties>
+   <style:header-style/>
+   <style:footer-style/>
+  </style:page-layout>
+  <style:page-layout style:name="pm4">
+   <style:page-layout-properties fo:page-width="21.001cm" 
fo:page-height="29.7cm" style:num-format="1" style:print-orientation="portrait" 
fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" 
fo:margin-right="2cm" style:writing-mode="lr-tb" 
style:layout-grid-color="#c0c0c0" style:layout-grid-lines="20" 
style:layout-grid-base-height="0.706cm" style:layout-grid-ruby-height="0.353cm" 
style:layout-grid-mode="none" style:layout-grid-ruby-below="false" 
style:layout-grid-print="false" style:layout-grid-display="false" 
style:footnote-max-height="0cm">
+    <style:footnote-sep style:line-style="none" style:adjustment="left" 
style:rel-width="25%" style:color="#000000"/>
+   </style:page-layout-properties>
+   <style:header-style/>
+   <style:footer-style/>
+  </style:page-layout>
+  <style:page-layout style:name="pm5" style:page-usage="mirrored">
+   <style:page-layout-properties fo:page-width="29.7cm" 
fo:page-height="21.001cm" style:num-format="1" style:paper-tray-name="[From 
printer settings]" style:print-orientation="landscape" fo:margin-top="2.9cm" 
fo:margin-bottom="1.799cm" fo:margin-left="2cm" fo:margin-right="2cm" 
fo:border="none" fo:padding="0cm" style:shadow="none" 
fo:background-color="transparent" style:writing-mode="lr-tb" 
style:layout-grid-color="#c0c0c0" style:layout-grid-lines="20" 
style:layout-grid-base-height="0.706cm" style:layout-grid-ruby-height="0.353cm" 
style:layout-grid-mode="none" style:layout-grid-ruby-below="false" 
style:layout-grid-print="true" style:layout-grid-display="true" 
draw:fill="none" draw:fill-color="#cfe7f5" style:footnote-max-height="0cm">
+    <style:columns fo:column-count="1" fo:column-gap="0cm"/>
+    <style:footnote-sep style:width="0.018cm" 
style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" 
style:line-style="none" style:adjustment="left" style:rel-width="25%" 
style:color="#000000"/>
+   </style:page-layout-properties>
+   <style:header-style>
+    <style:header-footer-properties fo:min-height="0.499cm" 
fo:margin-left="0cm" fo:margin-right="0cm" fo:margin-bottom="0.499cm" 
fo:border="none" fo:padding="0cm" fo:background-color="transparent" 
style:dynamic-spacing="false" draw:fill="none" draw:fill-color="#cfe7f5"/>
+   </style:header-style>
+   <style:footer-style/>
+  </style:page-layout>
+  <style:page-layout style:name="pm6">
+   <style:page-layout-properties fo:page-width="21.001cm" 
fo:page-height="29.7cm" style:num-format="1" style:paper-tray-name="[From 
printer settings]" style:print-orientation="portrait" fo:margin-top="10.7cm" 
fo:margin-bottom="2.2cm" fo:margin-left="2.9cm" fo:margin-right="1.799cm" 
fo:border="none" fo:padding="0cm" style:shadow="none" 
fo:background-color="transparent" style:writing-mode="lr-tb" 
style:layout-grid-color="#c0c0c0" style:layout-grid-lines="20" 
style:layout-grid-base-height="0.706cm" style:layout-grid-ruby-height="0.353cm" 
style:layout-grid-mode="none" style:layout-grid-ruby-below="false" 
style:layout-grid-print="true" style:layout-grid-display="true" 
draw:fill="none" draw:fill-color="#cfe7f5" style:footnote-max-height="0cm">
+    <style:columns fo:column-count="1" fo:column-gap="0cm"/>
+    <style:footnote-sep style:width="0.018cm" 
style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" 
style:line-style="none" style:adjustment="left" style:rel-width="25%" 
style:color="#000000"/>
+   </style:page-layout-properties>
+   <style:header-style/>
+   <style:footer-style>
+    <style:header-footer-properties svg:height="2.401cm" fo:margin-left="0cm" 
fo:margin-right="0cm" fo:margin-top="0.3cm" fo:border="none" fo:padding="0cm" 
style:shadow="none" fo:background-color="transparent" 
style:dynamic-spacing="false" draw:fill="none" draw:fill-color="#cfe7f5"/>
+   </style:footer-style>
+  </style:page-layout>
+ </office:automatic-styles>
+ <office:master-styles>
+  <style:master-page style:name="Standard" style:page-layout-name="pm1"/>
+  <style:master-page style:name="FABrief_5f_S2" 
style:display-name="FABrief_S2" style:page-layout-name="pm2">
+   <style:header>
+    <text:p text:style-name="TVS_20_KopfzeileFKB_5f_S2">- <text:page-number 
text:select-page="current">2</text:page-number><text:s/>-</text:p>
+   </style:header>
+  </style:master-page>
+  <style:master-page style:name="Standard2" style:page-layout-name="pm3" 
style:next-style-name="FABrief_5f_S2"/>
+  <style:master-page style:name="Endnote" style:page-layout-name="pm4"/>
+  <style:master-page style:name="FABrief_5f_S1" 
style:display-name="FABrief_S1" style:page-layout-name="pm6" 
style:next-style-name="FABrief_5f_S2">
+   <style:footer>
+    <text:p text:style-name="Footer"><draw:frame draw:style-name="fr1" 
draw:name="ES_FUSSZEILE" text:anchor-type="paragraph" svg:x="0cm" svg:y="0cm" 
svg:width="16.3cm" svg:height="2.101cm" draw:z-index="7">
+      <draw:text-box>
+       <text:p text:style-name="TVS_20_FußzeileFKB"><text:span 
text:style-name="TVS_20_Fett"/></text:p>
+      </draw:text-box>
+     </draw:frame></text:p>
+   </style:footer>
+  </style:master-page>
+ </office:master-styles>
+ <office:body>
+  <office:text text:use-soft-page-breaks="true">
+   <office:forms form:automatic-focus="false" form:apply-design-mode="false"/>
+   <text:sequence-decls>
+    <text:sequence-decl text:display-outline-level="0" 
text:name="Illustration"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Table"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Text"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Figure"/>
+   </text:sequence-decls>
+   <text:user-field-decls>
+    <text:user-field-decl office:value-type="string" office:string-value="" 
text:name="RF_POSTADR1"/>
+    <text:user-field-decl office:value-type="string" office:string-value="" 
text:name="RF_POSTADR2"/>
+    <text:user-field-decl office:value-type="string" office:string-value="" 
text:name="IF_MEHRFERTIGUNG"/>
+    <text:user-field-decl office:value-type="string" office:string-value="" 
text:name="ES_BRIEFANREDE"/>
+    <text:user-field-decl office:value-type="string" office:string-value="" 
text:name="IF_AUSBL_DSGVO"/>
+   </text:user-field-decls><draw:frame draw:style-name="fr2" 
draw:name="Rahmen2" text:anchor-type="page" text:anchor-page-number="2" 
svg:x="0.6cm" svg:width="0.497cm" svg:height="0.041cm" draw:z-index="0">
+    <draw:text-box>
+     <text:p text:style-name="Frame_20_contents"/>
+    </draw:text-box>
+   </draw:frame><draw:frame draw:style-name="fr3" draw:name="ES_ADRESSFELD" 
text:anchor-type="page" text:anchor-page-number="1" svg:x="2cm" svg:y="6.549cm" 
svg:width="8.5cm" svg:height="2.799cm" draw:z-index="1">
+    <draw:text-box>
+     <text:p text:style-name="P5"/>
+    </draw:text-box>
+   </draw:frame><draw:frame draw:style-name="fr4" draw:name="Absender" 
text:anchor-type="page" text:anchor-page-number="1" svg:x="2cm" svg:y="4.3cm" 
svg:width="8.5cm" svg:height="0.651cm" draw:z-index="2">
+    <draw:text-box>
+     <text:p text:style-name="TVS_20_Absender"><text:user-field-get 
text:name="RF_POSTADR1"/><text:line-break/><text:user-field-get 
text:name="RF_POSTADR2"/></text:p>
+    </draw:text-box>
+   </draw:frame><draw:frame draw:style-name="fr5" draw:name="Mehrfertigung" 
text:anchor-type="page" text:anchor-page-number="1" svg:x="10.901cm" 
svg:y="4.3cm" svg:width="8.4cm" svg:height="0.55cm" draw:z-index="3">
+    <draw:text-box>
+     <text:p text:style-name="TVS_20_Mehrfertigung"><text:user-field-get 
text:name="IF_MEHRFERTIGUNG"/></text:p>
+    </draw:text-box>
+   </draw:frame><draw:frame draw:style-name="fr6" 
draw:name="ES_ADRESSFELD_FA00" text:anchor-type="page" 
text:anchor-page-number="3" svg:x="2.221cm" svg:y="4.484cm" svg:width="7.878cm" 
draw:z-index="4">
+    <draw:text-box fo:min-height="3.701cm">
+     <text:p text:style-name="P7">Second box</text:p>
+    </draw:text-box>
+   </draw:frame><draw:frame draw:style-name="fr6" draw:name="Absender_Stpfl" 
text:anchor-type="page" text:anchor-page-number="3" svg:x="11.312cm" 
svg:y="4.228cm" svg:width="7.828cm" draw:z-index="5">
+    <draw:text-box fo:min-height="3.62cm">
+     <text:p text:style-name="P7">Third box</text:p>
+    </draw:text-box>
+   </draw:frame><draw:frame draw:style-name="fr7" draw:name="Kopf_Fragebogen" 
text:anchor-type="page" text:anchor-page-number="3" svg:x="2.17cm" 
svg:y="1.36cm" svg:width="16.574cm" draw:z-index="6">
+    <draw:text-box fo:min-height="1.353cm">
+     <table:table table:name="Tabelle1" table:style-name="Tabelle1">
+      <table:table-column table:style-name="Tabelle1.A"/>
+      <table:table-header-rows>
+       <table:table-row>
+        <table:table-cell table:style-name="Tabelle1.A1" 
office:value-type="string">
+         <text:p text:style-name="P2">Something</text:p>
+        </table:table-cell>
+       </table:table-row>
+      </table:table-header-rows>
+      <table:table-row>
+       <table:table-cell table:style-name="Tabelle1.A1" 
office:value-type="string">
+        <text:p text:style-name="P3">Important here</text:p>
+       </table:table-cell>
+      </table:table-row>
+     </table:table>
+     <text:p text:style-name="P1"/>
+    </draw:text-box>
+   </draw:frame>
+   <text:section text:style-name="Sect1" text:name="CopyA">
+    <text:p text:style-name="P9"><text:user-field-get 
text:name="ES_BRIEFANREDE"/></text:p>
+    <text:p text:style-name="TVS_20_Freitext"/>
+    <text:p text:style-name="TVS_20_Freitext"/>
+    <text:p text:style-name="TVS_20_Freitext"/>
+    <text:p text:style-name="TVS_20_Freitext"/>
+    <text:p text:style-name="P6">Lorem ipsum dolor sit amet, consectetur 
adipiscing elit. Vestibulum consequat mi quis pretium semper. Proin luctus orci 
ac neque venenatis, quis commodo dolor posuere. Curabitur dignissim sapien quis 
cursus egestas. Donec blandit auctor arcu, nec pellentesque eros molestie eget. 
In consectetur aliquam hendrerit. Sed cursus mauris vitae ligula pellentesque, 
non pellentesque urna aliquet. Fusce placerat mauris enim, nec rutrum purus 
semper vel. Praesent tincidunt neque eu pellentesque pharetra. Fusce 
pellentesque est orci.</text:p>
+    <text:p text:style-name="P6">Integer sodales tincidunt tristique. Sed a 
metus posuere, adipiscing nunc et, viverra odio. Donec auctor molestie sem, sit 
amet tristique lectus hendrerit sed. Cras sodales nisl sed orci mattis iaculis. 
Nunc eget dolor accumsan, pharetra risus a, vestibulum mauris. Nunc vulputate 
lobortis mollis. Vivamus nec tellus faucibus, tempor magna nec, facilisis 
felis. Donec commodo enim a vehicula pellentesque. Nullam vehicula vestibulum 
est vel ultricies.</text:p>
+    <text:p text:style-name="P6">Aliquam velit massa, laoreet vel leo nec, 
volutpat facilisis eros. Donec consequat arcu ut diam tempor luctus. Cum sociis 
natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. 
Praesent vitae lacus vel leo sodales pharetra a a nibh. Vestibulum ante ipsum 
primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nam luctus 
tempus nibh, fringilla dictum augue consectetur eget. Curabitur at ante sit 
amet tortor pharetra molestie eu nec ante. Mauris tincidunt, nibh eu 
sollicitudin molestie, dolor sapien congue tortor, a pulvinar sapien turpis sed 
ante. Donec nec est elementum, euismod nulla in, mollis nunc.</text:p>
+    <text:p 
text:style-name="TVS_20_Unsichtbar"><text:soft-page-break/><text:user-field-get 
text:name="IF_AUSBL_DSGVO"/><text:hidden-paragraph 
text:condition="ooow:IF_AUSBL_DSGVO eq &quot;1&quot;"/></text:p>
+   </text:section>
+   <text:p text:style-name="P4">Second page</text:p>
+   <text:section text:style-name="Sect1" text:name="CopyB">
+    <text:p text:style-name="P8">Page 3</text:p>
+   </text:section>
+  </office:text>
+ </office:body>
+</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 9f25b8506b29..5860cba7b4fb 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -108,6 +108,18 @@ void SwLayoutWriter::CheckRedlineFootnotesHidden()
     assertXPath(pXmlDoc, "/root/page[1]/ftncont/ftn[2]/txt[1]/Text[1]", 
"Portion", "mo");
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf156077)
+{
+    createDoc("s4_min2.fodt");
+
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Number of pages does not match!", 3, 
getPages());
+    xmlDocPtr pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, "/root/page[1]/anchored/fly", 3);
+    assertXPath(pXmlDoc, "/root/page[2]/anchored/fly", 1);
+    // this was 0, the at-page anchored flys were not displayed
+    assertXPath(pXmlDoc, "/root/page[3]/anchored/fly", 3);
+}
+
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testRedlineFootnotes)
 {
     createDoc("redline_footnotes.odt");
diff --git a/sw/source/core/layout/newfrm.cxx b/sw/source/core/layout/newfrm.cxx
index 1d1f4597fcf2..39ea1c9c2bc0 100644
--- a/sw/source/core/layout/newfrm.cxx
+++ b/sw/source/core/layout/newfrm.cxx
@@ -502,6 +502,11 @@ void SwRootFrame::Init( SwFrameFormat* pFormat )
     ::InsertCnt_( pLay, pDoc, aTmp.GetIndex(), true );
     //Remove masters that haven't been replaced yet from the list.
     RemoveMasterObjs( mpDrawPage );
+
+    // tdf#156077 create all pages for at-page anchored flys now because all
+    // these flys must be attached to some page when Init() is finished
+    AssertFlyPages();
+
     if( rSettingAccess.get(DocumentSettingId::GLOBAL_DOCUMENT) )
         rFieldsAccess.UpdateRefFields();
     //b6433357: Update page fields after loading
commit 7e985c49d2d948691b29f819e9d9bebdd669922e
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Thu Jun 1 20:19:36 2023 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Mon Jul 17 11:52:16 2023 +0200

    tdf#152983 sw: layout: fix crash in SwContentFrame::Cut()
    
    Surprisingly, SwContentFrame::Cut() is called in a situation where the
    frame is not connected to any SwPageFrame yet - it is in a follow fly of
    a fly chain that is anchored in a footer, and SwFlyFrame::ChainFrames()
    removes it.
    
    (regression from commit b9ef71476fd70bc13f50ebe80390e0730d1b7afb)
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152510
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit d3b64de9581bd5e36ced007ff2e9139bd0343a35)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152533
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    (cherry picked from commit ce863cf085e093e7385818a7d6d598a161e33a28)
    
    Change-Id: Iad84b7b422126e050493dc3b181d47c4dca2fae2

diff --git a/sw/qa/extras/layout/data/tdf152983-1-min.docx 
b/sw/qa/extras/layout/data/tdf152983-1-min.docx
new file mode 100644
index 000000000000..804e8fefe68f
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf152983-1-min.docx 
differ
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 5e2ae77f8f50..9f25b8506b29 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -829,6 +829,12 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, TestTdf150606)
 }
 #endif
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter, TestTdf152983)
+{
+    //just care it doesn't crash/assert
+    createDoc("tdf152983-1-min.docx");
+}
+
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testRedlineFlysInFootnote)
 {
     loadURL("private:factory/swriter", nullptr);
diff --git a/sw/source/core/layout/wsfrm.cxx b/sw/source/core/layout/wsfrm.cxx
index e92fb0391f74..14aa081621f1 100644
--- a/sw/source/core/layout/wsfrm.cxx
+++ b/sw/source/core/layout/wsfrm.cxx
@@ -1204,10 +1204,11 @@ void SwContentFrame::Cut()
                 // RemoveSuperfluous can only remove empty pages at the end;
                 // find if there are pages without content following pPage
                 // and if so request a call to CheckPageDescs()
-                SwPageFrame const* pNext(pPage);
                 SwViewShell *pSh = pRoot->GetCurrShell();
-                if (pSh && pSh->Imp()->IsAction())
+                // tdf#152983 pPage is null when called from SwHeadFootFrame 
ctor
+                if (pPage && pSh && pSh->Imp()->IsAction())
                 {
+                    SwPageFrame const* pNext(pPage);
                     while ((pNext = static_cast<SwPageFrame 
const*>(pNext->GetNext())))
                     {
                         if (!sw::IsPageFrameEmpty(*pNext) && 
!pNext->IsFootnotePage())
commit 635fbb4d2958730c0f3ae2bd525bc7f06fea6f73
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Tue Jul 5 16:47:10 2022 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Mon Jul 17 11:52:16 2023 +0200

    sw: fix null derefs of GetCurrShell()
    
    See 
https://crashreport.libreoffice.org/stats/signature/SwContentFrame::Cut()
    
    Change-Id: I00267b480d9c123f68996572d2e6fdebc4fb383f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136834
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    (cherry picked from commit f5ca3291e4f2c25fbff49301d6f3a7ed0017a708)

diff --git a/sw/source/core/layout/wsfrm.cxx b/sw/source/core/layout/wsfrm.cxx
index d1a54738812b..e92fb0391f74 100644
--- a/sw/source/core/layout/wsfrm.cxx
+++ b/sw/source/core/layout/wsfrm.cxx
@@ -1205,13 +1205,14 @@ void SwContentFrame::Cut()
                 // find if there are pages without content following pPage
                 // and if so request a call to CheckPageDescs()
                 SwPageFrame const* pNext(pPage);
-                if (pRoot->GetCurrShell()->Imp()->IsAction())
+                SwViewShell *pSh = pRoot->GetCurrShell();
+                if (pSh && pSh->Imp()->IsAction())
                 {
                     while ((pNext = static_cast<SwPageFrame 
const*>(pNext->GetNext())))
                     {
                         if (!sw::IsPageFrameEmpty(*pNext) && 
!pNext->IsFootnotePage())
                         {
-                            
pRoot->GetCurrShell()->Imp()->GetLayAction().SetCheckPageNum(pPage->GetPhyPageNum());
+                            
pSh->Imp()->GetLayAction().SetCheckPageNum(pPage->GetPhyPageNum());
                             break;
                         }
                     }
commit f243c0fd9a1d9a0885046e43b125daf5b5e269ff
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Thu Jun 1 12:45:20 2023 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Mon Jul 17 11:52:16 2023 +0200

    tdf#150606 sw: layout: leave follow SwTabFrame invalid in columns
    
    With the minimised bugdoc, on Undo, some 12 or so pages are created, and
    the end of the deleted table is shown in the document view.
    
    So first the last pages are layouted, and then once those are done
    layout proceeds from page 1.
    
    The problem is that on page 9, a table remains in the 2nd column of the
    section, and there is nothing in the 1st column and on pages 5-8.
    
    This is because ::CalcContent() is the last thing that formats the table
    on page 9, and it explicitly disables MoveBwd() for follow tables via
    m_bLockBackMove.
    
    That appears to be intentional but because it's already been there since
    initial CVS import it's unclear why; it might be based on the assumption
    that a previous column would have moved over rows from the follow table
    already.
    
    Try to encourage the table to try to MoveBwd() at a later time, when
    it's being formatted from the SwLayAction::FormatContent_() loop, which
    appears to help.
    
    (somehow regression from commit 723728cd358693b8f4bc9d913541aa4479f2bd48)
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152485
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit 5a739d98d0efa5be2130b7d758d494012abc87b3)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152446
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    (cherry picked from commit 560b94971b656914d17c9d1befdad2dbd3f1119a)
    
    Change-Id: I421525269948aa58888f5302e6db234c89230f00

diff --git a/sw/qa/extras/layout/data/tdf150606-1-min.odt 
b/sw/qa/extras/layout/data/tdf150606-1-min.odt
new file mode 100644
index 000000000000..63bd1ceb0a5b
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf150606-1-min.odt differ
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 0ab6e13debc0..5e2ae77f8f50 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -761,6 +761,74 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, 
testRedlineFlysInHeader)
     }
 }
 
+#if !defined(MACOSX)
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter, TestTdf150606)
+{
+    createDoc("tdf150606-1-min.odt");
+
+    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    CPPUNIT_ASSERT(pTextDoc);
+    SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
+
+    xmlDocPtr pXmlDoc = parseLayoutDump();
+
+    assertXPath(pXmlDoc, "/root/page[1]/body/section/column[1]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[1]/body/section/column[2]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[1]/body/section/column", 2);
+    assertXPath(pXmlDoc, "/root/page[2]/body/section/column[1]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[2]/body/section/column[2]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[2]/body/section/column", 2);
+    assertXPath(pXmlDoc, "/root/page[3]/body/section/column[1]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[3]/body/section/column[2]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[3]/body/section/column", 2);
+    assertXPath(pXmlDoc, "/root/page[4]/body/section/column[1]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[4]/body/section/column[2]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[4]/body/section/column", 2);
+    // on page 5 the table is split across balanced columns
+    assertXPath(pXmlDoc, "/root/page[5]/body/section/column[1]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[5]/body/section/column[2]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[5]/body/section/column", 2);
+    CPPUNIT_ASSERT_GREATEREQUAL(5, getPages());
+    CPPUNIT_ASSERT_LESSEQUAL(6, getPages());
+
+    pWrtShell->Down(false, 1);
+    lcl_dispatchCommand(mxComponent, ".uno:DeleteTable", {});
+
+    discardDumpedLayout();
+    pXmlDoc = parseLayoutDump();
+
+    assertXPath(pXmlDoc, "/root/page[1]/body/section/column/body/tab", 0);
+    assertXPath(pXmlDoc, "/root/page", 1);
+
+    pWrtShell->Undo();
+    Scheduler::ProcessEventsToIdle();
+
+    discardDumpedLayout();
+    pXmlDoc = parseLayoutDump();
+
+    assertXPath(pXmlDoc, "/root/page[1]/body/section/column[1]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[1]/body/section/column[2]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[1]/body/section/column", 2);
+    assertXPath(pXmlDoc, "/root/page[2]/body/section/column[1]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[2]/body/section/column[2]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[2]/body/section/column", 2);
+    assertXPath(pXmlDoc, "/root/page[3]/body/section/column[1]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[3]/body/section/column[2]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[3]/body/section/column", 2);
+    assertXPath(pXmlDoc, "/root/page[4]/body/section/column[1]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[4]/body/section/column[2]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[4]/body/section/column", 2);
+    // on page 5 the table is split across balanced columns
+    // (problem was that there were empty pages and table was on page 10)
+    assertXPath(pXmlDoc, "/root/page[5]/body/section/column[1]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[5]/body/section/column[2]/body/tab", 1);
+    assertXPath(pXmlDoc, "/root/page[5]/body/section/column", 2);
+    // somehow may be 6 pages on WNT on this branch - still better than 10
+    CPPUNIT_ASSERT_GREATEREQUAL(5, getPages());
+    CPPUNIT_ASSERT_LESSEQUAL(6, getPages());
+}
+#endif
+
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testRedlineFlysInFootnote)
 {
     loadURL("private:factory/swriter", nullptr);
diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx
index 23c815c3c994..6cdec269c2d9 100644
--- a/sw/source/core/layout/fly.cxx
+++ b/sw/source/core/layout/fly.cxx
@@ -1659,8 +1659,12 @@ void CalcContent( SwLayoutFrame *pLay, bool bNoColl )
             }
             if ( pFrame->IsTabFrame() )
             {
-                if ( static_cast<SwTabFrame*>(pFrame)->IsFollow() )
+                if (static_cast<SwTabFrame*>(pFrame)->m_bLockBackMove)
+                {
+                    assert(static_cast<SwTabFrame*>(pFrame)->IsFollow());
                     static_cast<SwTabFrame*>(pFrame)->m_bLockBackMove = false;
+                    pFrame->InvalidatePos();
+                }
             }
 
             pFrame = bPrevInvalid ? pTmpPrev : pFrame->FindNext();
commit da589225f747a1b0463084889e30c1a86ba78865
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Thu May 11 19:01:53 2023 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Fri Jul 14 17:32:53 2023 +0200

    tdf#144494 sw: fix layout loop
    
    There is a pre-existing loop here, where page 1 is layouted, the text
    frame splits due to the fly taking up space, page 2 is layouted, the fly
    moves to page 2 (invalidating page 1) and thus the text frame splits
    again, page 1 is layouted, happy to see all the free space, and joins all
    its follows.
    
    Previously this was eventually terminated by layact.cxx:639 calling
    SwLayouter::LoopControl() and this force-validates page 1, resulting in
    page 1 having the fly (which is actually anchored at the end of the text
    frame, on page 2).
    
    Now the CheckPageDescs() discovers that page 3 doesn't have any content,
    and deletes it; this causes it to be re-created on every iteration of
    the loop and somehow the SwLayouter now doesn't detect the loop.
    
    But the call that deletes the page 3 is actually unnecessary: the text
    frame does have a SwPageDescItem - but it is itself a follow, where
    break items doesn't matter anyway - so just check for this to get back
    to the previous layout result.
    
    (regression from commit b9ef71476fd70bc13f50ebe80390e0730d1b7afb)
    
    Change-Id: If15c31278bd36e51c64090a288e8bd1ab6753dd7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151680
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit ac9500105cc72d84ce120fd1dc125329aadb63a0)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151618
    Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com>
    (cherry picked from commit 5af29292af4564357b18610467d69ac35ad8271c)

diff --git a/sw/source/core/layout/flowfrm.cxx 
b/sw/source/core/layout/flowfrm.cxx
index d416b637c02f..2aaa2e2360fb 100644
--- a/sw/source/core/layout/flowfrm.cxx
+++ b/sw/source/core/layout/flowfrm.cxx
@@ -2034,7 +2034,7 @@ bool SwFlowFrame::MoveFwd( bool bMakePage, bool 
bPageBreak, bool bMoveAlways )
             // #i106452#
             // check page description not only in situation with sections.
             if ( !bSamePage &&
-                 ( m_rThis.GetPageDescItem().GetPageDesc() ||
+                 ((!IsFollow() && m_rThis.GetPageDescItem().GetPageDesc()) ||
                    pOldPage->GetPageDesc()->GetFollow() != 
pNewPage->GetPageDesc() ) )
             {
                 SwFrame::CheckPageDescs( pNewPage, false );

Reply via email to