From 8d9a567491db1822a0b8fd8d56af00fdfd544874 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Thu, 29 May 2014 14:31:20 +0200 Subject: handle direct formatting for numbering in .docx (bnc#875717) Change-Id: I3ed0f926e79f3878c5702c2becae97d99d00e201 --- sw/inc/IDocumentSettingAccess.hxx | 3 ++- sw/source/core/doc/DocumentSettingManager.cxx | 5 ++++ sw/source/core/inc/DocumentSettingManager.hxx | 1 + sw/source/core/text/txtfld.cxx | 31 +++++++++++++++++++++++ sw/source/core/uibase/uno/SwXDocumentSettings.cxx | 16 +++++++++++- 5 files changed, 54 insertions(+), 2 deletions(-) (limited to 'sw') diff --git a/sw/inc/IDocumentSettingAccess.hxx b/sw/inc/IDocumentSettingAccess.hxx index 6e66fd018d63..4e94a1ec3185 100644 --- a/sw/inc/IDocumentSettingAccess.hxx +++ b/sw/inc/IDocumentSettingAccess.hxx @@ -92,7 +92,8 @@ namespace com { namespace sun { namespace star { namespace i18n { struct Forbidd STYLES_NODEFAULT, FLOATTABLE_NOMARGINS, EMBED_FONTS, - EMBED_SYSTEM_FONTS + EMBED_SYSTEM_FONTS, + APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING }; public: diff --git a/sw/source/core/doc/DocumentSettingManager.cxx b/sw/source/core/doc/DocumentSettingManager.cxx index 8c5a88b323d4..68ff9970b3b6 100644 --- a/sw/source/core/doc/DocumentSettingManager.cxx +++ b/sw/source/core/doc/DocumentSettingManager.cxx @@ -75,6 +75,7 @@ sw::DocumentSettingManager::DocumentSettingManager(SwDoc &rDoc) mbBackgroundParaOverDrawings(false), mbTabOverMargin(false), mbSurroundTextWrapSmall(false), + mApplyParagraphMarkFormatToNumbering(false), mbLastBrowseMode( false ) // COMPATIBILITY FLAGS END @@ -162,6 +163,7 @@ bool sw::DocumentSettingManager::get(/*[in]*/ DocumentSettingId id) const case FLOATTABLE_NOMARGINS: return mbFloattableNomargins; case EMBED_FONTS: return mEmbedFonts; case EMBED_SYSTEM_FONTS: return mEmbedSystemFonts; + case APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING: return mApplyParagraphMarkFormatToNumbering; default: OSL_FAIL("Invalid setting id"); } @@ -357,6 +359,9 @@ void sw::DocumentSettingManager::set(/*[in]*/ DocumentSettingId id, /*[in]*/ boo case EMBED_SYSTEM_FONTS: mEmbedSystemFonts = value; break; + case APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING: + mApplyParagraphMarkFormatToNumbering = value; + break; default: OSL_FAIL("Invalid setting id"); } diff --git a/sw/source/core/inc/DocumentSettingManager.hxx b/sw/source/core/inc/DocumentSettingManager.hxx index 82a47f41a1fe..2e8ab4bdf3a3 100644 --- a/sw/source/core/inc/DocumentSettingManager.hxx +++ b/sw/source/core/inc/DocumentSettingManager.hxx @@ -85,6 +85,7 @@ class DocumentSettingManager : bool mbBackgroundParaOverDrawings; bool mbTabOverMargin; bool mbSurroundTextWrapSmall; + bool mApplyParagraphMarkFormatToNumbering; bool mbLastBrowseMode : 1; diff --git a/sw/source/core/text/txtfld.cxx b/sw/source/core/text/txtfld.cxx index 4b9db82590f2..4f39e5269ae4 100644 --- a/sw/source/core/text/txtfld.cxx +++ b/sw/source/core/text/txtfld.cxx @@ -50,6 +50,7 @@ #include "fmtmeta.hxx" #include "reffld.hxx" #include "flddat.hxx" +#include "fmtautofmt.hxx" static bool lcl_IsInBody( SwFrm *pFrm ) { @@ -401,6 +402,32 @@ SwLinePortion *SwTxtFormatter::NewExtraPortion( SwTxtFormatInfo &rInf ) return pRet; } +// OOXML spec says that w:rPr inside w:pPr specifies formatting for the paragraph mark symbol (i.e. the control +// character than can be configured to be shown). However, in practice MSO also uses it as direct formatting +// for numbering in that paragraph. I don't know if the problem is in the spec or in MSWord. +static void checkApplyParagraphMarkFormatToNumbering( SwFont* pNumFnt, SwTxtFormatInfo& rInf, const IDocumentSettingAccess* pIDSA ) +{ + SwTxtNode* node = rInf.GetTxtFrm()->GetTxtNode(); + if( !pIDSA->get(IDocumentSettingAccess::APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING )) + return; + if( SwpHints* hints = node->GetpSwpHints()) + { + for( int i = 0; i < hints->Count(); ++i ) + { + SwTxtAttr* hint = hints->GetTextHint( i ); + // Formatting for the paragraph mark is set to apply only to the (non-existent) extra character + // the at end of the txt node. + if( hint->Which() == RES_TXTATR_AUTOFMT && hint->GetStart() != NULL && hint->GetEnd() != NULL + && *hint->GetStart() == *hint->GetEnd() && *hint->GetStart() == node->Len()) + { + boost::shared_ptr pSet(hint->GetAutoFmt().GetStyleHandle()); + pNumFnt->SetDiffFnt( pSet.get(), pIDSA ); + } + } + } +} + + SwNumberPortion *SwTxtFormatter::NewNumberPortion( SwTxtFormatInfo &rInf ) const { if( rInf.IsNumDone() || rInf.GetTxtStart() != nStart @@ -487,6 +514,8 @@ SwNumberPortion *SwTxtFormatter::NewNumberPortion( SwTxtFormatInfo &rInf ) const if( pFmt ) pNumFnt->SetDiffFnt( pFmt, pIDSA ); + checkApplyParagraphMarkFormatToNumbering( pNumFnt, rInf, pIDSA ); + if ( pFmtFnt ) { const sal_uInt8 nAct = pNumFnt->GetActual(); @@ -544,6 +573,8 @@ SwNumberPortion *SwTxtFormatter::NewNumberPortion( SwTxtFormatInfo &rInf ) const if( pFmt ) pNumFnt->SetDiffFnt( pFmt, pIDSA ); + checkApplyParagraphMarkFormatToNumbering( pNumFnt, rInf, pIDSA ); + // we do not allow a vertical font pNumFnt->SetVertical( pNumFnt->GetOrientation(), pFrm->IsVertical() ); diff --git a/sw/source/core/uibase/uno/SwXDocumentSettings.cxx b/sw/source/core/uibase/uno/SwXDocumentSettings.cxx index 1643633f3262..3144c32bcf33 100644 --- a/sw/source/core/uibase/uno/SwXDocumentSettings.cxx +++ b/sw/source/core/uibase/uno/SwXDocumentSettings.cxx @@ -122,7 +122,8 @@ enum SwDocumentSettingsPropertyHandles HANDLE_EMBED_FONTS, HANDLE_EMBED_SYSTEM_FONTS, HANDLE_TAB_OVER_MARGIN, - HANDLE_SURROUND_TEXT_WRAP_SMALL + HANDLE_SURROUND_TEXT_WRAP_SMALL, + HANDLE_APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING }; static MasterPropertySetInfo * lcl_createSettingsInfo() @@ -193,6 +194,7 @@ static MasterPropertySetInfo * lcl_createSettingsInfo() { OUString("EmbedSystemFonts"), HANDLE_EMBED_SYSTEM_FONTS, cppu::UnoType::get(), 0, 0}, { OUString("TabOverMargin"), HANDLE_TAB_OVER_MARGIN, cppu::UnoType::get(), 0, 0}, { OUString("SurroundTextWrapSmall"), HANDLE_SURROUND_TEXT_WRAP_SMALL, cppu::UnoType::get(), 0, 0}, + { OUString("ApplyParagraphMarkFormatToNumbering"), HANDLE_APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING, cppu::UnoType::get(), 0, 0}, /* * As OS said, we don't have a view when we need to set this, so I have to * find another solution before adding them to this property set - MTG @@ -793,6 +795,12 @@ void SwXDocumentSettings::_setSingleValue( const comphelper::PropertyInfo & rInf mpDoc->set(IDocumentSettingAccess::SURROUND_TEXT_WRAP_SMALL, bTmp); } break; + case HANDLE_APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING: + { + bool bTmp = *(sal_Bool*)rValue.getValue(); + mpDoc->set(IDocumentSettingAccess::APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING, bTmp); + } + break; default: throw UnknownPropertyException(); } @@ -1215,6 +1223,12 @@ void SwXDocumentSettings::_getSingleValue( const comphelper::PropertyInfo & rInf rValue.setValue( &bTmp, ::getBooleanCppuType() ); } break; + case HANDLE_APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING: + { + sal_Bool bTmp = mpDoc->get( IDocumentSettingAccess::APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING ); + rValue.setValue( &bTmp, ::getBooleanCppuType() ); + } + break; default: throw UnknownPropertyException(); } -- cgit