sw/inc/format.hxx | 1 sw/source/core/attr/format.cxx | 3 - sw/source/filter/ww8/docxattributeoutput.cxx | 25 ++++------ sw/source/filter/ww8/wrtw8sty.cxx | 58 ++++++++++++++++++++++++ sw/source/filter/ww8/wrtww8.hxx | 9 +++ writerfilter/source/dmapper/StyleSheetTable.cxx | 24 ++++++--- 6 files changed, 92 insertions(+), 28 deletions(-)
New commits: commit e47c7970a43d95a65f2a6d6942777314aea41bba Author: Jan Holesovsky <[email protected]> Date: Wed Sep 18 12:19:45 2013 +0200 DOCX styles: Generate the styleIds similar ways as MSO does. Makes the id's nicer than the styleXY. Change-Id: Ica0da1404578f834a79f940bf31c93d25f842e7f diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index f005500..dc317ca 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -1280,11 +1280,12 @@ void DocxAttributeOutput::StartRuby( const SwTxtNode& rNode, xub_StrLen nPos, co StartRunProperties( ); SwWW8AttrIter aAttrIt( m_rExport, rNode ); aAttrIt.OutAttr( nPos, true ); + sal_uInt16 nStyle = m_rExport.GetId( *rRuby.GetTxtRuby()->GetCharFmt() ); - OString aStyleId( "style" ); - aStyleId += OString::number( nStyle ); + OString aStyleId(m_rExport.pStyles->GetStyleId(nStyle)); m_pSerializer->singleElementNS( XML_w, XML_rStyle, FSNS( XML_w, XML_val ), aStyleId.getStr(), FSEND ); + EndRunProperties( NULL ); RunText( rRuby.GetText( ) ); EndRun( ); @@ -1531,8 +1532,7 @@ void DocxAttributeOutput::FormatDrop( const SwTxtNode& /*rNode*/, const SwFmtDro void DocxAttributeOutput::ParagraphStyle( sal_uInt16 nStyle ) { - OString aStyleId( "style" ); - aStyleId += OString::number( nStyle ); + OString aStyleId(m_rExport.pStyles->GetStyleId(nStyle)); m_pSerializer->singleElementNS( XML_w, XML_pStyle, FSNS( XML_w, XML_val ), aStyleId.getStr(), FSEND ); } @@ -3249,11 +3249,9 @@ oox::drawingml::DrawingML& DocxAttributeOutput::GetDrawingML() void DocxAttributeOutput::StartStyle( const String& rName, bool bPapFmt, sal_uInt16 nBase, sal_uInt16 nNext, sal_uInt16 /*nWwId*/, sal_uInt16 nId, bool bAutoUpdate ) { - OString aStyle( "style" ); - m_pSerializer->startElementNS( XML_w, XML_style, FSNS( XML_w, XML_type ), bPapFmt? "paragraph": "character", // FIXME is this correct? - FSNS( XML_w, XML_styleId ), OString( aStyle + OString::number( nId ) ).getStr(), + FSNS( XML_w, XML_styleId ), m_rExport.pStyles->GetStyleId(nId).getStr(), FSEND ); m_pSerializer->singleElementNS( XML_w, XML_name, @@ -3263,12 +3261,12 @@ void DocxAttributeOutput::StartStyle( const String& rName, bool bPapFmt, if ( nBase != 0x0FFF ) { m_pSerializer->singleElementNS( XML_w, XML_basedOn, - FSNS( XML_w, XML_val ), OString( aStyle + OString::number( nBase ) ).getStr(), + FSNS( XML_w, XML_val ), m_rExport.pStyles->GetStyleId(nBase).getStr(), FSEND ); } m_pSerializer->singleElementNS( XML_w, XML_next, - FSNS( XML_w, XML_val ), OString( aStyle + OString::number( nNext ) ).getStr(), + FSNS( XML_w, XML_val ), m_rExport.pStyles->GetStyleId(nNext).getStr(), FSEND ); if ( bAutoUpdate ) @@ -4336,16 +4334,14 @@ void DocxAttributeOutput::TextINetFormat( const SwFmtINetFmt& rLink ) const SwTxtINetFmt* pINetFmt = rLink.GetTxtINetFmt(); const SwCharFmt* pCharFmt = pINetFmt->GetCharFmt(); - OString aStyleId( "style" ); - aStyleId += OString::number( m_rExport.GetId( *pCharFmt ) ); + OString aStyleId(m_rExport.pStyles->GetStyleId(m_rExport.GetId(*pCharFmt))); m_pSerializer->singleElementNS( XML_w, XML_rStyle, FSNS( XML_w, XML_val ), aStyleId.getStr(), FSEND ); } void DocxAttributeOutput::TextCharFormat( const SwFmtCharFmt& rCharFmt ) { - OString aStyleId( "style" ); - aStyleId += OString::number( m_rExport.GetId( *rCharFmt.GetCharFmt() ) ); + OString aStyleId(m_rExport.pStyles->GetStyleId(m_rExport.GetId(*rCharFmt.GetCharFmt()))); m_pSerializer->singleElementNS( XML_w, XML_rStyle, FSNS( XML_w, XML_val ), aStyleId.getStr(), FSEND ); } @@ -4534,8 +4530,7 @@ void DocxAttributeOutput::TextFootnote_Impl( const SwFmtFtn& rFootnote ) // footnote/endnote run properties const SwCharFmt* pCharFmt = rInfo.GetAnchorCharFmt( *m_rExport.pDoc ); - OString aStyleId( "style" ); - aStyleId += OString::number( m_rExport.GetId( *pCharFmt ) ); + OString aStyleId(m_rExport.pStyles->GetStyleId(m_rExport.GetId(*pCharFmt))); m_pSerializer->singleElementNS( XML_w, XML_rStyle, FSNS( XML_w, XML_val ), aStyleId.getStr(), FSEND ); diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx index 573e98a..2ca0b04 100644 --- a/sw/source/filter/ww8/wrtw8sty.cxx +++ b/sw/source/filter/ww8/wrtw8sty.cxx @@ -20,6 +20,7 @@ #include <algorithm> #include <functional> +#include <unordered_set> #include <boost/scoped_array.hpp> @@ -158,6 +159,7 @@ MSWordStyles::MSWordStyles( MSWordExportBase& rExport ) memset( pFmtA, 0, nAlloc * sizeof( SwFmt* ) ); BuildStylesTable(); + BuildStyleIds(); } MSWordStyles::~MSWordStyles() @@ -293,6 +295,62 @@ void MSWordStyles::BuildStylesTable() } } +void MSWordStyles::BuildStyleIds() +{ + std::unordered_set<OString, OStringHash> aUsed; + + m_aStyleIds.push_back("Normal"); + aUsed.insert("normal"); + + for (sal_uInt16 n = 1; n < nUsedSlots; ++n) + { + const OUString aName(pFmtA[n]? pFmtA[n]->GetName(): OUString()); + + OStringBuffer aStyleIdBuf(aName.getLength()); + for (int i = 0; i < aName.getLength(); ++i) + { + sal_Unicode nChar = aName[i]; + if (('0' <= nChar && nChar <= '9') || + ('a' <= nChar && nChar <= 'z') || + ('A' <= nChar && nChar <= 'Z')) + { + // first letter should be uppercase + if (aStyleIdBuf.isEmpty() && ('a' < nChar && nChar <= 'z')) + aStyleIdBuf.append(char(nChar - ('a' - 'A'))); + else + aStyleIdBuf.append(char(nChar)); + } + } + + OString aStyleId(aStyleIdBuf.makeStringAndClear()); + if (aStyleId.isEmpty()) + aStyleId = "Style"; + + OString aLower(aStyleId.toAsciiLowerCase()); + + // check for uniqueness & construct something unique if we have to + if (aUsed.find(aLower) == aUsed.end()) + { + aUsed.insert(aLower); + m_aStyleIds.push_back(aStyleId); + } + else + { + int nFree = 1; + while (aUsed.find(aLower + OString::number(nFree)) != aUsed.end()) + ++nFree; + + aUsed.insert(aLower + OString::number(nFree)); + m_aStyleIds.push_back(aStyleId + OString::number(nFree)); + } + } +} + +OString MSWordStyles::GetStyleId(sal_uInt16 nId) const +{ + return m_aStyleIds[nId]; +} + /// For WW8 only - extend pO so that the size of pTableStrm is even. static void impl_SkipOdd( ww::bytes* pO, sal_Size nTableStrmTell ) { diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx index 5ae203f..8d45349 100644 --- a/sw/source/filter/ww8/wrtww8.hxx +++ b/sw/source/filter/ww8/wrtww8.hxx @@ -1509,9 +1509,15 @@ class MSWordStyles SwFmt** pFmtA; sal_uInt16 nUsedSlots; + /// We need to build style id's for DOCX export; ideally we should roundtrip that, but this is good enough. + std::vector<OString> m_aStyleIds; + /// Create the style table, called from the constructor. void BuildStylesTable(); + /// Based on pFmtA, fill in m_aStyleIds with unique, MS-like names. + void BuildStyleIds(); + /// Get slot number during building the style table. sal_uInt16 BuildGetSlot( const SwFmt& rFmt ); @@ -1542,6 +1548,9 @@ public: /// Get id of the style (rFmt). sal_uInt16 GetSlot( const SwFmt& rFmt ) const; + /// Get styleId of the nId-th style (nId is its position in pFmtA). + OString GetStyleId(sal_uInt16 nId) const; + const SwFmt* GetSwFmt() const { return (*pFmtA); } }; commit 47fb53309cb8f5171431df6d49395880a3c034f2 Author: Jan Holesovsky <[email protected]> Date: Tue Sep 17 16:21:35 2013 +0200 Make the comments readable in the code. [And kill one unhelpful one - comments a removal of something.] Change-Id: Ia4229fe889aa0aae115e6ab9b6808e0f054bb199 diff --git a/writerfilter/source/dmapper/StyleSheetTable.cxx b/writerfilter/source/dmapper/StyleSheetTable.cxx index 481a35b..7b385d8 100644 --- a/writerfilter/source/dmapper/StyleSheetTable.cxx +++ b/writerfilter/source/dmapper/StyleSheetTable.cxx @@ -724,6 +724,7 @@ void StyleSheetTable::ApplyStyleSheets( FontTablePtr rFontTable ) uno::Reference< container::XNameContainer > xStyles = bParaStyle ? xParaStyles : xCharStyles; uno::Reference< style::XStyle > xStyle; OUString sConvertedStyleName = ConvertStyleName( pEntry->sStyleName ); + // When pasting, don't update existing styles. if(xStyles->hasByName( sConvertedStyleName ) && m_pImpl->m_bIsNewDoc) xStyles->getByName( sConvertedStyleName ) >>= xStyle; @@ -761,18 +762,21 @@ void StyleSheetTable::ApplyStyleSheets( FontTablePtr rFontTable ) if( !m_pImpl->m_rDMapper.IsOOXMLImport() && nFontCount > 2 ) { uno::Any aTwoHundredFortyTwip = uno::makeAny(12.); - // font size to 240 twip (12 pts) for all if not set + + // font size to 240 twip (12 pts) for all if not set pEntry->pProperties->Insert(PROP_CHAR_HEIGHT, aTwoHundredFortyTwip, false); - // western font not already set -> apply first font + + // western font not already set -> apply first font const FontEntry::Pointer_t pWesternFontEntry(rFontTable->getFontEntry( 0 )); OUString sWesternFontName = pWesternFontEntry->sFontName; pEntry->pProperties->Insert(PROP_CHAR_FONT_NAME, uno::makeAny( sWesternFontName ), false); - // CJK ... apply second font + // CJK ... apply second font const FontEntry::Pointer_t pCJKFontEntry(rFontTable->getFontEntry( 2 )); pEntry->pProperties->Insert(PROP_CHAR_FONT_NAME_ASIAN, uno::makeAny( pCJKFontEntry->sFontName ), false); pEntry->pProperties->Insert(PROP_CHAR_HEIGHT_ASIAN, aTwoHundredFortyTwip, false); - // CTL ... apply third font, if available + + // CTL ... apply third font, if available if( nFontCount > 3 ) { const FontEntry::Pointer_t pCTLFontEntry(rFontTable->getFontEntry( 3 )); @@ -780,13 +784,14 @@ void StyleSheetTable::ApplyStyleSheets( FontTablePtr rFontTable ) pEntry->pProperties->Insert(PROP_CHAR_HEIGHT_COMPLEX, aTwoHundredFortyTwip, false); } } - // Widow/Orphan -> set both to two if not already set + + // Widow/Orphan -> set both to two if not already set uno::Any aTwo = uno::makeAny(sal_Int8(2)); pEntry->pProperties->Insert(PROP_PARA_WIDOWS, aTwo, false); pEntry->pProperties->Insert(PROP_PARA_ORPHANS, aTwo, false); - // Left-to-right direction if not already set + + // Left-to-right direction if not already set pEntry->pProperties->Insert(PROP_WRITING_MODE, uno::makeAny( sal_Int16(text::WritingMode_LR_TB) ), false); - // Don't set font color to Auto if not already set: this could hide the default font color setting } uno::Sequence< beans::PropertyValue > aPropValues = pEntry->pProperties->GetPropertyValues(); @@ -795,7 +800,8 @@ void StyleSheetTable::ApplyStyleSheets( FontTablePtr rFontTable ) { bAddFollowStyle = true; } - //remove Left/RightMargin values from TOX heading styles + + // remove Left/RightMargin values from TOX heading styles if( bParaStyle ) { // Set the outline levels @@ -874,7 +880,7 @@ void StyleSheetTable::ApplyStyleSheets( FontTablePtr rFontTable ) PropValVector aSortedPropVals; for( sal_Int32 nProp = 0; nProp < aPropValues.getLength(); ++nProp) { - // Don't add the style name properties + // Don't add the style name properties bool bIsParaStyleName = aPropValues[nProp].Name == "ParaStyleName"; bool bIsCharStyleName = aPropValues[nProp].Name == "CharStyleName"; if ( !bIsParaStyleName && !bIsCharStyleName ) commit 33f6696f393363dc9c182dfc732f87465e5e53ea Author: Jan Holesovsky <[email protected]> Date: Tue Sep 17 14:17:02 2013 +0200 DOCX styles: nFmtId is unused, kill it. Change-Id: Id54c1c9b5cdbfd502cc3ca6cb7a101a40b3b169b diff --git a/sw/inc/format.hxx b/sw/inc/format.hxx index 2063ee3..a058dc6 100644 --- a/sw/inc/format.hxx +++ b/sw/inc/format.hxx @@ -40,7 +40,6 @@ class SW_DLLPUBLIC SwFmt : public SwModify SwAttrSet aSet; sal_uInt16 nWhichId; - sal_uInt16 nFmtId; ///< Format-ID for reading / writing. sal_uInt16 nPoolFmtId; /**< Id for "automatically" created formats. (is not hard attribution!!!) */ sal_uInt16 nPoolHelpId; ///< HelpId for this Pool-style. diff --git a/sw/source/core/attr/format.cxx b/sw/source/core/attr/format.cxx index 6777a2b..de54367 100644 --- a/sw/source/core/attr/format.cxx +++ b/sw/source/core/attr/format.cxx @@ -35,7 +35,6 @@ SwFmt::SwFmt( SwAttrPool& rPool, const sal_Char* pFmtNm, aFmtName( OUString::createFromAscii(pFmtNm) ), aSet( rPool, pWhichRanges ), nWhichId( nFmtWhich ), - nFmtId( 0 ), nPoolFmtId( USHRT_MAX ), nPoolHelpId( USHRT_MAX ), nPoolHlpFileId( UCHAR_MAX ) @@ -55,7 +54,6 @@ SwFmt::SwFmt( SwAttrPool& rPool, const OUString& rFmtNm, aFmtName( rFmtNm ), aSet( rPool, pWhichRanges ), nWhichId( nFmtWhich ), - nFmtId( 0 ), nPoolFmtId( USHRT_MAX ), nPoolHelpId( USHRT_MAX ), nPoolHlpFileId( UCHAR_MAX ) @@ -73,7 +71,6 @@ SwFmt::SwFmt( const SwFmt& rFmt ) aFmtName( rFmt.aFmtName ), aSet( rFmt.aSet ), nWhichId( rFmt.nWhichId ), - nFmtId( 0 ), nPoolFmtId( rFmt.GetPoolFmtId() ), nPoolHelpId( rFmt.GetPoolHelpId() ), nPoolHlpFileId( rFmt.GetPoolHlpFileId() ) _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
