sw/qa/extras/ooxmlexport/data/fly_fieldmark.fodt |   60 +++++++++++++++++++++++
 sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx    |   12 ++++
 sw/source/filter/ww8/wrtw8nds.cxx                |   23 +++++++-
 sw/source/filter/ww8/wrtww8.hxx                  |    1 
 4 files changed, 92 insertions(+), 4 deletions(-)

New commits:
commit e79c637f291d552bfe8f32ccfc23300c67f51fcc
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Wed Mar 10 11:26:07 2021 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Fri Mar 12 16:14:09 2021 +0100

    sw: DOCX export: put fly before fieldmark start into its own run
    
    If a fly starts at the same position as a CH_TXT_ATR_FIELDSTART, it is
    anchored before the field, and written in OutFlys() before the field is
    written in EndRun(), but the DOCX export reorders things in confusing
    ways.
    
    StartField_Impl() and CmdField_Impl() will actually end the current run
    (after putting the field char in it) and start a new one.
    
    So do something similar in this situation and create a new run if flys
    have been processed.
    
    Restrict this extra run to when there is actually a fly, because
    otherwise a dozen tests break; this requires a new FLY_NONE result for
    OutFlys() because FLY_PROCESSED is returned even if there are no flys.
    
    Change-Id: Id469c53d07eacad3992c7c0e451ab3756e02c8fa
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112267
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit 3eced2d52415abeac266804ab682bee022322a19)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112230
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sw/qa/extras/ooxmlexport/data/fly_fieldmark.fodt 
b/sw/qa/extras/ooxmlexport/data/fly_fieldmark.fodt
new file mode 100644
index 000000000000..af1ae9a86243
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/fly_fieldmark.fodt
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:css3t="http://www.w3.org/TR/css3-text/"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
xmlns:dc="http://purl.org/dc/elements/1.1/"; 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns
 :config:1.0" xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
 xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="ur
 n:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:xforms="http://www.w3.org/2002/xforms"; office:version="1.3" 
office:mimetype="application/vnd.oasis.opendocument.text">
+
+ <office:font-face-decls>
+  <style:font-face style:name="Lohit Devanagari1" svg:font-family="&apos;Lohit 
Devanagari&apos;"/>
+  <style:font-face style:name="Liberation Serif" 
svg:font-family="&apos;Liberation Serif&apos;" 
style:font-family-generic="roman" style:font-pitch="variable"/>
+  <style:font-face style:name="Liberation Sans" 
svg:font-family="&apos;Liberation Sans&apos;" style:font-family-generic="swiss" 
style:font-pitch="variable"/>
+  <style:font-face style:name="Lohit Devanagari" svg:font-family="&apos;Lohit 
Devanagari&apos;" style:font-family-generic="system" 
style:font-pitch="variable"/>
+  <style:font-face style:name="Source Han Sans CN" 
svg:font-family="&apos;Source Han Sans CN&apos;" 
style:font-family-generic="system" style:font-pitch="variable"/>
+  <style:font-face style:name="Source Han Serif CN" 
svg:font-family="&apos;Source Han Serif CN&apos;" 
style:font-family-generic="system" style:font-pitch="variable"/>
+ </office:font-face-decls>
+ <office:styles>
+  <style:default-style style:family="graphic">
+   <style:graphic-properties svg:stroke-color="#3465a4" 
draw:fill-color="#729fcf" 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="false"/>
+   <style:paragraph-properties style:text-autospace="ideograph-alpha" 
style:line-break="strict" style:writing-mode="lr-tb" 
style:font-independent-line-spacing="false">
+    <style:tab-stops/>
+   </style:paragraph-properties>
+   <style:text-properties style:use-window-font-color="true" 
loext:opacity="0%" style:font-name="Liberation Serif" fo:font-size="12pt" 
fo:language="de" fo:country="DE" style:letter-kerning="true" 
style:font-name-asian="Source Han Serif CN" style:font-size-asian="10.5pt" 
style:language-asian="zh" style:country-asian="CN" 
style:font-name-complex="Lohit Devanagari" style:font-size-complex="12pt" 
style:language-complex="hi" style:country-complex="IN"/>
+  </style:default-style>
+  <style:default-style style:family="paragraph">
+   <style:paragraph-properties fo:orphans="2" fo:widows="2" 
fo:hyphenation-ladder-count="no-limit" style:text-autospace="ideograph-alpha" 
style:punctuation-wrap="hanging" style:line-break="strict" 
style:tab-stop-distance="1.251cm" style:writing-mode="page"/>
+   <style:text-properties style:use-window-font-color="true" 
loext:opacity="0%" style:font-name="Liberation Serif" fo:font-size="12pt" 
fo:language="de" fo:country="DE" style:letter-kerning="true" 
style:font-name-asian="Source Han Serif CN" style:font-size-asian="10.5pt" 
style:language-asian="zh" style:country-asian="CN" 
style:font-name-complex="Lohit Devanagari" style:font-size-complex="12pt" 
style:language-complex="hi" style:country-complex="IN" fo:hyphenate="false" 
fo:hyphenation-remain-char-count="2" fo:hyphenation-push-char-count="2" 
loext:hyphenation-no-caps="false"/>
+  </style:default-style>
+  <style:style style:name="Standard" style:family="paragraph" 
style:class="text"/>
+ </office:styles>
+ <office:automatic-styles>
+  <style:style style:name="P1" style:family="paragraph">
+   <style:paragraph-properties fo:text-align="center"/>
+  </style:style>
+  <style:style style:name="gr1" style:family="graphic">
+   <style:graphic-properties draw:textarea-horizontal-align="justify" 
draw:textarea-vertical-align="middle" draw:auto-grow-height="false" 
fo:min-height="1.609cm" fo:min-width="1.609cm" style:run-through="foreground" 
style:wrap="run-through" 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:style>
+  <style:style style:name="gr2" style:family="graphic">
+   <style:graphic-properties draw:textarea-horizontal-align="justify" 
draw:textarea-vertical-align="middle" draw:auto-grow-height="false" 
fo:min-height="2.064cm" fo:min-width="3.44cm" style:run-through="foreground" 
style:wrap="run-through" style:number-wrapped-paragraphs="no-limit" 
style:vertical-pos="from-top" style:vertical-rel="paragraph" 
style:horizontal-pos="from-left" style:horizontal-rel="paragraph"/>
+  </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: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:footnote-max-height="0cm" loext:margin-gutter="0cm">
+    <style:footnote-sep style:width="0.018cm" 
style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" 
style:line-style="solid" style:adjustment="left" style:rel-width="25%" 
style:color="#000000"/>
+   </style:page-layout-properties>
+   <style:header-style/>
+   <style:footer-style/>
+  </style:page-layout>
+ </office:automatic-styles>
+ <office:master-styles>
+  <style:master-page style:name="Standard" style:page-layout-name="pm1"/>
+ </office:master-styles>
+ <office:body>
+  <office:text>
+   <draw:custom-shape text:anchor-type="page" text:anchor-page-number="1" 
draw:z-index="1" draw:name="Shape2" draw:style-name="gr1" 
draw:text-style-name="P1" svg:width="2.276cm" svg:height="2.276cm" 
svg:x="4.752cm" svg:y="2.902cm">
+    <text:p/>
+    <draw:enhanced-geometry svg:viewBox="0 0 21600 21600" 
draw:glue-points="10800 0 3163 3163 0 10800 3163 18437 10800 21600 18437 18437 
21600 10800 18437 3163" draw:text-areas="3163 3163 18437 18437" 
draw:type="ellipse" draw:enhanced-path="U 10800 10800 10800 10800 0 360 Z N"/>
+   </draw:custom-shape>
+   <text:p text:style-name="Standard"><draw:custom-shape 
text:anchor-type="char" draw:z-index="0" draw:name="Shape1" 
draw:style-name="gr2" svg:width="3.44cm" svg:height="2.065cm" svg:x="-1.337cm" 
svg:y="0.912cm">
+     <text:p/>
+     <draw:enhanced-geometry svg:viewBox="0 0 21600 21600" 
draw:type="rectangle" draw:enhanced-path="M 0 0 L 21600 0 21600 21600 0 21600 0 
0 Z N"/>
+    </draw:custom-shape><field:fieldmark-start 
text:name="__Fieldmark__0_1348794289" 
field:type="vnd.oasis.opendocument.field.FORMTEXT"/>foobar<field:fieldmark-end/></text:p>
+  </office:text>
+ </office:body>
+</office:document>
diff --git a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
index 240678318f9a..40f93ab67664 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
@@ -484,6 +484,18 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testEditTime, 
"fdo81341.docx")
     assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r[5]/w:fldChar", 
"fldCharType", "end");
 }
 
+DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testFlyFieldmark, "fly_fieldmark.fodt")
+{
+    // the problem was that the flys were written after the field start
+    xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+    // run 1 contains 2 shapes, one was at-page, one was at-char
+    assertXPath(pXmlDoc, 
"/w:document/w:body/w:p[1]/w:r[1]/mc:AlternateContent", 2);
+    // run 2 contains the field start
+    assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[2]/w:fldChar", 
"fldCharType", "begin");
+    // run 3 contains the field instruction text
+    assertXPathContent(pXmlDoc, 
"/w:document/w:body/w:p[1]/w:r[3]/w:instrText", " FORMTEXT ");
+}
+
 DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testFdo81945, "fdo81945.docx")
 {
     xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx 
b/sw/source/filter/ww8/wrtw8nds.cxx
index 77cdab41e879..1404aff20f3b 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -710,6 +710,11 @@ FlyProcessingState SwWW8AttrIter::OutFlys(sal_Int32 nSwPos)
         ++linkedTextboxesIter;
     }
 
+    if (maFlyIter == maFlyFrames.end())
+    {
+        return FLY_NONE;
+    }
+
     /*
      #i2916#
      May have an anchored graphic to be placed, loop through sorted array
@@ -2341,7 +2346,6 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode )
         do {
 
             const SwRedlineData* pRedlineData = aAttrIter.GetRunLevelRedline( 
nCurrentPos );
-            FlyProcessingState nStateOfFlyFrame = FLY_PROCESSED;
             bool bPostponeWritingText    = false ;
             OUString aSavedSnippet ;
 
@@ -2387,7 +2391,7 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode )
                 bPostponeWritingText = true ;
             }
 
-            nStateOfFlyFrame = aAttrIter.OutFlys( nCurrentPos );
+            FlyProcessingState nStateOfFlyFrame = aAttrIter.OutFlys( 
nCurrentPos );
             AttrOutput().SetStateOfFlyFrame( nStateOfFlyFrame );
             AttrOutput().SetAnchorIsLinkedToNode( bPostponeWritingText && 
(FLY_POSTPONED != nStateOfFlyFrame) );
             // Append bookmarks in this range after flys, exclusive of final
@@ -2415,6 +2419,15 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode 
)
                                     || ch == CH_TXT_ATR_FIELDEND
                                     || ch == CH_TXT_ATR_FORMELEMENT)
                                 ? 1 : 0;
+                if (ofs == 1
+                    && GetExportFormat() == 
MSWordExportBase::ExportFormat::DOCX
+                    // FLY_PROCESSED: there's at least 1 fly already written
+                    && nStateOfFlyFrame == FLY_PROCESSED)
+                {
+                    // write flys in a separate run before field character
+                    AttrOutput().EndRun(&rNode, nCurrentPos, nNextAttr == 
nEnd);
+                    AttrOutput().StartRun(pRedlineData, nCurrentPos, 
bSingleEmptyRun);
+                }
 
                 IDocumentMarkAccess* const pMarkAccess = 
m_rDoc.getIDocumentMarkAccess();
                 if ( ch == CH_TXT_ATR_FIELDSTART )
@@ -2597,7 +2610,8 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode )
                 AttrOutput().FormatDrop( rNode, aAttrIter.GetSwFormatDrop(), 
nStyle, pTextNodeInfo, pTextNodeInfoInner );
 
             // Only output character attributes if this is not a postponed 
text run.
-            if (0 != nEnd && !(bPostponeWritingText && FLY_PROCESSED == 
nStateOfFlyFrame))
+            if (0 != nEnd && !(bPostponeWritingText
+                    && (FLY_PROCESSED == nStateOfFlyFrame || FLY_NONE == 
nStateOfFlyFrame)))
             {
                 // Output the character attributes
                 // #i51277# do this before writing flys at end of paragraph
@@ -2704,7 +2718,8 @@ void MSWordExportBase::OutputTextNode( SwTextNode& rNode )
 
             AttrOutput().WritePostitFieldReference();
 
-            if( bPostponeWritingText && FLY_PROCESSED == nStateOfFlyFrame )
+            if (bPostponeWritingText
+                && (FLY_PROCESSED == nStateOfFlyFrame || FLY_NONE == 
nStateOfFlyFrame))
             {
                 AttrOutput().EndRun(&rNode, nCurrentPos, nNextAttr == nEnd);
                 //write the postponed text run
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index ae1d3dfffd25..1baa627ece71 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -161,6 +161,7 @@ enum to state the present state of the fly
 */
 enum FlyProcessingState
 {
+    FLY_NONE,
     FLY_PROCESSED,
     FLY_POSTPONED,
     FLY_NOT_PROCESSED
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to