diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2019-12-09 14:47:09 +0100 |
---|---|---|
committer | Szymon Kłos <eszkadev@gmail.com> | 2020-05-13 19:52:47 +0200 |
commit | 4c6ca777b1ea0ef2b36fc0c08b44220397f9361d (patch) | |
tree | c53abae8c7cc346d54acccf517dda0eb21339377 /svx | |
parent | 7f998e0ae09c712e7fd0d66a70a0f19855c27624 (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.sdi | 2 | ||||
-rw-r--r-- | svx/source/xoutdev/xattr.cxx | 58 |
2 files changed, 59 insertions, 1 deletions
diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi index ed413935bb25..0bd2964a6ad8 100644 --- a/svx/sdi/svx.sdi +++ b/svx/sdi/svx.sdi @@ -2649,7 +2649,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 a43a8be1cad7..f1ef70efcc09 100644 --- a/svx/source/xoutdev/xattr.cxx +++ b/svx/source/xoutdev/xattr.cxx @@ -95,6 +95,8 @@ using namespace ::com::sun::star; +typedef std::map<OUString, OUString> StringMap; + static long ScaleMetricValue( long nVal, long nMul, long nDiv ) { BigInt aVal( nVal ); @@ -1974,6 +1976,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 ), |