[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - sw/inc sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Thu Apr 7 09:34:28 UTC 2016


 sw/inc/pagedesc.hxx                      |    1 
 sw/qa/extras/ww8import/data/tdf99100.doc |binary
 sw/qa/extras/ww8import/data/tdf99120.doc |binary
 sw/qa/extras/ww8import/ww8import.cxx     |   18 +++++++++++++
 sw/source/filter/ww8/ww8par.cxx          |    3 +-
 sw/source/filter/ww8/ww8par.hxx          |    2 +
 sw/source/filter/ww8/ww8par5.cxx         |   42 +++++++++++++++++++++++++++++--
 7 files changed, 63 insertions(+), 3 deletions(-)

New commits:
commit c945d4166087e09798d812a466a85d424482e08b
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Apr 6 08:34:28 2016 +0200

    tdf#99100 DOC import: handle subset of STYLEREF natively
    
    Commit 4215bca95511af8e4ee96e3c8f521b35f638aef3 (export 'Chapter' field
    type as 'StyleRef' into .doc, 2015-08-21) mapped SwChapterField to
    STYLEREF in the DOC export. This field type was handled as a field mark
    on import. Instead of always handling it as a field mark, recognize the
    case when it's the subset we write and we can handle natively, and in
    that case create an SwChapterField again on import.
    
    Leave the complex case unchanged as before and keep using field marks
    for that.
    
    Also (because the header where STYLEREF is used is completely empty
    otherwise):
    
    tdf#99120 DOC import: fix lack of first share after odd section break
    
    Commit 848b1a05c5c41b5e7ff19c984f60c297a8143990 (fix for bnc#659631,
    2011-02-04) made wwSectionManager::InsertSegments() use
    SwPageDesc::WriteUseOn() directly, instead of going via
    SwPageDesc::SetUseOn() that takes care of not throwing away the higher
    share bits of the bitfield. This way the "is first shared" flag of the
    bitfield got cleared, even when the input document had no title page
    declared, so first header/footer must be shared.
    
    Fix the problem by using SetUseOn() in the DOC import as well when it
    comes to handling odd/even page section breaks.
    
    (cherry picked from commits d635b351849b8b576c907abf22500d0fa89ab54f and
    44a3eb37cd982c59f8350d53db3798b675230b35)
    
    Change-Id: Icfa8c4be6538da5e02e2d5071af30a46ccfa712b
    Reviewed-on: https://gerrit.libreoffice.org/23888
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Andras Timar <andras.timar at collabora.com>

diff --git a/sw/inc/pagedesc.hxx b/sw/inc/pagedesc.hxx
index db943eb..74551aa 100644
--- a/sw/inc/pagedesc.hxx
+++ b/sw/inc/pagedesc.hxx
@@ -189,6 +189,7 @@ public:
     bool IsHidden() const { return m_IsHidden; }
     void SetHidden(bool const bValue) { m_IsHidden = bValue; }
 
+    /// Same as WriteUseOn(), but the >= PD_HEADERSHARE part of the bitfield is not modified.
     inline void      SetUseOn( UseOnPage eNew );
     inline UseOnPage GetUseOn() const;
 
diff --git a/sw/qa/extras/ww8import/data/tdf99100.doc b/sw/qa/extras/ww8import/data/tdf99100.doc
new file mode 100644
index 0000000..6352ae3
Binary files /dev/null and b/sw/qa/extras/ww8import/data/tdf99100.doc differ
diff --git a/sw/qa/extras/ww8import/data/tdf99120.doc b/sw/qa/extras/ww8import/data/tdf99120.doc
new file mode 100644
index 0000000..a93721c
Binary files /dev/null and b/sw/qa/extras/ww8import/data/tdf99120.doc differ
diff --git a/sw/qa/extras/ww8import/ww8import.cxx b/sw/qa/extras/ww8import/ww8import.cxx
index 7e9307b..1df4a6c 100644
--- a/sw/qa/extras/ww8import/ww8import.cxx
+++ b/sw/qa/extras/ww8import/ww8import.cxx
@@ -535,6 +535,24 @@ DECLARE_WW8IMPORT_TEST(testfdo68963, "fdo68963.doc")
     CPPUNIT_ASSERT ( -1 == parseDump("/root/page/body/txt[24]/Special[2]","rText").indexOf("Reference source not found"));
 }
 
+DECLARE_WW8IMPORT_TEST(testTdf99100, "tdf99100.doc")
+{
+    uno::Reference<text::XText> xHeaderText = getProperty< uno::Reference<text::XText> >(getStyles("PageStyles")->getByName("Standard"), "HeaderText");
+    auto xField = getProperty< uno::Reference<lang::XServiceInfo> >(getRun(getParagraphOfText(1, xHeaderText), 2), "TextField");
+    // This failed: the second text portion wasn't a field.
+    CPPUNIT_ASSERT(xField.is());
+    CPPUNIT_ASSERT(xField->supportsService("com.sun.star.text.textfield.Chapter"));
+}
+
+DECLARE_WW8IMPORT_TEST(testTdf99120, "tdf99120.doc")
+{
+    CPPUNIT_ASSERT_EQUAL(OUString("Section 1, odd."),  parseDump("/root/page[1]/header/txt/text()"));
+    CPPUNIT_ASSERT_EQUAL(OUString("Section 1, even."),  parseDump("/root/page[2]/header/txt/text()"));
+    // This failed: the header was empty on the 3rd page, as the first page header was shown.
+    CPPUNIT_ASSERT_EQUAL(OUString("Section 2, odd."),  parseDump("/root/page[3]/header/txt/text()"));
+    CPPUNIT_ASSERT_EQUAL(OUString("Section 2, even."),  parseDump("/root/page[4]/header/txt/text()"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 95e6424..ee072bf 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -4526,7 +4526,8 @@ void wwSectionManager::InsertSegments()
                 if ( aIter->maSep.bkc == 4 ) // Odd ( right ) Section break
                     eUseOnPage = nsUseOnPage::PD_RIGHT;
 
-                aDesc.GetPageDesc()->WriteUseOn( eUseOnPage );
+                // Keep the share flags.
+                aDesc.GetPageDesc()->SetUseOn( eUseOnPage );
                 aDesc.GetPageDesc()->SetFollow( aFollow.GetPageDesc() );
             }
 
diff --git a/sw/source/filter/ww8/ww8par.hxx b/sw/source/filter/ww8/ww8par.hxx
index 0d2fb99..3ae9353 100644
--- a/sw/source/filter/ww8/ww8par.hxx
+++ b/sw/source/filter/ww8/ww8par.hxx
@@ -1853,6 +1853,8 @@ public:     // really private, but can only be done public
     eF_ResT Read_F_IncludePicture( WW8FieldDesc*, OUString& rStr );
     eF_ResT Read_F_IncludeText(    WW8FieldDesc*, OUString& rStr );
     eF_ResT Read_F_Seq( WW8FieldDesc*, OUString& rStr );
+    /// Reads a STYLEREF field.
+    eF_ResT Read_F_Styleref(WW8FieldDesc*, OUString& rStr);
 
     eF_ResT Read_F_OCX(WW8FieldDesc*, OUString&);
     eF_ResT Read_F_Hyperlink(WW8FieldDesc*, OUString& rStr);
diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx
index 77960c9..b31c871 100644
--- a/sw/source/filter/ww8/ww8par5.cxx
+++ b/sw/source/filter/ww8/ww8par5.cxx
@@ -723,7 +723,7 @@ long SwWW8ImplReader::Read_Field(WW8PLCFManResult* pRes)
         nullptr,
         &SwWW8ImplReader::Read_F_Tox,               // 8
         nullptr,
-        nullptr,
+        &SwWW8ImplReader::Read_F_Styleref,          // 10
         nullptr,
         &SwWW8ImplReader::Read_F_Seq,               // 12
         &SwWW8ImplReader::Read_F_Tox,               // 13
@@ -875,8 +875,25 @@ long SwWW8ImplReader::Read_Field(WW8PLCFManResult* pRes)
     if (aF.nId != 88 && m_pPlcxMan->GetDoingDrawTextBox())
         return aF.nLen;
 
+    bool bHasHandler = aWW8FieldTab[aF.nId] != nullptr;
+    if (aF.nId == ww::eSTYLEREF)
+    {
+        // STYLEREF, by default these are not handled.
+        bHasHandler = false;
+        sal_uInt64 nOldPos = m_pStrm->Tell();
+        OUString aStr;
+        aF.nLCode = m_pSBase->WW8ReadString(*m_pStrm, aStr, m_pPlcxMan->GetCpOfs() + aF.nSCode, aF.nLCode, m_eTextCharSet);
+        m_pStrm->Seek(nOldPos);
+
+        WW8ReadFieldParams aReadParam(aStr);
+        sal_Int32 nRet = aReadParam.SkipToNextToken();
+        if (nRet == -2 && !aReadParam.GetResult().isEmpty())
+            // Single numeric argument: this can be handled by SwChapterField.
+            bHasHandler = rtl::isAsciiDigit(aReadParam.GetResult()[0]);
+    }
+
     // keine Routine vorhanden
-    if (bNested || !aWW8FieldTab[aF.nId] || bCodeNest)
+    if (bNested || !bHasHandler || bCodeNest)
     {
         if( m_nFieldTagBad[nI] & nMask )      // Flag: Tag it when bad
             return Read_F_Tag( &aF );       // Resultat nicht als Text
@@ -1415,6 +1432,27 @@ eF_ResT SwWW8ImplReader::Read_F_Seq( WW8FieldDesc*, OUString& rStr )
     return FLD_OK;
 }
 
+eF_ResT SwWW8ImplReader::Read_F_Styleref(WW8FieldDesc*, OUString& rString)
+{
+    WW8ReadFieldParams aReadParam(rString);
+    sal_Int32 nRet = aReadParam.SkipToNextToken();
+    if (nRet != -2)
+        // \param was found, not normal text.
+        return FLD_TAGIGN;
+
+    OUString aResult = aReadParam.GetResult();
+    sal_Int32 nResult = aResult.toInt32();
+    if (nResult < 1)
+        return FLD_TAGIGN;
+
+    SwFieldType* pFieldType = m_rDoc.getIDocumentFieldsAccess().GetSysFieldType(RES_CHAPTERFLD);
+    SwChapterField aField(static_cast<SwChapterFieldType*>(pFieldType), CF_TITLE);
+    aField.SetLevel(nResult - 1);
+    m_rDoc.getIDocumentContentOperations().InsertPoolItem(*m_pPaM, SwFormatField(aField));
+
+    return FLD_OK;
+}
+
 eF_ResT SwWW8ImplReader::Read_F_DocInfo( WW8FieldDesc* pF, OUString& rStr )
 {
     sal_uInt16 nSub=0;


More information about the Libreoffice-commits mailing list