summaryrefslogtreecommitdiff
path: root/sw/source/filter/ww8
diff options
context:
space:
mode:
Diffstat (limited to 'sw/source/filter/ww8')
-rw-r--r--sw/source/filter/ww8/wrtww8.hxx3
-rw-r--r--sw/source/filter/ww8/ww8atr.cxx87
-rw-r--r--sw/source/filter/ww8/ww8par5.cxx15
3 files changed, 76 insertions, 29 deletions
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index 7f20ed491bc2..c30f0a257286 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -642,6 +642,9 @@ public:
/// Find the bookmark name.
OUString GetBookmarkName( sal_uInt16 nTyp, const OUString* pName, sal_uInt16 nSeqNo );
+ /// Find out which style we should use in OOXML
+ OUString GetStyleRefName(const OUString& rName);
+
/// Use OutputItem() on an item set according to the parameters.
void OutputItemSet( const SfxItemSet& rSet, bool bPapFormat, bool bChpFormat, sal_uInt16 nScript, bool bExportParentItemSet );
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 9a561c05dac6..0258ae7f303f 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -128,6 +128,7 @@
#include <fmthdft.hxx>
#include <authfld.hxx>
#include <dbfld.hxx>
+#include <docsh.hxx>
#include "sprmids.hxx"
@@ -1045,6 +1046,18 @@ OUString MSWordExportBase::GetBookmarkName( sal_uInt16 nTyp, const OUString* pNa
return BookmarkToWord( sRet ); // #i43956# - encode bookmark accordingly
}
+OUString MSWordExportBase::GetStyleRefName(const OUString& rName)
+{
+ SwTextFormatColls* pTextFormatColls = m_rDoc.GetTextFormatColls();
+ SwTextFormatColl* pTextFormat = pTextFormatColls->FindFormatByName(rName);
+
+ if (pTextFormat == nullptr)
+ return "\"" + rName + "\"";
+ // Didn't find the style, just keep the original name
+
+ return "\"" + m_pStyles->GetStyleWWName(pTextFormat) + "\"";
+}
+
/* File CHRATR.HXX: */
void WW8AttributeOutput::RTLAndCJKState( bool bIsRTL, sal_uInt16 nScript )
{
@@ -3293,26 +3306,45 @@ void AttributeOutputBase::TextField( const SwFormatField& rField )
sStr = FieldString(eField)
+ GetExport().GetBookmarkName(nSubType, nullptr, rRField.GetSeqNo());
break;
+ case REF_STYLE:
+ sStr = FieldString(ww::eSTYLEREF)
+ + GetExport().GetStyleRefName(pField->GetPar1());
+ eField = ww::eSTYLEREF;
+ break;
}
- if (eField != ww::eNONE)
+ OUString sExtraFlags = "\\h "; // by default, include a hyperlink
+
+ switch (eField)
{
- switch (pField->GetFormat())
- {
- case REF_UPDOWN:
- sStr += " \\p \\h "; // with hyperlink
- break;
- case REF_CHAPTER:
- sStr += " \\n \\h "; // with hyperlink
- break;
- default:
- sStr += " \\h "; // insert hyperlink
- break;
- }
- GetExport().OutputField(pField, eField, sStr);
+ case ww::eNONE:
+ bWriteExpand = true;
+ break;
+ case ww::eSTYLEREF:
+ sExtraFlags = ""; // styleref fields do not work if they have a hyperlink
+ [[fallthrough]];
+ default:
+ switch (pField->GetFormat())
+ {
+ case REF_NUMBER:
+ sStr += " \\r " + sExtraFlags;
+ break;
+ case REF_NUMBER_FULL_CONTEXT:
+ sStr += " \\w " + sExtraFlags;
+ break;
+ case REF_UPDOWN:
+ sStr += " \\p " + sExtraFlags;
+ break;
+ case REF_NUMBER_NO_CONTEXT:
+ case REF_CHAPTER:
+ sStr += " \\n " + sExtraFlags;
+ break;
+ default:
+ sStr += " " + sExtraFlags;
+ break;
+ }
+ GetExport().OutputField(pField, eField, sStr);
}
- else
- bWriteExpand = true;
}
break;
case SwFieldIds::CombinedChars:
@@ -3362,7 +3394,8 @@ void AttributeOutputBase::TextField( const SwFormatField& rField )
break;
case SwFieldIds::Chapter:
bWriteExpand = true;
- if (GetExport().m_bOutKF && rField.GetTextField())
+
+ if (rField.GetTextField())
{
const SwTextNode *pTextNd = GetExport().GetHdFtPageRoot();
if (!pTextNd)
@@ -3374,10 +3407,22 @@ void AttributeOutputBase::TextField( const SwFormatField& rField )
{
SwChapterField aCopy(*static_cast<const SwChapterField*>(pField));
aCopy.ChangeExpansion(*pTextNd, false);
- const OUString sStr = FieldString(ww::eSTYLEREF)
- + " "
- + OUString::number(aCopy.GetLevel() + 1)
- + " \\* MERGEFORMAT ";
+
+ OUString sStr;
+ if (GetExport().m_bOutKF) {
+ // In headers and footers, use the chapter number as the style name
+ sStr = FieldString(ww::eSTYLEREF)
+ + " "
+ + OUString::number(aCopy.GetLevel() + 1)
+ + " \\* MERGEFORMAT ";
+ } else {
+ // Otherwise, get the style of the text and use it as the style name
+ const SwTextNode* pOutlineNd = pTextNd->FindOutlineNodeOfLevel(aCopy.GetLevel());
+
+ sStr = FieldString(ww::eSTYLEREF)
+ + GetExport().GetStyleRefName(pOutlineNd->GetFormatColl()->GetName());
+ }
+
GetExport().OutputField(pField, ww::eSTYLEREF, sStr);
bWriteExpand = false;
}
diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx
index 7e7cedd3f4b5..e6dcca3f2cae 100644
--- a/sw/source/filter/ww8/ww8par5.cxx
+++ b/sw/source/filter/ww8/ww8par5.cxx
@@ -953,8 +953,7 @@ tools::Long SwWW8ImplReader::Read_Field(WW8PLCFManResult* pRes)
bool bHasHandler = aWW8FieldTab[aF.nId] != nullptr;
if (aF.nId == 10) // STYLEREF
{
- // STYLEREF, by default these are not handled.
- bHasHandler = false;
+ bool bHandledByChapter = false;
sal_uInt64 nOldPos = m_pStrm->Tell();
OUString aStr;
aF.nLCode = m_xSBase->WW8ReadString(*m_pStrm, aStr, m_xPlcxMan->GetCpOfs() + aF.nSCode, aF.nLCode, m_eTextCharSet);
@@ -964,9 +963,9 @@ tools::Long SwWW8ImplReader::Read_Field(WW8PLCFManResult* pRes)
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]);
+ bHandledByChapter = rtl::isAsciiDigit(aReadParam.GetResult()[0]);
- if (bHasHandler)
+ if (bHandledByChapter)
{
nRet = aReadParam.SkipToNextToken();
// Handle using SwChapterField only in case there is no \[a-z]
@@ -2158,7 +2157,7 @@ eF_ResT SwWW8ImplReader::Read_F_Ref( WW8FieldDesc*, OUString& rStr )
SwGetRefField aField(
static_cast<SwGetRefFieldType*>(m_rDoc.getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::GetRef )),
- sBkmName,"",REF_BOOKMARK,0,eFormat);
+ sBkmName,"",REF_BOOKMARK,0,eFormat,nullptr,nullptr);
if (eFormat == REF_CONTENT)
{
@@ -2214,14 +2213,14 @@ eF_ResT SwWW8ImplReader::Read_F_NoteReference( WW8FieldDesc*, OUString& rStr )
// (will be corrected in
SwGetRefField aField( static_cast<SwGetRefFieldType*>(
m_rDoc.getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::GetRef )), aBkmName, "", REF_FOOTNOTE, 0,
- REF_ONLYNUMBER );
+ REF_ONLYNUMBER, nullptr, nullptr );
m_xReffingStck->NewAttr(*m_pPaM->GetPoint(), SwFormatField(aField));
m_xReffingStck->SetAttr(*m_pPaM->GetPoint(), RES_TXTATR_FIELD);
if (bAboveBelow)
{
SwGetRefField aField2( static_cast<SwGetRefFieldType*>(
m_rDoc.getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::GetRef )),aBkmName, "", REF_FOOTNOTE, 0,
- REF_UPDOWN );
+ REF_UPDOWN, nullptr, nullptr );
m_xReffingStck->NewAttr(*m_pPaM->GetPoint(), SwFormatField(aField2));
m_xReffingStck->SetAttr(*m_pPaM->GetPoint(), RES_TXTATR_FIELD);
}
@@ -2293,7 +2292,7 @@ eF_ResT SwWW8ImplReader::Read_F_PgRef( WW8FieldDesc*, OUString& rStr )
sPageRefBookmarkName = sName;
}
SwGetRefField aField( static_cast<SwGetRefFieldType*>(m_rDoc.getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::GetRef )),
- sPageRefBookmarkName, "", REF_BOOKMARK, 0, REF_PAGE );
+ sPageRefBookmarkName, "", REF_BOOKMARK, 0, REF_PAGE, nullptr, nullptr );
m_rDoc.getIDocumentContentOperations().InsertPoolItem( *m_pPaM, SwFormatField( aField ) );
return eF_ResT::OK;