sw/qa/extras/ww8import/data/tdf99100.doc |binary sw/qa/extras/ww8import/ww8import.cxx | 9 ++++++ sw/source/filter/ww8/ww8par.hxx | 2 + sw/source/filter/ww8/ww8par5.cxx | 42 +++++++++++++++++++++++++++++-- 4 files changed, 51 insertions(+), 2 deletions(-)
New commits: commit d635b351849b8b576c907abf22500d0fa89ab54f Author: Miklos Vajna <vmik...@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. Change-Id: Icfa8c4be6538da5e02e2d5071af30a46ccfa712b 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/ww8import.cxx b/sw/qa/extras/ww8import/ww8import.cxx index 56fdf30..689cd86 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 1cda9e6..72f453b 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 555b07a..5e8bccc 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; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits