summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-04-06 08:34:28 +0200
committerAndras Timar <andras.timar@collabora.com>2016-04-10 21:23:43 +0200
commit08c0afe3efb776b28316423b3654f8879039f67e (patch)
treec9cb09ee0a22b64e8da0e99a4435da4db6c1c707 /sw
parent3fb4e30f6bf0f14172f8a97b463fbb3735f21fb6 (diff)
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) Conflicts: sw/source/filter/ww8/ww8par5.cxx Change-Id: Icfa8c4be6538da5e02e2d5071af30a46ccfa712b Reviewed-on: https://gerrit.libreoffice.org/23889 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Andras Timar <andras.timar@collabora.com> (cherry picked from commit f47143222ab5bacc48bc9a61b9d247e4a062fe9e)
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/pagedesc.hxx1
-rw-r--r--sw/qa/extras/ww8import/data/tdf99100.docbin0 -> 22528 bytes
-rw-r--r--sw/qa/extras/ww8import/data/tdf99120.docbin0 -> 23040 bytes
-rw-r--r--sw/qa/extras/ww8import/ww8import.cxx18
-rw-r--r--sw/source/filter/ww8/ww8par.cxx3
-rw-r--r--sw/source/filter/ww8/ww8par.hxx2
-rw-r--r--sw/source/filter/ww8/ww8par5.cxx42
7 files changed, 63 insertions, 3 deletions
diff --git a/sw/inc/pagedesc.hxx b/sw/inc/pagedesc.hxx
index 5bdb73884dbf..50fcb7f02c12 100644
--- a/sw/inc/pagedesc.hxx
+++ b/sw/inc/pagedesc.hxx
@@ -186,6 +186,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 000000000000..6352ae3559a3
--- /dev/null
+++ b/sw/qa/extras/ww8import/data/tdf99100.doc
Binary files differ
diff --git a/sw/qa/extras/ww8import/data/tdf99120.doc b/sw/qa/extras/ww8import/data/tdf99120.doc
new file mode 100644
index 000000000000..a93721c573a7
--- /dev/null
+++ b/sw/qa/extras/ww8import/data/tdf99120.doc
Binary files differ
diff --git a/sw/qa/extras/ww8import/ww8import.cxx b/sw/qa/extras/ww8import/ww8import.cxx
index 3a0860d8b30a..37bb2c28dab0 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 f43130542111..59ff292450e1 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -4527,7 +4527,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 072391224f97..e2c7e38424ca 100644
--- a/sw/source/filter/ww8/ww8par.hxx
+++ b/sw/source/filter/ww8/ww8par.hxx
@@ -1858,6 +1858,8 @@ public: // eigentlich private, geht aber leider nur 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 0d62c9a106ed..0d0897dde267 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)
0,
&SwWW8ImplReader::Read_F_Tox, // 8
0,
- 0,
+ &SwWW8ImplReader::Read_F_Styleref, // 10
0,
&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;