Bug Summary

File:home/maarten/src/libreoffice/core/include/tools/ref.hxx
Warning:line 56, column 30
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name StyleSheetTable.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -isystem /usr/include/libxml2 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D SYSTEM_LIBXML -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/oox/generated -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/writerfilter/source -I /home/maarten/src/libreoffice/core/writerfilter/inc -I /home/maarten/src/libreoffice/core/writerfilter/source -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx

/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx

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#include "StyleSheetTable.hxx"
20#include "util.hxx"
21#include "ConversionHelper.hxx"
22#include "TblStylePrHandler.hxx"
23#include "TagLogger.hxx"
24#include "BorderHandler.hxx"
25#include "LatentStyleHandler.hxx"
26#include <ooxml/resourceids.hxx>
27#include <vector>
28#include <iterator>
29#include <com/sun/star/beans/XMultiPropertySet.hpp>
30#include <com/sun/star/beans/XPropertyState.hpp>
31#include <com/sun/star/beans/PropertyValue.hpp>
32#include <com/sun/star/container/XNameContainer.hpp>
33#include <com/sun/star/container/XIndexReplace.hpp>
34#include <com/sun/star/text/XTextDocument.hpp>
35#include <com/sun/star/style/NumberingType.hpp>
36#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
37#include <com/sun/star/style/XStyle.hpp>
38#include <com/sun/star/style/ParagraphAdjust.hpp>
39#include <com/sun/star/text/WritingMode.hpp>
40#include <com/sun/star/lang/XMultiServiceFactory.hpp>
41#include <map>
42#include <osl/diagnose.h>
43#include <rtl/ustrbuf.hxx>
44#include <sal/log.hxx>
45#include <comphelper/string.hxx>
46#include <comphelper/sequence.hxx>
47#include <tools/diagnose_ex.h>
48#include <o3tl/sorted_vector.hxx>
49
50using namespace ::com::sun::star;
51
52namespace writerfilter::dmapper
53{
54
55StyleSheetEntry::StyleSheetEntry() :
56 sStyleIdentifierD()
57 ,bIsDefaultStyle(false)
58 ,bInvalidHeight(false)
59 ,bHasUPE(false)
60 ,nStyleTypeCode(STYLE_TYPE_UNKNOWN)
61 ,sBaseStyleIdentifier()
62 ,sNextStyleIdentifier()
63 ,pProperties(new StyleSheetPropertyMap)
64 ,bAutoRedefine(false)
65{
66}
67
68StyleSheetEntry::~StyleSheetEntry()
69{
70}
71
72TableStyleSheetEntry::TableStyleSheetEntry( StyleSheetEntry const & rEntry ):
73 StyleSheetEntry( )
74{
75 bIsDefaultStyle = rEntry.bIsDefaultStyle;
76 bInvalidHeight = rEntry.bInvalidHeight;
77 bHasUPE = rEntry.bHasUPE;
78 nStyleTypeCode = STYLE_TYPE_TABLE;
79 sBaseStyleIdentifier = rEntry.sBaseStyleIdentifier;
80 sNextStyleIdentifier = rEntry.sNextStyleIdentifier;
81 sStyleName = rEntry.sStyleName;
82 sStyleIdentifierD = rEntry.sStyleIdentifierD;
83}
84
85TableStyleSheetEntry::~TableStyleSheetEntry( )
86{
87}
88
89void TableStyleSheetEntry::AddTblStylePr( TblStyleType nType, const PropertyMapPtr& pProps )
90{
91 static const int nTypesProps = 4;
92 static const TblStyleType pTypesToFix[nTypesProps] =
93 {
94 TBL_STYLE_FIRSTROW,
95 TBL_STYLE_LASTROW,
96 TBL_STYLE_FIRSTCOL,
97 TBL_STYLE_LASTCOL
98 };
99
100 static const PropertyIds pPropsToCheck[nTypesProps] =
101 {
102 PROP_BOTTOM_BORDER,
103 PROP_TOP_BORDER,
104 PROP_RIGHT_BORDER,
105 PROP_LEFT_BORDER
106 };
107
108 for (int i=0; i < nTypesProps; ++i )
109 {
110 if ( nType == pTypesToFix[i] )
111 {
112 PropertyIds nChecked = pPropsToCheck[i];
113 std::optional<PropertyMap::Property> pChecked = pProps->getProperty(nChecked);
114
115 PropertyIds nInsideProp = ( i < 2 ) ? META_PROP_HORIZONTAL_BORDER : META_PROP_VERTICAL_BORDER;
116 std::optional<PropertyMap::Property> pInside = pProps->getProperty(nInsideProp);
117
118 if ( pChecked && pInside )
119 {
120 // In this case, remove the inside border
121 pProps->Erase( nInsideProp );
122 }
123
124 break;
125 }
126 }
127
128 // Append the tblStylePr
129 m_aStyles[nType] = pProps;
130}
131
132PropertyMapPtr TableStyleSheetEntry::GetProperties( sal_Int32 nMask )
133{
134 PropertyMapPtr pProps( new PropertyMap );
135
136 // And finally get the mask ones
137 pProps->InsertProps(GetLocalPropertiesFromMask(nMask));
138
139 return pProps;
140}
141
142beans::PropertyValues StyleSheetEntry::GetInteropGrabBagSeq() const
143{
144 return comphelper::containerToSequence(m_aInteropGrabBag);
145}
146
147beans::PropertyValue StyleSheetEntry::GetInteropGrabBag()
148{
149 beans::PropertyValue aRet;
150 aRet.Name = sStyleIdentifierD;
151
152 beans::PropertyValues aSeq = GetInteropGrabBagSeq();
153 aRet.Value <<= aSeq;
154 return aRet;
155}
156
157void StyleSheetEntry::AppendInteropGrabBag(const beans::PropertyValue& rValue)
158{
159 m_aInteropGrabBag.push_back(rValue);
160}
161
162PropertyMapPtr StyleSheetEntry::GetMergedInheritedProperties(const StyleSheetTablePtr& pStyleSheetTable)
163{
164 PropertyMapPtr pRet;
165 if ( pStyleSheetTable && !sBaseStyleIdentifier.isEmpty() && sBaseStyleIdentifier != sStyleIdentifierD )
166 {
167 const StyleSheetEntryPtr pParentStyleSheet = pStyleSheetTable->FindStyleSheetByISTD(sBaseStyleIdentifier);
168 if ( pParentStyleSheet )
169 pRet = pParentStyleSheet->GetMergedInheritedProperties(pStyleSheetTable);
170 }
171
172 if ( !pRet )
173 pRet = new PropertyMap;
174
175 pRet->InsertProps(pProperties);
176
177 return pRet;
178}
179
180static void lcl_mergeProps( const PropertyMapPtr& pToFill, const PropertyMapPtr& pToAdd, TblStyleType nStyleId )
181{
182 static const PropertyIds pPropsToCheck[] =
183 {
184 PROP_BOTTOM_BORDER,
185 PROP_TOP_BORDER,
186 PROP_RIGHT_BORDER,
187 PROP_LEFT_BORDER,
188 };
189
190 bool pRemoveInside[] =
191 {
192 ( nStyleId == TBL_STYLE_FIRSTROW ),
193 ( nStyleId == TBL_STYLE_LASTROW ),
194 ( nStyleId == TBL_STYLE_LASTCOL ),
195 ( nStyleId == TBL_STYLE_FIRSTCOL )
196 };
197
198 for ( unsigned i = 0 ; i != SAL_N_ELEMENTS(pPropsToCheck)(sizeof(sal_n_array_size(pPropsToCheck))); i++ )
199 {
200 PropertyIds nId = pPropsToCheck[i];
201 std::optional<PropertyMap::Property> pProp = pToAdd->getProperty(nId);
202
203 if ( pProp )
204 {
205 if ( pRemoveInside[i] )
206 {
207 // Remove the insideH and insideV depending on the cell pos
208 PropertyIds nInsideProp = ( i < 2 ) ? META_PROP_HORIZONTAL_BORDER : META_PROP_VERTICAL_BORDER;
209 pToFill->Erase(nInsideProp);
210 }
211 }
212 }
213
214 pToFill->InsertProps(pToAdd);
215}
216
217PropertyMapPtr TableStyleSheetEntry::GetLocalPropertiesFromMask( sal_Int32 nMask )
218{
219 // Order from right to left
220 struct TblStyleTypeAndMask {
221 sal_Int32 mask;
222 TblStyleType type;
223 };
224
225 static const TblStyleTypeAndMask aOrderedStyleTable[] =
226 {
227 { 0x010, TBL_STYLE_BAND2HORZ },
228 { 0x020, TBL_STYLE_BAND1HORZ },
229 { 0x040, TBL_STYLE_BAND2VERT },
230 { 0x080, TBL_STYLE_BAND1VERT },
231 { 0x100, TBL_STYLE_LASTCOL },
232 { 0x200, TBL_STYLE_FIRSTCOL },
233 { 0x400, TBL_STYLE_LASTROW },
234 { 0x800, TBL_STYLE_FIRSTROW },
235 { 0x001, TBL_STYLE_SWCELL },
236 { 0x002, TBL_STYLE_SECELL },
237 { 0x004, TBL_STYLE_NWCELL },
238 { 0x008, TBL_STYLE_NECELL }
239 };
240
241 // Get the properties applying according to the mask
242 PropertyMapPtr pProps( new PropertyMap( ) );
243 for (const TblStyleTypeAndMask & i : aOrderedStyleTable)
244 {
245 TblStylePrs::iterator pIt = m_aStyles.find( i.type );
246 if ( ( nMask & i.mask ) && ( pIt != m_aStyles.end( ) ) )
247 lcl_mergeProps( pProps, pIt->second, i.type );
248 }
249 return pProps;
250}
251
252namespace {
253
254struct ListCharStylePropertyMap_t
255{
256 OUString sCharStyleName;
257 PropertyValueVector_t aPropertyValues;
258
259 ListCharStylePropertyMap_t(const OUString& rCharStyleName, const PropertyValueVector_t& rPropertyValues):
260 sCharStyleName( rCharStyleName ),
261 aPropertyValues( rPropertyValues )
262 {}
263};
264
265}
266
267typedef std::vector< ListCharStylePropertyMap_t > ListCharStylePropertyVector_t;
268
269
270struct StyleSheetTable_Impl
271{
272 DomainMapper& m_rDMapper;
273 uno::Reference< text::XTextDocument> m_xTextDocument;
274 uno::Reference< beans::XPropertySet> m_xTextDefaults;
275 std::vector< StyleSheetEntryPtr > m_aStyleSheetEntries;
276 StyleSheetEntryPtr m_pCurrentEntry;
277 PropertyMapPtr m_pDefaultParaProps, m_pDefaultCharProps;
278 OUString m_sDefaultParaStyleName; //WW8 name
279 ListCharStylePropertyVector_t m_aListCharStylePropertyVector;
280 bool m_bHasImportedDefaultParaProps;
281 bool m_bIsNewDoc;
282
283 StyleSheetTable_Impl(DomainMapper& rDMapper, uno::Reference< text::XTextDocument> const& xTextDocument, bool bIsNewDoc);
284
285 OUString HasListCharStyle( const PropertyValueVector_t& rCharProperties );
286
287 /// Appends the given key-value pair to the list of latent style properties of the current entry.
288 void AppendLatentStyleProperty(const OUString& aName, Value const & rValue);
289 /// Sets all properties of xStyle back to default.
290 static void SetPropertiesToDefault(const uno::Reference<style::XStyle>& xStyle);
291};
292
293
294StyleSheetTable_Impl::StyleSheetTable_Impl(DomainMapper& rDMapper,
295 uno::Reference< text::XTextDocument> const& xTextDocument,
296 bool const bIsNewDoc)
297 :
298 m_rDMapper( rDMapper ),
299 m_xTextDocument( xTextDocument ),
300 m_pCurrentEntry(),
301 m_pDefaultParaProps(new PropertyMap),
302 m_pDefaultCharProps(new PropertyMap),
303 m_sDefaultParaStyleName("Normal"),
304 m_bHasImportedDefaultParaProps(false),
305 m_bIsNewDoc(bIsNewDoc)
306{
307 //set font height default to 10pt
308 uno::Any aVal = uno::makeAny( 10.0 );
309 m_pDefaultCharProps->Insert( PROP_CHAR_HEIGHT, aVal );
310 m_pDefaultCharProps->Insert( PROP_CHAR_HEIGHT_ASIAN, aVal );
311 m_pDefaultCharProps->Insert( PROP_CHAR_HEIGHT_COMPLEX, aVal );
312
313 // See SwDoc::RemoveAllFormatLanguageDependencies(), internal filters
314 // disable kerning by default, do the same here.
315 m_pDefaultCharProps->Insert(PROP_CHAR_AUTO_KERNING, uno::Any(false));
316}
317
318
319OUString StyleSheetTable_Impl::HasListCharStyle( const PropertyValueVector_t& rPropValues )
320{
321 for( const auto& rListVector : m_aListCharStylePropertyVector )
322 {
323 const auto& rPropertyValues = rListVector.aPropertyValues;
324 //if size is identical
325 if( rPropertyValues.size() == rPropValues.size() )
326 {
327 bool bBreak = false;
328 //then search for all contained properties
329 for( const auto& rPropVal1 : rPropValues)
330 {
331 //find the property
332 auto aListIter = std::find_if(rPropertyValues.begin(), rPropertyValues.end(),
333 [&rPropVal1](const css::beans::PropertyValue& rPropVal2) { return rPropVal2.Name == rPropVal1.Name; });
334 //set break flag if property hasn't been found
335 bBreak = (aListIter == rPropertyValues.end()) || (aListIter->Value != rPropVal1.Value);
336 if( bBreak )
337 break;
338 }
339 if( !bBreak )
340 return rListVector.sCharStyleName;
341 }
342 }
343 return OUString();
344}
345
346void StyleSheetTable_Impl::AppendLatentStyleProperty(const OUString& aName, Value const & rValue)
347{
348 beans::PropertyValue aValue;
349 aValue.Name = aName;
350 aValue.Value <<= rValue.getString();
351 m_pCurrentEntry->aLatentStyles.push_back(aValue);
352}
353
354void StyleSheetTable_Impl::SetPropertiesToDefault(const uno::Reference<style::XStyle>& xStyle)
355{
356 // See if the existing style has any non-default properties. If so, reset them back to default.
357 uno::Reference<beans::XPropertySet> xPropertySet(xStyle, uno::UNO_QUERY);
358 uno::Reference<beans::XPropertySetInfo> xPropertySetInfo = xPropertySet->getPropertySetInfo();
359 uno::Sequence<beans::Property> aProperties = xPropertySetInfo->getProperties();
360 std::vector<OUString> aPropertyNames;
361 aPropertyNames.reserve(aProperties.getLength());
362 std::transform(aProperties.begin(), aProperties.end(), std::back_inserter(aPropertyNames),
363 [](const beans::Property& rProp) { return rProp.Name; });
364
365 uno::Reference<beans::XPropertyState> xPropertyState(xStyle, uno::UNO_QUERY);
366 uno::Sequence<beans::PropertyState> aStates = xPropertyState->getPropertyStates(comphelper::containerToSequence(aPropertyNames));
367 for (sal_Int32 i = 0; i < aStates.getLength(); ++i)
368 {
369 if (aStates[i] == beans::PropertyState_DIRECT_VALUE)
370 {
371 try
372 {
373 xPropertyState->setPropertyToDefault(aPropertyNames[i]);
374 }
375 catch(const uno::Exception&)
376 {
377 TOOLS_INFO_EXCEPTION("writerfilter", "setPropertyToDefault(" << aPropertyNames[i] << ") failed")do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "writerfilter")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "setPropertyToDefault("
<< aPropertyNames[i] << ") failed" << " " <<
exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "377" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "setPropertyToDefault(" << aPropertyNames
[i] << ") failed" << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "setPropertyToDefault(" <<
aPropertyNames[i] << ") failed" << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "377" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "setPropertyToDefault(" << aPropertyNames[i
] << ") failed" << " " << exceptionToString
(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "377" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "setPropertyToDefault(" << aPropertyNames
[i] << ") failed" << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "setPropertyToDefault(" <<
aPropertyNames[i] << ") failed" << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "377" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
378 }
379 }
380 }
381}
382
383StyleSheetTable::StyleSheetTable(DomainMapper& rDMapper,
384 uno::Reference< text::XTextDocument> const& xTextDocument,
385 bool const bIsNewDoc)
386: LoggedProperties("StyleSheetTable")
387, LoggedTable("StyleSheetTable")
388, m_pImpl( new StyleSheetTable_Impl(rDMapper, xTextDocument, bIsNewDoc) )
389{
390}
391
392
393StyleSheetTable::~StyleSheetTable()
394{
395}
396
397void StyleSheetTable::SetDefaultParaProps(PropertyIds eId, const css::uno::Any& rAny)
398{
399 m_pImpl->m_pDefaultParaProps->Insert(eId, rAny, /*bOverwrite=*/false, NO_GRAB_BAG, /*bDocDefault=*/true);
400}
401
402PropertyMapPtr const & StyleSheetTable::GetDefaultParaProps() const
403{
404 return m_pImpl->m_pDefaultParaProps;
405}
406
407PropertyMapPtr const & StyleSheetTable::GetDefaultCharProps() const
408{
409 return m_pImpl->m_pDefaultCharProps;
410}
411
412void StyleSheetTable::lcl_attribute(Id Name, Value & val)
413{
414 OSL_ENSURE( m_pImpl->m_pCurrentEntry, "current entry has to be set here")do { if (true && (!(m_pImpl->m_pCurrentEntry))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "414" ": "), "%s", "current entry has to be set here"); }
} while (false)
;
1
Taking false branch
2
Loop condition is false. Exiting loop
415 if(!m_pImpl->m_pCurrentEntry)
3
Taking false branch
416 return ;
417 int nIntValue = val.getInt();
418 OUString sValue = val.getString();
419
420 // The default type is paragraph, and it needs to be processed first,
421 // because the NS_ooxml::LN_CT_Style_type handling may set m_pImpl->m_pCurrentEntry
422 // to point to a different object.
423 if( m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_UNKNOWN )
4
Assuming field 'nStyleTypeCode' is equal to STYLE_TYPE_UNKNOWN
5
Taking true branch
424 {
425 if( Name != NS_ooxml::LN_CT_Style_type )
6
Assuming 'Name' is equal to 'LN_CT_Style_type'
7
Taking false branch
426 m_pImpl->m_pCurrentEntry->nStyleTypeCode = STYLE_TYPE_PARA;
427 }
428 switch(Name)
8
Control jumps to 'case 93140:' at line 430
429 {
430 case NS_ooxml::LN_CT_Style_type:
431 {
432 SAL_WARN_IF( m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN,do { if (true && (m_pImpl->m_pCurrentEntry->nStyleTypeCode
!= STYLE_TYPE_UNKNOWN)) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "writerfilter")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "Style type needs to be processed first"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "433" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Style type needs to be processed first"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "Style type needs to be processed first"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "433" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Style type needs to be processed first") == 1) {
::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "433" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Style type needs to be processed first"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "Style type needs to be processed first"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "433" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
9
Taking false branch
10
Loop condition is false. Exiting loop
433 "writerfilter", "Style type needs to be processed first" )do { if (true && (m_pImpl->m_pCurrentEntry->nStyleTypeCode
!= STYLE_TYPE_UNKNOWN)) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "writerfilter")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "Style type needs to be processed first"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "433" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Style type needs to be processed first"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "Style type needs to be processed first"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "433" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Style type needs to be processed first") == 1) {
::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "433" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Style type needs to be processed first"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "Style type needs to be processed first"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "433" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
434 StyleType nType(STYLE_TYPE_UNKNOWN);
435 switch (nIntValue)
11
Control jumps to 'case 93116:' at line 443
436 {
437 case NS_ooxml::LN_Value_ST_StyleType_paragraph:
438 nType = STYLE_TYPE_PARA;
439 break;
440 case NS_ooxml::LN_Value_ST_StyleType_character:
441 nType = STYLE_TYPE_CHAR;
442 break;
443 case NS_ooxml::LN_Value_ST_StyleType_table:
444 nType = STYLE_TYPE_TABLE;
445 break;
12
Execution continues on line 456
446 case NS_ooxml::LN_Value_ST_StyleType_numbering:
447 nType = STYLE_TYPE_LIST;
448 break;
449 default:
450 SAL_WARN("writerfilter", "unknown LN_CT_Style_type " << nType)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "writerfilter")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "unknown LN_CT_Style_type "
<< nType) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "450" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "unknown LN_CT_Style_type " << nType
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "unknown LN_CT_Style_type " << nType; ::sal::
detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter"),
("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "450" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "unknown LN_CT_Style_type " << nType) == 1)
{ ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "450" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "unknown LN_CT_Style_type " << nType
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "unknown LN_CT_Style_type " << nType; ::sal::
detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter"),
("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "450" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
451 [[fallthrough]];
452 case 0: // explicit unknown set by tokenizer
453 break;
454
455 }
456 if ( nType
12.1
'nType' is equal to STYLE_TYPE_TABLE
12.1
'nType' is equal to STYLE_TYPE_TABLE
== STYLE_TYPE_TABLE )
13
Taking true branch
457 {
458 StyleSheetEntryPtr pEntry = m_pImpl->m_pCurrentEntry;
459 tools::SvRef<TableStyleSheetEntry> pTableEntry( new TableStyleSheetEntry( *pEntry ) );
460 m_pImpl->m_pCurrentEntry = pTableEntry.get();
14
Calling move assignment operator for 'SvRef<writerfilter::dmapper::StyleSheetEntry>'
23
Returning; memory was released
461 }
24
Calling '~SvRef'
462 else
463 m_pImpl->m_pCurrentEntry->nStyleTypeCode = nType;
464 }
465 break;
466 case NS_ooxml::LN_CT_Style_default:
467 m_pImpl->m_pCurrentEntry->bIsDefaultStyle = (nIntValue != 0);
468
469 if (m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN)
470 {
471 // "If this attribute is specified by multiple styles, then the last instance shall be used."
472 if ( m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_PARA && !m_pImpl->m_pCurrentEntry->sStyleIdentifierD.isEmpty() )
473 m_pImpl->m_sDefaultParaStyleName = m_pImpl->m_pCurrentEntry->sStyleIdentifierD;
474
475 beans::PropertyValue aValue;
476 aValue.Name = "default";
477 aValue.Value <<= m_pImpl->m_pCurrentEntry->bIsDefaultStyle;
478 m_pImpl->m_pCurrentEntry->AppendInteropGrabBag(aValue);
479 }
480 break;
481 case NS_ooxml::LN_CT_Style_customStyle:
482 if (m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN)
483 {
484 beans::PropertyValue aValue;
485 aValue.Name = "customStyle";
486 aValue.Value <<= (nIntValue != 0);
487 m_pImpl->m_pCurrentEntry->AppendInteropGrabBag(aValue);
488 }
489 break;
490 case NS_ooxml::LN_CT_Style_styleId:
491 m_pImpl->m_pCurrentEntry->sStyleIdentifierD = sValue;
492 if(m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
493 {
494 TableStyleSheetEntry* pTableEntry = static_cast<TableStyleSheetEntry *>(m_pImpl->m_pCurrentEntry.get());
495 beans::PropertyValue aValue;
496 aValue.Name = "styleId";
497 aValue.Value <<= sValue;
498 pTableEntry->AppendInteropGrabBag(aValue);
499 }
500 break;
501 case NS_ooxml::LN_CT_TblWidth_w:
502 break;
503 case NS_ooxml::LN_CT_TblWidth_type:
504 break;
505 case NS_ooxml::LN_CT_LatentStyles_defQFormat:
506 m_pImpl->AppendLatentStyleProperty("defQFormat", val);
507 break;
508 case NS_ooxml::LN_CT_LatentStyles_defUnhideWhenUsed:
509 m_pImpl->AppendLatentStyleProperty("defUnhideWhenUsed", val);
510 break;
511 case NS_ooxml::LN_CT_LatentStyles_defSemiHidden:
512 m_pImpl->AppendLatentStyleProperty("defSemiHidden", val);
513 break;
514 case NS_ooxml::LN_CT_LatentStyles_count:
515 m_pImpl->AppendLatentStyleProperty("count", val);
516 break;
517 case NS_ooxml::LN_CT_LatentStyles_defUIPriority:
518 m_pImpl->AppendLatentStyleProperty("defUIPriority", val);
519 break;
520 case NS_ooxml::LN_CT_LatentStyles_defLockedState:
521 m_pImpl->AppendLatentStyleProperty("defLockedState", val);
522 break;
523 default:
524 {
525#ifdef DBG_UTIL
526 TagLogger::getInstance().element("unhandled");
527#endif
528 }
529 break;
530 }
531}
532
533
534void StyleSheetTable::lcl_sprm(Sprm & rSprm)
535{
536 sal_uInt32 nSprmId = rSprm.getId();
537 Value::Pointer_t pValue = rSprm.getValue();
538 sal_Int32 nIntValue = pValue ? pValue->getInt() : 0;
539 OUString sStringValue = pValue ? pValue->getString() : OUString();
540
541 switch(nSprmId)
542 {
543 case NS_ooxml::LN_CT_Style_name:
544 //this is only a UI name!
545 m_pImpl->m_pCurrentEntry->sStyleName = sStringValue;
546 if(m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
547 {
548 TableStyleSheetEntry* pTableEntry = static_cast<TableStyleSheetEntry *>(m_pImpl->m_pCurrentEntry.get());
549 beans::PropertyValue aValue;
550 aValue.Name = "name";
551 aValue.Value <<= sStringValue;
552 pTableEntry->AppendInteropGrabBag(aValue);
553 }
554 break;
555 case NS_ooxml::LN_CT_Style_basedOn:
556 m_pImpl->m_pCurrentEntry->sBaseStyleIdentifier = sStringValue;
557 if(m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
558 {
559 TableStyleSheetEntry* pTableEntry = static_cast<TableStyleSheetEntry *>(m_pImpl->m_pCurrentEntry.get());
560 beans::PropertyValue aValue;
561 aValue.Name = "basedOn";
562 aValue.Value <<= sStringValue;
563 pTableEntry->AppendInteropGrabBag(aValue);
564 }
565 break;
566 case NS_ooxml::LN_CT_Style_next:
567 m_pImpl->m_pCurrentEntry->sNextStyleIdentifier = sStringValue;
568 break;
569 case NS_ooxml::LN_CT_Style_aliases:
570 case NS_ooxml::LN_CT_Style_hidden:
571 case NS_ooxml::LN_CT_Style_personal:
572 case NS_ooxml::LN_CT_Style_personalCompose:
573 case NS_ooxml::LN_CT_Style_personalReply:
574 break;
575 case NS_ooxml::LN_CT_Style_autoRedefine:
576 m_pImpl->m_pCurrentEntry->bAutoRedefine = nIntValue;
577 break;
578 case NS_ooxml::LN_CT_Style_tcPr:
579 {
580 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
581 if( pProperties && m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
582 {
583 auto pTblStylePrHandler = std::make_shared<TblStylePrHandler>(m_pImpl->m_rDMapper);
584 pProperties->resolve(*pTblStylePrHandler);
585 StyleSheetEntry* pEntry = m_pImpl->m_pCurrentEntry.get();
586 TableStyleSheetEntry& rTableEntry = dynamic_cast<TableStyleSheetEntry&>(*pEntry);
587 rTableEntry.AppendInteropGrabBag(pTblStylePrHandler->getInteropGrabBag("tcPr"));
588
589 // This is a <w:tcPr> directly under <w:style>, so it affects the whole table.
590 rTableEntry.pProperties->InsertProps(pTblStylePrHandler->getProperties());
591 }
592 }
593 break;
594 case NS_ooxml::LN_CT_Style_trPr:
595 break;
596 case NS_ooxml::LN_CT_Style_rsid:
597 case NS_ooxml::LN_CT_Style_qFormat:
598 case NS_ooxml::LN_CT_Style_semiHidden:
599 case NS_ooxml::LN_CT_Style_unhideWhenUsed:
600 case NS_ooxml::LN_CT_Style_uiPriority:
601 case NS_ooxml::LN_CT_Style_link:
602 case NS_ooxml::LN_CT_Style_locked:
603 if (m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN)
604 {
605 StyleSheetEntryPtr pEntry = m_pImpl->m_pCurrentEntry;
606 beans::PropertyValue aValue;
607 switch (nSprmId)
608 {
609 case NS_ooxml::LN_CT_Style_rsid:
610 {
611 // We want the rsid as a hex string, but always with the length of 8.
612 OUStringBuffer aBuf = OUString::number(nIntValue, 16);
613 OUStringBuffer aStr;
614 comphelper::string::padToLength(aStr, 8 - aBuf.getLength(), '0');
615 aStr.append(aBuf.getStr());
616
617 aValue.Name = "rsid";
618 aValue.Value <<= aStr.makeStringAndClear();
619 }
620 break;
621 case NS_ooxml::LN_CT_Style_qFormat:
622 aValue.Name = "qFormat";
623 break;
624 case NS_ooxml::LN_CT_Style_semiHidden:
625 aValue.Name = "semiHidden";
626 break;
627 case NS_ooxml::LN_CT_Style_unhideWhenUsed:
628 aValue.Name = "unhideWhenUsed";
629 break;
630 case NS_ooxml::LN_CT_Style_uiPriority:
631 {
632 aValue.Name = "uiPriority";
633 aValue.Value <<= OUString::number(nIntValue);
634 }
635 break;
636 case NS_ooxml::LN_CT_Style_link:
637 {
638 aValue.Name = "link";
639 aValue.Value <<= sStringValue;
640 }
641 break;
642 case NS_ooxml::LN_CT_Style_locked:
643 aValue.Name = "locked";
644 break;
645 }
646 pEntry->AppendInteropGrabBag(aValue);
647 }
648 break;
649 case NS_ooxml::LN_CT_Style_tblPr: //contains table properties
650 case NS_ooxml::LN_CT_Style_tblStylePr: //contains to table properties
651 case NS_ooxml::LN_CT_TblPrBase_tblInd: //table properties - at least width value and type
652 case NS_ooxml::LN_EG_RPrBase_rFonts: //table fonts
653 {
654 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
655 if( pProperties )
656 {
657 auto pTblStylePrHandler = std::make_shared<TblStylePrHandler>( m_pImpl->m_rDMapper );
658 pProperties->resolve( *pTblStylePrHandler );
659
660 // Add the properties to the table style
661 TblStyleType nType = pTblStylePrHandler->getType( );
662 PropertyMapPtr pProps = pTblStylePrHandler->getProperties( );
663 StyleSheetEntry * pEntry = m_pImpl->m_pCurrentEntry.get();
664
665 TableStyleSheetEntry * pTableEntry = dynamic_cast<TableStyleSheetEntry*>( pEntry );
666 if (nType == TBL_STYLE_UNKNOWN)
667 {
668 pEntry->pProperties->InsertProps(pProps);
669 }
670 else
671 {
672 if (pTableEntry != nullptr)
673 pTableEntry->AddTblStylePr( nType, pProps );
674 }
675
676 if (nSprmId == NS_ooxml::LN_CT_Style_tblPr)
677 {
678 if (pTableEntry != nullptr)
679 pTableEntry->AppendInteropGrabBag(pTblStylePrHandler->getInteropGrabBag("tblPr"));
680 }
681 else if (nSprmId == NS_ooxml::LN_CT_Style_tblStylePr)
682 {
683 pTblStylePrHandler->appendInteropGrabBag("type", pTblStylePrHandler->getTypeString());
684 if (pTableEntry != nullptr)
685 pTableEntry->AppendInteropGrabBag(pTblStylePrHandler->getInteropGrabBag("tblStylePr"));
686 }
687 }
688 break;
689 }
690 case NS_ooxml::LN_CT_PPrDefault_pPr:
691 case NS_ooxml::LN_CT_DocDefaults_pPrDefault:
692 m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pDefaultParaProps );
693 resolveSprmProps( m_pImpl->m_rDMapper, rSprm );
694 if ( nSprmId == NS_ooxml::LN_CT_DocDefaults_pPrDefault && m_pImpl->m_pDefaultParaProps &&
695 !m_pImpl->m_pDefaultParaProps->isSet( PROP_PARA_TOP_MARGIN ) )
696 {
697 SetDefaultParaProps( PROP_PARA_TOP_MARGIN, uno::makeAny( sal_Int32(0) ) );
698 }
699 m_pImpl->m_rDMapper.PopStyleSheetProperties();
700 applyDefaults( true );
701 m_pImpl->m_bHasImportedDefaultParaProps = true;
702 break;
703 case NS_ooxml::LN_CT_RPrDefault_rPr:
704 case NS_ooxml::LN_CT_DocDefaults_rPrDefault:
705 m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pDefaultCharProps );
706 resolveSprmProps( m_pImpl->m_rDMapper, rSprm );
707 m_pImpl->m_rDMapper.PopStyleSheetProperties();
708 applyDefaults( false );
709 break;
710 case NS_ooxml::LN_CT_TblPrBase_jc: //table alignment - row properties!
711 m_pImpl->m_pCurrentEntry->pProperties->Insert( PROP_HORI_ORIENT,
712 uno::makeAny( ConversionHelper::convertTableJustification( nIntValue )));
713 break;
714 case NS_ooxml::LN_CT_TrPrBase_jc: //table alignment - row properties!
715 break;
716 case NS_ooxml::LN_CT_TblPrBase_tblBorders: //table borders, might be defined in table style
717 {
718 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
719 if( pProperties )
720 {
721 auto pBorderHandler = std::make_shared<BorderHandler>(m_pImpl->m_rDMapper.IsOOXMLImport());
722 pProperties->resolve(*pBorderHandler);
723 m_pImpl->m_pCurrentEntry->pProperties->InsertProps(
724 pBorderHandler->getProperties());
725 }
726 }
727 break;
728 case NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize:
729 case NS_ooxml::LN_CT_TblPrBase_tblStyleColBandSize:
730 break;
731 case NS_ooxml::LN_CT_TblPrBase_tblCellMar:
732 //no cell margins in styles
733 break;
734 case NS_ooxml::LN_CT_LatentStyles_lsdException:
735 {
736 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
737 if (pProperties)
738 {
739 tools::SvRef<LatentStyleHandler> pLatentStyleHandler(new LatentStyleHandler());
740 pProperties->resolve(*pLatentStyleHandler);
741 beans::PropertyValue aValue;
742 aValue.Name = "lsdException";
743 aValue.Value <<= comphelper::containerToSequence(pLatentStyleHandler->getAttributes());
744 m_pImpl->m_pCurrentEntry->aLsdExceptions.push_back(aValue);
745 }
746 }
747 break;
748 case NS_ooxml::LN_CT_Style_pPr:
749 // no break
750 case NS_ooxml::LN_CT_Style_rPr:
751 // no break
752 default:
753 {
754 if (!m_pImpl->m_pCurrentEntry)
755 break;
756
757 tools::SvRef<TablePropertiesHandler> pTblHandler(new TablePropertiesHandler());
758 pTblHandler->SetProperties( m_pImpl->m_pCurrentEntry->pProperties );
759 if ( !pTblHandler->sprm( rSprm ) )
760 {
761 m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pCurrentEntry->pProperties );
762
763 PropertyMapPtr pProps(new PropertyMap());
764 if (m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
765 {
766 if (nSprmId == NS_ooxml::LN_CT_Style_pPr)
767 m_pImpl->m_rDMapper.enableInteropGrabBag("pPr");
768 else if (nSprmId == NS_ooxml::LN_CT_Style_rPr)
769 m_pImpl->m_rDMapper.enableInteropGrabBag("rPr");
770 }
771 m_pImpl->m_rDMapper.sprmWithProps( rSprm, pProps );
772 if (m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
773 {
774 if (nSprmId == NS_ooxml::LN_CT_Style_pPr || nSprmId == NS_ooxml::LN_CT_Style_rPr)
775 {
776 TableStyleSheetEntry* pTableEntry = static_cast<TableStyleSheetEntry *>(m_pImpl->m_pCurrentEntry.get());
777 pTableEntry->AppendInteropGrabBag(m_pImpl->m_rDMapper.getInteropGrabBag());
778 }
779 }
780
781 m_pImpl->m_pCurrentEntry->pProperties->InsertProps(pProps);
782
783 m_pImpl->m_rDMapper.PopStyleSheetProperties( );
784 }
785 }
786 break;
787}
788}
789
790
791void StyleSheetTable::lcl_entry(writerfilter::Reference<Properties>::Pointer_t ref)
792{
793 //create a new style entry
794 OSL_ENSURE( !m_pImpl->m_pCurrentEntry, "current entry has to be NULL here")do { if (true && (!(!m_pImpl->m_pCurrentEntry))) {
sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "794" ": "), "%s", "current entry has to be NULL here");
} } while (false)
;
795 StyleSheetEntryPtr pNewEntry( new StyleSheetEntry );
796 m_pImpl->m_pCurrentEntry = pNewEntry;
797 m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pCurrentEntry->pProperties );
798 ref->resolve(*this);
799 //append it to the table
800 m_pImpl->m_rDMapper.PopStyleSheetProperties();
801 if( !m_pImpl->m_rDMapper.IsOOXMLImport() || !m_pImpl->m_pCurrentEntry->sStyleName.isEmpty())
802 {
803 m_pImpl->m_pCurrentEntry->sConvertedStyleName = ConvertStyleName( m_pImpl->m_pCurrentEntry->sStyleName );
804 m_pImpl->m_aStyleSheetEntries.push_back( m_pImpl->m_pCurrentEntry );
805 }
806 else
807 {
808 //TODO: this entry contains the default settings - they have to be added to the settings
809 }
810
811 if (!m_pImpl->m_pCurrentEntry->aLatentStyles.empty())
812 {
813 // We have latent styles for this entry, then process them.
814 std::vector<beans::PropertyValue>& rLatentStyles = m_pImpl->m_pCurrentEntry->aLatentStyles;
815
816 if (!m_pImpl->m_pCurrentEntry->aLsdExceptions.empty())
817 {
818 std::vector<beans::PropertyValue>& rLsdExceptions = m_pImpl->m_pCurrentEntry->aLsdExceptions;
819 beans::PropertyValue aValue;
820 aValue.Name = "lsdExceptions";
821 aValue.Value <<= comphelper::containerToSequence(rLsdExceptions);
822 rLatentStyles.push_back(aValue);
823 }
824
825 uno::Sequence<beans::PropertyValue> aLatentStyles( comphelper::containerToSequence(rLatentStyles) );
826
827 // We can put all latent style info directly to the document interop
828 // grab bag, as we can be sure that only a single style entry has
829 // latent style info.
830 uno::Reference<beans::XPropertySet> xPropertySet(m_pImpl->m_xTextDocument, uno::UNO_QUERY);
831 auto aGrabBag = comphelper::sequenceToContainer< std::vector<beans::PropertyValue> >(xPropertySet->getPropertyValue("InteropGrabBag").get< uno::Sequence<beans::PropertyValue> >());
832 beans::PropertyValue aValue;
833 aValue.Name = "latentStyles";
834 aValue.Value <<= aLatentStyles;
835 aGrabBag.push_back(aValue);
836 xPropertySet->setPropertyValue("InteropGrabBag", uno::makeAny(comphelper::containerToSequence(aGrabBag)));
837 }
838
839 StyleSheetEntryPtr pEmptyEntry;
840 m_pImpl->m_pCurrentEntry = pEmptyEntry;
841}
842/*-------------------------------------------------------------------------
843 sorting helper
844 -----------------------------------------------------------------------*/
845namespace {
846
847class PropValVector
848{
849 std::vector<beans::PropertyValue> m_aValues;
850public:
851 PropValVector(){}
852
853 void Insert(const beans::PropertyValue& rVal);
854 uno::Sequence< uno::Any > getValues();
855 uno::Sequence< OUString > getNames();
856 const std::vector<beans::PropertyValue>& getProperties() const { return m_aValues; };
857};
858
859}
860
861void PropValVector::Insert(const beans::PropertyValue& rVal)
862{
863 auto aIt = std::find_if(m_aValues.begin(), m_aValues.end(),
864 [&rVal](beans::PropertyValue& rPropVal) { return rPropVal.Name > rVal.Name; });
865 if (aIt != m_aValues.end())
866 {
867 m_aValues.insert( aIt, rVal );
868 return;
869 }
870 m_aValues.push_back(rVal);
871}
872
873uno::Sequence< uno::Any > PropValVector::getValues()
874{
875 std::vector<uno::Any> aRet;
876 std::transform(m_aValues.begin(), m_aValues.end(), std::back_inserter(aRet), [](const beans::PropertyValue& rValue) { return rValue.Value; });
877 return comphelper::containerToSequence(aRet);
878}
879
880uno::Sequence< OUString > PropValVector::getNames()
881{
882 std::vector<OUString> aRet;
883 std::transform(m_aValues.begin(), m_aValues.end(), std::back_inserter(aRet), [](const beans::PropertyValue& rValue) { return rValue.Name; });
884 return comphelper::containerToSequence(aRet);
885}
886
887void StyleSheetTable::ApplyNumberingStyleNameToParaStyles()
888{
889 try
890 {
891 uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
892 uno::Reference< lang::XMultiServiceFactory > xDocFactory( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
893 uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies();
894 uno::Reference<container::XNameContainer> xParaStyles;
895 xStyleFamilies->getByName(getPropertyName( PROP_PARAGRAPH_STYLES )) >>= xParaStyles;
896
897 if ( !xParaStyles.is() )
898 return;
899
900 for ( auto& pEntry : m_pImpl->m_aStyleSheetEntries )
901 {
902 StyleSheetPropertyMap* pStyleSheetProperties = nullptr;
903 if ( pEntry->nStyleTypeCode == STYLE_TYPE_PARA && (pStyleSheetProperties = dynamic_cast<StyleSheetPropertyMap*>(pEntry->pProperties.get())) )
904 {
905 // ListId 0 means turn off numbering - to cancel inheritance - so make sure that can be set.
906 // Ignore the special "chapter numbering" outline styles as they are handled internally.
907 if ( pStyleSheetProperties->GetListId() > -1 && pStyleSheetProperties->GetOutlineLevel() == -1 )
908 {
909 uno::Reference< style::XStyle > xStyle;
910 xParaStyles->getByName( ConvertStyleName(pEntry->sStyleName) ) >>= xStyle;
911
912 if ( !xStyle.is() )
913 break;
914
915 uno::Reference<beans::XPropertySet> xPropertySet( xStyle, uno::UNO_QUERY_THROW );
916 const OUString sNumberingStyleName = m_pImpl->m_rDMapper.GetListStyleName( pStyleSheetProperties->GetListId() );
917 if ( !sNumberingStyleName.isEmpty() || !pStyleSheetProperties->GetListId() )
918 xPropertySet->setPropertyValue( getPropertyName(PROP_NUMBERING_STYLE_NAME), uno::makeAny(sNumberingStyleName) );
919 }
920 }
921 }
922 }
923 catch( const uno::Exception& )
924 {
925 DBG_UNHANDLED_EXCEPTION("writerfilter", "Failed applying numbering style name to Paragraph styles")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "925" ": ", "writerfilter", "Failed applying numbering style name to Paragraph styles"
);
;
926 }
927}
928
929void StyleSheetTable::ApplyStyleSheets( const FontTablePtr& rFontTable )
930{
931 try
932 {
933 uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
934 uno::Reference< lang::XMultiServiceFactory > xDocFactory( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
935 uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies();
936 uno::Reference<container::XNameContainer> xCharStyles;
937 uno::Reference<container::XNameContainer> xParaStyles;
938 uno::Reference<container::XNameContainer> xNumberingStyles;
939
940 xStyleFamilies->getByName(getPropertyName( PROP_CHARACTER_STYLES )) >>= xCharStyles;
941 xStyleFamilies->getByName(getPropertyName( PROP_PARAGRAPH_STYLES )) >>= xParaStyles;
942 xStyleFamilies->getByName("NumberingStyles") >>= xNumberingStyles;
943 if(xCharStyles.is() && xParaStyles.is())
944 {
945 std::vector< ::std::pair<OUString, uno::Reference<style::XStyle>> > aMissingParent;
946 std::vector< ::std::pair<OUString, uno::Reference<style::XStyle>> > aMissingFollow;
947 std::vector<beans::PropertyValue> aTableStylesVec;
948 for( auto& pEntry : m_pImpl->m_aStyleSheetEntries )
949 {
950 if( pEntry->nStyleTypeCode == STYLE_TYPE_UNKNOWN && !pEntry->sStyleName.isEmpty() )
951 pEntry->nStyleTypeCode = STYLE_TYPE_PARA; // unspecified style types are considered paragraph styles
952
953 if( pEntry->nStyleTypeCode == STYLE_TYPE_CHAR || pEntry->nStyleTypeCode == STYLE_TYPE_PARA || pEntry->nStyleTypeCode == STYLE_TYPE_LIST )
954 {
955 bool bParaStyle = pEntry->nStyleTypeCode == STYLE_TYPE_PARA;
956 bool bListStyle = pEntry->nStyleTypeCode == STYLE_TYPE_LIST;
957 bool bInsert = false;
958 uno::Reference< container::XNameContainer > xStyles = bParaStyle ? xParaStyles : (bListStyle ? xNumberingStyles : xCharStyles);
959 uno::Reference< style::XStyle > xStyle;
960 const OUString sConvertedStyleName = ConvertStyleName( pEntry->sStyleName );
961
962 if(xStyles->hasByName( sConvertedStyleName ))
963 {
964 // When pasting, don't update existing styles.
965 if (!m_pImpl->m_bIsNewDoc)
966 {
967 continue;
968 }
969 xStyles->getByName( sConvertedStyleName ) >>= xStyle;
970
971 {
972 StyleSheetTable_Impl::SetPropertiesToDefault(xStyle);
973
974 // resolve import conflicts with built-in styles (only if defaults have been defined)
975 if ( m_pImpl->m_bHasImportedDefaultParaProps
976 && pEntry->sBaseStyleIdentifier.isEmpty() //imported style has no inheritance
977 && !xStyle->getParentStyle().isEmpty() ) //built-in style has a default inheritance
978 {
979 xStyle->setParentStyle( "" );
980 }
981 }
982 }
983 else
984 {
985 bInsert = true;
986 xStyle.set(xDocFactory->createInstance(
987 bParaStyle ?
988 getPropertyName( PROP_SERVICE_PARA_STYLE ) :
989 (bListStyle ? OUString("com.sun.star.style.NumberingStyle") : getPropertyName( PROP_SERVICE_CHAR_STYLE ))),
990 uno::UNO_QUERY_THROW);
991
992 // Numbering styles have to be inserted early, as e.g. the NumberingRules property is only available after insertion.
993 if (bListStyle)
994 {
995 xStyles->insertByName( sConvertedStyleName, uno::makeAny( xStyle ) );
996 xStyle.set(xStyles->getByName(sConvertedStyleName), uno::UNO_QUERY_THROW);
997
998 StyleSheetPropertyMap* pPropertyMap = dynamic_cast<StyleSheetPropertyMap*>(pEntry->pProperties.get());
999 if (pPropertyMap && pPropertyMap->GetListId() == -1)
1000 {
1001 // No properties? Word default is 'none', Writer one is 'arabic', handle this.
1002 uno::Reference<beans::XPropertySet> xPropertySet(xStyle, uno::UNO_QUERY_THROW);
1003 uno::Reference<container::XIndexReplace> xNumberingRules;
1004 xPropertySet->getPropertyValue("NumberingRules") >>= xNumberingRules;
1005 uno::Reference<container::XIndexAccess> xIndexAccess(xNumberingRules, uno::UNO_QUERY_THROW);
1006 for (sal_Int32 i = 0; i < xIndexAccess->getCount(); ++i)
1007 {
1008 uno::Sequence< beans::PropertyValue > aLvlProps(1);
1009 aLvlProps[0].Name = "NumberingType";
1010 aLvlProps[0].Value <<= style::NumberingType::NUMBER_NONE;
1011 xNumberingRules->replaceByIndex(i, uno::makeAny(aLvlProps));
1012 xPropertySet->setPropertyValue("NumberingRules", uno::makeAny(xNumberingRules));
1013 }
1014 }
1015 }
1016 }
1017 if( !pEntry->sBaseStyleIdentifier.isEmpty() )
1018 {
1019 try
1020 {
1021 //TODO: Handle cases where a paragraph <> character style relation is needed
1022 StyleSheetEntryPtr pParent = FindStyleSheetByISTD( pEntry->sBaseStyleIdentifier );
1023 // Writer core doesn't support numbering styles having a parent style, it seems
1024 if (pParent && !bListStyle)
1025 {
1026 const OUString sParentStyleName = ConvertStyleName( pParent->sStyleName );
1027 if ( !sParentStyleName.isEmpty() && !xStyles->hasByName( sParentStyleName ) )
1028 aMissingParent.emplace_back( sParentStyleName, xStyle );
1029 else
1030 xStyle->setParentStyle( sParentStyleName );
1031 }
1032 }
1033 catch( const uno::RuntimeException& )
1034 {
1035 OSL_FAIL( "Styles parent could not be set")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "1035" ": "), "%s", "Styles parent could not be set"); }
} while (false)
;
1036 }
1037 }
1038 else if( bParaStyle )
1039 {
1040 // Paragraph styles that don't inherit from some parent need to apply the DocDefaults
1041 pEntry->pProperties->InsertProps( m_pImpl->m_pDefaultParaProps, /*bOverwrite=*/false );
1042
1043 //now it's time to set the default parameters - for paragraph styles
1044 //Fonts: Western first entry in font table
1045 //CJK: second entry
1046 //CTL: third entry, if it exists
1047
1048 sal_uInt32 nFontCount = rFontTable->size();
1049 if( !m_pImpl->m_rDMapper.IsOOXMLImport() && nFontCount > 2 )
1050 {
1051 uno::Any aTwoHundredFortyTwip = uno::makeAny(12.);
1052
1053 // font size to 240 twip (12 pts) for all if not set
1054 pEntry->pProperties->Insert(PROP_CHAR_HEIGHT, aTwoHundredFortyTwip, false);
1055
1056 // western font not already set -> apply first font
1057 const FontEntry::Pointer_t pWesternFontEntry(rFontTable->getFontEntry( 0 ));
1058 OUString sWesternFontName = pWesternFontEntry->sFontName;
1059 pEntry->pProperties->Insert(PROP_CHAR_FONT_NAME, uno::makeAny( sWesternFontName ), false);
1060
1061 // CJK ... apply second font
1062 const FontEntry::Pointer_t pCJKFontEntry(rFontTable->getFontEntry( 2 ));
1063 pEntry->pProperties->Insert(PROP_CHAR_FONT_NAME_ASIAN, uno::makeAny( pCJKFontEntry->sFontName ), false);
1064 pEntry->pProperties->Insert(PROP_CHAR_HEIGHT_ASIAN, aTwoHundredFortyTwip, false);
1065
1066 // CTL ... apply third font, if available
1067 if( nFontCount > 3 )
1068 {
1069 const FontEntry::Pointer_t pCTLFontEntry(rFontTable->getFontEntry( 3 ));
1070 pEntry->pProperties->Insert(PROP_CHAR_FONT_NAME_COMPLEX, uno::makeAny( pCTLFontEntry->sFontName ), false);
1071 pEntry->pProperties->Insert(PROP_CHAR_HEIGHT_COMPLEX, aTwoHundredFortyTwip, false);
1072 }
1073 }
1074 }
1075
1076 auto aPropValues = comphelper::sequenceToContainer< std::vector<beans::PropertyValue> >(pEntry->pProperties->GetPropertyValues());
1077
1078 if( bParaStyle )
1079 {
1080 // delay adding FollowStyle property: all styles need to be created first
1081 if ( !pEntry->sNextStyleIdentifier.isEmpty() )
1082 {
1083 StyleSheetEntryPtr pFollowStyle = FindStyleSheetByISTD( pEntry->sNextStyleIdentifier );
1084 if ( pFollowStyle && !pFollowStyle->sStyleName.isEmpty() )
1085 aMissingFollow.emplace_back( ConvertStyleName( pFollowStyle->sStyleName ), xStyle );
1086 }
1087
1088 // Set the outline levels
1089 StyleSheetPropertyMap* pStyleSheetProperties = dynamic_cast<StyleSheetPropertyMap*>(pEntry ? pEntry->pProperties.get() : nullptr);
1090
1091 if ( pStyleSheetProperties )
1092 {
1093 beans::PropertyValue aLvlVal( getPropertyName( PROP_OUTLINE_LEVEL ), 0,
1094 uno::makeAny( sal_Int16( pStyleSheetProperties->GetOutlineLevel( ) + 1 ) ),
1095 beans::PropertyState_DIRECT_VALUE );
1096 aPropValues.push_back(aLvlVal);
1097
1098 // tdf#95495 missing list level settings in custom styles in old DOCX: apply settings of the parent style
1099 if (pStyleSheetProperties->GetListLevel() == -1 && pStyleSheetProperties->GetOutlineLevel() == -1)
1100 {
1101 const beans::PropertyValues aPropGrabBag = pEntry->GetInteropGrabBagSeq();
1102 for (const auto& rVal : aPropGrabBag)
1103 {
1104 if (rVal.Name == "customStyle" && rVal.Value == true)
1105 {
1106 OUString sBaseId = pEntry->sBaseStyleIdentifier;
1107 for (const auto& aSheetProps : m_pImpl->m_aStyleSheetEntries)
1108 {
1109 if (aSheetProps->sStyleIdentifierD == sBaseId)
1110 {
1111 StyleSheetPropertyMap& rStyleSheetProps
1112 = dynamic_cast<StyleSheetPropertyMap&>(*aSheetProps->pProperties);
1113 pStyleSheetProperties->SetListLevel(rStyleSheetProps.GetListLevel());
1114 pStyleSheetProperties->SetOutlineLevel(rStyleSheetProps.GetOutlineLevel());
1115 break;
1116 }
1117 }
1118 }
1119 }
1120 }
1121 }
1122
1123 uno::Reference< beans::XPropertyState >xState( xStyle, uno::UNO_QUERY_THROW );
1124 if( sConvertedStyleName == "Contents Heading" ||
1125 sConvertedStyleName == "User Index Heading" ||
1126 sConvertedStyleName == "Index Heading" )
1127 {
1128 // remove Left/RightMargin values from TOX heading styles
1129 //left margin is set to NULL by default
1130 xState->setPropertyToDefault(getPropertyName( PROP_PARA_LEFT_MARGIN ));
1131 }
1132 else if ( sConvertedStyleName == "Text body" )
1133 xState->setPropertyToDefault(getPropertyName( PROP_PARA_BOTTOM_MARGIN ));
1134 else if ( sConvertedStyleName == "Heading 1" ||
1135 sConvertedStyleName == "Heading 2" ||
1136 sConvertedStyleName == "Heading 3" ||
1137 sConvertedStyleName == "Heading 4" ||
1138 sConvertedStyleName == "Heading 5" ||
1139 sConvertedStyleName == "Heading 6" ||
1140 sConvertedStyleName == "Heading 7" ||
1141 sConvertedStyleName == "Heading 8" ||
1142 sConvertedStyleName == "Heading 9" )
1143 {
1144 xState->setPropertyToDefault(getPropertyName( PROP_CHAR_WEIGHT ));
1145 xState->setPropertyToDefault(getPropertyName( PROP_CHAR_WEIGHT_ASIAN ));
1146 xState->setPropertyToDefault(getPropertyName( PROP_CHAR_WEIGHT_COMPLEX ));
1147 xState->setPropertyToDefault(getPropertyName( PROP_CHAR_POSTURE ));
1148 xState->setPropertyToDefault(getPropertyName( PROP_CHAR_POSTURE_ASIAN ));
1149 xState->setPropertyToDefault(getPropertyName( PROP_CHAR_POSTURE_COMPLEX ));
1150 xState->setPropertyToDefault(getPropertyName( PROP_CHAR_PROP_HEIGHT ));
1151 xState->setPropertyToDefault(getPropertyName( PROP_CHAR_PROP_HEIGHT_ASIAN ));
1152 xState->setPropertyToDefault(getPropertyName( PROP_CHAR_PROP_HEIGHT_COMPLEX));
1153
1154 }
1155 }
1156
1157 if ( !aPropValues.empty() )
1158 {
1159 PropValVector aSortedPropVals;
1160 for (const beans::PropertyValue& rValue : aPropValues)
1161 {
1162 // Don't add the style name properties
1163 bool bIsParaStyleName = rValue.Name == "ParaStyleName";
1164 bool bIsCharStyleName = rValue.Name == "CharStyleName";
1165 if ( !bIsParaStyleName && !bIsCharStyleName )
1166 {
1167 aSortedPropVals.Insert(rValue);
1168 }
1169 }
1170
1171 try
1172 {
1173 uno::Reference< beans::XMultiPropertySet > xMultiPropertySet( xStyle, uno::UNO_QUERY_THROW);
1174 try
1175 {
1176 xMultiPropertySet->setPropertyValues( aSortedPropVals.getNames(), aSortedPropVals.getValues() );
1177 }
1178 catch ( const uno::Exception& )
1179 {
1180 uno::Reference<beans::XPropertySet> xPropertySet(xStyle, uno::UNO_QUERY_THROW);
1181 for ( const beans::PropertyValue& rValue : aSortedPropVals.getProperties() )
1182 {
1183 try
1184 {
1185 xPropertySet->setPropertyValue( rValue.Name, rValue.Value );
1186 }
1187 catch ( const uno::Exception& )
1188 {
1189 SAL_WARN( "writerfilter", "StyleSheetTable::ApplyStyleSheets could not set property " << rValue.Name )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "writerfilter")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "StyleSheetTable::ApplyStyleSheets could not set property "
<< rValue.Name) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "1189" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "StyleSheetTable::ApplyStyleSheets could not set property "
<< rValue.Name), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "StyleSheetTable::ApplyStyleSheets could not set property "
<< rValue.Name; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "1189" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "StyleSheetTable::ApplyStyleSheets could not set property "
<< rValue.Name) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "1189" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "StyleSheetTable::ApplyStyleSheets could not set property "
<< rValue.Name), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "StyleSheetTable::ApplyStyleSheets could not set property "
<< rValue.Name; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "1189" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1190 }
1191 }
1192 }
1193 // Duplicate MSWord's single footnote reference into Footnote Characters and Footnote anchor
1194 if( pEntry->sStyleName.equalsIgnoreAsciiCase("footnote reference")
1195 || pEntry->sStyleName.equalsIgnoreAsciiCase("endnote reference") )
1196 {
1197 uno::Reference< style::XStyle > xCopyStyle;
1198 if( pEntry->sStyleName.equalsIgnoreAsciiCase("footnote reference") )
1199 xStyles->getByName( "Footnote anchor" ) >>= xCopyStyle;
1200 else
1201 xStyles->getByName( "Endnote anchor" ) >>= xCopyStyle;
1202
1203 xMultiPropertySet.set( xCopyStyle, uno::UNO_QUERY_THROW);
1204 xMultiPropertySet->setPropertyValues( aSortedPropVals.getNames(), aSortedPropVals.getValues() );
1205 }
1206 }
1207 catch( const lang::WrappedTargetException& rWrapped)
1208 {
1209#ifdef DBG_UTIL
1210 OUString aMessage("StyleSheetTable::ApplyStyleSheets: Some style properties could not be set");
1211 beans::UnknownPropertyException aUnknownPropertyException;
1212
1213 if (rWrapped.TargetException >>= aUnknownPropertyException)
1214 aMessage += ": " + aUnknownPropertyException.Message;
1215
1216 SAL_WARN("writerfilter", aMessage)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "writerfilter")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break
; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << aMessage) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "1216" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << aMessage), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << aMessage; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "1216" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << aMessage) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "1216" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << aMessage), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << aMessage; ::sal
::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "1216" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1217#else
1218 (void) rWrapped;
1219#endif
1220 }
1221 catch( const uno::Exception& )
1222 {
1223 OSL_FAIL( "Some style properties could not be set")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "1223" ": "), "%s", "Some style properties could not be set"
); } } while (false)
;
1224 }
1225 }
1226 // Numbering style got inserted earlier.
1227 if(bInsert && !bListStyle)
1228 {
1229 const OUString sParentStyle = xStyle->getParentStyle();
1230 if( !sParentStyle.isEmpty() && !xStyles->hasByName( sParentStyle ) )
1231 aMissingParent.emplace_back( sParentStyle, xStyle );
1232
1233 xStyles->insertByName( sConvertedStyleName, uno::makeAny( xStyle) );
1234 }
1235
1236 beans::PropertyValues aGrabBag = pEntry->GetInteropGrabBagSeq();
1237 uno::Reference<beans::XPropertySet> xPropertySet(xStyle, uno::UNO_QUERY);
1238 if (aGrabBag.hasElements())
1239 {
1240 xPropertySet->setPropertyValue("StyleInteropGrabBag", uno::makeAny(aGrabBag));
1241 }
1242
1243 // Only paragraph styles support automatic updates.
1244 if (pEntry->bAutoRedefine && bParaStyle)
1245 xPropertySet->setPropertyValue("IsAutoUpdate", uno::makeAny(true));
1246 }
1247 else if(pEntry->nStyleTypeCode == STYLE_TYPE_TABLE)
1248 {
1249 // If this is a table style, save its contents as-is for roundtrip purposes.
1250 TableStyleSheetEntry* pTableEntry = static_cast<TableStyleSheetEntry *>(pEntry.get());
1251 aTableStylesVec.push_back(pTableEntry->GetInteropGrabBag());
1252
1253 // if DocDefaults exist, MS Word includes these in the table style definition.
1254 pEntry->pProperties->InsertProps( m_pImpl->m_pDefaultCharProps, /*bOverwrite=*/false );
1255 pEntry->pProperties->InsertProps( m_pImpl->m_pDefaultParaProps, /*bOverwrite=*/false );
1256 }
1257 }
1258
1259 // Update the styles that were created before their parents or next-styles
1260 for( auto const & iter : aMissingParent )
1261 {
1262 iter.second->setParentStyle( iter.first );
1263 }
1264
1265 for( auto const & iter : aMissingFollow )
1266 {
1267 try
1268 {
1269 uno::Reference<beans::XPropertySet> xPropertySet(iter.second, uno::UNO_QUERY);
1270 xPropertySet->setPropertyValue( "FollowStyle", uno::makeAny(iter.first) );
1271 }
1272 catch( uno::Exception & ) {}
1273 }
1274
1275 if (!aTableStylesVec.empty())
1276 {
1277 // If we had any table styles, add a new document-level InteropGrabBag entry for them.
1278 uno::Reference<beans::XPropertySet> xPropertySet(m_pImpl->m_xTextDocument, uno::UNO_QUERY);
1279 uno::Any aAny = xPropertySet->getPropertyValue("InteropGrabBag");
1280 auto aGrabBag = comphelper::sequenceToContainer< std::vector<beans::PropertyValue> >(aAny.get< uno::Sequence<beans::PropertyValue> >());
1281 beans::PropertyValue aValue;
1282 aValue.Name = "tableStyles";
1283 aValue.Value <<= comphelper::containerToSequence(aTableStylesVec);
1284 aGrabBag.push_back(aValue);
1285 xPropertySet->setPropertyValue("InteropGrabBag", uno::makeAny(comphelper::containerToSequence(aGrabBag)));
1286 }
1287 }
1288 }
1289 catch( const uno::Exception& )
1290 {
1291 DBG_UNHANDLED_EXCEPTION("writerfilter", "Styles could not be imported completely")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "1291" ": ", "writerfilter", "Styles could not be imported completely"
);
;
1292 }
1293}
1294
1295
1296StyleSheetEntryPtr StyleSheetTable::FindStyleSheetByISTD(const OUString& sIndex)
1297{
1298 StyleSheetEntryPtr pRet;
1299 for(const StyleSheetEntryPtr & rpEntry : m_pImpl->m_aStyleSheetEntries)
1300 {
1301 if( rpEntry->sStyleIdentifierD == sIndex)
1302 {
1303 pRet = rpEntry;
1304 break;
1305 }
1306 }
1307 return pRet;
1308}
1309
1310
1311StyleSheetEntryPtr StyleSheetTable::FindStyleSheetByConvertedStyleName(const OUString& sIndex)
1312{
1313 StyleSheetEntryPtr pRet;
1314 for(const StyleSheetEntryPtr & rpEntry : m_pImpl->m_aStyleSheetEntries)
1315 {
1316 if( rpEntry->sConvertedStyleName == sIndex)
1317 {
1318 pRet = rpEntry;
1319 break;
1320 }
1321 }
1322 return pRet;
1323}
1324
1325
1326StyleSheetEntryPtr StyleSheetTable::FindDefaultParaStyle()
1327{
1328 return FindStyleSheetByISTD( m_pImpl->m_sDefaultParaStyleName );
1329}
1330
1331const StyleSheetEntryPtr & StyleSheetTable::GetCurrentEntry() const
1332{
1333 return m_pImpl->m_pCurrentEntry;
1334}
1335
1336OUString StyleSheetTable::ConvertStyleName( const OUString& rWWName, bool bExtendedSearch)
1337{
1338 OUString sRet( rWWName );
1339 if( bExtendedSearch )
1340 {
1341 //search for the rWWName in the IdentifierD of the existing styles and convert the sStyleName member
1342 //TODO: performance issue - put styles list into a map sorted by its sStyleIdentifierD members
1343 for( const auto& rStyleSheetEntryPtr : m_pImpl->m_aStyleSheetEntries )
1344 {
1345 if( rWWName == rStyleSheetEntryPtr->sStyleIdentifierD )
1346 sRet = rStyleSheetEntryPtr->sStyleName;
1347 }
1348 }
1349
1350 // create a map only once
1351 static const std::map< OUString, OUString> StyleNameMap {
1352 { "Normal", "Standard" },
1353 { "heading 1", "Heading 1" },
1354 { "heading 2", "Heading 2" },
1355 { "heading 3", "Heading 3" },
1356 { "heading 4", "Heading 4" },
1357 { "heading 5", "Heading 5" },
1358 { "heading 6", "Heading 6" },
1359 { "heading 7", "Heading 7" },
1360 { "heading 8", "Heading 8" },
1361 { "heading 9", "Heading 9" },
1362 { "Heading 1", "Heading 1" },
1363 { "Heading 2", "Heading 2" },
1364 { "Heading 3", "Heading 3" },
1365 { "Heading 4", "Heading 4" },
1366 { "Heading 5", "Heading 5" },
1367 { "Heading 6", "Heading 6" },
1368 { "Heading 7", "Heading 7" },
1369 { "Heading 8", "Heading 8" },
1370 { "Heading 9", "Heading 9" },
1371 { "Index 1", "Index 1" },
1372 { "Index 2", "Index 2" },
1373 { "Index 3", "Index 3" },
1374// { "Index 4", "" },
1375// { "Index 5", "" },
1376// { "Index 6", "" },
1377// { "Index 7", "" },
1378// { "Index 8", "" },
1379// { "Index 9", "" },
1380 { "TOC 1", "Contents 1" },
1381 { "TOC 2", "Contents 2" },
1382 { "TOC 3", "Contents 3" },
1383 { "TOC 4", "Contents 4" },
1384 { "TOC 5", "Contents 5" },
1385 { "TOC 6", "Contents 6" },
1386 { "TOC 7", "Contents 7" },
1387 { "TOC 8", "Contents 8" },
1388 { "TOC 9", "Contents 9" },
1389 { "TOCHeading", "Contents Heading" },
1390 { "toc 1", "Contents 1" },
1391 { "toc 2", "Contents 2" },
1392 { "toc 3", "Contents 3" },
1393 { "toc 4", "Contents 4" },
1394 { "toc 5", "Contents 5" },
1395 { "toc 6", "Contents 6" },
1396 { "toc 7", "Contents 7" },
1397 { "toc 8", "Contents 8" },
1398 { "toc 9", "Contents 9" },
1399 { "TOC1", "Contents 1" },
1400 { "TOC2", "Contents 2" },
1401 { "TOC3", "Contents 3" },
1402 { "TOC4", "Contents 4" },
1403 { "TOC5", "Contents 5" },
1404 { "TOC6", "Contents 6" },
1405 { "TOC7", "Contents 7" },
1406 { "TOC8", "Contents 8" },
1407 { "TOC9", "Contents 9" },
1408// { "Normal Indent", "" },
1409 { "footnote text", "Footnote" },
1410 { "Footnote Text", "Footnote" },
1411// { "Annotation Text", "" },
1412 { "Header", "Header" },
1413 { "header", "Header" },
1414 { "Footer", "Footer" },
1415 { "footer", "Footer" },
1416 { "Index Heading", "Index Heading" },
1417// { "Caption", "" },
1418// { "Table of Figures", "" },
1419 { "Envelope Address", "Addressee" },
1420 { "Envelope Return", "Sender" },
1421 { "footnote reference", "Footnote Characters" },
1422 { "Footnote Reference", "Footnote Characters" },
1423// { "Annotation Reference", "" },
1424 { "Line Number", "Line numbering" },
1425 { "Page Number", "Page Number" },
1426 { "endnote reference", "Endnote Characters" },
1427 { "Endnote Reference", "Endnote Characters" },
1428 { "endnote text", "Endnote" },
1429 { "Endnote Text", "Endnote" },
1430// { "Table of Authorities", "" },
1431// { "Macro Text", "" },
1432// { "TOA Heading", "" },
1433 { "List", "List" },
1434// { "List 2", "" },
1435// { "List 3", "" },
1436// { "List 4", "" },
1437// { "List 5", "" },
1438// { "List Bullet", "" },
1439// { "List Bullet 2", "" },
1440// { "List Bullet 3", "" },
1441// { "List Bullet 4", "" },
1442// { "List Bullet 5", "" },
1443// { "List Number", "" },
1444// { "List Number 2", "" },
1445// { "List Number 3", "" },
1446// { "List Number 4", "" },
1447// { "List Number 5", "" },
1448 { "Title", "Title" },
1449// { "Closing", "" },
1450 { "Signature", "Signature" },
1451// { "Default Paragraph Font", "" },
1452 { "DefaultParagraphFont", "Default Paragraph Font" },
1453 { "Body Text", "Text body" },
1454 { "BodyText", "Text body" },
1455 { "BodyTextIndentItalic", "Text body indent italic" },
1456 { "Body Text Indent", "Text body indent" },
1457 { "BodyTextIndent", "Text body indent" },
1458 { "BodyTextIndent2", "Text body indent2" },
1459// { "List Continue", "" },
1460// { "List Continue 2", "" },
1461// { "List Continue 3", "" },
1462// { "List Continue 4", "" },
1463// { "List Continue 5", "" },
1464// { "Message Header", "" },
1465 { "Subtitle", "Subtitle" },
1466// { "Salutation", "" },
1467// { "Date", "" },
1468 { "Body Text First Indent", "Body Text Indent" },
1469// { "Body Text First Indent 2", "" },
1470// { "Note Heading", "" },
1471// { "Body Text 2", "" },
1472// { "Body Text 3", "" },
1473// { "Body Text Indent 2", "" },
1474// { "Body Text Indent 3", "" },
1475// { "Block Text", "" },
1476 { "Hyperlink", "Internet link" },
1477 { "FollowedHyperlink", "Visited Internet Link" },
1478 { "Emphasis", "Emphasis" },
1479// { "Document Map", "" },
1480// { "Plain Text", "" },
1481 { "NoList", "No List" },
1482 { "AbstractHeading", "Abstract Heading" },
1483 { "AbstractBody", "Abstract Body" },
1484 { "PageNumber", "page number" },
1485 { "TableNormal", "Normal Table" },
1486 { "DocumentMap", "Document Map" },
1487 };
1488
1489 // find style-name using map
1490 if (const auto aIt = StyleNameMap.find(sRet); aIt != StyleNameMap.end())
1491 {
1492 sRet = aIt->second;
1493 }
1494 else
1495 {
1496 // Style names which should not be used without a " (user)" suffix
1497 static const o3tl::sorted_vector<OUString> ReservedStyleNames = [] {
1498 o3tl::sorted_vector<OUString> set;
1499 for (const auto& pair : StyleNameMap)
1500 set.insert(pair.second);
1501 return set;
1502 }();
1503 // SwStyleNameMapper doc says: If the UI style name equals a
1504 // programmatic name, then it must append " (user)" to the end.
1505 if (ReservedStyleNames.find(sRet) != ReservedStyleNames.end())
1506 sRet += " (user)";
1507 }
1508
1509 return sRet;
1510}
1511
1512void StyleSheetTable::applyDefaults(bool bParaProperties)
1513{
1514 try{
1515
1516 if (!m_pImpl->m_bIsNewDoc)
1517 {
1518 // tdf#72942: do not corrupts original styles in master document
1519 // during inserting of text from second document
1520 return;
1521 }
1522
1523 if(!m_pImpl->m_xTextDefaults.is())
1524 {
1525 m_pImpl->m_xTextDefaults.set(
1526 m_pImpl->m_rDMapper.GetTextFactory()->createInstance("com.sun.star.text.Defaults"),
1527 uno::UNO_QUERY_THROW );
1528 }
1529
1530 // WARNING: these defaults only take effect IF there is a DocDefaults style section. Normally there is, but not always.
1531 if( bParaProperties && m_pImpl->m_pDefaultParaProps)
1532 {
1533 // tdf#87533 LO will have different defaults here, depending on the locale. Import with documented defaults
1534 SetDefaultParaProps(PROP_WRITING_MODE, uno::makeAny(sal_Int16(text::WritingMode_LR_TB)));
1535 SetDefaultParaProps(PROP_PARA_ADJUST, uno::makeAny(sal_Int16(style::ParagraphAdjust_LEFT)));
1536
1537 // Widow/Orphan -> set both to two if not already set
1538 uno::Any aTwo = uno::makeAny(sal_Int8(2));
1539 SetDefaultParaProps(PROP_PARA_WIDOWS, aTwo);
1540 SetDefaultParaProps(PROP_PARA_ORPHANS, aTwo);
1541
1542 uno::Reference<style::XStyleFamiliesSupplier> xStylesSupplier(m_pImpl->m_xTextDocument, uno::UNO_QUERY);
1543 uno::Reference<container::XNameAccess> xStyleFamilies = xStylesSupplier->getStyleFamilies();
1544 uno::Reference<container::XNameAccess> xParagraphStyles;
1545 xStyleFamilies->getByName("ParagraphStyles") >>= xParagraphStyles;
1546 uno::Reference<beans::XPropertySet> xDefault;
1547 // This is the built-in default style that every style inherits from
1548 xParagraphStyles->getByName("Paragraph style") >>= xDefault;
1549
1550 const uno::Sequence< beans::PropertyValue > aPropValues = m_pImpl->m_pDefaultParaProps->GetPropertyValues();
1551 for( const auto& rPropValue : aPropValues )
1552 {
1553 try
1554 {
1555 xDefault->setPropertyValue(rPropValue.Name, rPropValue.Value);
1556 }
1557 catch( const uno::Exception& )
1558 {
1559 OSL_FAIL( "setPropertyValue exception")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "1559" ": "), "%s", "setPropertyValue exception"); } } while
(false)
;
1560 }
1561 }
1562 }
1563 if( !bParaProperties && m_pImpl->m_pDefaultCharProps )
1564 {
1565 // tdf#108350: Earlier in DomainMapper for DOCX, Calibri/11pt was set to match MSWord 2007+,
1566 // but that is valid only if DocDefaults_rPrDefault is omitted.
1567 // Now that DocDefaults_rPrDefault is known, the defaults should be reset to Times New Roman/10pt.
1568 if ( m_pImpl->m_rDMapper.IsOOXMLImport() )
1569 m_pImpl->m_xTextDefaults->setPropertyValue( getPropertyName(PROP_CHAR_FONT_NAME), css::uno::Any(OUString("Times New Roman")) );
1570
1571 const uno::Sequence< beans::PropertyValue > aPropValues = m_pImpl->m_pDefaultCharProps->GetPropertyValues();
1572 for( const auto& rPropValue : aPropValues )
1573 {
1574 try
1575 {
1576 m_pImpl->m_xTextDefaults->setPropertyValue( rPropValue.Name, rPropValue.Value );
1577 }
1578 catch( const uno::Exception& )
1579 {
1580 OSL_FAIL( "setPropertyValue exception")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "1580" ": "), "%s", "setPropertyValue exception"); } } while
(false)
;
1581 }
1582 }
1583 }
1584 }
1585 catch( const uno::Exception& )
1586 {
1587 }
1588}
1589
1590
1591OUString StyleSheetTable::getOrCreateCharStyle( PropertyValueVector_t& rCharProperties, bool bAlwaysCreate )
1592{
1593 //find out if any of the styles already has the required properties then return its name
1594 OUString sListLabel = m_pImpl->HasListCharStyle(rCharProperties);
1595 // Don't try to reuse an existing character style if requested.
1596 if( !sListLabel.isEmpty() && !bAlwaysCreate)
1597 return sListLabel;
1598 const char cListLabel[] = "ListLabel ";
1599 uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
1600 uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies();
1601 uno::Reference<container::XNameContainer> xCharStyles;
1602 xStyleFamilies->getByName("CharacterStyles") >>= xCharStyles;
1603 //search for all character styles with the name sListLabel + <index>
1604 sal_Int32 nStyleFound = 0;
1605 const uno::Sequence< OUString > aStyleNames = xCharStyles->getElementNames();
1606 for( const auto& rStyleName : aStyleNames )
1607 {
1608 OUString sSuffix;
1609 if( rStyleName.startsWith( cListLabel, &sSuffix ) )
1610 {
1611 sal_Int32 nSuffix = sSuffix.toInt32();
1612 if( nSuffix > 0 && nSuffix > nStyleFound )
1613 nStyleFound = nSuffix;
1614 }
1615 }
1616 sListLabel = cListLabel + OUString::number( ++nStyleFound );
1617 //create a new one otherwise
1618 uno::Reference< lang::XMultiServiceFactory > xDocFactory( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
1619 try
1620 {
1621 uno::Reference< style::XStyle > xStyle( xDocFactory->createInstance(
1622 getPropertyName( PROP_SERVICE_CHAR_STYLE )), uno::UNO_QUERY_THROW);
1623 uno::Reference< beans::XPropertySet > xStyleProps(xStyle, uno::UNO_QUERY_THROW );
1624 for( const auto& rCharProp : rCharProperties)
1625 {
1626 try
1627 {
1628 xStyleProps->setPropertyValue( rCharProp.Name, rCharProp.Value );
1629 }
1630 catch( const uno::Exception& )
1631 {
1632 OSL_FAIL( "Exception in StyleSheetTable::getOrCreateCharStyle - Style::setPropertyValue")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "1632" ": "), "%s", "Exception in StyleSheetTable::getOrCreateCharStyle - Style::setPropertyValue"
); } } while (false)
;
1633 }
1634 }
1635 xCharStyles->insertByName( sListLabel, uno::makeAny( xStyle) );
1636 m_pImpl->m_aListCharStylePropertyVector.emplace_back( sListLabel, rCharProperties );
1637 }
1638 catch( const uno::Exception& )
1639 {
1640 OSL_FAIL( "Exception in StyleSheetTable::getOrCreateCharStyle")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/writerfilter/source/dmapper/StyleSheetTable.cxx"
":" "1640" ": "), "%s", "Exception in StyleSheetTable::getOrCreateCharStyle"
); } } while (false)
;
1641 }
1642
1643 return sListLabel;
1644}
1645
1646}//namespace writerfilter
1647
1648/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/tools/ref.hxx

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#ifndef INCLUDED_TOOLS_REF_HXX
20#define INCLUDED_TOOLS_REF_HXX
21
22#include <sal/config.h>
23#include <cassert>
24#include <tools/toolsdllapi.h>
25#include <utility>
26
27/**
28 This implements similar functionality to boost::intrusive_ptr
29*/
30
31namespace tools {
32
33/** T must be a class that extends SvRefBase */
34template<typename T> class SAL_DLLPUBLIC_RTTI__attribute__ ((type_visibility("default"))) SvRef final {
35public:
36 SvRef(): pObj(nullptr) {}
37
38 SvRef(SvRef&& rObj) noexcept
39 {
40 pObj = rObj.pObj;
41 rObj.pObj = nullptr;
42 }
43
44 SvRef(SvRef const & rObj): pObj(rObj.pObj)
45 {
46 if (pObj != nullptr) pObj->AddNextRef();
47 }
48
49 SvRef(T * pObjP): pObj(pObjP)
50 {
51 if (pObj != nullptr) pObj->AddFirstRef();
52 }
53
54 ~SvRef()
55 {
56 if (pObj != nullptr) pObj->ReleaseRef();
25
Taking true branch
26
Use of memory after it is freed
57 }
58
59 void clear()
60 {
61 if (pObj != nullptr) {
62 T * pRefObj = pObj;
63 pObj = nullptr;
64 pRefObj->ReleaseRef();
65 }
66 }
67
68 SvRef & operator =(SvRef const & rObj)
69 {
70 if (rObj.pObj != nullptr) {
71 rObj.pObj->AddNextRef();
72 }
73 T * pRefObj = pObj;
74 pObj = rObj.pObj;
75 if (pRefObj != nullptr) {
76 pRefObj->ReleaseRef();
77 }
78 return *this;
79 }
80
81 SvRef & operator =(SvRef && rObj)
82 {
83 if (pObj != nullptr) {
15
Taking true branch
84 pObj->ReleaseRef();
16
Calling 'SvRefBase::ReleaseRef'
22
Returning; memory was released
85 }
86 pObj = rObj.pObj;
87 rObj.pObj = nullptr;
88 return *this;
89 }
90
91 bool is() const { return pObj != nullptr; }
92
93 explicit operator bool() const { return is(); }
94
95 T * get() const { return pObj; }
96
97 T * operator ->() const { assert(pObj != nullptr)(static_cast <bool> (pObj != nullptr) ? void (0) : __assert_fail
("pObj != nullptr", "/home/maarten/src/libreoffice/core/include/tools/ref.hxx"
, 97, __extension__ __PRETTY_FUNCTION__))
; return pObj; }
98
99 T & operator *() const { assert(pObj != nullptr)(static_cast <bool> (pObj != nullptr) ? void (0) : __assert_fail
("pObj != nullptr", "/home/maarten/src/libreoffice/core/include/tools/ref.hxx"
, 99, __extension__ __PRETTY_FUNCTION__))
; return *pObj; }
100
101 bool operator ==(const SvRef<T> &rhs) const { return pObj == rhs.pObj; }
102 bool operator !=(const SvRef<T> &rhs) const { return !(*this == rhs); }
103
104private:
105 T * pObj;
106};
107
108/**
109 * This implements similar functionality to std::make_shared.
110 */
111template<typename T, typename... Args>
112SvRef<T> make_ref(Args&& ... args)
113{
114 return SvRef<T>(new T(std::forward<Args>(args)...));
115}
116
117}
118
119/** Classes that want to be referenced-counted via SvRef<T>, should extend this base class */
120class TOOLS_DLLPUBLIC__attribute__ ((visibility("default"))) SvRefBase
121{
122 // work around a clang 3.5 optimization bug: if the bNoDelete is *first*
123 // it mis-compiles "if (--nRefCount == 0)" and never deletes any object
124 unsigned int nRefCount : 31;
125 // the only reason this is not bool is because MSVC cannot handle mixed type bitfields
126 unsigned int bNoDelete : 1;
127
128protected:
129 virtual ~SvRefBase() COVERITY_NOEXCEPT_FALSE;
130
131public:
132 SvRefBase() : nRefCount(0), bNoDelete(1) {}
133 SvRefBase(const SvRefBase &) : nRefCount(0), bNoDelete(1) {}
134
135 SvRefBase & operator=(const SvRefBase &) { return *this; }
136
137 void RestoreNoDelete()
138 { bNoDelete = 1; }
139
140 void AddNextRef()
141 {
142 assert( nRefCount < (1 << 30) && "Do not add refs to dead objects" )(static_cast <bool> (nRefCount < (1 << 30) &&
"Do not add refs to dead objects") ? void (0) : __assert_fail
("nRefCount < (1 << 30) && \"Do not add refs to dead objects\""
, "/home/maarten/src/libreoffice/core/include/tools/ref.hxx",
142, __extension__ __PRETTY_FUNCTION__))
;
143 ++nRefCount;
144 }
145
146 void AddFirstRef()
147 {
148 assert( nRefCount < (1 << 30) && "Do not add refs to dead objects" )(static_cast <bool> (nRefCount < (1 << 30) &&
"Do not add refs to dead objects") ? void (0) : __assert_fail
("nRefCount < (1 << 30) && \"Do not add refs to dead objects\""
, "/home/maarten/src/libreoffice/core/include/tools/ref.hxx",
148, __extension__ __PRETTY_FUNCTION__))
;
149 if( bNoDelete )
150 bNoDelete = 0;
151 ++nRefCount;
152 }
153
154 void ReleaseRef()
155 {
156 assert( nRefCount >= 1)(static_cast <bool> (nRefCount >= 1) ? void (0) : __assert_fail
("nRefCount >= 1", "/home/maarten/src/libreoffice/core/include/tools/ref.hxx"
, 156, __extension__ __PRETTY_FUNCTION__))
;
17
'?' condition is true
157 if( --nRefCount == 0 && !bNoDelete)
18
Assuming the condition is true
19
Assuming field 'bNoDelete' is 0
20
Taking true branch
158 {
159 // I'm not sure about the original purpose of this line, but right now
160 // it serves the purpose that anything that attempts to do an AddRef()
161 // after an object is deleted will trip an assert.
162 nRefCount = 1 << 30;
163 delete this;
21
Memory is released
164 }
165 }
166
167 unsigned int GetRefCount() const
168 { return nRefCount; }
169};
170
171template<typename T>
172class SvCompatWeakBase;
173
174/** SvCompatWeakHdl acts as an intermediary between SvCompatWeakRef<T> and T.
175*/
176template<typename T>
177class SvCompatWeakHdl final : public SvRefBase
178{
179 friend class SvCompatWeakBase<T>;
180 T* _pObj;
181
182 SvCompatWeakHdl( T* pObj ) : _pObj( pObj ) {}
183
184public:
185 void ResetWeakBase( ) { _pObj = nullptr; }
186 T* GetObj() { return _pObj; }
187};
188
189/** We only have one place that extends this, in include/sfx2/frame.hxx, class SfxFrame.
190 Its function is to notify the SvCompatWeakHdl when an SfxFrame object is deleted.
191*/
192template<typename T>
193class SvCompatWeakBase
194{
195 tools::SvRef< SvCompatWeakHdl<T> > _xHdl;
196
197public:
198 /** Does not use initializer due to compiler warnings,
199 because the lifetime of the _xHdl object can exceed the lifetime of this class.
200 */
201 SvCompatWeakBase( T* pObj ) { _xHdl = new SvCompatWeakHdl<T>( pObj ); }
202
203 ~SvCompatWeakBase() { _xHdl->ResetWeakBase(); }
204
205 SvCompatWeakHdl<T>* GetHdl() { return _xHdl.get(); }
206};
207
208/** We only have one weak reference in LO, in include/sfx2/frame.hxx, class SfxFrameWeak.
209*/
210template<typename T>
211class SAL_WARN_UNUSED__attribute__((warn_unused)) SvCompatWeakRef
212{
213 tools::SvRef< SvCompatWeakHdl<T> > _xHdl;
214public:
215 SvCompatWeakRef( ) {}
216 SvCompatWeakRef( T* pObj )
217 { if( pObj ) _xHdl = pObj->GetHdl(); }
218#if defined(__COVERITY__)
219 ~SvCompatWeakRef() COVERITY_NOEXCEPT_FALSE {}
220#endif
221 SvCompatWeakRef& operator = ( T * pObj )
222 { _xHdl = pObj ? pObj->GetHdl() : nullptr; return *this; }
223 bool is() const
224 { return _xHdl.is() && _xHdl->GetObj(); }
225 explicit operator bool() const { return is(); }
226 T* operator -> () const
227 { return _xHdl.is() ? _xHdl->GetObj() : nullptr; }
228 operator T* () const
229 { return _xHdl.is() ? _xHdl->GetObj() : nullptr; }
230};
231
232#endif
233
234/* vim:set shiftwidth=4 softtabstop=4 expandtab: */