Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / oox / source / ppt / animvariantcontext.cxx
blob5d7c1a14005992e91d9672077c764c18c53c6dde
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 "animvariantcontext.hxx"
22 #include "comphelper/anytostring.hxx"
23 #include "cppuhelper/exc_hlp.hxx"
25 #include <com/sun/star/uno/Any.hxx>
26 #include <rtl/ustring.hxx>
28 #include "oox/helper/attributelist.hxx"
29 #include "oox/core/fragmenthandler.hxx"
30 #include "oox/core/xmlfilterbase.hxx"
31 #include "drawingml/colorchoicecontext.hxx"
32 #include <oox/token/namespaces.hxx>
33 #include <oox/token/tokens.hxx>
35 using namespace ::oox::core;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::xml::sax;
39 namespace oox { namespace ppt {
41 bool convertMeasure( OUString& rString )
43 bool bRet = false;
45 /* here we want to substitute all occurrences of
46 * [#]ppt_[xyhw] with
47 * x,y,height and width respectively
49 sal_Int32 nIndex = 0;
50 sal_Int32 nLastIndex = 0;
52 nIndex = rString.indexOf("ppt_");
53 // bail out early if there is no substitution to be made
54 if(nIndex >= 0)
56 OUStringBuffer sRes(rString.getLength());
60 // copy the non matching interval verbatim
61 if(nIndex > nLastIndex)
63 sRes.append(rString.getStr() + nLastIndex, (nIndex - nLastIndex));
65 // we are searching for ppt_[xywh] so we need and extra char behind the match
66 if(nIndex + 4 < rString.getLength())
68 switch(rString[nIndex + 4])
70 case 'h': // we found ppt_h
71 // if it was #ppt_h we already copied the #
72 // which we do not want in the target, so remove it
73 if(nIndex && (rString[nIndex - 1] == '#'))
75 sRes.remove(sRes.getLength() - 1, 1);
77 sRes.append("height");
78 bRet = true;
79 break;
80 case 'w':
81 if(nIndex && (rString[nIndex - 1] == '#'))
83 sRes.remove(sRes.getLength() - 1, 1);
85 sRes.append("width");
86 bRet = true;
87 break;
88 case 'x':
89 if(nIndex && (rString[nIndex - 1] == '#'))
91 sRes[sRes.getLength() - 1] = 'x';
93 else
95 sRes.append('x');
97 bRet = true;
98 break;
99 case 'y':
100 if(nIndex && (rString[nIndex - 1] == '#'))
102 sRes[sRes.getLength() - 1] = 'y';
104 else
106 sRes.append('y');
108 bRet = true;
109 break;
110 default:
111 // this was ppt_ without an interesting thing after that
112 // just copy it verbatim
113 sRes.append("ppt_");
114 // we are going to adjust for ppt_@ after the switch
115 // so compensate for the fact we did not really process
116 // an extra character after ppt_
117 nIndex -= 1;
118 break;
121 else
123 sRes.append("ppt_");
124 nIndex += 4;
125 nLastIndex = nIndex;
126 break;
128 nIndex += 5;
129 nLastIndex = nIndex;
131 while((nIndex = rString.indexOf("ppt_", nIndex)) > 0);
132 // copy the non matching tail if any
133 if(nLastIndex < rString.getLength())
135 sRes.append(rString.getStr() + nLastIndex, rString.getLength() - nLastIndex );
137 rString = sRes.makeStringAndClear();
139 return bRet;
142 AnimVariantContext::AnimVariantContext( FragmentHandler2& rParent, sal_Int32 aElement, Any & aValue )
143 : FragmentHandler2( rParent )
144 , mnElement( aElement )
145 , maValue( aValue )
149 AnimVariantContext::~AnimVariantContext( ) throw( )
153 void AnimVariantContext::onEndElement()
155 if( isCurrentElement( mnElement ) && maColor.isUsed() )
157 maValue <<= maColor.getColor( getFilter().getGraphicHelper() );
161 ContextHandlerRef AnimVariantContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
163 switch( aElementToken )
165 case PPT_TOKEN( boolVal ):
167 bool val = rAttribs.getBool( XML_val, false );
168 maValue <<= val;
169 return this;
171 case PPT_TOKEN( clrVal ):
172 return new ::oox::drawingml::ColorContext( *this, maColor );
173 // we'll defer setting the Any until the end.
174 case PPT_TOKEN( fltVal ):
176 double val = rAttribs.getDouble( XML_val, 0.0 );
177 maValue <<= val;
178 return this;
180 case PPT_TOKEN( intVal ):
182 sal_Int32 val = rAttribs.getInteger( XML_val, 0 );
183 maValue <<= val;
184 return this;
186 case PPT_TOKEN( strVal ):
188 OUString val = rAttribs.getString( XML_val, OUString() );
189 convertMeasure( val ); // ignore success or failure if it fails, use as is
190 maValue <<= val;
191 return this;
193 default:
194 break;
197 return this;
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */