diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-04-06 08:34:28 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-04-06 08:34:46 +0200 |
commit | d635b351849b8b576c907abf22500d0fa89ab54f (patch) | |
tree | f3927767eecf4adb533b3aac64653208ba1677d3 | |
parent | 9351353b63886f494782f28f5400f5d71d22bcbd (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.
Change-Id: Icfa8c4be6538da5e02e2d5071af30a46ccfa712b
-rw-r--r-- | sw/qa/extras/ww8import/data/tdf99100.doc | bin | 0 -> 22528 bytes | |||
-rw-r--r-- | sw/qa/extras/ww8import/ww8import.cxx | 9 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par.hxx | 2 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8par5.cxx | 42 |
4 files changed, 51 insertions, 2 deletions
diff --git a/sw/qa/extras/ww8import/data/tdf99100.doc b/sw/qa/extras/ww8import/data/tdf99100.doc Binary files differnew file mode 100644 index 000000000000..6352ae3559a3 --- /dev/null +++ b/sw/qa/extras/ww8import/data/tdf99100.doc diff --git a/sw/qa/extras/ww8import/ww8import.cxx b/sw/qa/extras/ww8import/ww8import.cxx index 56fdf30e1b69..689cd863624b 100644 --- a/sw/qa/extras/ww8import/ww8import.cxx +++ b/sw/qa/extras/ww8import/ww8import.cxx @@ -535,6 +535,15 @@ 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")); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/ww8/ww8par.hxx b/sw/source/filter/ww8/ww8par.hxx index 1cda9e6f01c9..72f453ba91ca 100644 --- a/sw/source/filter/ww8/ww8par.hxx +++ b/sw/source/filter/ww8/ww8par.hxx @@ -1855,6 +1855,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 555b07ab814c..5e8bccc32dba 100644 --- a/sw/source/filter/ww8/ww8par5.cxx +++ b/sw/source/filter/ww8/ww8par5.cxx @@ -742,7 +742,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 @@ -894,8 +894,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 @@ -1434,6 +1451,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; |