File: | home/maarten/src/libreoffice/core/sw/source/filter/writer/writer.cxx |
Warning: | line 256, column 16 Potential leak of memory pointed to by 'aRef.pObj' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |||
2 | /* | |||
3 | * This file is part of the LibreOffice project. | |||
4 | * | |||
5 | * This Source Code Form is subject to the terms of the Mozilla Public | |||
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this | |||
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. | |||
8 | * | |||
9 | * This file incorporates work covered by the following license notice: | |||
10 | * | |||
11 | * Licensed to the Apache Software Foundation (ASF) under one or more | |||
12 | * contributor license agreements. See the NOTICE file distributed | |||
13 | * with this work for additional information regarding copyright | |||
14 | * ownership. The ASF licenses this file to you under the Apache | |||
15 | * License, Version 2.0 (the "License"); you may not use this file | |||
16 | * except in compliance with the License. You may obtain a copy of | |||
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . | |||
18 | */ | |||
19 | ||||
20 | #include <memory> | |||
21 | #include <hintids.hxx> | |||
22 | ||||
23 | #include <sot/storage.hxx> | |||
24 | #include <sfx2/docfile.hxx> | |||
25 | #include <tools/diagnose_ex.h> | |||
26 | #include <editeng/fontitem.hxx> | |||
27 | #include <editeng/eeitem.hxx> | |||
28 | #include <osl/diagnose.h> | |||
29 | #include <shellio.hxx> | |||
30 | #include <doc.hxx> | |||
31 | #include <docary.hxx> | |||
32 | #include <IMark.hxx> | |||
33 | #include <IDocumentSettingAccess.hxx> | |||
34 | #include <IDocumentMarkAccess.hxx> | |||
35 | #include <numrule.hxx> | |||
36 | #include <swerror.h> | |||
37 | #include <com/sun/star/ucb/ContentCreationException.hpp> | |||
38 | ||||
39 | using namespace css; | |||
40 | ||||
41 | namespace | |||
42 | { | |||
43 | SvStream& lcl_OutLongExt( SvStream& rStrm, sal_uLong nVal, bool bNeg ) | |||
44 | { | |||
45 | char aBuf[28]; | |||
46 | ||||
47 | int i = SAL_N_ELEMENTS(aBuf)(sizeof(sal_n_array_size(aBuf))); | |||
48 | aBuf[--i] = 0; | |||
49 | do | |||
50 | { | |||
51 | aBuf[--i] = '0' + static_cast<char>(nVal % 10); | |||
52 | nVal /= 10; | |||
53 | } while (nVal); | |||
54 | ||||
55 | if (bNeg) | |||
56 | aBuf[--i] = '-'; | |||
57 | ||||
58 | return rStrm.WriteCharPtr( &aBuf[i] ); | |||
59 | } | |||
60 | } | |||
61 | ||||
62 | typedef std::multimap<sal_uLong, const ::sw::mark::IMark*> SwBookmarkNodeTable; | |||
63 | ||||
64 | struct Writer_Impl | |||
65 | { | |||
66 | SvStream * m_pStream; | |||
67 | ||||
68 | std::unique_ptr< std::map<OUString, OUString> > pFileNameMap; | |||
69 | std::vector<const SvxFontItem*> aFontRemoveLst; | |||
70 | SwBookmarkNodeTable aBkmkNodePos; | |||
71 | ||||
72 | Writer_Impl(); | |||
73 | ||||
74 | void RemoveFontList( SwDoc& rDoc ); | |||
75 | void InsertBkmk( const ::sw::mark::IMark& rBkmk ); | |||
76 | }; | |||
77 | ||||
78 | Writer_Impl::Writer_Impl() | |||
79 | : m_pStream(nullptr) | |||
80 | { | |||
81 | } | |||
82 | ||||
83 | void Writer_Impl::RemoveFontList( SwDoc& rDoc ) | |||
84 | { | |||
85 | for( const auto& rpFontItem : aFontRemoveLst ) | |||
86 | { | |||
87 | rDoc.GetAttrPool().Remove( *rpFontItem ); | |||
88 | } | |||
89 | } | |||
90 | ||||
91 | void Writer_Impl::InsertBkmk(const ::sw::mark::IMark& rBkmk) | |||
92 | { | |||
93 | sal_uLong nNd = rBkmk.GetMarkPos().nNode.GetIndex(); | |||
94 | ||||
95 | aBkmkNodePos.emplace( nNd, &rBkmk ); | |||
96 | ||||
97 | if(rBkmk.IsExpanded() && rBkmk.GetOtherMarkPos().nNode != nNd) | |||
98 | { | |||
99 | nNd = rBkmk.GetOtherMarkPos().nNode.GetIndex(); | |||
100 | aBkmkNodePos.emplace( nNd, &rBkmk ); | |||
101 | } | |||
102 | } | |||
103 | ||||
104 | /* | |||
105 | * This module is the central collection point for all writer-filters | |||
106 | * and is a DLL ! | |||
107 | * | |||
108 | * So that the Writer can work with different writers, the output-functions | |||
109 | * of the content carrying objects have to be mapped to the various | |||
110 | * output-functions. | |||
111 | * | |||
112 | * For that, to inquire its output function, every object can be gripped | |||
113 | * via the which-value in a table. | |||
114 | * These functions are available in the corresponding Writer-DLL's. | |||
115 | */ | |||
116 | ||||
117 | Writer::Writer() | |||
118 | : m_pImpl(std::make_unique<Writer_Impl>()) | |||
119 | , m_pOrigFileName(nullptr), m_pDoc(nullptr), m_pOrigPam(nullptr) | |||
120 | , m_bHideDeleteRedlines(false) | |||
121 | { | |||
122 | m_bWriteAll = m_bShowProgress = m_bUCS2_WithStartChar = true; | |||
123 | m_bASCII_NoLastLineEnd = m_bASCII_ParaAsBlank = m_bASCII_ParaAsCR = | |||
124 | m_bWriteClipboardDoc = m_bWriteOnlyFirstTable = m_bBlock = | |||
125 | m_bOrganizerMode = false; | |||
126 | m_bExportParagraphNumbering = true; | |||
127 | } | |||
128 | ||||
129 | Writer::~Writer() | |||
130 | { | |||
131 | } | |||
132 | ||||
133 | /* | |||
134 | * Document Interface Access | |||
135 | */ | |||
136 | IDocumentSettingAccess& Writer::getIDocumentSettingAccess() { return m_pDoc->getIDocumentSettingAccess(); } | |||
137 | const IDocumentSettingAccess& Writer::getIDocumentSettingAccess() const { return m_pDoc->getIDocumentSettingAccess(); } | |||
138 | IDocumentStylePoolAccess& Writer::getIDocumentStylePoolAccess() { return m_pDoc->getIDocumentStylePoolAccess(); } | |||
139 | const IDocumentStylePoolAccess& Writer::getIDocumentStylePoolAccess() const { return m_pDoc->getIDocumentStylePoolAccess(); } | |||
140 | ||||
141 | void Writer::ResetWriter() | |||
142 | { | |||
143 | m_pImpl->RemoveFontList( *m_pDoc ); | |||
144 | m_pImpl.reset(new Writer_Impl); | |||
145 | ||||
146 | if( m_pCurrentPam ) | |||
147 | { | |||
148 | while (m_pCurrentPam->GetNext() != m_pCurrentPam.get()) | |||
149 | delete m_pCurrentPam->GetNext(); | |||
150 | m_pCurrentPam.reset(); | |||
151 | } | |||
152 | m_pCurrentPam = nullptr; | |||
153 | m_pOrigFileName = nullptr; | |||
154 | m_pDoc = nullptr; | |||
155 | ||||
156 | m_bShowProgress = m_bUCS2_WithStartChar = true; | |||
157 | m_bASCII_NoLastLineEnd = m_bASCII_ParaAsBlank = m_bASCII_ParaAsCR = | |||
158 | m_bWriteClipboardDoc = m_bWriteOnlyFirstTable = m_bBlock = | |||
159 | m_bOrganizerMode = false; | |||
160 | } | |||
161 | ||||
162 | bool Writer::CopyNextPam( SwPaM ** ppPam ) | |||
163 | { | |||
164 | if( (*ppPam)->GetNext() == m_pOrigPam ) | |||
165 | { | |||
166 | *ppPam = m_pOrigPam; // set back to the beginning pam | |||
167 | return false; // end of the ring | |||
168 | } | |||
169 | ||||
170 | // otherwise copy the next value from the next Pam | |||
171 | *ppPam = (*ppPam)->GetNext(); | |||
172 | ||||
173 | *m_pCurrentPam->GetPoint() = *(*ppPam)->Start(); | |||
174 | *m_pCurrentPam->GetMark() = *(*ppPam)->End(); | |||
175 | ||||
176 | return true; | |||
177 | } | |||
178 | ||||
179 | // search the next Bookmark-Position from the Bookmark-Table | |||
180 | ||||
181 | sal_Int32 Writer::FindPos_Bkmk(const SwPosition& rPos) const | |||
182 | { | |||
183 | const IDocumentMarkAccess* const pMarkAccess = m_pDoc->getIDocumentMarkAccess(); | |||
184 | const IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->findFirstBookmarkStartsAfter(rPos); | |||
185 | if(ppBkmk != pMarkAccess->getBookmarksEnd()) | |||
186 | return ppBkmk - pMarkAccess->getBookmarksBegin(); | |||
187 | return -1; | |||
188 | } | |||
189 | ||||
190 | std::shared_ptr<SwUnoCursor> | |||
191 | Writer::NewUnoCursor(SwDoc & rDoc, sal_uLong const nStartIdx, sal_uLong const nEndIdx) | |||
192 | { | |||
193 | SwNodes *const pNds = &rDoc.GetNodes(); | |||
194 | ||||
195 | SwNodeIndex aStt( *pNds, nStartIdx ); | |||
196 | SwContentNode* pCNode = aStt.GetNode().GetContentNode(); | |||
197 | if( !pCNode && nullptr == pNds->GoNext( &aStt ) ) | |||
198 | { | |||
199 | OSL_FAIL( "No more ContentNode at StartPos" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/filter/writer/writer.cxx" ":" "199" ": "), "%s", "No more ContentNode at StartPos"); } } while (false); | |||
200 | } | |||
201 | ||||
202 | auto const pNew = rDoc.CreateUnoCursor(SwPosition(aStt), false); | |||
203 | pNew->SetMark(); | |||
204 | aStt = nEndIdx; | |||
205 | pCNode = aStt.GetNode().GetContentNode(); | |||
206 | if (!pCNode) | |||
207 | pCNode = SwNodes::GoPrevious(&aStt); | |||
208 | assert(pCNode && "No more ContentNode at StartPos")(static_cast <bool> (pCNode && "No more ContentNode at StartPos" ) ? void (0) : __assert_fail ("pCNode && \"No more ContentNode at StartPos\"" , "/home/maarten/src/libreoffice/core/sw/source/filter/writer/writer.cxx" , 208, __extension__ __PRETTY_FUNCTION__)); | |||
209 | pCNode->MakeEndIndex( &pNew->GetPoint()->nContent ); | |||
210 | pNew->GetPoint()->nNode = aStt; | |||
211 | return pNew; | |||
212 | } | |||
213 | ||||
214 | // Stream-specific | |||
215 | SvStream& Writer::Strm() | |||
216 | { | |||
217 | assert(m_pImpl->m_pStream && "Oh-oh. Writer with no Stream!")(static_cast <bool> (m_pImpl->m_pStream && "Oh-oh. Writer with no Stream!" ) ? void (0) : __assert_fail ("m_pImpl->m_pStream && \"Oh-oh. Writer with no Stream!\"" , "/home/maarten/src/libreoffice/core/sw/source/filter/writer/writer.cxx" , 217, __extension__ __PRETTY_FUNCTION__)); | |||
218 | return *m_pImpl->m_pStream; | |||
219 | } | |||
220 | ||||
221 | void Writer::SetStream(SvStream *const pStream) | |||
222 | { | |||
223 | m_pImpl->m_pStream = pStream; | |||
224 | } | |||
225 | ||||
226 | SvStream& Writer::OutLong( SvStream& rStrm, long nVal ) | |||
227 | { | |||
228 | const bool bNeg = nVal < 0; | |||
229 | if (bNeg) | |||
230 | nVal = -nVal; | |||
231 | ||||
232 | return lcl_OutLongExt(rStrm, static_cast<sal_uLong>(nVal), bNeg); | |||
233 | } | |||
234 | ||||
235 | SvStream& Writer::OutULong( SvStream& rStrm, sal_uLong nVal ) | |||
236 | { | |||
237 | return lcl_OutLongExt(rStrm, nVal, false); | |||
238 | } | |||
239 | ||||
240 | ErrCode Writer::Write( SwPaM& rPaM, SvStream& rStrm, const OUString* pFName ) | |||
241 | { | |||
242 | if ( IsStgWriter() ) | |||
243 | { | |||
244 | ErrCode nResult = ERRCODE_ABORTErrCode( ErrCodeArea::Io, ErrCodeClass::Abort, 27 ); | |||
245 | try | |||
246 | { | |||
247 | tools::SvRef<SotStorage> aRef = new SotStorage( rStrm ); | |||
248 | nResult = Write( rPaM, *aRef, pFName ); | |||
249 | if ( nResult == ERRCODE_NONEErrCode(0) ) | |||
250 | aRef->Commit(); | |||
251 | } | |||
252 | catch (const css::ucb::ContentCreationException &) | |||
253 | { | |||
254 | TOOLS_WARN_EXCEPTION("sw", "Writer::Write caught")do { css::uno::Any tools_warn_exception( DbgGetCaughtException () ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "sw")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Writer::Write caught" << " " << exceptionToString (tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw"), ("/home/maarten/src/libreoffice/core/sw/source/filter/writer/writer.cxx" ":" "254" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Writer::Write caught" << " " << exceptionToString(tools_warn_exception)), 0); } else { ::std ::ostringstream sal_detail_stream; sal_detail_stream << "Writer::Write caught" << " " << exceptionToString (tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw"), ("/home/maarten/src/libreoffice/core/sw/source/filter/writer/writer.cxx" ":" "254" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "Writer::Write caught" << " " << exceptionToString (tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw"), ("/home/maarten/src/libreoffice/core/sw/source/filter/writer/writer.cxx" ":" "254" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "Writer::Write caught" << " " << exceptionToString(tools_warn_exception)), 0); } else { ::std ::ostringstream sal_detail_stream; sal_detail_stream << "Writer::Write caught" << " " << exceptionToString (tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("sw"), ("/home/maarten/src/libreoffice/core/sw/source/filter/writer/writer.cxx" ":" "254" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); } while (false); | |||
255 | } | |||
256 | return nResult; | |||
| ||||
257 | } | |||
258 | ||||
259 | m_pDoc = &rPaM.GetDoc(); | |||
260 | m_pOrigFileName = pFName; | |||
261 | m_pImpl->m_pStream = &rStrm; | |||
262 | ||||
263 | // Copy PaM, so that it can be modified | |||
264 | m_pCurrentPam = m_pDoc->CreateUnoCursor(*rPaM.End(), false); | |||
265 | m_pCurrentPam->SetMark(); | |||
266 | *m_pCurrentPam->GetPoint() = *rPaM.Start(); | |||
267 | // for comparison secure to the current Pam | |||
268 | m_pOrigPam = &rPaM; | |||
269 | ||||
270 | ErrCode nRet = WriteStream(); | |||
271 | ||||
272 | ResetWriter(); | |||
273 | ||||
274 | return nRet; | |||
275 | } | |||
276 | ||||
277 | void Writer::SetupFilterOptions(SfxMedium& /*rMedium*/) | |||
278 | {} | |||
279 | ||||
280 | ErrCode Writer::Write( SwPaM& rPam, SfxMedium& rMedium, const OUString* pFileName ) | |||
281 | { | |||
282 | SetupFilterOptions(rMedium); | |||
283 | // This method must be overridden in SwXMLWriter a storage from medium will be used there. | |||
284 | // The microsoft format can write to storage but the storage will be based on the stream. | |||
285 | return Write( rPam, *rMedium.GetOutStream(), pFileName ); | |||
| ||||
286 | } | |||
287 | ||||
288 | ErrCode Writer::Write( SwPaM& /*rPam*/, SotStorage&, const OUString* ) | |||
289 | { | |||
290 | OSL_ENSURE( false, "Write in Storages on a stream?" )do { if (true && (!(false))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/filter/writer/writer.cxx" ":" "290" ": "), "%s", "Write in Storages on a stream?"); } } while (false); | |||
291 | return ERR_SWG_WRITE_ERRORErrCode(ErrCodeArea::Sw, ErrCodeClass::Write, 30 ); | |||
292 | } | |||
293 | ||||
294 | ErrCode Writer::Write( SwPaM&, const uno::Reference < embed::XStorage >&, const OUString*, SfxMedium* ) | |||
295 | { | |||
296 | OSL_ENSURE( false, "Write in Storages on a stream?" )do { if (true && (!(false))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/filter/writer/writer.cxx" ":" "296" ": "), "%s", "Write in Storages on a stream?"); } } while (false); | |||
297 | return ERR_SWG_WRITE_ERRORErrCode(ErrCodeArea::Sw, ErrCodeClass::Write, 30 ); | |||
298 | } | |||
299 | ||||
300 | bool Writer::CopyLocalFileToINet( OUString& rFileNm ) | |||
301 | { | |||
302 | if( !m_pOrigFileName ) // can be happen, by example if we | |||
303 | return false; // write into the clipboard | |||
304 | ||||
305 | bool bRet = false; | |||
306 | INetURLObject aFileUrl( rFileNm ), aTargetUrl( *m_pOrigFileName ); | |||
307 | ||||
308 | // this is our old without the Mail-Export | |||
309 | if( ! ( INetProtocol::File == aFileUrl.GetProtocol() && | |||
310 | INetProtocol::File != aTargetUrl.GetProtocol() && | |||
311 | INetProtocol::Ftp <= aTargetUrl.GetProtocol() && | |||
312 | INetProtocol::VndSunStarWebdav >= aTargetUrl.GetProtocol() ) ) | |||
313 | return bRet; | |||
314 | ||||
315 | if (m_pImpl->pFileNameMap) | |||
316 | { | |||
317 | // has the file been moved? | |||
318 | std::map<OUString, OUString>::iterator it = m_pImpl->pFileNameMap->find( rFileNm ); | |||
319 | if ( it != m_pImpl->pFileNameMap->end() ) | |||
320 | { | |||
321 | rFileNm = it->second; | |||
322 | return true; | |||
323 | } | |||
324 | } | |||
325 | else | |||
326 | { | |||
327 | m_pImpl->pFileNameMap.reset( new std::map<OUString, OUString> ); | |||
328 | } | |||
329 | ||||
330 | OUString aSrc = rFileNm; | |||
331 | OUString aDest = aTargetUrl.GetPartBeforeLastName() + aFileUrl.GetLastName(); | |||
332 | ||||
333 | SfxMedium aSrcFile( aSrc, StreamMode::READ ); | |||
334 | SfxMedium aDstFile( aDest, StreamMode::WRITE | StreamMode::SHARE_DENYNONE ); | |||
335 | ||||
336 | aDstFile.GetOutStream()->WriteStream( *aSrcFile.GetInStream() ); | |||
337 | ||||
338 | aSrcFile.Close(); | |||
339 | aDstFile.Commit(); | |||
340 | ||||
341 | bRet = ERRCODE_NONEErrCode(0) == aDstFile.GetError(); | |||
342 | ||||
343 | if( bRet ) | |||
344 | { | |||
345 | m_pImpl->pFileNameMap->insert( std::make_pair( aSrc, aDest ) ); | |||
346 | rFileNm = aDest; | |||
347 | } | |||
348 | ||||
349 | return bRet; | |||
350 | } | |||
351 | ||||
352 | void Writer::PutNumFormatFontsInAttrPool() | |||
353 | { | |||
354 | // then there are a few fonts in the NumRules | |||
355 | // These put into the Pool. After this does they have a RefCount > 1 | |||
356 | // it can be removed - it is already in the Pool | |||
357 | SfxItemPool& rPool = m_pDoc->GetAttrPool(); | |||
358 | const SwNumRuleTable& rListTable = m_pDoc->GetNumRuleTable(); | |||
359 | const SwNumRule* pRule; | |||
360 | const SwNumFormat* pFormat; | |||
361 | const vcl::Font* pFont; | |||
362 | const vcl::Font* pDefFont = &numfunc::GetDefBulletFont(); | |||
363 | bool bCheck = false; | |||
364 | ||||
365 | for( size_t nGet = rListTable.size(); nGet; ) | |||
366 | if( SwDoc::IsUsed( *(pRule = rListTable[ --nGet ] ))) | |||
367 | for( sal_uInt8 nLvl = 0; nLvl < MAXLEVEL; ++nLvl ) | |||
368 | if( SVX_NUM_CHAR_SPECIAL == (pFormat = &pRule->Get( nLvl ))->GetNumberingType() || | |||
369 | SVX_NUM_BITMAP == pFormat->GetNumberingType() ) | |||
370 | { | |||
371 | pFont = pFormat->GetBulletFont(); | |||
372 | if( nullptr == pFont ) | |||
373 | pFont = pDefFont; | |||
374 | ||||
375 | if( bCheck ) | |||
376 | { | |||
377 | if( *pFont == *pDefFont ) | |||
378 | continue; | |||
379 | } | |||
380 | else if( *pFont == *pDefFont ) | |||
381 | bCheck = true; | |||
382 | ||||
383 | AddFontItem( rPool, SvxFontItem( pFont->GetFamilyType(), | |||
384 | pFont->GetFamilyName(), pFont->GetStyleName(), | |||
385 | pFont->GetPitch(), pFont->GetCharSet(), RES_CHRATR_FONT )); | |||
386 | } | |||
387 | } | |||
388 | ||||
389 | void Writer::PutEditEngFontsInAttrPool() | |||
390 | { | |||
391 | SfxItemPool& rPool = m_pDoc->GetAttrPool(); | |||
392 | if( rPool.GetSecondaryPool() ) | |||
393 | { | |||
394 | AddFontItems_( rPool, EE_CHAR_FONTINFO ); | |||
395 | AddFontItems_( rPool, EE_CHAR_FONTINFO_CJK ); | |||
396 | AddFontItems_( rPool, EE_CHAR_FONTINFO_CTL ); | |||
397 | } | |||
398 | } | |||
399 | ||||
400 | void Writer::AddFontItems_( SfxItemPool& rPool, sal_uInt16 nW ) | |||
401 | { | |||
402 | const SvxFontItem* pFont = static_cast<const SvxFontItem*>(&rPool.GetDefaultItem( nW )); | |||
403 | AddFontItem( rPool, *pFont ); | |||
404 | ||||
405 | pFont = static_cast<const SvxFontItem*>(rPool.GetPoolDefaultItem( nW )); | |||
406 | if( nullptr != pFont ) | |||
407 | AddFontItem( rPool, *pFont ); | |||
408 | ||||
409 | for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(nW)) | |||
410 | AddFontItem( rPool, *static_cast<const SvxFontItem*>(pItem) ); | |||
411 | } | |||
412 | ||||
413 | void Writer::AddFontItem( SfxItemPool& rPool, const SvxFontItem& rFont ) | |||
414 | { | |||
415 | const SvxFontItem* pItem; | |||
416 | if( RES_CHRATR_FONT != rFont.Which() ) | |||
417 | { | |||
418 | SvxFontItem aFont( rFont ); | |||
419 | aFont.SetWhich( RES_CHRATR_FONT ); | |||
420 | pItem = &rPool.Put( aFont ); | |||
421 | } | |||
422 | else | |||
423 | pItem = &rPool.Put( rFont ); | |||
424 | ||||
425 | if( 1 < pItem->GetRefCount() ) | |||
426 | rPool.Remove( *pItem ); | |||
427 | else | |||
428 | { | |||
429 | m_pImpl->aFontRemoveLst.push_back( pItem ); | |||
430 | } | |||
431 | } | |||
432 | ||||
433 | // build a bookmark table, which is sort by the node position. The | |||
434 | // OtherPos of the bookmarks also inserted. | |||
435 | void Writer::CreateBookmarkTable() | |||
436 | { | |||
437 | const IDocumentMarkAccess* const pMarkAccess = m_pDoc->getIDocumentMarkAccess(); | |||
438 | for(IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->getBookmarksBegin(); | |||
439 | ppBkmk != pMarkAccess->getBookmarksEnd(); | |||
440 | ++ppBkmk) | |||
441 | { | |||
442 | m_pImpl->InsertBkmk(**ppBkmk); | |||
443 | } | |||
444 | } | |||
445 | ||||
446 | // search all Bookmarks in the range and return it in the Array | |||
447 | bool Writer::GetBookmarks(const SwContentNode& rNd, sal_Int32 nStt, | |||
448 | sal_Int32 nEnd, std::vector< const ::sw::mark::IMark* >& rArr) | |||
449 | { | |||
450 | OSL_ENSURE( rArr.empty(), "there are still entries available" )do { if (true && (!(rArr.empty()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/filter/writer/writer.cxx" ":" "450" ": "), "%s", "there are still entries available"); } } while (false); | |||
451 | ||||
452 | sal_uLong nNd = rNd.GetIndex(); | |||
453 | std::pair<SwBookmarkNodeTable::const_iterator, SwBookmarkNodeTable::const_iterator> aIterPair | |||
454 | = m_pImpl->aBkmkNodePos.equal_range( nNd ); | |||
455 | if( aIterPair.first != aIterPair.second ) | |||
456 | { | |||
457 | // there exist some bookmarks, search now all which is in the range | |||
458 | if( !nStt && nEnd == rNd.Len() ) | |||
459 | // all | |||
460 | for( SwBookmarkNodeTable::const_iterator it = aIterPair.first; it != aIterPair.second; ++it ) | |||
461 | rArr.push_back( it->second ); | |||
462 | else | |||
463 | { | |||
464 | for( SwBookmarkNodeTable::const_iterator it = aIterPair.first; it != aIterPair.second; ++it ) | |||
465 | { | |||
466 | const ::sw::mark::IMark& rBkmk = *(it->second); | |||
467 | sal_Int32 nContent; | |||
468 | if( rBkmk.GetMarkPos().nNode == nNd && | |||
469 | (nContent = rBkmk.GetMarkPos().nContent.GetIndex() ) >= nStt && | |||
470 | nContent < nEnd ) | |||
471 | { | |||
472 | rArr.push_back( &rBkmk ); | |||
473 | } | |||
474 | else if( rBkmk.IsExpanded() && nNd == | |||
475 | rBkmk.GetOtherMarkPos().nNode.GetIndex() && (nContent = | |||
476 | rBkmk.GetOtherMarkPos().nContent.GetIndex() ) >= nStt && | |||
477 | nContent < nEnd ) | |||
478 | { | |||
479 | rArr.push_back( &rBkmk ); | |||
480 | } | |||
481 | } | |||
482 | } | |||
483 | } | |||
484 | return !rArr.empty(); | |||
485 | } | |||
486 | ||||
487 | // Storage-specific | |||
488 | ErrCode StgWriter::WriteStream() | |||
489 | { | |||
490 | OSL_ENSURE( false, "Write in Storages on a stream?" )do { if (true && (!(false))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/filter/writer/writer.cxx" ":" "490" ": "), "%s", "Write in Storages on a stream?"); } } while (false); | |||
491 | return ERR_SWG_WRITE_ERRORErrCode(ErrCodeArea::Sw, ErrCodeClass::Write, 30 ); | |||
492 | } | |||
493 | ||||
494 | ErrCode StgWriter::Write( SwPaM& rPaM, SotStorage& rStg, const OUString* pFName ) | |||
495 | { | |||
496 | SetStream(nullptr); | |||
497 | m_pStg = &rStg; | |||
498 | m_pDoc = &rPaM.GetDoc(); | |||
499 | m_pOrigFileName = pFName; | |||
500 | ||||
501 | // Copy PaM, so that it can be modified | |||
502 | m_pCurrentPam = m_pDoc->CreateUnoCursor(*rPaM.End(), false); | |||
503 | m_pCurrentPam->SetMark(); | |||
504 | *m_pCurrentPam->GetPoint() = *rPaM.Start(); | |||
505 | // for comparison secure to the current Pam | |||
506 | m_pOrigPam = &rPaM; | |||
507 | ||||
508 | ErrCode nRet = WriteStorage(); | |||
509 | ||||
510 | m_pStg = nullptr; | |||
511 | ResetWriter(); | |||
512 | ||||
513 | return nRet; | |||
514 | } | |||
515 | ||||
516 | ErrCode StgWriter::Write( SwPaM& rPaM, const uno::Reference < embed::XStorage >& rStg, const OUString* pFName, SfxMedium* pMedium ) | |||
517 | { | |||
518 | SetStream(nullptr); | |||
519 | m_pStg = nullptr; | |||
520 | m_xStg = rStg; | |||
521 | m_pDoc = &rPaM.GetDoc(); | |||
522 | m_pOrigFileName = pFName; | |||
523 | ||||
524 | // Copy PaM, so that it can be modified | |||
525 | m_pCurrentPam = m_pDoc->CreateUnoCursor(*rPaM.End(), false); | |||
526 | m_pCurrentPam->SetMark(); | |||
527 | *m_pCurrentPam->GetPoint() = *rPaM.Start(); | |||
528 | // for comparison secure to the current Pam | |||
529 | m_pOrigPam = &rPaM; | |||
530 | ||||
531 | ErrCode nRet = pMedium ? WriteMedium( *pMedium ) : WriteStorage(); | |||
532 | ||||
533 | m_pStg = nullptr; | |||
534 | ResetWriter(); | |||
535 | ||||
536 | return nRet; | |||
537 | } | |||
538 | ||||
539 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |