sw/source/filter/ww8/docxattributeoutput.cxx | 22 +++++++++++++++++++--- sw/source/filter/ww8/docxattributeoutput.hxx | 2 +- sw/source/filter/ww8/wrtw8nds.cxx | 4 ++-- sw/source/filter/ww8/wrtww8.hxx | 4 ++-- sw/source/filter/ww8/ww8atr.cxx | 18 ++++++++++++++++-- 5 files changed, 40 insertions(+), 10 deletions(-)
New commits: commit a3dbed366cdebac4e8cad5ecab6e735cd4b4efe3 Author: Andreas Brandner <andreas.brand...@cib.de> Date: Sun Nov 5 20:41:31 2017 +0100 tdf#66401 don't lose docx-combined-characters' font props on roundtrip - font-size will now get halfed, if exported within a combined-characters-field in docx - font-property will get exported for every run in a field, this redundancy is required by MS Word Change-Id: Idbdb5bf3066e2ed86b494255d72d66eebf72f755 Reviewed-on: https://gerrit.libreoffice.org/44509 Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de> Tested-by: Thorsten Behrens <thorsten.behr...@cib.de> diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 467177d013fa..e8cdfc86182c 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -1740,12 +1740,18 @@ void DocxAttributeOutput::DoWriteCmd( const OUString& rCmd ) void DocxAttributeOutput::CmdField_Impl( const SwTextNode* pNode, sal_Int32 nPos, FieldInfos const & rInfos, bool bWriteRun ) { + bool bWriteCombChars(false); + // Write the Field instruction { if ( bWriteRun ) { m_pSerializer->startElementNS( XML_w, XML_r, FSEND ); - DoWriteFieldRunProperties( pNode, nPos ); + + if (rInfos.eType == ww::eEQ) + bWriteCombChars = true; + + DoWriteFieldRunProperties( pNode, nPos, bWriteCombChars ); } sal_Int32 nNbToken = comphelper::string::getTokenCount(rInfos.sCmd, '\t'); @@ -1829,7 +1835,7 @@ void DocxAttributeOutput::CmdField_Impl( const SwTextNode* pNode, sal_Int32 nPos /// <w:fldChar w:fldCharType="end" /> /// </w:r> /// See, tdf#38778 -void DocxAttributeOutput::DoWriteFieldRunProperties( const SwTextNode * pNode, sal_Int32 nPos ) +void DocxAttributeOutput::DoWriteFieldRunProperties( const SwTextNode * pNode, sal_Int32 nPos, bool bWriteCombChars) { if (! pNode) { @@ -1859,7 +1865,17 @@ void DocxAttributeOutput::DoWriteFieldRunProperties( const SwTextNode * pNode, s // 3. output all other character properties SwWW8AttrIter aAttrIt( m_rExport, *pNode ); - aAttrIt.OutAttr( nPos, false ); + aAttrIt.OutAttr( nPos, false, bWriteCombChars ); + + // 4. explicitly write the font-properties, to ensure all runs in the field have them + // see tdf#66401 + if ( m_pFontsAttrList.is() ) + { + XFastAttributeListRef xAttrList( m_pFontsAttrList.get() ); + m_pFontsAttrList.clear(); + + m_pSerializer->singleElementNS( XML_w, XML_rFonts, xAttrList ); + } m_pSerializer->endElementNS( XML_w, XML_rPr ); diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index 4c41f83d2f30..64fa4238e617 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -729,7 +729,7 @@ private: void DoWriteCmd( const OUString& rCmd ); void CmdField_Impl( const SwTextNode* pNode, sal_Int32 nPos, FieldInfos const & rInfos, bool bWriteRun ); void EndField_Impl( const SwTextNode* pNode, sal_Int32 nPos, FieldInfos& rInfos ); - void DoWriteFieldRunProperties( const SwTextNode* pNode, sal_Int32 nPos ); + void DoWriteFieldRunProperties( const SwTextNode* pNode, sal_Int32 nPos, bool bWriteCombChars = false ); virtual void GenerateBookmarksForSequenceField(const SwTextNode& rNode, SwWW8AttrIter& rAttrIter) override; static void AddToAttrList( css::uno::Reference<sax_fastparser::FastAttributeList>& pAttrList, sal_Int32 nAttrName, const sal_Char* sAttrValue ); diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx index e9ba18f40d6f..33b67ea5e627 100644 --- a/sw/source/filter/ww8/wrtw8nds.cxx +++ b/sw/source/filter/ww8/wrtw8nds.cxx @@ -382,7 +382,7 @@ static bool lcl_isFontsizeItem( const SfxPoolItem& rItem ) rItem.Which( ) == RES_CHRATR_CTL_FONTSIZE ); } -void SwWW8AttrIter::OutAttr( sal_Int32 nSwPos, bool bRuby ) +void SwWW8AttrIter::OutAttr( sal_Int32 nSwPos, bool bRuby , bool bWriteCombChars) { m_rExport.AttrOutput().RTLAndCJKState( IsCharRTL(), GetScript() ); @@ -488,7 +488,7 @@ void SwWW8AttrIter::OutAttr( sal_Int32 nSwPos, bool bRuby ) // tdf#38778 Fix output of the font in DOC run for fields const SvxFontItem * pFontToOutput = ( rParentFont != *pFont )? pFont : nullptr; - m_rExport.ExportPoolItemsToCHP( aExportItems, GetScript(), pFontToOutput ); + m_rExport.ExportPoolItemsToCHP( aExportItems, GetScript(), pFontToOutput, bWriteCombChars ); // HasTextItem only allowed in the above range m_rExport.m_aCurrentCharPropStarts.pop(); diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx index dafffeaafd44..ff25dedd1c3e 100644 --- a/sw/source/filter/ww8/wrtww8.hxx +++ b/sw/source/filter/ww8/wrtww8.hxx @@ -584,7 +584,7 @@ public: void WriteSpecialText( sal_uLong nStart, sal_uLong nEnd, sal_uInt8 nTTyp ); /// Export the pool items to attributes (through an attribute output class). - void ExportPoolItemsToCHP( ww8::PoolItems &rItems, sal_uInt16 nScript, const SvxFontItem *pFont ); + void ExportPoolItemsToCHP( ww8::PoolItems &rItems, sal_uInt16 nScript, const SvxFontItem *pFont, bool bWriteCombChars = false ); /// Return the numeric id of the numbering rule sal_uInt16 GetId( const SwNumRule& rNumRule ); @@ -1490,7 +1490,7 @@ public: void NextPos() { if ( nAktSwPos < SAL_MAX_INT32 ) nAktSwPos = SearchNext( nAktSwPos + 1 ); } - void OutAttr( sal_Int32 nSwPos, bool bRuby = false ); + void OutAttr( sal_Int32 nSwPos, bool bRuby = false, bool bWriteCombinedChars = false ); virtual const SfxPoolItem* HasTextItem( sal_uInt16 nWhich ) const override; virtual const SfxPoolItem& GetItem( sal_uInt16 nWhich ) const override; int OutAttrWithRange(const SwTextNode& rNode, sal_Int32 nPos); diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx index fbb763a1459a..3250808165a8 100644 --- a/sw/source/filter/ww8/ww8atr.cxx +++ b/sw/source/filter/ww8/ww8atr.cxx @@ -204,7 +204,7 @@ bool WW8Export::CollapseScriptsforWordOk( sal_uInt16 nScript, sal_uInt16 nWhich // Hilfsroutinen fuer Styles -void MSWordExportBase::ExportPoolItemsToCHP( ww8::PoolItems &rItems, sal_uInt16 nScript, const SvxFontItem *pFont ) +void MSWordExportBase::ExportPoolItemsToCHP( ww8::PoolItems &rItems, sal_uInt16 nScript, const SvxFontItem *pFont, bool bWriteCombChars ) { ww8::cPoolItemIter aEnd = rItems.end(); for ( ww8::cPoolItemIter aI = rItems.begin(); aI != aEnd; ++aI ) @@ -228,7 +228,21 @@ void MSWordExportBase::ExportPoolItemsToCHP( ww8::PoolItems &rItems, sal_uInt16 AttrOutput().OutputItem( *pFont ); } - AttrOutput().OutputItem( *pItem ); + // tdf#66401 For Combined Characters in docx, MS Word uses half the normal font-size for the field's + // font-size, but only for <w:sz>. Therefore, we check if we are currently writing a field of type + // Combined Characters and if so, we half the font size. + if (bWriteCombChars && + nWhich == RES_CHRATR_FONTSIZE) + { + SvxFontHeightItem fontHeight(item_cast<SvxFontHeightItem>( *pItem )); + fontHeight.SetHeight( fontHeight.GetHeight() / 2 ); + + AttrOutput().OutputItem( fontHeight ); + } + else + { + AttrOutput().OutputItem( *pItem ); + } } } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits