1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
)
45 /* here we want to substitute all occurrences of
47 * x,y,height and width respectively
50 sal_Int32 nLastIndex
= 0;
52 nIndex
= rString
.indexOf("ppt_");
53 // bail out early if there is no substitution to be made
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");
81 if(nIndex
&& (rString
[nIndex
- 1] == '#'))
83 sRes
.remove(sRes
.getLength() - 1, 1);
89 if(nIndex
&& (rString
[nIndex
- 1] == '#'))
91 sRes
[sRes
.getLength() - 1] = 'x';
100 if(nIndex
&& (rString
[nIndex
- 1] == '#'))
102 sRes
[sRes
.getLength() - 1] = 'y';
111 // this was ppt_ without an interesting thing after that
112 // just copy it verbatim
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_
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();
142 AnimVariantContext::AnimVariantContext( FragmentHandler2
& rParent
, sal_Int32 aElement
, Any
& aValue
)
143 : FragmentHandler2( rParent
)
144 , mnElement( aElement
)
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 );
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 );
180 case PPT_TOKEN( intVal
):
182 sal_Int32 val
= rAttribs
.getInteger( XML_val
, 0 );
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
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */