sw/source/filter/html/htmlcss1.cxx | 76 ++++++++--------- sw/source/filter/html/htmlctxt.cxx | 66 +++++++------- sw/source/filter/html/htmldrawreader.cxx | 2 sw/source/filter/html/htmlgrin.cxx | 30 +++--- sw/source/filter/html/htmlsect.cxx | 2 sw/source/filter/html/htmltab.cxx | 44 +++++---- sw/source/filter/html/swhtml.cxx | 138 +++++++++++++++---------------- sw/source/filter/html/swhtml.hxx | 125 ++++++++++++++-------------- 8 files changed, 246 insertions(+), 237 deletions(-)
New commits: commit d9533e4c3f36c283681893c66b11343834ca45fa Author: Caolán McNamara <caol...@redhat.com> Date: Thu Dec 14 13:10:26 2017 +0000 ofz: dangling pointers make attribute table a shared_ptr and get HTMLAttrs that belong to it to add a reference to it while they exist Change-Id: I2d3ba433700d4a98fd466b38a495ed5a7adae020 Reviewed-on: https://gerrit.libreoffice.org/46449 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/sw/source/filter/html/htmlcss1.cxx b/sw/source/filter/html/htmlcss1.cxx index fa4e9a4951b8..14f7061c6233 100644 --- a/sw/source/filter/html/htmlcss1.cxx +++ b/sw/source/filter/html/htmlcss1.cxx @@ -1541,119 +1541,119 @@ HTMLAttr **SwHTMLParser::GetAttrTabEntry( sal_uInt16 nWhich ) switch( nWhich ) { case RES_CHRATR_BLINK: - ppAttr = &m_aAttrTab.pBlink; + ppAttr = &m_xAttrTab->pBlink; break; case RES_CHRATR_CASEMAP: - ppAttr = &m_aAttrTab.pCaseMap; + ppAttr = &m_xAttrTab->pCaseMap; break; case RES_CHRATR_COLOR: - ppAttr = &m_aAttrTab.pFontColor; + ppAttr = &m_xAttrTab->pFontColor; break; case RES_CHRATR_CROSSEDOUT: - ppAttr = &m_aAttrTab.pStrike; + ppAttr = &m_xAttrTab->pStrike; break; case RES_CHRATR_ESCAPEMENT: - ppAttr = &m_aAttrTab.pEscapement; + ppAttr = &m_xAttrTab->pEscapement; break; case RES_CHRATR_FONT: - ppAttr = &m_aAttrTab.pFont; + ppAttr = &m_xAttrTab->pFont; break; case RES_CHRATR_CJK_FONT: - ppAttr = &m_aAttrTab.pFontCJK; + ppAttr = &m_xAttrTab->pFontCJK; break; case RES_CHRATR_CTL_FONT: - ppAttr = &m_aAttrTab.pFontCTL; + ppAttr = &m_xAttrTab->pFontCTL; break; case RES_CHRATR_FONTSIZE: - ppAttr = &m_aAttrTab.pFontHeight; + ppAttr = &m_xAttrTab->pFontHeight; break; case RES_CHRATR_CJK_FONTSIZE: - ppAttr = &m_aAttrTab.pFontHeightCJK; + ppAttr = &m_xAttrTab->pFontHeightCJK; break; case RES_CHRATR_CTL_FONTSIZE: - ppAttr = &m_aAttrTab.pFontHeightCTL; + ppAttr = &m_xAttrTab->pFontHeightCTL; break; case RES_CHRATR_KERNING: - ppAttr = &m_aAttrTab.pKerning; + ppAttr = &m_xAttrTab->pKerning; break; case RES_CHRATR_POSTURE: - ppAttr = &m_aAttrTab.pItalic; + ppAttr = &m_xAttrTab->pItalic; break; case RES_CHRATR_CJK_POSTURE: - ppAttr = &m_aAttrTab.pItalicCJK; + ppAttr = &m_xAttrTab->pItalicCJK; break; case RES_CHRATR_CTL_POSTURE: - ppAttr = &m_aAttrTab.pItalicCTL; + ppAttr = &m_xAttrTab->pItalicCTL; break; case RES_CHRATR_UNDERLINE: - ppAttr = &m_aAttrTab.pUnderline; + ppAttr = &m_xAttrTab->pUnderline; break; case RES_CHRATR_WEIGHT: - ppAttr = &m_aAttrTab.pBold; + ppAttr = &m_xAttrTab->pBold; break; case RES_CHRATR_CJK_WEIGHT: - ppAttr = &m_aAttrTab.pBoldCJK; + ppAttr = &m_xAttrTab->pBoldCJK; break; case RES_CHRATR_CTL_WEIGHT: - ppAttr = &m_aAttrTab.pBoldCTL; + ppAttr = &m_xAttrTab->pBoldCTL; break; case RES_CHRATR_BACKGROUND: - ppAttr = &m_aAttrTab.pCharBrush; + ppAttr = &m_xAttrTab->pCharBrush; break; case RES_CHRATR_BOX: - ppAttr = &m_aAttrTab.pCharBox; + ppAttr = &m_xAttrTab->pCharBox; break; case RES_PARATR_LINESPACING: - ppAttr = &m_aAttrTab.pLineSpacing; + ppAttr = &m_xAttrTab->pLineSpacing; break; case RES_PARATR_ADJUST: - ppAttr = &m_aAttrTab.pAdjust; + ppAttr = &m_xAttrTab->pAdjust; break; case RES_LR_SPACE: - ppAttr = &m_aAttrTab.pLRSpace; + ppAttr = &m_xAttrTab->pLRSpace; break; case RES_UL_SPACE: - ppAttr = &m_aAttrTab.pULSpace; + ppAttr = &m_xAttrTab->pULSpace; break; case RES_BOX: - ppAttr = &m_aAttrTab.pBox; + ppAttr = &m_xAttrTab->pBox; break; case RES_BACKGROUND: - ppAttr = &m_aAttrTab.pBrush; + ppAttr = &m_xAttrTab->pBrush; break; case RES_BREAK: - ppAttr = &m_aAttrTab.pBreak; + ppAttr = &m_xAttrTab->pBreak; break; case RES_PAGEDESC: - ppAttr = &m_aAttrTab.pPageDesc; + ppAttr = &m_xAttrTab->pPageDesc; break; case RES_PARATR_SPLIT: - ppAttr = &m_aAttrTab.pSplit; + ppAttr = &m_xAttrTab->pSplit; break; case RES_PARATR_WIDOWS: - ppAttr = &m_aAttrTab.pWidows; + ppAttr = &m_xAttrTab->pWidows; break; case RES_PARATR_ORPHANS: - ppAttr = &m_aAttrTab.pOrphans; + ppAttr = &m_xAttrTab->pOrphans; break; case RES_KEEP: - ppAttr = &m_aAttrTab.pKeep; + ppAttr = &m_xAttrTab->pKeep; break; case RES_CHRATR_LANGUAGE: - ppAttr = &m_aAttrTab.pLanguage; + ppAttr = &m_xAttrTab->pLanguage; break; case RES_CHRATR_CJK_LANGUAGE: - ppAttr = &m_aAttrTab.pLanguageCJK; + ppAttr = &m_xAttrTab->pLanguageCJK; break; case RES_CHRATR_CTL_LANGUAGE: - ppAttr = &m_aAttrTab.pLanguageCTL; + ppAttr = &m_xAttrTab->pLanguageCTL; break; case RES_FRAMEDIR: - ppAttr = &m_aAttrTab.pDirection; + ppAttr = &m_xAttrTab->pDirection; break; } @@ -2261,7 +2261,7 @@ void SwHTMLParser::InsertParaAttrs( const SfxItemSet& rItemSet ) if( ppAttr ) { - NewAttr( ppAttr, *pItem ); + NewAttr(m_xAttrTab, ppAttr, *pItem); if( RES_PARATR_BEGIN > nWhich ) (*ppAttr)->SetLikePara(); m_aParaAttrs.push_back( *ppAttr ); diff --git a/sw/source/filter/html/htmlctxt.cxx b/sw/source/filter/html/htmlctxt.cxx index 263c347b01b7..bd48c6a9c223 100644 --- a/sw/source/filter/html/htmlctxt.cxx +++ b/sw/source/filter/html/htmlctxt.cxx @@ -46,8 +46,8 @@ class HTMLAttrContext_SaveDoc SwHTMLNumRuleInfo aNumRuleInfo; // Numbering for this environment std::unique_ptr<SwPosition> pPos; // Jump back to here when leaving context - std::unique_ptr<HTMLAttrTable> - pAttrTab; // Valid attributes for the environment, + std::shared_ptr<HTMLAttrTable> + xAttrTab; // Valid attributes for the environment, // if attributes shouldn't be preserved size_t nContextStMin; // Stack lower bound for the environment @@ -62,7 +62,7 @@ class HTMLAttrContext_SaveDoc public: HTMLAttrContext_SaveDoc() : - pPos( nullptr ), pAttrTab( nullptr ), + pPos( nullptr ), nContextStMin( SIZE_MAX ), nContextStAttrMin( SIZE_MAX ), bStripTrailingPara( false ), bKeepNumRules( false ), bFixHeaderDist( false ), bFixFooterDist( false ) @@ -76,7 +76,7 @@ public: void SetNumInfo( const SwHTMLNumRuleInfo& rInf ) { aNumRuleInfo.Set(rInf); } const SwHTMLNumRuleInfo& GetNumInfo() const { return aNumRuleInfo; } - HTMLAttrTable *GetAttrTab( bool bCreate= false ); + std::shared_ptr<HTMLAttrTable> GetAttrTab(bool bCreate = false); void SetContextStMin( size_t nMin ) { nContextStMin = nMin; } size_t GetContextStMin() const { return nContextStMin; } @@ -97,14 +97,14 @@ public: bool GetFixFooterDist() const { return bFixFooterDist; } }; -HTMLAttrTable *HTMLAttrContext_SaveDoc::GetAttrTab( bool bCreate ) +std::shared_ptr<HTMLAttrTable> HTMLAttrContext_SaveDoc::GetAttrTab( bool bCreate ) { - if( !pAttrTab && bCreate ) + if (!xAttrTab && bCreate) { - pAttrTab.reset( new HTMLAttrTable ); - memset( pAttrTab.get(), 0, sizeof( HTMLAttrTable )); + xAttrTab.reset(new HTMLAttrTable); + memset(xAttrTab.get(), 0, sizeof(HTMLAttrTable)); } - return pAttrTab.get(); + return xAttrTab; } HTMLAttrContext_SaveDoc *HTMLAttrContext::GetSaveDocContext( bool bCreate ) @@ -139,7 +139,7 @@ void SwHTMLParser::SplitAttrTab( const SwPosition& rNewPos ) bool bMoveBack = false; // close all open attributes and re-open them after the table - HTMLAttr** pHTMLAttributes = reinterpret_cast<HTMLAttr**>(&m_aAttrTab); + HTMLAttr** pHTMLAttributes = reinterpret_cast<HTMLAttr**>(m_xAttrTab.get()); for (auto nCnt = sizeof(HTMLAttrTable) / sizeof(HTMLAttr*); nCnt--; ++pHTMLAttributes) { HTMLAttr *pAttr = *pHTMLAttributes; @@ -244,8 +244,8 @@ void SwHTMLParser::SaveDocContext( HTMLAttrContext *pCntxt, } else { - HTMLAttrTable *pSaveAttrTab = pSave->GetAttrTab( true ); - SaveAttrTab( *pSaveAttrTab ); + std::shared_ptr<HTMLAttrTable> xSaveAttrTab = pSave->GetAttrTab(true); + SaveAttrTab(xSaveAttrTab); } pSave->SetPos( *m_pPam->GetPoint() ); @@ -282,15 +282,15 @@ void SwHTMLParser::RestoreDocContext( HTMLAttrContext *pCntxt ) FixHeaderFooterDistance( pSave->GetFixHeaderDist(), pSave->GetPos() ); - HTMLAttrTable *pSaveAttrTab = pSave->GetAttrTab(); - if( !pSaveAttrTab ) + std::shared_ptr<HTMLAttrTable> xSaveAttrTab = pSave->GetAttrTab(); + if (!xSaveAttrTab) { // Close attribute on current position and start on the old one SplitAttrTab( *pSave->GetPos() ); } else { - RestoreAttrTab( *pSaveAttrTab ); + RestoreAttrTab(xSaveAttrTab); } *m_pPam->GetPoint() = *pSave->GetPos(); @@ -480,10 +480,10 @@ void SwHTMLParser::InsertAttrs( SfxItemSet &rItemSet, // We only set the DropCap attribute if the initial spans multiple lines if( aDrop.GetLines() > 1 ) { - NewAttr( &m_aAttrTab.pDropCap, aDrop ); + NewAttr(m_xAttrTab, &m_xAttrTab->pDropCap, aDrop); HTMLAttrs &rAttrs = pContext->GetAttrs(); - rAttrs.push_back( m_aAttrTab.pDropCap ); + rAttrs.push_back( m_xAttrTab->pDropCap ); return; } @@ -562,8 +562,8 @@ void SwHTMLParser::InsertAttrs( SfxItemSet &rItemSet, aLRItem.SetTextFirstLineOfst( nIndent ); aLRItem.SetTextLeft( nLeft ); aLRItem.SetRight( nRight ); - NewAttr( &m_aAttrTab.pLRSpace, aLRItem ); - EndAttr( m_aAttrTab.pLRSpace, false ); + NewAttr(m_xAttrTab, &m_xAttrTab->pLRSpace, aLRItem); + EndAttr( m_xAttrTab->pLRSpace, false ); } break; @@ -578,33 +578,33 @@ void SwHTMLParser::InsertAttrs( SfxItemSet &rItemSet, if( !rPropInfo.m_bBottomMargin ) aULSpace.SetLower( nLower ); - NewAttr( &m_aAttrTab.pULSpace, aULSpace ); + NewAttr(m_xAttrTab, &m_xAttrTab->pULSpace, aULSpace); // save context information HTMLAttrs &rAttrs = pContext->GetAttrs(); - rAttrs.push_back( m_aAttrTab.pULSpace ); + rAttrs.push_back( m_xAttrTab->pULSpace ); pContext->SetULSpace( aULSpace.GetUpper(), aULSpace.GetLower() ); } else { - ppAttr = &m_aAttrTab.pULSpace; + ppAttr = &m_xAttrTab->pULSpace; } break; case RES_CHRATR_FONTSIZE: // don't set attributes with a % property if( static_cast<const SvxFontHeightItem *>(pItem)->GetProp() == 100 ) - ppAttr = &m_aAttrTab.pFontHeight; + ppAttr = &m_xAttrTab->pFontHeight; break; case RES_CHRATR_CJK_FONTSIZE: // don't set attributes with a % property if( static_cast<const SvxFontHeightItem *>(pItem)->GetProp() == 100 ) - ppAttr = &m_aAttrTab.pFontHeightCJK; + ppAttr = &m_xAttrTab->pFontHeightCJK; break; case RES_CHRATR_CTL_FONTSIZE: // don't set attributes with a % property if( static_cast<const SvxFontHeightItem *>(pItem)->GetProp() == 100 ) - ppAttr = &m_aAttrTab.pFontHeightCTL; + ppAttr = &m_xAttrTab->pFontHeightCTL; break; case RES_BACKGROUND: @@ -615,16 +615,16 @@ void SwHTMLParser::InsertAttrs( SfxItemSet &rItemSet, aBrushItem.SetWhich( RES_CHRATR_BACKGROUND ); // Set the attribute - NewAttr( &m_aAttrTab.pCharBrush, aBrushItem ); + NewAttr(m_xAttrTab, &m_xAttrTab->pCharBrush, aBrushItem); // and save context information HTMLAttrs &rAttrs = pContext->GetAttrs(); - rAttrs.push_back( m_aAttrTab.pCharBrush ); + rAttrs.push_back( m_xAttrTab->pCharBrush ); } else if( pContext->GetToken() != HtmlTokenId::TABLEHEADER_ON && pContext->GetToken() != HtmlTokenId::TABLEDATA_ON ) { - ppAttr = &m_aAttrTab.pBrush; + ppAttr = &m_xAttrTab->pBrush; } break; @@ -634,14 +634,14 @@ void SwHTMLParser::InsertAttrs( SfxItemSet &rItemSet, SvxBoxItem aBoxItem( *static_cast<const SvxBoxItem *>(pItem) ); aBoxItem.SetWhich( RES_CHRATR_BOX ); - NewAttr( &m_aAttrTab.pCharBox, aBoxItem ); + NewAttr(m_xAttrTab, &m_xAttrTab->pCharBox, aBoxItem); HTMLAttrs &rAttrs = pContext->GetAttrs(); - rAttrs.push_back( m_aAttrTab.pCharBox ); + rAttrs.push_back( m_xAttrTab->pCharBox ); } else { - ppAttr = &m_aAttrTab.pBox; + ppAttr = &m_xAttrTab->pBox; } break; @@ -653,7 +653,7 @@ void SwHTMLParser::InsertAttrs( SfxItemSet &rItemSet, if( ppAttr ) { // Set the attribute - NewAttr( ppAttr, *pItem ); + NewAttr(m_xAttrTab, ppAttr, *pItem); // and save context information HTMLAttrs &rAttrs = pContext->GetAttrs(); @@ -678,7 +678,7 @@ void SwHTMLParser::InsertAttr( HTMLAttr **ppAttr, const SfxPoolItem & rItem, } // Set the attribute - NewAttr( ppAttr, rItem ); + NewAttr(m_xAttrTab, ppAttr, rItem); // save context information HTMLAttrs &rAttrs = pCntxt->GetAttrs(); diff --git a/sw/source/filter/html/htmldrawreader.cxx b/sw/source/filter/html/htmldrawreader.cxx index 9720a399de2f..b937eea4608d 100644 --- a/sw/source/filter/html/htmldrawreader.cxx +++ b/sw/source/filter/html/htmldrawreader.cxx @@ -425,7 +425,7 @@ void SwHTMLParser::NewMarquee( HTMLTable *pCurTable ) } // set attribute of environment at the Draw object - HTMLAttr** pHTMLAttributes = reinterpret_cast<HTMLAttr**>(&m_aAttrTab); + HTMLAttr** pHTMLAttributes = reinterpret_cast<HTMLAttr**>(m_xAttrTab.get()); for (auto nCnt = sizeof(HTMLAttrTable) / sizeof(HTMLAttr*); nCnt--; ++pHTMLAttributes) { HTMLAttr *pAttr = *pHTMLAttributes; diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx index 54e967e661f4..53842661bd95 100644 --- a/sw/source/filter/html/htmlgrin.cxx +++ b/sw/source/filter/html/htmlgrin.cxx @@ -229,9 +229,9 @@ void SwHTMLParser::SetAnchorAndAdjustment( sal_Int16 eVertOri, if( nUpper ) { - NewAttr( &m_aAttrTab.pULSpace, SvxULSpaceItem( 0, nLower, RES_UL_SPACE ) ); - m_aParaAttrs.push_back( m_aAttrTab.pULSpace ); - EndAttr( m_aAttrTab.pULSpace, false ); + NewAttr(m_xAttrTab, &m_xAttrTab->pULSpace, SvxULSpaceItem(0, nLower, RES_UL_SPACE)); + m_aParaAttrs.push_back( m_xAttrTab->pULSpace ); + EndAttr( m_xAttrTab->pULSpace, false ); } } @@ -311,7 +311,7 @@ void SwHTMLParser::InsertImage() long nWidth=0, nHeight=0; long nVSpace=0, nHSpace=0; - sal_uInt16 nBorder = (m_aAttrTab.pINetFormat ? 1 : 0); + sal_uInt16 nBorder = (m_xAttrTab->pINetFormat ? 1 : 0); bool bIsMap = false; bool bPrcWidth = false; bool bPrcHeight = false; @@ -509,10 +509,10 @@ IMAGE_SETEVENT: ::editeng::SvxBorderLine aHBorderLine( nullptr, nHBorderWidth ); ::editeng::SvxBorderLine aVBorderLine( nullptr, nVBorderWidth ); - if( m_aAttrTab.pINetFormat ) + if( m_xAttrTab->pINetFormat ) { const OUString& rURL = - static_cast<const SwFormatINetFormat&>(m_aAttrTab.pINetFormat->GetItem()).GetValue(); + static_cast<const SwFormatINetFormat&>(m_xAttrTab->pINetFormat->GetItem()).GetValue(); m_pCSS1Parser->SetATagStyles(); sal_uInt16 nPoolId = static_cast< sal_uInt16 >(m_xDoc->IsVisitedURL( rURL ) @@ -524,8 +524,8 @@ IMAGE_SETEVENT: } else { - const SvxColorItem& rColorItem = m_aAttrTab.pFontColor ? - static_cast<const SvxColorItem &>(m_aAttrTab.pFontColor->GetItem()) : + const SvxColorItem& rColorItem = m_xAttrTab->pFontColor ? + static_cast<const SvxColorItem &>(m_xAttrTab->pFontColor->GetItem()) : static_cast<const SvxColorItem &>(m_xDoc->GetDefault(RES_CHRATR_COLOR)); aHBorderLine.SetColor( rColorItem.GetValue() ); aVBorderLine.SetColor( aHBorderLine.GetColor() ); @@ -749,10 +749,10 @@ IMAGE_SETEVENT: pGrfNd->SetScaleImageMap( true ); } - if( m_aAttrTab.pINetFormat ) + if( m_xAttrTab->pINetFormat ) { const SwFormatINetFormat &rINetFormat = - static_cast<const SwFormatINetFormat&>(m_aAttrTab.pINetFormat->GetItem()); + static_cast<const SwFormatINetFormat&>(m_xAttrTab->pINetFormat->GetItem()); SwFormatURL aURL( pFlyFormat->GetURL() ); @@ -776,14 +776,14 @@ IMAGE_SETEVENT: } if ((RndStdIds::FLY_AS_CHAR == pFlyFormat->GetAnchor().GetAnchorId()) && - m_aAttrTab.pINetFormat->GetSttPara() == + m_xAttrTab->pINetFormat->GetSttPara() == m_pPam->GetPoint()->nNode && - m_aAttrTab.pINetFormat->GetSttCnt() == + m_xAttrTab->pINetFormat->GetSttCnt() == m_pPam->GetPoint()->nContent.GetIndex() - 1 ) { // the attribute was insert right before as-character anchored // graphic, therefore we move it - m_aAttrTab.pINetFormat->SetStart( *m_pPam->GetPoint() ); + m_xAttrTab->pINetFormat->SetStart( *m_pPam->GetPoint() ); // When the attribute is also an anchor, we'll insert // a bookmark before the graphic, because SwFormatURL @@ -1233,7 +1233,7 @@ ANCHOR_SETEVENT: aINetFormat.SetMacroTable( &aMacroTable ); // set the default attribute - InsertAttr(&m_aAttrTab.pINetFormat, aINetFormat, xCntxt.get()); + InsertAttr(&m_xAttrTab->pINetFormat, aINetFormat, xCntxt.get()); } else if( !aName.isEmpty() ) { @@ -1274,7 +1274,7 @@ void SwHTMLParser::EndAnchor() void SwHTMLParser::InsertBookmark( const OUString& rName ) { HTMLAttr* pTmp = new HTMLAttr( *m_pPam->GetPoint(), - SfxStringItem( RES_FLTR_BOOKMARK, rName )); + SfxStringItem(RES_FLTR_BOOKMARK, rName), nullptr, std::shared_ptr<HTMLAttrTable>()); m_aSetAttrTab.push_back( pTmp ); } diff --git a/sw/source/filter/html/htmlsect.cxx b/sw/source/filter/html/htmlsect.cxx index a158212e09d8..67fa9d916d8a 100644 --- a/sw/source/filter/html/htmlsect.cxx +++ b/sw/source/filter/html/htmlsect.cxx @@ -368,7 +368,7 @@ void SwHTMLParser::NewDivision( HtmlTokenId nToken ) if( SvxAdjust::End != eAdjust ) { - InsertAttr(&m_aAttrTab.pAdjust, SvxAdjustItem(eAdjust, RES_PARATR_ADJUST), xCntxt.get()); + InsertAttr(&m_xAttrTab->pAdjust, SvxAdjustItem(eAdjust, RES_PARATR_ADJUST), xCntxt.get()); } // parse style diff --git a/sw/source/filter/html/htmltab.cxx b/sw/source/filter/html/htmltab.cxx index 6810a222c742..18d3a45f62af 100644 --- a/sw/source/filter/html/htmltab.cxx +++ b/sw/source/filter/html/htmltab.cxx @@ -122,7 +122,7 @@ class HTMLTableContext public: - HTMLAttrTable aAttrTab; // attributes + std::shared_ptr<HTMLAttrTable> xAttrTab; // attributes HTMLTableContext( SwPosition *pPs, size_t nCntxtStMin, size_t nCntxtStAttrMin ) : @@ -133,9 +133,10 @@ public: nContextStMin( nCntxtStMin ), bRestartPRE( false ), bRestartXMP( false ), - bRestartListing( false ) + bRestartListing( false ), + xAttrTab(new HTMLAttrTable) { - memset( &aAttrTab, 0, sizeof( HTMLAttrTable )); + memset(xAttrTab.get(), 0, sizeof(HTMLAttrTable)); } void SetNumInfo( const SwHTMLNumRuleInfo& rInf ) { aNumRuleInfo.Set(rInf); } @@ -3109,7 +3110,7 @@ CellSaveStruct::CellSaveStruct( SwHTMLParser& rParser, HTMLTable const *pCurTabl } std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(nToken, nColl, aEmptyOUStr, true)); if( SvxAdjust::End != m_eAdjust ) - rParser.InsertAttr(&rParser.m_aAttrTab.pAdjust, SvxAdjustItem(m_eAdjust, RES_PARATR_ADJUST), + rParser.InsertAttr(&rParser.m_xAttrTab->pAdjust, SvxAdjustItem(m_eAdjust, RES_PARATR_ADJUST), xCntxt.get()); if( SwHTMLParser::HasStyleOptions( m_aStyle, m_aId, m_aClass, &m_aLang, &m_aDir ) ) @@ -3165,7 +3166,7 @@ void CellSaveStruct::InsertCell( SwHTMLParser& rParser, if( rParser.m_nContextStAttrMin == GetContextStAttrMin() ) { - HTMLAttr** pTable = reinterpret_cast<HTMLAttr**>(&rParser.m_aAttrTab); + HTMLAttr** pTable = reinterpret_cast<HTMLAttr**>(rParser.m_xAttrTab.get()); for( auto nCnt = sizeof( HTMLAttrTable ) / sizeof( HTMLAttr* ); nCnt--; ++pTable ) @@ -3263,7 +3264,7 @@ HTMLTableCnts *SwHTMLParser::InsertTableContents( const SwNodeIndex& rSttPara = m_pPam->GetPoint()->nNode; sal_Int32 nSttCnt = m_pPam->GetPoint()->nContent.GetIndex(); - HTMLAttr** pHTMLAttributes = reinterpret_cast<HTMLAttr**>(&m_aAttrTab); + HTMLAttr** pHTMLAttributes = reinterpret_cast<HTMLAttr**>(m_xAttrTab.get()); for (sal_uInt16 nCnt = sizeof(HTMLAttrTable) / sizeof(HTMLAttr*); nCnt--; ++pHTMLAttributes) { HTMLAttr *pAttr = *pHTMLAttributes; @@ -3422,21 +3423,21 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions, SvxFontHeightItem aFontHeight( 40, 100, RES_CHRATR_FONTSIZE ); HTMLAttr* pTmp = - new HTMLAttr( *m_pPam->GetPoint(), aFontHeight ); + new HTMLAttr( *m_pPam->GetPoint(), aFontHeight, nullptr, std::shared_ptr<HTMLAttrTable>() ); m_aSetAttrTab.push_back( pTmp ); SvxFontHeightItem aFontHeightCJK( 40, 100, RES_CHRATR_CJK_FONTSIZE ); pTmp = - new HTMLAttr( *m_pPam->GetPoint(), aFontHeightCJK ); + new HTMLAttr( *m_pPam->GetPoint(), aFontHeightCJK, nullptr, std::shared_ptr<HTMLAttrTable>() ); m_aSetAttrTab.push_back( pTmp ); SvxFontHeightItem aFontHeightCTL( 40, 100, RES_CHRATR_CTL_FONTSIZE ); pTmp = - new HTMLAttr( *m_pPam->GetPoint(), aFontHeightCTL ); + new HTMLAttr( *m_pPam->GetPoint(), aFontHeightCTL, nullptr, std::shared_ptr<HTMLAttrTable>() ); m_aSetAttrTab.push_back( pTmp ); pTmp = new HTMLAttr( *m_pPam->GetPoint(), - SvxULSpaceItem( 0, 0, RES_UL_SPACE ) ); + SvxULSpaceItem( 0, 0, RES_UL_SPACE ), nullptr, std::shared_ptr<HTMLAttrTable>() ); m_aSetAttrTab.push_front( pTmp ); // Position 0, since // something can be set by // the table end before @@ -3482,7 +3483,7 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions, HTMLAttrs *pPostIts = nullptr; if( !bForceFrame && (bTopTable || pCurTable->HasParentSection()) ) { - SplitAttrTab( pTCntxt->aAttrTab, bTopTable ); + SplitAttrTab(pTCntxt->xAttrTab, bTopTable); // If we reuse a already existing paragraph, we can't add // PostIts since the paragraph gets behind that table. // They're gonna be moved into the first paragraph of the table @@ -3496,7 +3497,7 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions, } else { - SaveAttrTab( pTCntxt->aAttrTab ); + SaveAttrTab(pTCntxt->xAttrTab); if( bTopTable && !bAppended ) { pPostIts = new HTMLAttrs; @@ -3763,8 +3764,8 @@ void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, bool bReadOptions, } // There could be a section in the cell - eTabAdjust = m_aAttrTab.pAdjust - ? static_cast<const SvxAdjustItem&>(m_aAttrTab.pAdjust->GetItem()). + eTabAdjust = m_xAttrTab->pAdjust + ? static_cast<const SvxAdjustItem&>(m_xAttrTab->pAdjust->GetItem()). GetAdjust() : SvxAdjust::End; } @@ -4565,12 +4566,13 @@ class CaptionSaveStruct : public SectionSaveStruct public: - HTMLAttrTable aAttrTab; // attributes + std::shared_ptr<HTMLAttrTable> xAttrTab; // attributes CaptionSaveStruct( SwHTMLParser& rParser, const SwPosition& rPos ) : - SectionSaveStruct( rParser ), aSavePos( rPos ) + SectionSaveStruct( rParser ), aSavePos( rPos ), + xAttrTab(new HTMLAttrTable) { - rParser.SaveAttrTab( aAttrTab ); + rParser.SaveAttrTab(xAttrTab); // The current numbering was remembered and just needs to be closed aNumRuleInfo.Set( rParser.GetNumInfo() ); @@ -4585,7 +4587,7 @@ public: Restore( rParser ); // Recover the old attribute tables - rParser.RestoreAttrTab( aAttrTab ); + rParser.RestoreAttrTab(xAttrTab); // Re-open the old numbering rParser.GetNumInfo().Set( aNumRuleInfo ); @@ -4651,10 +4653,10 @@ void SwHTMLParser::BuildTableCaption( HTMLTable *pCurTable ) std::unique_ptr<HTMLAttrContext> xCntxt(new HTMLAttrContext(HtmlTokenId::CAPTION_ON)); // Table headers are always centered - NewAttr( &m_aAttrTab.pAdjust, SvxAdjustItem(SvxAdjust::Center, RES_PARATR_ADJUST) ); + NewAttr(m_xAttrTab, &m_xAttrTab->pAdjust, SvxAdjustItem(SvxAdjust::Center, RES_PARATR_ADJUST)); HTMLAttrs &rAttrs = xCntxt->GetAttrs(); - rAttrs.push_back( m_aAttrTab.pAdjust ); + rAttrs.push_back( m_xAttrTab->pAdjust ); PushContext(xCntxt); @@ -5181,7 +5183,7 @@ std::shared_ptr<HTMLTable> SwHTMLParser::BuildTable(SvxAdjust eParentAdjust, GetNumInfo().Set( pTCntxt->GetNumInfo() ); pTCntxt->RestorePREListingXMP( *this ); - RestoreAttrTab( pTCntxt->aAttrTab ); + RestoreAttrTab(pTCntxt->xAttrTab); if (m_xTable == xCurTable && eState != SvParserState::Error) { diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx index ef5b157fbe9c..88d926472082 100644 --- a/sw/source/filter/html/swhtml.cxx +++ b/sw/source/filter/html/swhtml.cxx @@ -246,6 +246,7 @@ SwHTMLParser::SwHTMLParser( SwDoc* pD, SwPaM& rCursor, SvStream& rIn, SwClient( nullptr ), m_aPathToFile( rPath ), m_sBaseURL( rBaseURL ), + m_xAttrTab(new HTMLAttrTable), m_pAppletImpl( nullptr ), m_pCSS1Parser( nullptr ), m_pNumRuleInfo( new SwHTMLNumRuleInfo ), @@ -305,7 +306,7 @@ SwHTMLParser::SwHTMLParser( SwDoc* pD, SwPaM& rCursor, SvStream& rIn, rCursor.DeleteMark(); m_pPam = &rCursor; // re-use existing cursor: avoids spurious ~SwIndexReg assert - memset( &m_aAttrTab, 0, sizeof( HTMLAttrTable )); + memset(m_xAttrTab.get(), 0, sizeof(HTMLAttrTable)); // Read the font sizes 1-7 from the INI file SvxHtmlOptions& rHtmlOptions = SvxHtmlOptions::Get(); @@ -1441,8 +1442,8 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken ) AppendTextNode(); if (!m_xTable && !m_xDoc->IsInHeaderFooter(m_pPam->GetPoint()->nNode)) { - NewAttr( &m_aAttrTab.pBreak, SvxFormatBreakItem(SvxBreak::PageBefore, RES_BREAK) ); - EndAttr( m_aAttrTab.pBreak, false ); + NewAttr(m_xAttrTab, &m_xAttrTab->pBreak, SvxFormatBreakItem(SvxBreak::PageBefore, RES_BREAK)); + EndAttr( m_xAttrTab->pBreak, false ); } break; @@ -1686,8 +1687,8 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken ) if ( m_nParaCnt < 5 ) Show(); // show what we have up to here - SvxAdjust eAdjust = m_aAttrTab.pAdjust - ? static_cast<const SvxAdjustItem&>(m_aAttrTab.pAdjust->GetItem()). + SvxAdjust eAdjust = m_xAttrTab->pAdjust + ? static_cast<const SvxAdjustItem&>(m_xAttrTab->pAdjust->GetItem()). GetAdjust() : SvxAdjust::End; BuildTable( eAdjust ); @@ -1743,9 +1744,9 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken ) SvxPostureItem aPostureCJK( ITALIC_NORMAL, RES_CHRATR_CJK_POSTURE ); SvxPostureItem aPostureCTL( ITALIC_NORMAL, RES_CHRATR_CTL_POSTURE ); NewStdAttr( HtmlTokenId::ITALIC_ON, - &m_aAttrTab.pItalic, aPosture, - &m_aAttrTab.pItalicCJK, &aPostureCJK, - &m_aAttrTab.pItalicCTL, &aPostureCTL ); + &m_xAttrTab->pItalic, aPosture, + &m_xAttrTab->pItalicCJK, &aPostureCJK, + &m_xAttrTab->pItalicCTL, &aPostureCTL ); } break; @@ -1755,44 +1756,44 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken ) SvxWeightItem aWeightCJK( WEIGHT_BOLD, RES_CHRATR_CJK_WEIGHT ); SvxWeightItem aWeightCTL( WEIGHT_BOLD, RES_CHRATR_CTL_WEIGHT ); NewStdAttr( HtmlTokenId::BOLD_ON, - &m_aAttrTab.pBold, aWeight, - &m_aAttrTab.pBoldCJK, &aWeightCJK, - &m_aAttrTab.pBoldCTL, &aWeightCTL ); + &m_xAttrTab->pBold, aWeight, + &m_xAttrTab->pBoldCJK, &aWeightCJK, + &m_xAttrTab->pBoldCTL, &aWeightCTL ); } break; case HtmlTokenId::STRIKE_ON: case HtmlTokenId::STRIKETHROUGH_ON: { - NewStdAttr( HtmlTokenId::STRIKE_ON, &m_aAttrTab.pStrike, + NewStdAttr( HtmlTokenId::STRIKE_ON, &m_xAttrTab->pStrike, SvxCrossedOutItem(STRIKEOUT_SINGLE, RES_CHRATR_CROSSEDOUT) ); } break; case HtmlTokenId::UNDERLINE_ON: { - NewStdAttr( HtmlTokenId::UNDERLINE_ON, &m_aAttrTab.pUnderline, + NewStdAttr( HtmlTokenId::UNDERLINE_ON, &m_xAttrTab->pUnderline, SvxUnderlineItem(LINESTYLE_SINGLE, RES_CHRATR_UNDERLINE) ); } break; case HtmlTokenId::SUPERSCRIPT_ON: { - NewStdAttr( HtmlTokenId::SUPERSCRIPT_ON, &m_aAttrTab.pEscapement, + NewStdAttr( HtmlTokenId::SUPERSCRIPT_ON, &m_xAttrTab->pEscapement, SvxEscapementItem(HTML_ESC_SUPER,HTML_ESC_PROP, RES_CHRATR_ESCAPEMENT) ); } break; case HtmlTokenId::SUBSCRIPT_ON: { - NewStdAttr( HtmlTokenId::SUBSCRIPT_ON, &m_aAttrTab.pEscapement, + NewStdAttr( HtmlTokenId::SUBSCRIPT_ON, &m_xAttrTab->pEscapement, SvxEscapementItem(HTML_ESC_SUB,HTML_ESC_PROP, RES_CHRATR_ESCAPEMENT) ); } break; case HtmlTokenId::BLINK_ON: { - NewStdAttr( HtmlTokenId::BLINK_ON, &m_aAttrTab.pBlink, + NewStdAttr( HtmlTokenId::BLINK_ON, &m_xAttrTab->pBlink, SvxBlinkItem( true, RES_CHRATR_BLINK ) ); } break; @@ -2140,7 +2141,7 @@ bool SwHTMLParser::AppendTextNode( SwHTMLAppendMode eMode, bool bUpdateNum ) const sal_Int32 nEndCnt = aOldPos.nContent.GetIndex(); const SwPosition& rPos = *m_pPam->GetPoint(); - HTMLAttr** pHTMLAttributes = reinterpret_cast<HTMLAttr**>(&m_aAttrTab); + HTMLAttr** pHTMLAttributes = reinterpret_cast<HTMLAttr**>(m_xAttrTab.get()); for (auto nCnt = sizeof(HTMLAttrTable) / sizeof(HTMLAttr*); nCnt--; ++pHTMLAttributes) { HTMLAttr *pAttr = *pHTMLAttributes; @@ -2966,7 +2967,7 @@ void SwHTMLParser::SetAttr_( bool bChkEnd, bool bBeforeTable, } } -void SwHTMLParser::NewAttr( HTMLAttr **ppAttr, const SfxPoolItem& rItem ) +void SwHTMLParser::NewAttr(const std::shared_ptr<HTMLAttrTable>& rAttrTable, HTMLAttr **ppAttr, const SfxPoolItem& rItem ) { // Font height and font colour as well as escape attributes may not be // combined. Therefore they're saved in a list and in it the last opened @@ -2974,13 +2975,12 @@ void SwHTMLParser::NewAttr( HTMLAttr **ppAttr, const SfxPoolItem& rItem ) // attributes count is just incremented. if( *ppAttr ) { - HTMLAttr *pAttr = new HTMLAttr( *m_pPam->GetPoint(), rItem, - ppAttr ); + HTMLAttr *pAttr = new HTMLAttr(*m_pPam->GetPoint(), rItem, ppAttr, rAttrTable); pAttr->InsertNext( *ppAttr ); (*ppAttr) = pAttr; } else - (*ppAttr) = new HTMLAttr( *m_pPam->GetPoint(), rItem, ppAttr ); + (*ppAttr) = new HTMLAttr(*m_pPam->GetPoint(), rItem, ppAttr, rAttrTable); } bool SwHTMLParser::EndAttr( HTMLAttr* pAttr, bool bChkEmpty ) @@ -3202,7 +3202,7 @@ void SwHTMLParser::DeleteAttr( HTMLAttr* pAttr ) *ppHead = pNext; } -void SwHTMLParser::SaveAttrTab( HTMLAttrTable& rNewAttrTab ) +void SwHTMLParser::SaveAttrTab(std::shared_ptr<HTMLAttrTable>& rNewAttrTab) { // preliminary paragraph attributes are not allowed here, they could // be set here and then the pointers become invalid! @@ -3211,8 +3211,8 @@ void SwHTMLParser::SaveAttrTab( HTMLAttrTable& rNewAttrTab ) if( !m_aParaAttrs.empty() ) m_aParaAttrs.clear(); - HTMLAttr** pHTMLAttributes = reinterpret_cast<HTMLAttr**>(&m_aAttrTab); - HTMLAttr** pSaveAttributes = reinterpret_cast<HTMLAttr**>(&rNewAttrTab); + HTMLAttr** pHTMLAttributes = reinterpret_cast<HTMLAttr**>(m_xAttrTab.get()); + HTMLAttr** pSaveAttributes = reinterpret_cast<HTMLAttr**>(rNewAttrTab.get()); for (auto nCnt = sizeof(HTMLAttrTable) / sizeof(HTMLAttr*); nCnt--; ++pHTMLAttributes, ++pSaveAttributes) { @@ -3221,7 +3221,7 @@ void SwHTMLParser::SaveAttrTab( HTMLAttrTable& rNewAttrTab ) HTMLAttr *pAttr = *pSaveAttributes; while (pAttr) { - pAttr->SetHead(pSaveAttributes); + pAttr->SetHead(pSaveAttributes, rNewAttrTab); pAttr = pAttr->GetNext(); } @@ -3229,7 +3229,7 @@ void SwHTMLParser::SaveAttrTab( HTMLAttrTable& rNewAttrTab ) } } -void SwHTMLParser::SplitAttrTab( HTMLAttrTable& rNewAttrTab, +void SwHTMLParser::SplitAttrTab( std::shared_ptr<HTMLAttrTable>& rNewAttrTab, bool bMoveEndBack ) { // preliminary paragraph attributes are not allowed here, they could @@ -3243,8 +3243,8 @@ void SwHTMLParser::SplitAttrTab( HTMLAttrTable& rNewAttrTab, SwNodeIndex nEndIdx( nSttIdx ); // close all still open attributes and re-open them after the table - HTMLAttr** pHTMLAttributes = reinterpret_cast<HTMLAttr**>(&m_aAttrTab); - HTMLAttr** pSaveAttributes = reinterpret_cast<HTMLAttr**>(&rNewAttrTab); + HTMLAttr** pHTMLAttributes = reinterpret_cast<HTMLAttr**>(m_xAttrTab.get()); + HTMLAttr** pSaveAttributes = reinterpret_cast<HTMLAttr**>(rNewAttrTab.get()); bool bSetAttr = true; const sal_Int32 nSttCnt = m_pPam->GetPoint()->nContent.GetIndex(); sal_Int32 nEndCnt = nSttCnt; @@ -3311,7 +3311,7 @@ void SwHTMLParser::SplitAttrTab( HTMLAttrTable& rNewAttrTab, } // set the start of the attribute anew and break link - pAttr->Reset(nSttIdx, nSttCnt, pSaveAttributes); + pAttr->Reset(nSttIdx, nSttCnt, pSaveAttributes, rNewAttrTab); if (*pSaveAttributes) { @@ -3330,7 +3330,7 @@ void SwHTMLParser::SplitAttrTab( HTMLAttrTable& rNewAttrTab, } } -void SwHTMLParser::RestoreAttrTab( HTMLAttrTable& rNewAttrTab ) +void SwHTMLParser::RestoreAttrTab(std::shared_ptr<HTMLAttrTable>& rNewAttrTab) { // preliminary paragraph attributes are not allowed here, they could // be set here and then the pointers become invalid! @@ -3339,8 +3339,8 @@ void SwHTMLParser::RestoreAttrTab( HTMLAttrTable& rNewAttrTab ) if( !m_aParaAttrs.empty() ) m_aParaAttrs.clear(); - HTMLAttr** pHTMLAttributes = reinterpret_cast<HTMLAttr**>(&m_aAttrTab); - HTMLAttr** pSaveAttributes = reinterpret_cast<HTMLAttr**>(&rNewAttrTab); + HTMLAttr** pHTMLAttributes = reinterpret_cast<HTMLAttr**>(m_xAttrTab.get()); + HTMLAttr** pSaveAttributes = reinterpret_cast<HTMLAttr**>(rNewAttrTab.get()); for (auto nCnt = sizeof(HTMLAttrTable) / sizeof(HTMLAttr*); nCnt--; ++pHTMLAttributes, ++pSaveAttributes) { @@ -3353,7 +3353,7 @@ void SwHTMLParser::RestoreAttrTab( HTMLAttrTable& rNewAttrTab ) { OSL_ENSURE( !pAttr->GetPrev() || !pAttr->GetPrev()->ppHead, "Previous attribute has still a header" ); - pAttr->SetHead(pHTMLAttributes); + pAttr->SetHead(pHTMLAttributes, m_xAttrTab); pAttr = pAttr->GetNext(); } @@ -3363,8 +3363,7 @@ void SwHTMLParser::RestoreAttrTab( HTMLAttrTable& rNewAttrTab ) void SwHTMLParser::InsertAttr( const SfxPoolItem& rItem, bool bInsAtStart ) { - HTMLAttr* pTmp = new HTMLAttr( *m_pPam->GetPoint(), - rItem ); + HTMLAttr* pTmp = new HTMLAttr(*m_pPam->GetPoint(), rItem, nullptr, std::shared_ptr<HTMLAttrTable>()); if (bInsAtStart) m_aSetAttrTab.push_front( pTmp ); else @@ -3583,11 +3582,11 @@ void SwHTMLParser::NewBasefontAttr() else { SvxFontHeightItem aFontHeight( m_aFontHeights[nSize-1], 100, RES_CHRATR_FONTSIZE ); - InsertAttr( &m_aAttrTab.pFontHeight, aFontHeight, xCntxt.get() ); + InsertAttr( &m_xAttrTab->pFontHeight, aFontHeight, xCntxt.get() ); SvxFontHeightItem aFontHeightCJK( m_aFontHeights[nSize-1], 100, RES_CHRATR_CJK_FONTSIZE ); - InsertAttr( &m_aAttrTab.pFontHeightCJK, aFontHeightCJK, xCntxt.get() ); + InsertAttr( &m_xAttrTab->pFontHeightCJK, aFontHeightCJK, xCntxt.get() ); SvxFontHeightItem aFontHeightCTL( m_aFontHeights[nSize-1], 100, RES_CHRATR_CTL_FONTSIZE ); - InsertAttr( &m_aAttrTab.pFontHeightCTL, aFontHeightCTL, xCntxt.get() ); + InsertAttr( &m_xAttrTab->pFontHeightCTL, aFontHeightCTL, xCntxt.get() ); } // save the context @@ -3799,22 +3798,22 @@ void SwHTMLParser::NewFontAttr( HtmlTokenId nToken ) if( nFontHeight ) { SvxFontHeightItem aFontHeight( nFontHeight, 100, RES_CHRATR_FONTSIZE ); - InsertAttr( &m_aAttrTab.pFontHeight, aFontHeight, xCntxt.get() ); + InsertAttr( &m_xAttrTab->pFontHeight, aFontHeight, xCntxt.get() ); SvxFontHeightItem aFontHeightCJK( nFontHeight, 100, RES_CHRATR_CJK_FONTSIZE ); - InsertAttr( &m_aAttrTab.pFontHeight, aFontHeightCJK, xCntxt.get() ); + InsertAttr( &m_xAttrTab->pFontHeight, aFontHeightCJK, xCntxt.get() ); SvxFontHeightItem aFontHeightCTL( nFontHeight, 100, RES_CHRATR_CTL_FONTSIZE ); - InsertAttr( &m_aAttrTab.pFontHeight, aFontHeightCTL, xCntxt.get() ); + InsertAttr( &m_xAttrTab->pFontHeight, aFontHeightCTL, xCntxt.get() ); } if( bColor ) - InsertAttr( &m_aAttrTab.pFontColor, SvxColorItem(aColor, RES_CHRATR_COLOR), xCntxt.get() ); + InsertAttr( &m_xAttrTab->pFontColor, SvxColorItem(aColor, RES_CHRATR_COLOR), xCntxt.get() ); if( !aFontName.isEmpty() ) { SvxFontItem aFont( eFamily, aFontName, aStyleName, ePitch, eEnc, RES_CHRATR_FONT ); - InsertAttr( &m_aAttrTab.pFont, aFont, xCntxt.get() ); + InsertAttr( &m_xAttrTab->pFont, aFont, xCntxt.get() ); SvxFontItem aFontCJK( eFamily, aFontName, aStyleName, ePitch, eEnc, RES_CHRATR_CJK_FONT ); - InsertAttr( &m_aAttrTab.pFont, aFontCJK, xCntxt.get() ); + InsertAttr( &m_xAttrTab->pFont, aFontCJK, xCntxt.get() ); SvxFontItem aFontCTL( eFamily, aFontName, aStyleName, ePitch, eEnc, RES_CHRATR_CTL_FONT ); - InsertAttr( &m_aAttrTab.pFont, aFontCTL, xCntxt.get() ); + InsertAttr( &m_xAttrTab->pFont, aFontCTL, xCntxt.get() ); } } @@ -3894,7 +3893,7 @@ void SwHTMLParser::NewPara() } if( SvxAdjust::End != m_eParaAdjust ) - InsertAttr( &m_aAttrTab.pAdjust, SvxAdjustItem(m_eParaAdjust, RES_PARATR_ADJUST), xCntxt.get() ); + InsertAttr( &m_xAttrTab->pAdjust, SvxAdjustItem(m_eParaAdjust, RES_PARATR_ADJUST), xCntxt.get() ); // and push on stack PushContext( xCntxt ); @@ -4028,7 +4027,7 @@ void SwHTMLParser::NewHeading( HtmlTokenId nToken ) } if( SvxAdjust::End != m_eParaAdjust ) - InsertAttr( &m_aAttrTab.pAdjust, SvxAdjustItem(m_eParaAdjust, RES_PARATR_ADJUST), xCntxt.get() ); + InsertAttr( &m_xAttrTab->pAdjust, SvxAdjustItem(m_eParaAdjust, RES_PARATR_ADJUST), xCntxt.get() ); // and push on stack PushContext(xCntxt); @@ -4706,10 +4705,10 @@ void SwHTMLParser::SetTextCollAttrs( HTMLAttrContext *pContext ) pItemSet->Put( aLRItem ); else { - NewAttr( &m_aAttrTab.pLRSpace, aLRItem ); - m_aAttrTab.pLRSpace->SetLikePara(); - m_aParaAttrs.push_back( m_aAttrTab.pLRSpace ); - EndAttr( m_aAttrTab.pLRSpace, false ); + NewAttr(m_xAttrTab, &m_xAttrTab->pLRSpace, aLRItem); + m_xAttrTab->pLRSpace->SetLikePara(); + m_aParaAttrs.push_back( m_xAttrTab->pLRSpace ); + EndAttr( m_xAttrTab->pLRSpace, false ); } } @@ -4776,7 +4775,7 @@ void SwHTMLParser::NewCharFormat( HtmlTokenId nToken ) // Character formats are stored in their own stack and can never be inserted // by styles. Therefore the attribute doesn't exist in CSS1-Which-Range. if( pCFormat ) - InsertAttr( &m_aAttrTab.pCharFormats, SwFormatCharFormat( pCFormat ), xCntxt.get() ); + InsertAttr( &m_xAttrTab->pCharFormats, SwFormatCharFormat( pCFormat ), xCntxt.get() ); // save the context PushContext(xCntxt); @@ -4910,8 +4909,8 @@ void SwHTMLParser::InsertSpacer() } else { - NewAttr( &m_aAttrTab.pULSpace, SvxULSpaceItem( 0, (sal_uInt16)nSize, RES_UL_SPACE ) ); - EndAttr( m_aAttrTab.pULSpace, false ); + NewAttr(m_xAttrTab, &m_xAttrTab->pULSpace, SvxULSpaceItem(0, (sal_uInt16)nSize, RES_UL_SPACE)); + EndAttr( m_xAttrTab->pULSpace, false ); AppendTextNode(); // Don't change spacing! } @@ -4943,15 +4942,15 @@ void SwHTMLParser::InsertSpacer() aLRItem.SetRight( nRight ); aLRItem.SetTextFirstLineOfst( nIndent ); - NewAttr( &m_aAttrTab.pLRSpace, aLRItem ); - EndAttr( m_aAttrTab.pLRSpace, false ); + NewAttr(m_xAttrTab, &m_xAttrTab->pLRSpace, aLRItem); + EndAttr( m_xAttrTab->pLRSpace, false ); } else { - NewAttr( &m_aAttrTab.pKerning, SvxKerningItem( (short)nSize, RES_CHRATR_KERNING ) ); + NewAttr(m_xAttrTab, &m_xAttrTab->pKerning, SvxKerningItem( (short)nSize, RES_CHRATR_KERNING )); OUString aTmp( ' ' ); m_xDoc->getIDocumentContentOperations().InsertString( *m_pPam, aTmp ); - EndAttr( m_aAttrTab.pKerning ); + EndAttr( m_xAttrTab->pKerning ); } } } @@ -5137,8 +5136,8 @@ void SwHTMLParser::InsertLineBreak() if( bBreakItem && SvxBreak::PageAfter==aBreakItem.GetBreak() ) { - NewAttr( &m_aAttrTab.pBreak, aBreakItem ); - EndAttr( m_aAttrTab.pBreak, false ); + NewAttr(m_xAttrTab, &m_xAttrTab->pBreak, aBreakItem); + EndAttr( m_xAttrTab->pBreak, false ); } if( !bCleared && !bBreakItem ) @@ -5158,8 +5157,8 @@ void SwHTMLParser::InsertLineBreak() } if( bBreakItem && SvxBreak::PageBefore==aBreakItem.GetBreak() ) { - NewAttr( &m_aAttrTab.pBreak, aBreakItem ); - EndAttr( m_aAttrTab.pBreak, false ); + NewAttr(m_xAttrTab, &m_xAttrTab->pBreak, aBreakItem); + EndAttr( m_xAttrTab->pBreak, false ); } } @@ -5264,7 +5263,7 @@ void SwHTMLParser::InsertHorzRule() SvxBoxItem aBoxItem(RES_BOX); aBoxItem.SetLine( &aBorderLine, SvxBoxItemLine::BOTTOM ); - HTMLAttr* pTmp = new HTMLAttr( *m_pPam->GetPoint(), aBoxItem ); + HTMLAttr* pTmp = new HTMLAttr(*m_pPam->GetPoint(), aBoxItem, nullptr, std::shared_ptr<HTMLAttrTable>()); m_aSetAttrTab.push_back( pTmp ); } if( nWidth ) @@ -5304,7 +5303,7 @@ void SwHTMLParser::InsertHorzRule() break; } - HTMLAttr* pTmp = new HTMLAttr( *m_pPam->GetPoint(), aLRItem ); + HTMLAttr* pTmp = new HTMLAttr(*m_pPam->GetPoint(), aLRItem, nullptr, std::shared_ptr<HTMLAttrTable>()); m_aSetAttrTab.push_back( pTmp ); } } @@ -5398,7 +5397,7 @@ void SwHTMLParser::ParseMoreMetaOptions() } HTMLAttr::HTMLAttr( const SwPosition& rPos, const SfxPoolItem& rItem, - HTMLAttr **ppHd ) : + HTMLAttr **ppHd, const std::shared_ptr<HTMLAttrTable>& rAttrTab ) : nSttPara( rPos.nNode ), nEndPara( rPos.nNode ), nSttContent( rPos.nContent.GetIndex() ), @@ -5407,6 +5406,7 @@ HTMLAttr::HTMLAttr( const SwPosition& rPos, const SfxPoolItem& rItem, bLikePara( false ), bValid( true ), pItem( rItem.Clone() ), + xAttrTab( rAttrTab ), pNext( nullptr ), pPrev( nullptr ), ppHead( ppHd ) @@ -5414,7 +5414,7 @@ HTMLAttr::HTMLAttr( const SwPosition& rPos, const SfxPoolItem& rItem, } HTMLAttr::HTMLAttr( const HTMLAttr &rAttr, const SwNodeIndex &rEndPara, - sal_Int32 nEndCnt, HTMLAttr **ppHd ) : + sal_Int32 nEndCnt, HTMLAttr **ppHd, const std::shared_ptr<HTMLAttrTable>& rAttrTab ) : nSttPara( rAttr.nSttPara ), nEndPara( rEndPara ), nSttContent( rAttr.nSttContent ), @@ -5423,6 +5423,7 @@ HTMLAttr::HTMLAttr( const HTMLAttr &rAttr, const SwNodeIndex &rEndPara, bLikePara( rAttr.bLikePara ), bValid( rAttr.bValid ), pItem( rAttr.pItem->Clone() ), + xAttrTab( rAttrTab ), pNext( nullptr ), pPrev( nullptr ), ppHead( ppHd ) @@ -5436,7 +5437,7 @@ HTMLAttr::~HTMLAttr() HTMLAttr *HTMLAttr::Clone(const SwNodeIndex& rEndPara, sal_Int32 nEndCnt) const { // create the attribute anew with old start position - HTMLAttr *pNew = new HTMLAttr( *this, rEndPara, nEndCnt, ppHead ); + HTMLAttr *pNew = new HTMLAttr( *this, rEndPara, nEndCnt, ppHead, xAttrTab ); // The Previous-List must be taken over, the Next-List not! pNew->pPrev = pPrev; @@ -5445,7 +5446,7 @@ HTMLAttr *HTMLAttr::Clone(const SwNodeIndex& rEndPara, sal_Int32 nEndCnt) const } void HTMLAttr::Reset(const SwNodeIndex& rSttPara, sal_Int32 nSttCnt, - HTMLAttr **ppHd) + HTMLAttr **ppHd, const std::shared_ptr<HTMLAttrTable>& rAttrTab) { // reset the start (and the end) nSttPara = rSttPara; @@ -5457,6 +5458,7 @@ void HTMLAttr::Reset(const SwNodeIndex& rSttPara, sal_Int32 nSttCnt, pNext = nullptr; pPrev = nullptr; ppHead = ppHd; + xAttrTab = rAttrTab; } void HTMLAttr::InsertPrev( HTMLAttr *pPrv ) diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx index c02309b7e4c0..198cc2ab739b 100644 --- a/sw/source/filter/html/swhtml.hxx +++ b/sw/source/filter/html/swhtml.hxx @@ -72,6 +72,57 @@ extern HTMLOptionEnum<sal_Int16> aHTMLImgVAlignTable[]; class HTMLAttr; typedef std::deque<HTMLAttr *> HTMLAttrs; +// Table of attributes: The order here is important: The attributes in the +// beginning of the table will set first in EndAllAttrs. +struct HTMLAttrTable +{ + HTMLAttr + *pKeep, // frame attributes + *pBox, + *pBrush, + *pBreak, + *pPageDesc, + + *pLRSpace, // paragraph attributes + *pULSpace, + *pLineSpacing, + *pAdjust, + *pDropCap, + *pSplit, + *pWidows, + *pOrphans, + *pDirection, + + *pCharFormats, // text attributes + *pINetFormat, + + *pBold, // character attributes + *pBoldCJK, + *pBoldCTL, + *pItalic, + *pItalicCJK, + *pItalicCTL, + *pStrike, + *pUnderline, + *pBlink, + *pFont, + *pFontCJK, + *pFontCTL, + *pFontHeight, + *pFontHeightCJK, + *pFontHeightCTL, + *pFontColor, + *pEscapement, + *pCaseMap, + *pKerning, // (only for SPACER) + *pCharBrush, // character background + *pLanguage, + *pLanguageCJK, + *pLanguageCTL, + *pCharBox + ; +}; + class HTMLAttr { friend class SwHTMLParser; @@ -84,15 +135,16 @@ class HTMLAttr bool bValid : 1; // is the attribute valid? std::unique_ptr<SfxPoolItem> pItem; + std::shared_ptr<HTMLAttrTable> xAttrTab; HTMLAttr *pNext; // still to close attributes with different values HTMLAttr *pPrev; // already closed but not set attributes HTMLAttr **ppHead; // list head HTMLAttr( const SwPosition& rPos, const SfxPoolItem& rItem, - HTMLAttr **pHd=nullptr ); + HTMLAttr **pHd, const std::shared_ptr<HTMLAttrTable>& rAttrTab ); HTMLAttr( const HTMLAttr &rAttr, const SwNodeIndex &rEndPara, - sal_Int32 nEndCnt, HTMLAttr **pHd ); + sal_Int32 nEndCnt, HTMLAttr **pHd, const std::shared_ptr<HTMLAttrTable>& rAttrTab ); public: @@ -100,7 +152,7 @@ public: HTMLAttr *Clone( const SwNodeIndex& rEndPara, sal_Int32 nEndCnt ) const; void Reset( const SwNodeIndex& rSttPara, sal_Int32 nSttCnt, - HTMLAttr **pHd ); + HTMLAttr **pHd, const std::shared_ptr<HTMLAttrTable>& rAttrTab ); inline void SetStart( const SwPosition& rPos ); sal_uInt32 GetSttParaIdx() const { return nSttPara.GetIndex(); } @@ -125,7 +177,11 @@ public: void InsertPrev( HTMLAttr *pPrv ); void ClearPrev() { pPrev = nullptr; } - void SetHead( HTMLAttr **ppHd ) { ppHead = ppHd; } + void SetHead(HTMLAttr **ppHd, const std::shared_ptr<HTMLAttrTable>& rAttrTab) + { + ppHead = ppHd; + xAttrTab = rAttrTab; + } // During setting attributes from styles it can happen that these // shouldn't be set anymore. To delete them would be very expensive, because @@ -134,57 +190,6 @@ public: void Invalidate() { bValid = false; } }; -// Table of attributes: The order here is important: The attributes in the -// beginning of the table will set first in EndAllAttrs. -struct HTMLAttrTable -{ - HTMLAttr - *pKeep, // frame attributes - *pBox, - *pBrush, - *pBreak, - *pPageDesc, - - *pLRSpace, // paragraph attributes - *pULSpace, - *pLineSpacing, - *pAdjust, - *pDropCap, - *pSplit, - *pWidows, - *pOrphans, - *pDirection, - - *pCharFormats, // text attributes - *pINetFormat, - - *pBold, // character attributes - *pBoldCJK, - *pBoldCTL, - *pItalic, - *pItalicCJK, - *pItalicCTL, - *pStrike, - *pUnderline, - *pBlink, - *pFont, - *pFontCJK, - *pFontCTL, - *pFontHeight, - *pFontHeightCJK, - *pFontHeightCTL, - *pFontColor, - *pEscapement, - *pCaseMap, - *pKerning, // (only for SPACER) - *pCharBrush, // character background - *pLanguage, - *pLanguageCJK, - *pLanguageCTL, - *pCharBox - ; -}; - class HTMLAttrContext_SaveDoc; enum SwHTMLAppendMode { @@ -391,7 +396,7 @@ class SwHTMLParser : public SfxHTMLParser, public SwClient HTMLAttrs m_aSetAttrTab;// "closed", not set attributes HTMLAttrs m_aParaAttrs; // temporary paragraph attributes - HTMLAttrTable m_aAttrTab; // "open" attributes + std::shared_ptr<HTMLAttrTable> m_xAttrTab; // "open" attributes HTMLAttrContexts m_aContexts;// the current context of attribute/token std::vector<SwFrameFormat *> m_aMoveFlyFrames;// Fly-Frames, the anchor is moved std::deque<sal_Int32> m_aMoveFlyCnts;// and the Content-Positions @@ -512,15 +517,15 @@ class SwHTMLParser : public SfxHTMLParser, public SwClient // start/end an attribute // ppDepAttr indicated an attribute table entry, which attribute has to be // set, before the attribute is closed - void NewAttr( HTMLAttr **ppAttr, const SfxPoolItem& rItem ); + void NewAttr(const std::shared_ptr<HTMLAttrTable>& rAttrTab, HTMLAttr **ppAttr, const SfxPoolItem& rItem); bool EndAttr( HTMLAttr *pAttr, bool bChkEmpty=true ); void DeleteAttr( HTMLAttr* pAttr ); void EndContextAttrs( HTMLAttrContext *pContext ); - void SaveAttrTab( HTMLAttrTable& rNewAttrTab ); + void SaveAttrTab(std::shared_ptr<HTMLAttrTable>& rNewAttrTab); void SplitAttrTab( const SwPosition& rNewPos ); - void SplitAttrTab( HTMLAttrTable& rNewAttrTab, bool bMoveEndBack ); - void RestoreAttrTab( HTMLAttrTable& rNewAttrTab ); + void SplitAttrTab(std::shared_ptr<HTMLAttrTable>& rNewAttrTab, bool bMoveEndBack); + void RestoreAttrTab(std::shared_ptr<HTMLAttrTable>& rNewAttrTab); void InsertAttr( const SfxPoolItem& rItem, bool bInsAtStart ); void InsertAttrs( HTMLAttrs& rAttrs );
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits