summaryrefslogtreecommitdiff
path: root/oox/source/ppt
diff options
context:
space:
mode:
authorMark Hung <marklh9@gmail.com>2018-07-12 00:49:47 +0800
committerMark Hung <marklh9@gmail.com>2018-07-13 16:00:05 +0200
commit660c0b54a18be5ec0c87dc55e6ca8196606ea999 (patch)
treefe3df4e9e27c1e95c638aafd2290eb9595e10122 /oox/source/ppt
parent2da75024f88f7c3242fedd9b5bf4832a596402c0 (diff)
Move convertMeasrue and convertAnimationValue from sd to oox.
1. convertAnimationValue convert the attribute value of a animation target from MS ppt to the format that slideshow understand, moving it so that it can be resued in oox. 2. convertMeasure is used by convertAnimationValue, moving it togehter eliminate the duplicated function in oox. Change-Id: I41cd1cf731b6496d7ae96b174a1748326415593f Reviewed-on: https://gerrit.libreoffice.org/57287 Tested-by: Jenkins Reviewed-by: Mark Hung <marklh9@gmail.com>
Diffstat (limited to 'oox/source/ppt')
-rw-r--r--oox/source/ppt/animvariantcontext.cxx102
-rw-r--r--oox/source/ppt/pptfilterhelpers.cxx283
2 files changed, 284 insertions, 101 deletions
diff --git a/oox/source/ppt/animvariantcontext.cxx b/oox/source/ppt/animvariantcontext.cxx
index 972fe0b1e9aa..6cf91351bf30 100644
--- a/oox/source/ppt/animvariantcontext.cxx
+++ b/oox/source/ppt/animvariantcontext.cxx
@@ -31,6 +31,7 @@
#include <drawingml/colorchoicecontext.hxx>
#include <oox/token/namespaces.hxx>
#include <oox/token/tokens.hxx>
+#include <oox/ppt/pptfilterhelpers.hxx>
using namespace ::oox::core;
using namespace ::com::sun::star::uno;
@@ -38,107 +39,6 @@ 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 '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] == '#'))
- {
- sRes.remove(sRes.getLength() - 1, 1);
- }
- sRes.append("height");
- bRet = true;
- break;
- case 'w':
- if(nIndex && (rString[nIndex - 1] == '#'))
- {
- sRes.remove(sRes.getLength() - 1, 1);
- }
- sRes.append("width");
- bRet = true;
- break;
- case 'x':
- if(nIndex && (rString[nIndex - 1] == '#'))
- {
- sRes[sRes.getLength() - 1] = 'x';
- }
- else
- {
- sRes.append('x');
- }
- bRet = true;
- break;
- case 'y':
- if(nIndex && (rString[nIndex - 1] == '#'))
- {
- sRes[sRes.getLength() - 1] = '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;
- }
-
bool convertFillStyle( const OUString& rString, css::drawing::FillStyle& rValue )
{
if( rString == "solid" )
diff --git a/oox/source/ppt/pptfilterhelpers.cxx b/oox/source/ppt/pptfilterhelpers.cxx
index f117e2a1210d..f473d60a73ec 100644
--- a/oox/source/ppt/pptfilterhelpers.cxx
+++ b/oox/source/ppt/pptfilterhelpers.cxx
@@ -19,8 +19,30 @@
#include <com/sun/star/animations/TransitionType.hpp>
#include <com/sun/star/animations/TransitionSubType.hpp>
+#include <com/sun/star/animations/ValuePair.hpp>
+#include <com/sun/star/awt/FontWeight.hpp>
+#include <com/sun/star/awt/FontUnderline.hpp>
+#include <com/sun/star/awt/FontSlant.hpp>
+#include <com/sun/star/drawing/LineStyle.hpp>
+#include <com/sun/star/drawing/FillStyle.hpp>
+#include <com/sun/star/uno/Sequence.hxx>
#include <oox/ppt/pptfilterhelpers.hxx>
#include <rtl/ustrbuf.hxx>
+#include <tools/color.hxx>
+
+namespace {
+ int lcl_gethex(int nChar)
+ {
+ if (nChar >= '0' && nChar <= '9')
+ return nChar - '0';
+ else if (nChar >= 'a' && nChar <= 'f')
+ return nChar - 'a' + 10;
+ else if (nChar >= 'A' && nChar <= 'F')
+ return nChar - 'A' + 10;
+ else
+ return 0;
+ }
+}
namespace oox { namespace ppt {
@@ -120,6 +142,267 @@ namespace oox { namespace ppt {
return nullptr;
}
+ bool convertMeasure(OUString& rString)
+ {
+ bool bRet = false;
+
+ const sal_Char* pSource[] = { "ppt_x", "ppt_y", "ppt_w", "ppt_h", nullptr };
+ const sal_Char* pDest[] = { "x", "y", "width", "height", nullptr };
+
+ /* here we want to substitute all occurrences of
+ * [#]ppt_[xyhw] with
+ * x,y,height and width respectively
+ */
+ sal_Int32 nIndex = 0;
+
+ const sal_Char** ps = pSource;
+ const sal_Char** pd = pDest;
+
+ while (*ps)
+ {
+ const OUString aSearch(OUString::createFromAscii(*ps));
+ while ((nIndex = rString.indexOf(aSearch, nIndex)) != -1)
+ {
+ sal_Int32 nLength = aSearch.getLength();
+ if (nIndex && (rString[nIndex - 1] == '#'))
+ {
+ nIndex--;
+ nLength++;
+ }
+
+ const OUString aNew(OUString::createFromAscii(*pd));
+ rString = rString.replaceAt(nIndex, nLength, aNew);
+ nIndex += aNew.getLength();
+ bRet = true;
+ }
+ ps++;
+ pd++;
+ }
+
+ return bRet;
+ }
+
+ bool convertAnimationValue(MS_AttributeNames eAttribute, css::uno::Any& rValue)
+ {
+ using css::animations::ValuePair;
+ bool bRet = false;
+ switch (eAttribute)
+ {
+ case MS_PPT_X:
+ case MS_PPT_Y:
+ case MS_PPT_W:
+ case MS_PPT_H:
+ {
+ OUString aString;
+
+ if (rValue.getValueType() == cppu::UnoType<ValuePair>::get())
+ {
+ ValuePair aValuePair;
+ if (rValue >>= aValuePair)
+ {
+ if (aValuePair.First >>= aString)
+ {
+ if (convertMeasure(aString))
+ {
+ aValuePair.First <<= aString;
+ bRet = true;
+ }
+ }
+
+ if (aValuePair.Second >>= aString)
+ {
+ if (convertMeasure(aString))
+ {
+ aValuePair.Second <<= aString;
+ bRet = true;
+ }
+ }
+ }
+ }
+ else if (rValue.getValueType() == cppu::UnoType<OUString>::get())
+ {
+ if (rValue >>= aString)
+ {
+ bRet = convertMeasure(aString);
+
+ if (bRet)
+ rValue <<= aString;
+ }
+ }
+ }
+ break;
+
+ case MS_XSHEAR:
+ case MS_R:
+ {
+ OUString aString;
+ if (rValue >>= aString)
+ {
+ rValue <<= aString.toDouble();
+ bRet = true;
+ }
+ }
+ break;
+
+ case MS_STYLEROTATION:
+ {
+ if (rValue.getValueType() == cppu::UnoType<OUString>::get())
+ {
+ OUString aString;
+ rValue >>= aString;
+ rValue <<= static_cast<sal_Int16>(aString.toDouble());
+ bRet = true;
+ }
+ else if (rValue.getValueType() == cppu::UnoType<double>::get())
+ {
+ double fValue = 0.0;
+ rValue >>= fValue;
+ rValue <<= static_cast<sal_Int16>(fValue);
+ bRet = true;
+ }
+ }
+ break;
+
+ case MS_FILLCOLOR:
+ case MS_STROKECOLOR:
+ case MS_STYLECOLOR:
+ case MS_PPT_C:
+ {
+ OUString aString;
+ if (rValue >>= aString)
+ {
+ if (aString.getLength() >= 7 && aString[0] == '#')
+ {
+ Color aColor;
+ aColor.SetRed(static_cast<sal_uInt8>(lcl_gethex(aString[1]) * 16
+ + lcl_gethex(aString[2])));
+ aColor.SetGreen(static_cast<sal_uInt8>(lcl_gethex(aString[3]) * 16
+ + lcl_gethex(aString[4])));
+ aColor.SetBlue(static_cast<sal_uInt8>(lcl_gethex(aString[5]) * 16
+ + lcl_gethex(aString[6])));
+ rValue <<= aColor;
+ bRet = true;
+ }
+ else if (aString.startsWith("rgb("))
+ {
+ aString = aString.copy(4, aString.getLength() - 5);
+ Color aColor;
+ sal_Int32 index = 0;
+ aColor.SetRed(
+ static_cast<sal_uInt8>(aString.getToken(0, ',', index).toInt32()));
+ aColor.SetGreen(
+ static_cast<sal_uInt8>(aString.getToken(0, ',', index).toInt32()));
+ aColor.SetRed(
+ static_cast<sal_uInt8>(aString.getToken(0, ',', index).toInt32()));
+ rValue <<= aColor;
+ bRet = true;
+ }
+ else if (aString.startsWith("hsl("))
+ {
+ sal_Int32 index = 0;
+ sal_Int32 nA = aString.getToken(0, ',', index).toInt32();
+ sal_Int32 nB = aString.getToken(0, ',', index).toInt32();
+ sal_Int32 nC = aString.getToken(0, ',', index).toInt32();
+ css::uno::Sequence<double> aHSL(3);
+ aHSL[0] = nA * 360.0 / 255.0;
+ aHSL[1] = nB / 255.0;
+ aHSL[2] = nC / 255.0;
+ rValue <<= aHSL;
+ bRet = true;
+ }
+ }
+ }
+ break;
+
+ case MS_FILLTYPE:
+ {
+ OUString aString;
+ if (rValue >>= aString)
+ {
+ rValue <<= aString == "solid" ? css::drawing::FillStyle_SOLID
+ : css::drawing::FillStyle_NONE;
+ bRet = true;
+ }
+ }
+ break;
+
+ case MS_STROKEON:
+ {
+ OUString aString;
+ if (rValue >>= aString)
+ {
+ rValue <<= aString == "true" ? css::drawing::LineStyle_SOLID
+ : css::drawing::LineStyle_NONE;
+ bRet = true;
+ }
+ }
+ break;
+
+ case MS_FONTWEIGHT:
+ {
+ OUString aString;
+ if (rValue >>= aString)
+ {
+ rValue <<= aString == "bold" ? css::awt::FontWeight::BOLD
+ : css::awt::FontWeight::NORMAL;
+ bRet = true;
+ }
+ }
+ break;
+
+ case MS_STYLEFONTSTYLE:
+ {
+ OUString aString;
+ if (rValue >>= aString)
+ {
+ rValue
+ <<= aString == "italic" ? css::awt::FontSlant_ITALIC : css::awt::FontSlant_NONE;
+ bRet = true;
+ }
+ }
+ break;
+
+ case MS_STYLEUNDERLINE:
+ {
+ OUString aString;
+ if (rValue >>= aString)
+ {
+ rValue <<= aString == "true" ? css::awt::FontUnderline::SINGLE
+ : css::awt::FontUnderline::NONE;
+ bRet = true;
+ }
+ }
+ break;
+
+ case MS_STYLEOPACITY:
+ case MS_STYLEFONTSIZE:
+ {
+ OUString aString;
+ if (rValue >>= aString)
+ {
+ rValue <<= static_cast<float>(aString.toDouble());
+ bRet = true;
+ }
+ }
+ break;
+
+ case MS_STYLEVISIBILITY:
+ {
+ OUString aString;
+ if (rValue >>= aString)
+ {
+ rValue <<= aString == "visible";
+ bRet = true;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+
+ return bRet;
+ }
+
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */