Avoid potential negative array index access to cached text.
[LibreOffice.git] / xmloff / source / text / txtstyle.cxx
blob552e6883383eb42eb1043ec48c51030f9acb2607
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 <sal/config.h>
22 #include <com/sun/star/frame/XModel.hpp>
23 #include <com/sun/star/style/ParagraphStyleCategory.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/beans/XPropertySetInfo.hpp>
26 #include <com/sun/star/beans/XPropertyState.hpp>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/style/XStyle.hpp>
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/xmlnamespace.hxx>
31 #include <xmloff/families.hxx>
32 #include <xmloff/txtparae.hxx>
33 #include <xmloff/xmlnume.hxx>
34 #include <xmloff/xmlexp.hxx>
35 #include <xmloff/ProgressBarHelper.hxx>
36 #include "XMLSectionExport.hxx"
37 #include "XMLLineNumberingExport.hxx"
38 #include "txtexppr.hxx"
39 #include <xmloff/txtprmap.hxx>
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::style;
45 using namespace ::com::sun::star::container;
46 using namespace ::com::sun::star::beans;
47 using namespace ::xmloff::token;
49 void XMLTextParagraphExport::exportStyleAttributes(
50 const css::uno::Reference< css::style::XStyle > & rStyle )
52 Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY );
53 Reference< XPropertySetInfo > xPropSetInfo(
54 xPropSet->getPropertySetInfo());
55 if( xPropSetInfo->hasPropertyByName( gsCategory ) )
57 sal_Int16 nCategory = 0;
58 xPropSet->getPropertyValue( gsCategory ) >>= nCategory;
59 enum XMLTokenEnum eValue = XML_TOKEN_INVALID;
60 if( -1 != nCategory )
62 switch( nCategory )
64 case ParagraphStyleCategory::TEXT:
65 eValue = XML_TEXT;
66 break;
67 case ParagraphStyleCategory::CHAPTER:
68 eValue = XML_CHAPTER;
69 break;
70 case ParagraphStyleCategory::LIST:
71 eValue = XML_LIST;
72 break;
73 case ParagraphStyleCategory::INDEX:
74 eValue = XML_INDEX;
75 break;
76 case ParagraphStyleCategory::EXTRA:
77 eValue = XML_EXTRA;
78 break;
79 case ParagraphStyleCategory::HTML:
80 eValue = XML_HTML;
81 break;
84 if( eValue != XML_TOKEN_INVALID )
85 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_CLASS, eValue);
87 if( xPropSetInfo->hasPropertyByName( gsPageDescName ) )
89 Reference< XPropertyState > xPropState( xPropSet, uno::UNO_QUERY );
90 if( PropertyState_DIRECT_VALUE ==
91 xPropState->getPropertyState( gsPageDescName ) )
93 OUString sName;
94 xPropSet->getPropertyValue( gsPageDescName ) >>= sName;
95 // fix for #i5551# if( sName.getLength() > 0 )
96 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
97 XML_MASTER_PAGE_NAME,
98 GetExport().EncodeStyleName( sName ) );
101 if( m_bProgress )
103 ProgressBarHelper *pProgress = GetExport().GetProgressBarHelper();
104 pProgress->SetValue( pProgress->GetValue()+2 );
108 void XMLTextParagraphExport::exportNumStyles( bool bUsed )
110 SvxXMLNumRuleExport aNumRuleExport( GetExport() );
111 aNumRuleExport.exportStyles(bUsed, !IsBlockMode());
114 void XMLTextParagraphExport::exportTextStyles( bool bUsed, bool bProg )
116 bool bOldProg = m_bProgress;
117 m_bProgress = bProg;
119 Reference < lang::XMultiServiceFactory > xFactory (GetExport().GetModel(), UNO_QUERY);
120 if (xFactory.is())
122 Reference < XPropertySet > xPropSet (xFactory->createInstance ( "com.sun.star.text.Defaults" ), UNO_QUERY);
123 if (xPropSet.is())
125 exportDefaultStyle( xPropSet, GetXMLToken(XML_PARAGRAPH), GetParaPropMapper());
127 exportDefaultStyle(
128 xPropSet,
129 GetXMLToken(XML_TABLE),
130 new XMLTextExportPropertySetMapper(
131 new XMLTextPropertySetMapper(
132 TextPropMap::TABLE_DEFAULTS, true ),
133 GetExport() ) );
135 exportDefaultStyle(
136 xPropSet,
137 GetXMLToken(XML_TABLE_ROW),
138 new XMLTextExportPropertySetMapper(
139 new XMLTextPropertySetMapper(
140 TextPropMap::TABLE_ROW_DEFAULTS, true ),
141 GetExport() ) );
144 exportStyleFamily( "ParagraphStyles", GetXMLToken(XML_PARAGRAPH), GetParaPropMapper(),
145 bUsed, XmlStyleFamily::TEXT_PARAGRAPH);
146 exportStyleFamily( "CharacterStyles", GetXMLToken(XML_TEXT), GetTextPropMapper(),
147 bUsed, XmlStyleFamily::TEXT_TEXT );
148 // get shape export to make sure the frame family is added correctly.
149 GetExport().GetShapeExport();
150 exportStyleFamily( "FrameStyles", XML_STYLE_FAMILY_SD_GRAPHICS_NAME, m_xFramePropMapper,
151 bUsed, XmlStyleFamily::TEXT_FRAME);
152 exportNumStyles( bUsed );
153 if( !IsBlockMode() )
155 exportTextFootnoteConfiguration();
156 XMLSectionExport::ExportBibliographyConfiguration(GetExport());
157 XMLLineNumberingExport aLineNumberingExport(GetExport());
158 aLineNumberingExport.Export();
161 m_bProgress = bOldProg;
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */