Avoid potential negative array index access to cached text.
[LibreOffice.git] / xmloff / source / text / XMLTextPropertySetContext.cxx
blob472001287e05828f34662fbcada821bf62549298
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <tools/debug.hxx>
21 #include "XMLTextPropertySetContext.hxx"
22 #include <XMLTextColumnsContext.hxx>
23 #include <xmloff/XMLComplexColorContext.hxx>
24 #include <XMLBackgroundImageContext.hxx>
25 #include "XMLSectionFootnoteConfigImport.hxx"
27 #include <xmloff/xmlimppr.hxx>
28 #include <xmloff/txtprmap.hxx>
29 #include <xmltabi.hxx>
30 #include "txtdropi.hxx"
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star;
35 XMLTextPropertySetContext::XMLTextPropertySetContext(
36 SvXMLImport& rImport, sal_Int32 nElement,
37 const Reference< xml::sax::XFastAttributeList > & xAttrList,
38 sal_uInt32 nFamily,
39 ::std::vector< XMLPropertyState > &rProps,
40 const rtl::Reference < SvXMLImportPropertyMapper > &rMap,
41 OUString& rDCTextStyleName ) :
42 SvXMLPropertySetContext( rImport, nElement, xAttrList, nFamily,
43 rProps, rMap ),
44 rDropCapTextStyleName( rDCTextStyleName )
48 XMLTextPropertySetContext::~XMLTextPropertySetContext()
52 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextPropertySetContext::createFastChildContext(
53 sal_Int32 nElement,
54 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList,
55 ::std::vector< XMLPropertyState > &rProperties,
56 const XMLPropertyState& rProp )
58 switch( mxMapper->getPropertySetMapper()
59 ->GetEntryContextId( rProp.mnIndex ) )
61 case CTF_TABSTOP:
62 return new SvxXMLTabStopImportContext( GetImport(), nElement,
63 rProp,
64 rProperties );
65 break;
66 case CTF_TEXTCOLUMNS:
67 return new XMLTextColumnsContext( GetImport(), nElement,
68 xAttrList, rProp,
69 rProperties );
70 break;
72 case CTF_COMPLEX_COLOR:
73 return new XMLPropertyComplexColorContext(GetImport(), nElement, xAttrList, rProp, rProperties);
74 break;
76 case CTF_DROPCAPFORMAT:
78 DBG_ASSERT( rProp.mnIndex >= 2 &&
79 CTF_DROPCAPWHOLEWORD == mxMapper->getPropertySetMapper()
80 ->GetEntryContextId( rProp.mnIndex-2 ),
81 "invalid property map!");
82 XMLTextDropCapImportContext *pDCContext =
83 new XMLTextDropCapImportContext( GetImport(), nElement,
84 xAttrList,
85 rProp,
86 rProp.mnIndex-2,
87 rProperties );
88 rDropCapTextStyleName = pDCContext->GetStyleName();
89 return pDCContext;
91 break;
93 case CTF_BACKGROUND_URL:
95 DBG_ASSERT( rProp.mnIndex >= 2 &&
96 CTF_BACKGROUND_POS == mxMapper->getPropertySetMapper()
97 ->GetEntryContextId( rProp.mnIndex-2 ) &&
98 CTF_BACKGROUND_FILTER == mxMapper->getPropertySetMapper()
99 ->GetEntryContextId( rProp.mnIndex-1 ),
100 "invalid property map!");
102 // #99657# Transparency might be there as well... but doesn't have
103 // to. Thus, this is checked with an if, rather than with an assertion.
104 sal_Int32 nTranspIndex = -1;
105 if( (rProp.mnIndex >= 3) &&
106 ( CTF_BACKGROUND_TRANSPARENCY ==
107 mxMapper->getPropertySetMapper()->GetEntryContextId(
108 rProp.mnIndex-3 ) ) )
109 nTranspIndex = rProp.mnIndex-3;
111 return
112 new XMLBackgroundImageContext( GetImport(), nElement,
113 xAttrList,
114 rProp,
115 rProp.mnIndex-2,
116 rProp.mnIndex-1,
117 nTranspIndex,
119 rProperties );
121 break;
122 case CTF_SECTION_FOOTNOTE_END:
123 case CTF_SECTION_ENDNOTE_END:
124 return new XMLSectionFootnoteConfigImport(
125 GetImport(), nElement, rProperties,
126 mxMapper->getPropertySetMapper());
127 break;
130 return SvXMLPropertySetContext::createFastChildContext( nElement,
131 xAttrList,
132 rProperties, rProp );
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */