sw/qa/core/text/data/placeholder.fodt | 9 + sw/qa/core/text/text.cxx | 28 ++++ sw/source/core/text/itrform2.cxx | 2 sw/source/core/text/porfld.cxx | 69 ++++++++++- sw/source/core/text/porfld.hxx | 24 +++ sw/source/core/text/txtfld.cxx | 210 +++++++++------------------------- 6 files changed, 184 insertions(+), 158 deletions(-)
New commits: commit 9299afbbd6bd264ba90e5e0ac21a700e88f56c0f Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Tue Oct 24 23:20:30 2023 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Wed Oct 25 15:54:59 2023 +0200 Export text placeholder fields as PDF form fields Inspired by commit 82d90529dc2b3cb8359dec78852cbd910a66d275 (sw content controls, rich text: add initial PDF export, 2022-09-12). Change-Id: I16cc45b6f2e070ab9dc83ba15e3c66ca0caa5e53 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158407 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sw/qa/core/text/data/placeholder.fodt b/sw/qa/core/text/data/placeholder.fodt new file mode 100644 index 000000000000..01cb60437618 --- /dev/null +++ b/sw/qa/core/text/data/placeholder.fodt @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:body> + <office:text> + <text:p><text:placeholder text:placeholder-type="text" text:description="reference text"><placeholder text></text:placeholder></text:p> + </office:text> + </office:body> +</office:document> \ No newline at end of file diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx index 8a48b75a03e4..496c14006539 100644 --- a/sw/qa/core/text/text.cxx +++ b/sw/qa/core/text/text.cxx @@ -1174,6 +1174,34 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testRichContentControlPDF) CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationCount()); } +CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testPlaceholderFieldPDF) +{ + std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get(); + if (!pPDFium) + return; + + // Given a file with a text-type placeholder field: + createSwDoc("placeholder.fodt"); + + // When exporting to PDF (default setting is "create a PDF form"): + save("writer_pdf_Export"); + + // Then make sure that a fillable form widget is emitted: + std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument = parsePDFExport(); + std::unique_ptr<vcl::pdf::PDFiumPage> pPage = pPdfDocument->openPage(0); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // i.e. the placeholder field was just exported as normal text. + CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationCount()); + std::unique_ptr<vcl::pdf::PDFiumAnnotation> pAnnotation = pPage->getAnnotation(0); + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Widget, pAnnotation->getSubType()); + + // Also verify that the widget description is correct: + CPPUNIT_ASSERT_EQUAL(OUString("reference text"), + pAnnotation->getFormFieldAlternateName(pPdfDocument.get())); +} + CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testNumberPortionFormat) { // Given a document with a single paragraph, direct formatting asks 24pt font size for the diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx index c3e718871189..b5077e6c775f 100644 --- a/sw/source/core/text/itrform2.cxx +++ b/sw/source/core/text/itrform2.cxx @@ -1182,7 +1182,7 @@ SwTextPortion *SwTextFormatter::WhichTextPor( SwTextFormatInfo &rInf ) const } } assert(2 <= sal_Int32(nFieldLen)); - pPor = new SwFieldPortion(aFieldName, nullptr, false, nFieldLen); + pPor = new SwFieldPortion(aFieldName, nullptr, nFieldLen); } else { diff --git a/sw/source/core/text/porfld.cxx b/sw/source/core/text/porfld.cxx index 66f39644ffed..580b4a2635a7 100644 --- a/sw/source/core/text/porfld.cxx +++ b/sw/source/core/text/porfld.cxx @@ -22,10 +22,14 @@ #include <com/sun/star/i18n/ScriptType.hpp> #include <com/sun/star/i18n/XBreakIterator.hpp> #include <utility> + +#include <comphelper/string.hxx> #include <vcl/graph.hxx> #include <editeng/brushitem.hxx> #include <vcl/metric.hxx> #include <vcl/outdev.hxx> +#include <vcl/pdfextoutdevdata.hxx> +#include <vcl/pdfwriter.hxx> #include <viewopt.hxx> #include <SwPortionHandler.hxx> #include "porlay.hxx" @@ -44,6 +48,7 @@ #include <editeng/lrspitem.hxx> #include <unicode/ubidi.h> #include <bookmark.hxx> +#include <docufld.hxx> using namespace ::com::sun::star; @@ -59,7 +64,7 @@ SwFieldPortion *SwFieldPortion::Clone( const OUString &rExpand ) const } // #i107143# // pass placeholder property to created <SwFieldPortion> instance. - SwFieldPortion* pClone = new SwFieldPortion( rExpand, std::move(pNewFnt), m_bPlaceHolder ); + SwFieldPortion* pClone = new SwFieldPortion(rExpand, std::move(pNewFnt)); pClone->SetNextOffset( m_nNextOffset ); pClone->m_bNoLength = m_bNoLength; return pClone; @@ -73,13 +78,13 @@ void SwFieldPortion::TakeNextOffset( const SwFieldPortion* pField ) m_bFollow = true; } -SwFieldPortion::SwFieldPortion(OUString aExpand, std::unique_ptr<SwFont> pFont, bool bPlaceHold, TextFrameIndex const nFieldLen) +SwFieldPortion::SwFieldPortion(OUString aExpand, std::unique_ptr<SwFont> pFont, TextFrameIndex const nFieldLen) : m_aExpand(std::move(aExpand)), m_pFont(std::move(pFont)), m_nNextOffset(0) , m_nNextScriptChg(COMPLETE_STRING), m_nFieldLen(nFieldLen), m_nViewWidth(0) , m_bFollow( false ), m_bLeft( false), m_bHide( false) , m_bCenter (false), m_bHasFollow( false ) , m_bAnimated( false), m_bNoPaint( false) - , m_bReplace( false), m_bPlaceHolder( bPlaceHold ) + , m_bReplace(false) , m_bNoLength( false ) { SetWhichPor( PortionType::Field ); @@ -100,7 +105,6 @@ SwFieldPortion::SwFieldPortion( const SwFieldPortion& rField ) , m_bAnimated ( rField.m_bAnimated ) , m_bNoPaint( rField.m_bNoPaint) , m_bReplace( rField.m_bReplace ) - , m_bPlaceHolder( rField.m_bPlaceHolder ) , m_bNoLength( rField.m_bNoLength ) { if ( rField.HasFont() ) @@ -458,7 +462,7 @@ void SwFieldPortion::Paint( const SwTextPaintInfo &rInf ) const SwFontSave aSave( rInf, m_pFont.get() ); // OSL_ENSURE(GetLen() <= TextFrameIndex(1), "SwFieldPortion::Paint: rest-portion pollution?"); - if( Width() && ( !m_bPlaceHolder || rInf.GetOpt().IsShowPlaceHolderFields() ) && !m_bContentControl ) + if (Width() && !m_bContentControl) { // A very liberal use of the background rInf.DrawViewOpt( *this, PortionType::Field ); @@ -536,7 +540,7 @@ SwNumberPortion::SwNumberPortion( const OUString &rExpand, const bool bCntr, const sal_uInt16 nMinDst, const bool bLabelAlignmentPosAndSpaceModeActive ) - : SwFieldPortion(rExpand, std::move(pFont), false, TextFrameIndex(0)) + : SwFieldPortion(rExpand, std::move(pFont), TextFrameIndex(0)) , m_nFixWidth(0) , m_nMinDist(nMinDst) , mbLabelAlignmentPosAndSpaceModeActive(bLabelAlignmentPosAndSpaceModeActive) @@ -1392,4 +1396,57 @@ void SwFieldFormDatePortion::Paint( const SwTextPaintInfo &rInf ) const } } +SwFieldPortion* SwJumpFieldPortion::Clone(const OUString& rExpand) const +{ + auto pRet = new SwJumpFieldPortion(*this); + pRet->m_aExpand = rExpand; + return pRet; +} + +bool SwJumpFieldPortion::DescribePDFControl(const SwTextPaintInfo& rInf) const +{ + auto pPDFExtOutDevData + = dynamic_cast<vcl::PDFExtOutDevData*>(rInf.GetOut()->GetExtOutDevData()); + if (!pPDFExtOutDevData) + return false; + + if (!pPDFExtOutDevData->GetIsExportFormFields()) + return false; + + if (m_nFormat != SwJumpEditFormat::JE_FMT_TEXT) + return false; + + vcl::PDFWriter::EditWidget aDescriptor; + + aDescriptor.Border = true; + aDescriptor.BorderColor = COL_BLACK; + + SwRect aLocation; + rInf.CalcRect(*this, &aLocation); + aDescriptor.Location = aLocation.SVRect(); + + // Map the text of the field to the descriptor's text. + static sal_Unicode constexpr aForbidden[] = { CH_TXTATR_BREAKWORD, 0 }; + aDescriptor.Text = comphelper::string::removeAny(GetExp(), aForbidden); + + // Description for accessibility purposes. + if (!m_sHelp.isEmpty()) + aDescriptor.Description = m_sHelp; + + pPDFExtOutDevData->WrapBeginStructureElement(vcl::PDFWriter::Form); + pPDFExtOutDevData->CreateControl(aDescriptor); + pPDFExtOutDevData->EndStructureElement(); + + return true; +} + +void SwJumpFieldPortion::Paint(const SwTextPaintInfo& rInf) const +{ + if (Width() && DescribePDFControl(rInf)) + return; + + if (rInf.GetOpt().IsShowPlaceHolderFields()) + SwFieldPortion::Paint(rInf); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/text/porfld.hxx b/sw/source/core/text/porfld.hxx index e1c18fc9bd18..b92372942425 100644 --- a/sw/source/core/text/porfld.hxx +++ b/sw/source/core/text/porfld.hxx @@ -50,7 +50,6 @@ protected: bool m_bAnimated : 1; // Used by SwGrfNumPortion bool m_bNoPaint : 1; // Used by SwGrfNumPortion bool m_bReplace : 1; // Used by SwGrfNumPortion - const bool m_bPlaceHolder : 1; bool m_bNoLength : 1; // HACK for meta suffix (no CH_TXTATR) bool m_bContentControl = false; @@ -60,7 +59,7 @@ protected: public: SwFieldPortion( const SwFieldPortion& rField ); - SwFieldPortion(OUString aExpand, std::unique_ptr<SwFont> pFnt = nullptr, bool bPlaceHolder = false, TextFrameIndex nLen = TextFrameIndex(1)); + SwFieldPortion(OUString aExpand, std::unique_ptr<SwFont> pFnt = nullptr, TextFrameIndex nLen = TextFrameIndex(1)); virtual ~SwFieldPortion() override; void TakeNextOffset( const SwFieldPortion* pField ); @@ -262,4 +261,25 @@ private: bool m_bStart; }; +class SwJumpFieldPortion final : public SwFieldPortion +{ +public: + explicit SwJumpFieldPortion(OUString aExpand, OUString aHelp, std::unique_ptr<SwFont> pFont, + sal_uInt32 nFormat) + : SwFieldPortion(std::move(aExpand), std::move(pFont)) + , m_nFormat(nFormat) + , m_sHelp(std::move(aHelp)) + { + } + virtual SwFieldPortion* Clone(const OUString& rExpand) const override; + + virtual void Paint(const SwTextPaintInfo& rInf) const override; + +private: + sal_uInt32 m_nFormat; // SwJumpEditFormat from SwField::GetFormat() + OUString m_sHelp; + + bool DescribePDFControl(const SwTextPaintInfo& rInf) const; +}; + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/text/txtfld.cxx b/sw/source/core/text/txtfld.cxx index e0859265a51b..2cffd26eeef7 100644 --- a/sw/source/core/text/txtfld.cxx +++ b/sw/source/core/text/txtfld.cxx @@ -180,7 +180,8 @@ SwExpandPortion *SwTextFormatter::NewFieldPortion( SwTextFormatInfo &rInf, &static_cast<SwJumpEditField*>(pField)->GetCharFormat()->GetAttrSet(), &m_pFrame->GetDoc().getIDocumentSettingAccess()); } - return new SwFieldPortion(ExpandField(*pField, *this, rInf), std::move(pFont), true); + return new SwJumpFieldPortion(ExpandField(*pField, *this, rInf), pField->GetPar2(), + std::move(pFont), pField->GetFormat()); } case SwFieldIds::GetRef: if (!bName) commit ec54e7330ad3bbada1bfabd58a3fe66cef69a0ce Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Oct 25 12:34:51 2023 +0200 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Wed Oct 25 15:54:46 2023 +0200 Simplify SwTextFormatter::NewFieldPortion Change-Id: I7e5cbce45bba4550f572606f44300b914ff5a41c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158433 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sw/source/core/text/txtfld.cxx b/sw/source/core/text/txtfld.cxx index 462c9085036b..e0859265a51b 100644 --- a/sw/source/core/text/txtfld.cxx +++ b/sw/source/core/text/txtfld.cxx @@ -70,219 +70,130 @@ static bool lcl_IsInBody( SwFrame const *pFrame ) return pFrame->IsInDocBody(); } +static OUString ExpandField(const SwField& rField, const SwTextFormatter& rFormatter, + const SwTextFormatInfo& rInf) +{ + if (rInf.GetOpt().IsFieldName()) + return rField.GetFieldName(); + + const SwViewShell* pSh = rInf.GetVsh(); + const SwDoc* pDoc(pSh ? pSh->GetDoc() : nullptr); + const bool bInClipboard(!pDoc || pDoc->IsClipBoard()); + return rField.ExpandField(bInClipboard, rFormatter.GetTextFrame()->getRootFrame()); +} + SwExpandPortion *SwTextFormatter::NewFieldPortion( SwTextFormatInfo &rInf, const SwTextAttr *pHint ) const { - SwExpandPortion *pRet = nullptr; - SwFrame *pFrame = m_pFrame; SwField *pField = const_cast<SwField*>(pHint->GetFormatField().GetField()); const bool bName = rInf.GetOpt().IsFieldName(); - SwCharFormat* pChFormat = nullptr; - bool bNewFlyPor = false; - sal_uInt16 subType = 0; - // set language const_cast<SwTextFormatter*>(this)->SeekAndChg( rInf ); if (pField->GetLanguage() != GetFnt()->GetLanguage()) pField->SetLanguage( GetFnt()->GetLanguage() ); SwViewShell *pSh = rInf.GetVsh(); - SwDoc *const pDoc( pSh ? pSh->GetDoc() : nullptr ); - bool const bInClipboard( pDoc == nullptr || pDoc->IsClipBoard() ); - bool bPlaceHolder = false; - switch( pField->GetTyp()->Which() ) + switch (pField->GetTyp()->Which()) { case SwFieldIds::Script: case SwFieldIds::Postit: - pRet = new SwPostItsPortion( SwFieldIds::Script == pField->GetTyp()->Which() ); - break; - + return new SwPostItsPortion(SwFieldIds::Script == pField->GetTyp()->Which()); case SwFieldIds::CombinedChars: - { - if( bName ) - pRet = new SwFieldPortion( pField->GetFieldName() ); - else - pRet = new SwCombinedPortion( pField->ExpandField(bInClipboard, pFrame->getRootFrame()) ); - } + if (!bName) + return new SwCombinedPortion(ExpandField(*pField, *this, rInf)); break; - case SwFieldIds::HiddenText: - { - OUString const aStr( bName - ? pField->GetFieldName() - : pField->ExpandField(bInClipboard, pFrame->getRootFrame()) ); - pRet = new SwHiddenPortion(aStr); - } - break; - + return new SwHiddenPortion(ExpandField(*pField, *this, rInf)); case SwFieldIds::Chapter: - if( !bName && pSh && !pSh->Imp()->IsUpdateExpFields() ) - { - static_cast<SwChapterField*>(pField)->ChangeExpansion(*pFrame, - &static_txtattr_cast<SwTextField const*>(pHint)->GetTextNode()); - } + if (!bName && pSh && !pSh->Imp()->IsUpdateExpFields()) { - OUString const aStr( bName - ? pField->GetFieldName() - : pField->ExpandField(bInClipboard, pFrame->getRootFrame()) ); - pRet = new SwFieldPortion( aStr ); + static_cast<SwChapterField*>(pField)->ChangeExpansion( + *m_pFrame, &static_txtattr_cast<SwTextField const*>(pHint)->GetTextNode()); } break; - case SwFieldIds::DocStat: - if( !bName && pSh && !pSh->Imp()->IsUpdateExpFields() ) + if (!bName && pSh && !pSh->Imp()->IsUpdateExpFields()) { - static_cast<SwDocStatField*>(pField)->ChangeExpansion( pFrame ); - } - { - OUString const aStr( bName - ? pField->GetFieldName() - : pField->ExpandField(bInClipboard, pFrame->getRootFrame()) ); - pRet = new SwFieldPortion( aStr ); + static_cast<SwDocStatField*>(pField)->ChangeExpansion(m_pFrame); } break; - case SwFieldIds::PageNumber: - { - if( !bName && pSh && pSh->GetLayout() && !pSh->Imp()->IsUpdateExpFields() ) + if (!bName && pSh && pSh->GetLayout() && !pSh->Imp()->IsUpdateExpFields()) { - SwPageNumberFieldType *pPageNr = static_cast<SwPageNumberFieldType *>(pField->GetTyp()); + auto pPageNr = static_cast<SwPageNumberFieldType*>(pField->GetTyp()); const SwRootFrame* pTmpRootFrame = pSh->GetLayout(); const bool bVirt = pTmpRootFrame->IsVirtPageNum(); - sal_uInt16 nVirtNum = pFrame->GetVirtPageNum(); + sal_uInt16 nVirtNum = m_pFrame->GetVirtPageNum(); sal_uInt16 nNumPages = pTmpRootFrame->GetPageNum(); SvxNumType nNumFormat = SvxNumType(-1); - if(SVX_NUM_PAGEDESC == pField->GetFormat()) - nNumFormat = pFrame->FindPageFrame()->GetPageDesc()->GetNumType().GetNumberingType(); - static_cast<SwPageNumberField*>(pField) - ->ChangeExpansion(nVirtNum, nNumPages); - pPageNr->ChangeExpansion(pDoc, - bVirt, nNumFormat != SvxNumType(-1) ? &nNumFormat : nullptr); - } - { - OUString const aStr( bName - ? pField->GetFieldName() - : pField->ExpandField(bInClipboard, pFrame->getRootFrame()) ); - pRet = new SwFieldPortion( aStr ); + if (SVX_NUM_PAGEDESC == pField->GetFormat()) + nNumFormat + = m_pFrame->FindPageFrame()->GetPageDesc()->GetNumType().GetNumberingType(); + static_cast<SwPageNumberField*>(pField)->ChangeExpansion(nVirtNum, nNumPages); + pPageNr->ChangeExpansion(pSh->GetDoc(), bVirt, + nNumFormat != SvxNumType(-1) ? &nNumFormat : nullptr); } break; - } case SwFieldIds::GetExp: - { - if( !bName && pSh && !pSh->Imp()->IsUpdateExpFields() ) + if (!bName && pSh && !pSh->Imp()->IsUpdateExpFields()) { - SwGetExpField* pExpField = static_cast<SwGetExpField*>(pField); - if( !::lcl_IsInBody( pFrame ) ) + auto pExpField = static_cast<SwGetExpField*>(pField); + if (!::lcl_IsInBody(m_pFrame)) { - pExpField->ChgBodyTextFlag( false ); - pExpField->ChangeExpansion(*pFrame, - *static_txtattr_cast<SwTextField const*>(pHint)); + pExpField->ChgBodyTextFlag(false); + pExpField->ChangeExpansion(*m_pFrame, + *static_txtattr_cast<SwTextField const*>(pHint)); } - else if( !pExpField->IsInBodyText() ) + else if (!pExpField->IsInBodyText()) { // Was something else previously, thus: expand first, then convert it! - pExpField->ChangeExpansion(*pFrame, - *static_txtattr_cast<SwTextField const*>(pHint)); - pExpField->ChgBodyTextFlag( true ); + pExpField->ChangeExpansion(*m_pFrame, + *static_txtattr_cast<SwTextField const*>(pHint)); + pExpField->ChgBodyTextFlag(true); } } - { - OUString const aStr( bName - ? pField->GetFieldName() - : pField->ExpandField(bInClipboard, pFrame->getRootFrame()) ); - pRet = new SwFieldPortion( aStr ); - } break; - } case SwFieldIds::Database: - { - if( !bName ) + if (!bName) { - SwDBField* pDBField = static_cast<SwDBField*>(pField); - pDBField->ChgBodyTextFlag( ::lcl_IsInBody( pFrame ) ); - } - { - OUString const aStr( bName - ? pField->GetFieldName() - : pField->ExpandField(bInClipboard, pFrame->getRootFrame()) ); - pRet = new SwFieldPortion(aStr); + static_cast<SwDBField*>(pField)->ChgBodyTextFlag(::lcl_IsInBody(m_pFrame)); } break; - } case SwFieldIds::RefPageGet: - if( !bName && pSh && !pSh->Imp()->IsUpdateExpFields() ) + if (!bName && pSh && !pSh->Imp()->IsUpdateExpFields()) { - static_cast<SwRefPageGetField*>(pField)->ChangeExpansion(*pFrame, - static_txtattr_cast<SwTextField const*>(pHint)); - } - { - OUString const aStr( bName - ? pField->GetFieldName() - : pField->ExpandField(bInClipboard, pFrame->getRootFrame()) ); - pRet = new SwFieldPortion(aStr); + static_cast<SwRefPageGetField*>(pField)->ChangeExpansion( + *m_pFrame, static_txtattr_cast<SwTextField const*>(pHint)); } break; - case SwFieldIds::JumpEdit: - if( !bName ) - pChFormat = static_cast<SwJumpEditField*>(pField)->GetCharFormat(); - bNewFlyPor = true; - bPlaceHolder = true; - break; - case SwFieldIds::GetRef: { - subType = static_cast<SwGetRefField*>(pField)->GetSubType(); - if (!bName && subType == REF_STYLE) + std::unique_ptr<SwFont> pFont; + if (!bName) { - static_cast<SwGetRefField*>(pField)->UpdateField( - static_txtattr_cast<SwTextField const*>(pHint), pFrame); - } - - { - OUString const str( bName - ? pField->GetFieldName() - : pField->ExpandField(bInClipboard, pFrame->getRootFrame()) ); - pRet = new SwFieldPortion(str); + pFont = std::make_unique<SwFont>(*m_pFont); + pFont->SetDiffFnt( + &static_cast<SwJumpEditField*>(pField)->GetCharFormat()->GetAttrSet(), + &m_pFrame->GetDoc().getIDocumentSettingAccess()); } + return new SwFieldPortion(ExpandField(*pField, *this, rInf), std::move(pFont), true); } - break; - case SwFieldIds::DateTime: - subType = static_cast<SwDateTimeField*>(pField)->GetSubType(); + case SwFieldIds::GetRef: + if (!bName) { - OUString const str( bName - ? pField->GetFieldName() - : pField->ExpandField(bInClipboard, pFrame->getRootFrame()) ); - pRet = new SwFieldPortion(str); + auto pGetRef = static_cast<SwGetRefField*>(pField); + if (pGetRef->GetSubType() == REF_STYLE) + pGetRef->UpdateField(static_txtattr_cast<SwTextField const*>(pHint), m_pFrame); } break; default: - { - OUString const aStr( bName - ? pField->GetFieldName() - : pField->ExpandField(bInClipboard, pFrame->getRootFrame()) ); - pRet = new SwFieldPortion(aStr); - } - } - - if( bNewFlyPor ) - { - std::unique_ptr<SwFont> pTmpFnt; - if( !bName ) - { - pTmpFnt.reset(new SwFont( *m_pFont )); - pTmpFnt->SetDiffFnt(&pChFormat->GetAttrSet(), &m_pFrame->GetDoc().getIDocumentSettingAccess()); - } - OUString const aStr( bName - ? pField->GetFieldName() - : pField->ExpandField(bInClipboard, pFrame->getRootFrame()) ); - pRet = new SwFieldPortion(aStr, std::move(pTmpFnt), bPlaceHolder); + break; } - - return pRet; + return new SwFieldPortion(ExpandField(*pField, *this, rInf)); } static SwFieldPortion * lcl_NewMetaPortion(SwTextAttr & rHint, const bool bPrefix)