diff options
author | Tor Lillqvist <tml@collabora.com> | 2015-10-29 15:18:19 +0200 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2015-10-29 15:41:21 +0200 |
commit | 93e2e45e497bd55cd0fa0502a618d5326ce382b0 (patch) | |
tree | 0c3ef0b47044227dc6ed05027410d48c67368815 /oox/source/ppt/animvariantcontext.cxx | |
parent | 326b21356784a382a3880835f5f24353730e4e30 (diff) |
Too much copy pasta is not good for you
Change-Id: Ie5a3cddd6fcf9d1a763284c1aea0fca579da4f8d
Diffstat (limited to 'oox/source/ppt/animvariantcontext.cxx')
-rw-r--r-- | oox/source/ppt/animvariantcontext.cxx | 102 |
1 files changed, 101 insertions, 1 deletions
diff --git a/oox/source/ppt/animvariantcontext.cxx b/oox/source/ppt/animvariantcontext.cxx index 92cb578e83a6..7e8d36da6674 100644 --- a/oox/source/ppt/animvariantcontext.cxx +++ b/oox/source/ppt/animvariantcontext.cxx @@ -30,7 +30,6 @@ #include "oox/core/fragmenthandler.hxx" #include "oox/core/xmlfilterbase.hxx" #include "drawingml/colorchoicecontext.hxx" -#include "pptfilterhelpers.hxx" using namespace ::oox::core; using namespace ::com::sun::star::uno; @@ -38,6 +37,107 @@ using namespace ::com::sun::star::xml::sax; namespace oox { namespace ppt { + bool convertMeasure( OUString& rString ) + { + bool bRet = false; + + /* here we want to substitute all occurrences of + * [#]ppt_[xyhw] with + * x,y,height and width respectively + */ + sal_Int32 nIndex = 0; + sal_Int32 nLastIndex = 0; + + nIndex = rString.indexOf("ppt_"); + // bail out early if there is no substitution to be made + if(nIndex >= 0) + { + OUStringBuffer sRes(rString.getLength()); + + do + { + // copy the non matching interval verbatim + if(nIndex > nLastIndex) + { + sRes.append(rString.getStr() + nLastIndex, (nIndex - nLastIndex)); + } + // we are searching for ppt_[xywh] so we need and extra char behind the match + if(nIndex + 4 < rString.getLength()) + { + switch(rString[nIndex + 4]) + { + case (sal_Unicode)'h': // we found ppt_h + // if it was #ppt_h we already copied the # + // which we do not want in the target, so remove it + if(nIndex && (rString[nIndex - 1] == (sal_Unicode)'#')) + { + sRes.remove(sRes.getLength() - 1, 1); + } + sRes.append("height"); + bRet = true; + break; + case (sal_Unicode)'w': + if(nIndex && (rString[nIndex - 1] == (sal_Unicode)'#')) + { + sRes.remove(sRes.getLength() - 1, 1); + } + sRes.append("width"); + bRet = true; + break; + case (sal_Unicode)'x': + if(nIndex && (rString[nIndex - 1] == (sal_Unicode)'#')) + { + sRes[sRes.getLength() - 1] = (sal_Unicode)'x'; + } + else + { + sRes.append('x'); + } + bRet = true; + break; + case (sal_Unicode)'y': + if(nIndex && (rString[nIndex - 1] == (sal_Unicode)'#')) + { + sRes[sRes.getLength() - 1] = (sal_Unicode)'y'; + } + else + { + sRes.append('y'); + } + bRet = true; + break; + default: + // this was ppt_ without an interesting thing after that + // just copy it verbatim + sRes.append("ppt_"); + // we are going to adjust for ppt_@ after the switch + // so compensate for the fact we did not really process + // an extra character after ppt_ + nIndex -= 1; + break; + } + } + else + { + sRes.append("ppt_"); + nIndex += 4; + nLastIndex = nIndex; + break; + } + nIndex += 5; + nLastIndex = nIndex; + } + while((nIndex = rString.indexOf("ppt_", nIndex)) > 0); + // copy the non matching tail if any + if(nLastIndex < rString.getLength()) + { + sRes.append(rString.getStr() + nLastIndex, rString.getLength() - nLastIndex ); + } + rString = sRes.makeStringAndClear(); + } + return bRet; + } + AnimVariantContext::AnimVariantContext( FragmentHandler2& rParent, sal_Int32 aElement, Any & aValue ) : FragmentHandler2( rParent ) , mnElement( aElement ) |