diff options
Diffstat (limited to 'sw/source/filter/ww8/wrtww8gr.cxx')
-rw-r--r-- | sw/source/filter/ww8/wrtww8gr.cxx | 172 |
1 files changed, 82 insertions, 90 deletions
diff --git a/sw/source/filter/ww8/wrtww8gr.cxx b/sw/source/filter/ww8/wrtww8gr.cxx index b79641c5372a..9b041e4a5c32 100644 --- a/sw/source/filter/ww8/wrtww8gr.cxx +++ b/sw/source/filter/ww8/wrtww8gr.cxx @@ -60,6 +60,7 @@ #include <IDocumentDrawModelAccess.hxx> #include <drawdoc.hxx> +#include <o3tl/string_view.hxx> using namespace ::com::sun::star; @@ -78,12 +79,12 @@ void WW8Export::OutputGrfNode( const SwGrfNode& /*rNode*/ ) if ( m_pParentFrame ) { OutGrf( *m_pParentFrame ); - pFib->m_fHasPic = true; + m_pFib->m_fHasPic = true; } } -bool WW8Export::TestOleNeedsGraphic(const SwAttrSet& rSet, tools::SvRef<SotStorage> const& xOleStg, - const tools::SvRef<SotStorage>& xObjStg, +bool WW8Export::TestOleNeedsGraphic(const SwAttrSet& rSet, rtl::Reference<SotStorage> const& xOleStg, + const rtl::Reference<SotStorage>& xObjStg, OUString const& rStorageName, SwOLENode* pOLENd) { bool bGraphicNeeded = false; @@ -129,7 +130,7 @@ bool WW8Export::TestOleNeedsGraphic(const SwAttrSet& rSet, tools::SvRef<SotStora sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT; if ( pOLENd ) nAspect = pOLENd->GetAspect(); - SdrOle2Obj *pRet = SvxMSDffManager::CreateSdrOLEFromStorage( + rtl::Reference<SdrOle2Obj> pRet = SvxMSDffManager::CreateSdrOLEFromStorage( *m_rDoc.getIDocumentDrawModelAccess().GetOrCreateDrawModel(), rStorageName, xObjStg, @@ -169,12 +170,12 @@ bool WW8Export::TestOleNeedsGraphic(const SwAttrSet& rSet, tools::SvRef<SotStora { Graphic aGr1; GraphicFilter& rGF = GraphicFilter::GetGraphicFilter(); - if( rGF.ImportGraphic( aGr1, OUString(), *pGraphicStream ) == ERRCODE_NONE ) + if( rGF.ImportGraphic( aGr1, u"", *pGraphicStream ) == ERRCODE_NONE ) { Graphic aGr2; pGraphicStream = ::utl::UcbStreamHelper::CreateStream( aCnt.GetGraphicStream( pRet->GetObjRef() ) ); - if( pGraphicStream && rGF.ImportGraphic( aGr2, OUString(), *pGraphicStream ) == ERRCODE_NONE ) + if( pGraphicStream && rGF.ImportGraphic( aGr2, u"", *pGraphicStream ) == ERRCODE_NONE ) { if ( aGr1 == aGr2 ) bGraphicNeeded = false; @@ -182,10 +183,6 @@ bool WW8Export::TestOleNeedsGraphic(const SwAttrSet& rSet, tools::SvRef<SotStora } } } - - // always use SdrObject::Free(...) for SdrObjects (!) - SdrObject* pTemp(pRet); - SdrObject::Free(pTemp); } } else @@ -209,7 +206,7 @@ void WW8Export::OutputOLENode( const SwOLENode& rOLENode ) nSize = sizeof( aSpecOLE_WW8 ); pDataAdr = pSpecOLE + 2; //WW6 sprm is 1 but has 1 byte len as well. - tools::SvRef<SotStorage> xObjStg = GetWriter().GetStorage().OpenSotStorage(SL::aObjectPool); + rtl::Reference<SotStorage> xObjStg = GetWriter().GetStorage().OpenSotStorage(SL::aObjectPool); if( !xObjStg.is() ) return; @@ -230,7 +227,7 @@ void WW8Export::OutputOLENode( const SwOLENode& rOLENode ) nPictureId = aRes.first->second; Set_UInt32(pDataAdr, nPictureId); OUString sStorageName = "_" + OUString::number( nPictureId ); - tools::SvRef<SotStorage> xOleStg = xObjStg->OpenSotStorage( sStorageName ); + rtl::Reference<SotStorage> xOleStg = xObjStg->OpenSotStorage(sStorageName); if( !xOleStg.is() ) return; @@ -242,14 +239,14 @@ void WW8Export::OutputOLENode( const SwOLENode& rOLENode ) { sal_Int64 nAspect = rOLENode.GetAspect(); svt::EmbeddedObjectRef aObjRef( xObj, nAspect ); - m_pOLEExp->ExportOLEObject( aObjRef, *xOleStg ); + m_oOLEExp->ExportOLEObject( aObjRef, *xOleStg ); if ( nAspect == embed::Aspects::MSOLE_ICON ) { OUString aObjInfo( "\3ObjInfo" ); if ( !xOleStg->IsStream( aObjInfo ) ) { const sal_uInt8 pObjInfoData[] = { 0x40, 0x00, 0x03, 0x00 }; - tools::SvRef<SotStorageStream> rObjInfoStream = xOleStg->OpenSotStream( aObjInfo ); + rtl::Reference<SotStorageStream> rObjInfoStream = xOleStg->OpenSotStream(aObjInfo); if ( rObjInfoStream.is() && !rObjInfoStream->GetError() ) { rObjInfoStream->WriteBytes(pObjInfoData, sizeof(pObjInfoData)); @@ -320,14 +317,14 @@ void WW8Export::OutputLinkedOLE( const OUString& rOleId ) { uno::Reference< embed::XStorage > xDocStg = m_rDoc.GetDocStorage(); uno::Reference< embed::XStorage > xOleStg = xDocStg->openStorageElement( "OLELinks", embed::ElementModes::READ ); - tools::SvRef<SotStorage> xObjSrc = SotStorage::OpenOLEStorage( xOleStg, rOleId, StreamMode::READ ); + rtl::Reference<SotStorage> xObjSrc = SotStorage::OpenOLEStorage( xOleStg, rOleId, StreamMode::READ ); - tools::SvRef<SotStorage> xObjStg = GetWriter().GetStorage().OpenSotStorage(SL::aObjectPool); + rtl::Reference<SotStorage> xObjStg = GetWriter().GetStorage().OpenSotStorage(SL::aObjectPool); if( !(xObjStg.is() && xObjSrc.is()) ) return; - tools::SvRef<SotStorage> xOleDst = xObjStg->OpenSotStorage( rOleId ); + rtl::Reference<SotStorage> xOleDst = xObjStg->OpenSotStorage(rOleId); if ( xOleDst.is() ) xObjSrc->CopyTo( xOleDst.get() ); @@ -339,7 +336,7 @@ void WW8Export::OutputLinkedOLE( const OUString& rOleId ) // Output the cPicLocation attribute std::unique_ptr<ww::bytes> pBuf( new ww::bytes ); SwWW8Writer::InsUInt16( *pBuf, NS_sprm::CPicLocation::val ); - SwWW8Writer::InsUInt32( *pBuf, rOleId.copy( 1 ).toInt32() ); + SwWW8Writer::InsUInt32( *pBuf, o3tl::toInt32(rOleId.subView( 1 )) ); SwWW8Writer::InsUInt16( *pBuf, NS_sprm::CFOle2::val ); pBuf->push_back( 1 ); @@ -368,8 +365,8 @@ void WW8Export::OutGrf(const ww8::Frame &rFrame) // Store the graphic settings in GrfNode so they may be written-out later m_pGrf->Insert(rFrame); - m_pChpPlc->AppendFkpEntry( Strm().Tell(), pO->size(), pO->data() ); - pO->clear(); + m_pChpPlc->AppendFkpEntry( Strm().Tell(), m_pO->size(), m_pO->data() ); + m_pO->clear(); // #i29408# // linked, as-character anchored graphics have to be exported as fields. @@ -444,15 +441,15 @@ void WW8Export::OutGrf(const ww8::Frame &rFrame) WriteChar( char(0x0d) ); // close the surrounding frame with CR static sal_uInt8 nSty[2] = { 0, 0 }; - pO->insert( pO->end(), nSty, nSty+2 ); // Style #0 + m_pO->insert( m_pO->end(), nSty, nSty+2 ); // Style #0 bool bOldGrf = m_bOutGrf; m_bOutGrf = true; OutputFormat( rFrame.GetFrameFormat(), false, false, true ); // Fly-Attrs m_bOutGrf = bOldGrf; - m_pPapPlc->AppendFkpEntry( Strm().Tell(), pO->size(), pO->data() ); - pO->clear(); + m_pPapPlc->AppendFkpEntry( Strm().Tell(), m_pO->size(), m_pO->data() ); + m_pO->clear(); } // #i29408# // linked, as-character anchored graphics have to be exported as fields. @@ -481,17 +478,16 @@ void SwWW8WrGrf::WritePICFHeader(SvStream& rStrm, const ww8::Frame &rFly, sal_Int16 nCropL = 0, nCropR = 0, nCropT = 0, nCropB = 0; // write Crop-Attribute content in Header ( if available ) - const SfxPoolItem* pItem; - if (pAttrSet && (SfxItemState::SET - == pAttrSet->GetItemState(RES_GRFATR_CROPGRF, false, &pItem))) + const SwCropGrf* pCropItem; + if (pAttrSet && (pCropItem + = pAttrSet->GetItemIfSet(RES_GRFATR_CROPGRF, false))) { - const SwCropGrf& rCr = *static_cast<const SwCropGrf*>(pItem); - nCropL = static_cast<sal_Int16>(rCr.GetLeft()); - nCropR = static_cast<sal_Int16>(rCr.GetRight()); - nCropT = static_cast<sal_Int16>(rCr.GetTop()); - nCropB = static_cast<sal_Int16>(rCr.GetBottom()); - nXSizeAdd = nXSizeAdd - static_cast<sal_Int16>( rCr.GetLeft() + rCr.GetRight() ); - nYSizeAdd = nYSizeAdd - static_cast<sal_Int16>( rCr.GetTop() + rCr.GetBottom() ); + nCropL = static_cast<sal_Int16>(pCropItem->GetLeft()); + nCropR = static_cast<sal_Int16>(pCropItem->GetRight()); + nCropT = static_cast<sal_Int16>(pCropItem->GetTop()); + nCropB = static_cast<sal_Int16>(pCropItem->GetBottom()); + nXSizeAdd = nXSizeAdd - static_cast<sal_Int16>( pCropItem->GetLeft() + pCropItem->GetRight() ); + nYSizeAdd = nYSizeAdd - static_cast<sal_Int16>( pCropItem->GetTop() + pCropItem->GetBottom() ); } Size aGrTwipSz(rFly.GetSize()); @@ -502,58 +498,54 @@ void SwWW8WrGrf::WritePICFHeader(SvStream& rStrm, const ww8::Frame &rFly, sal_uInt8* pArr = aArr + 0x2E; // Do borders first const SwAttrSet& rAttrSet = rFly.GetFrameFormat().GetAttrSet(); - if (SfxItemState::SET == rAttrSet.GetItemState(RES_BOX, false, &pItem)) + if (const SvxBoxItem* pBox = rAttrSet.GetItemIfSet(RES_BOX, false)) { - const SvxBoxItem* pBox = static_cast<const SvxBoxItem*>(pItem); - if( pBox ) + bool bShadow = false; // Shadow ? + if (const SvxShadowItem* pSI = rAttrSet.GetItem<SvxShadowItem>(RES_SHADOW)) + { + bShadow = (pSI->GetLocation() != SvxShadowLocation::NONE) && + (pSI->GetWidth() != 0); + } + + static const SvxBoxItemLine aLnArr[4] = { SvxBoxItemLine::TOP, SvxBoxItemLine::LEFT, + SvxBoxItemLine::BOTTOM, SvxBoxItemLine::RIGHT }; + for(const SvxBoxItemLine & i : aLnArr) { - bool bShadow = false; // Shadow ? - if (const SvxShadowItem* pSI = rAttrSet.GetItem<SvxShadowItem>(RES_SHADOW)) + const ::editeng::SvxBorderLine* pLn = pBox->GetLine( i ); + WW8_BRC aBrc; + if (pLn) { - bShadow = (pSI->GetLocation() != SvxShadowLocation::NONE) && - (pSI->GetWidth() != 0); + WW8_BRCVer9 aBrc90 = WW8Export::TranslateBorderLine( *pLn, + pBox->GetDistance( i ), bShadow ); + sal_uInt8 ico = msfilter::util::TransColToIco(msfilter::util::BGRToRGB( + aBrc90.cv())); + aBrc = WW8_BRC(aBrc90.dptLineWidth(), aBrc90.brcType(), ico, + aBrc90.dptSpace(), aBrc90.fShadow(), aBrc90.fFrame()); } - static const SvxBoxItemLine aLnArr[4] = { SvxBoxItemLine::TOP, SvxBoxItemLine::LEFT, - SvxBoxItemLine::BOTTOM, SvxBoxItemLine::RIGHT }; - for(const SvxBoxItemLine & i : aLnArr) + // use importer logic to determine how large the exported + // border will really be in word and adjust accordingly + short nSpacing; + short nThick = aBrc.DetermineBorderProperties(&nSpacing); + switch (i) { - const ::editeng::SvxBorderLine* pLn = pBox->GetLine( i ); - WW8_BRC aBrc; - if (pLn) - { - WW8_BRCVer9 aBrc90 = WW8Export::TranslateBorderLine( *pLn, - pBox->GetDistance( i ), bShadow ); - sal_uInt8 ico = msfilter::util::TransColToIco(msfilter::util::BGRToRGB( - aBrc90.cv())); - aBrc = WW8_BRC(aBrc90.dptLineWidth(), aBrc90.brcType(), ico, - aBrc90.dptSpace(), aBrc90.fShadow(), aBrc90.fFrame()); - } - - // use importer logic to determine how large the exported - // border will really be in word and adjust accordingly - short nSpacing; - short nThick = aBrc.DetermineBorderProperties(&nSpacing); - switch (i) - { - case SvxBoxItemLine::TOP: - case SvxBoxItemLine::BOTTOM: - nHeight -= bShadow ? nThick*2 : nThick; - nHeight = nHeight - nSpacing; - break; - case SvxBoxItemLine::LEFT: - case SvxBoxItemLine::RIGHT: - default: - nWidth -= bShadow ? nThick*2 : nThick; - nWidth = nWidth - nSpacing; - break; - } - memcpy( pArr, &aBrc.aBits1, 2); - pArr+=2; - - memcpy( pArr, &aBrc.aBits2, 2); - pArr+=2; + case SvxBoxItemLine::TOP: + case SvxBoxItemLine::BOTTOM: + nHeight -= bShadow ? nThick*2 : nThick; + nHeight = nHeight - nSpacing; + break; + case SvxBoxItemLine::LEFT: + case SvxBoxItemLine::RIGHT: + default: + nWidth -= bShadow ? nThick*2 : nThick; + nWidth = nWidth - nSpacing; + break; } + memcpy( pArr, &aBrc.aBits1, 2); + pArr+=2; + + memcpy( pArr, &aBrc.aBits2, 2); + pArr+=2; } } @@ -589,7 +581,7 @@ void SwWW8WrGrf::WritePICFHeader(SvStream& rStrm, const ww8::Frame &rFly, if ( !bIsSubstitutedSize ) { const double fVal = nWidth * 1000.0 / (aGrTwipSz.Width() + nXSizeAdd ); - Set_UInt16( pArr, static_cast<sal_uInt16>(::rtl::math::round(fVal)) ); + Set_UInt16( pArr, o3tl::narrowing<sal_uInt16>(::rtl::math::round(fVal)) ); } else { @@ -606,7 +598,7 @@ void SwWW8WrGrf::WritePICFHeader(SvStream& rStrm, const ww8::Frame &rFly, if ( !bIsSubstitutedSize ) { const double fVal = nHeight * 1000.0 / (aGrTwipSz.Height() + nYSizeAdd); - Set_UInt16( pArr, static_cast<sal_uInt16>(::rtl::math::round(fVal)) ); + Set_UInt16( pArr, o3tl::narrowing<sal_uInt16>(::rtl::math::round(fVal)) ); } else { @@ -649,7 +641,7 @@ void SwWW8WrGrf::WriteGrfFromGrfNode(SvStream& rStrm, const SwGrfNode &rGrfNd, { WritePICFHeader(rStrm, rFly, 0x64, nWidth, nHeight, rGrfNd.GetpSwAttrSet()); - SwBasicEscherEx aInlineEscher(&rStrm, rWrt); + SwBasicEscherEx aInlineEscher(&rStrm, m_rWrt); aInlineEscher.WriteGrfFlyFrame(rFly.GetFrameFormat(), 0x401); aInlineEscher.WritePictures(); } @@ -720,7 +712,7 @@ void SwWW8WrGrf::WritePICBulletFHeader(SvStream& rStrm, const Graphic &rGrf, if( aGrTwipSz.Width() + nXSizeAdd ) // set mx { double fVal = nWidth * 1000.0 / (aGrTwipSz.Width() + nXSizeAdd); - Set_UInt16( pArr, static_cast<sal_uInt16>(::rtl::math::round(fVal)) ); + Set_UInt16( pArr, o3tl::narrowing<sal_uInt16>(::rtl::math::round(fVal)) ); } else pArr += 2; @@ -728,7 +720,7 @@ void SwWW8WrGrf::WritePICBulletFHeader(SvStream& rStrm, const Graphic &rGrf, if( aGrTwipSz.Height() + nYSizeAdd ) // set my { double fVal = nHeight * 1000.0 / (aGrTwipSz.Height() + nYSizeAdd); - Set_UInt16( pArr, static_cast<sal_uInt16>(::rtl::math::round(fVal)) ); + Set_UInt16( pArr, o3tl::narrowing<sal_uInt16>(::rtl::math::round(fVal)) ); } else pArr += 2; @@ -744,7 +736,7 @@ void SwWW8WrGrf::WritePICBulletFHeader(SvStream& rStrm, const Graphic &rGrf, void SwWW8WrGrf::WriteGrfForBullet(SvStream& rStrm, const Graphic &rGrf, sal_uInt16 nWidth, sal_uInt16 nHeight) { WritePICBulletFHeader(rStrm,rGrf, 0x64,nWidth,nHeight); - SwBasicEscherEx aInlineEscher(&rStrm, rWrt); + SwBasicEscherEx aInlineEscher(&rStrm, m_rWrt); aInlineEscher.WriteGrfBullet(rGrf); aInlineEscher.WritePictures(); } @@ -753,7 +745,7 @@ void SwWW8WrGrf::WriteGraphicNode(SvStream& rStrm, const GraphicDetails &rItem) { sal_uInt16 nWidth = rItem.mnWid; sal_uInt16 nHeight = rItem.mnHei; - sal_uInt32 nPos = rStrm.Tell(); // store start of graphic + sal_uInt64 nPos = rStrm.Tell(); // store start of graphic const ww8::Frame &rFly = rItem.maFly; switch (rFly.GetWriterType()) @@ -792,7 +784,7 @@ void SwWW8WrGrf::WriteGraphicNode(SvStream& rStrm, const GraphicDetails &rItem) //documents. WritePICFHeader(rStrm, rFly, 0x64, nWidth, nHeight, pNd->GetpSwAttrSet()); - SwBasicEscherEx aInlineEscher(&rStrm, rWrt); + SwBasicEscherEx aInlineEscher(&rStrm, m_rWrt); aInlineEscher.WriteOLEFlyFrame(rFly.GetFrameFormat(), 0x401); aInlineEscher.WritePictures(); #else @@ -833,7 +825,7 @@ void SwWW8WrGrf::WriteGraphicNode(SvStream& rStrm, const GraphicDetails &rItem) */ { WritePICFHeader(rStrm, rFly, 0x64, nWidth, nHeight); - SwBasicEscherEx aInlineEscher(&rStrm, rWrt); + SwBasicEscherEx aInlineEscher(&rStrm, m_rWrt); aInlineEscher.WriteEmptyFlyFrame(rFly.GetFrameFormat(), 0x401); } break; @@ -842,7 +834,7 @@ void SwWW8WrGrf::WriteGraphicNode(SvStream& rStrm, const GraphicDetails &rItem) break; } - sal_uInt32 nPos2 = rStrm.Tell(); // store the end + sal_uInt64 nPos2 = rStrm.Tell(); // store the end rStrm.Seek( nPos ); rStrm.WriteUInt32(nPos2 - nPos); // patch graphic length in the header rStrm.Seek( nPos2 ); // restore Pos @@ -856,11 +848,11 @@ void SwWW8WrGrf::WriteGraphicNode(SvStream& rStrm, const GraphicDetails &rItem) // GetFPos() sequentially the positions void SwWW8WrGrf::Write() { - SvStream& rStrm = *rWrt.pDataStrm; + SvStream& rStrm = *m_rWrt.m_pDataStrm; auto aEnd = maDetails.end(); for (auto aIter = maDetails.begin(); aIter != aEnd; ++aIter) { - sal_uInt32 nPos = rStrm.Tell(); // align to 4 Bytes + sal_uInt64 nPos = rStrm.Tell(); // align to 4 Bytes if( nPos & 0x3 ) SwWW8Writer::FillCount( rStrm, 4 - ( nPos & 0x3 ) ); |