Kaydet (Commit) d635b351 authored tarafından Miklos Vajna's avatar Miklos Vajna

tdf#99100 DOC import: handle subset of STYLEREF natively

Commit 4215bca9 (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
üst 9351353b
This diff was suppressed by a .gitattributes entry.
......@@ -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: */
......@@ -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);
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment