summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2019-12-09 14:47:09 +0100
committerSzymon Kłos <szymon.klos@collabora.com>2019-12-10 11:07:52 +0100
commit570834b55ff7303ca977f0e6d6a03f2d8cb4ee68 (patch)
tree482ccca8a0020a4a8f00b6c0dca9dd9636f306e1 /svx
parente7a38270abd5c16af2a28055688d9998e958b127 (diff)
jsdialog: apply FillGradient with JSON arg
Change-Id: I0ca53a53ff53e66d2f25ad4eb13305edbc3aaa12 Reviewed-on: https://gerrit.libreoffice.org/84749 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/sdi/svx.sdi2
-rw-r--r--svx/source/xoutdev/xattr.cxx58
2 files changed, 59 insertions, 1 deletions
diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi
index 2600e6f13d2c..9429689d8e81 100644
--- a/svx/sdi/svx.sdi
+++ b/svx/sdi/svx.sdi
@@ -2634,7 +2634,7 @@ XFillColorItem FillPageColor SID_ATTR_PAGE_COLOR
]
XFillGradientItem FillGradient SID_ATTR_FILL_GRADIENT
-
+(SfxStringItem FillGradientJSON SID_FILL_GRADIENT_JSON)
[
AutoUpdate = TRUE,
FastCall = FALSE,
diff --git a/svx/source/xoutdev/xattr.cxx b/svx/source/xoutdev/xattr.cxx
index 4a898d440fa9..83e052231b58 100644
--- a/svx/source/xoutdev/xattr.cxx
+++ b/svx/source/xoutdev/xattr.cxx
@@ -68,6 +68,8 @@
using namespace ::com::sun::star;
+typedef std::map<OUString, OUString> StringMap;
+
static long ScaleMetricValue( long nVal, long nMul, long nDiv )
{
BigInt aVal( nVal );
@@ -1980,6 +1982,62 @@ std::string XGradient::GradientStyleToString(css::awt::GradientStyle eStyle)
return "";
}
+namespace
+{
+ css::awt::GradientStyle lcl_getStyleFromString(const OUString& rStyle)
+ {
+ if (rStyle == "LINEAR")
+ return css::awt::GradientStyle_LINEAR;
+ else if (rStyle == "AXIAL")
+ return css::awt::GradientStyle_AXIAL;
+ else if (rStyle == "RADIAL")
+ return css::awt::GradientStyle_RADIAL;
+ else if (rStyle == "ELLIPTICAL")
+ return css::awt::GradientStyle_ELLIPTICAL;
+ else if (rStyle == "SQUARE")
+ return css::awt::GradientStyle_SQUARE;
+ else if (rStyle == "RECT")
+ return css::awt::GradientStyle_RECT;
+
+ return css::awt::GradientStyle_LINEAR;
+ }
+
+ StringMap lcl_jsonToStringMap(const OUString& rJSON)
+ {
+ StringMap aArgs;
+ if (rJSON.getLength() && rJSON[0] != '\0')
+ {
+ std::stringstream aStream(OUStringToOString(rJSON, RTL_TEXTENCODING_ASCII_US).getStr());
+ boost::property_tree::ptree aTree;
+ boost::property_tree::read_json(aStream, aTree);
+
+ for (const auto& rPair : aTree)
+ {
+ aArgs[OUString::fromUtf8(rPair.first.c_str())] = OUString::fromUtf8(rPair.second.get_value<std::string>(".").c_str());
+ }
+ }
+ return aArgs;
+ }
+
+ XGradient lcl_buildGradientFromStringMap(StringMap& rMap)
+ {
+ XGradient aGradient;
+
+ aGradient.SetStartColor(rMap["startcolor"].toInt32(16));
+ aGradient.SetEndColor(rMap["endcolor"].toInt32(16));
+ aGradient.SetGradientStyle(lcl_getStyleFromString(rMap["style"]));
+ aGradient.SetAngle(rMap["angle"].toInt32());
+
+ return aGradient;
+ }
+}
+
+XGradient XGradient::fromJSON(const OUString& rJSON)
+{
+ StringMap aMap(lcl_jsonToStringMap(rJSON));
+ return lcl_buildGradientFromStringMap(aMap);
+}
+
XGradient::XGradient() :
eStyle( css::awt::GradientStyle_LINEAR ),
aStartColor( COL_BLACK ),