include/svx/svxids.hrc | 1 include/svx/xgrad.hxx | 1 sc/source/ui/drawfunc/drawsh.cxx | 11 ++++++ sd/source/ui/view/drviews2.cxx | 11 ++++++ svx/sdi/svx.sdi | 2 - svx/source/xoutdev/xattr.cxx | 58 ++++++++++++++++++++++++++++++++++++ sw/source/uibase/shells/drawdlg.cxx | 11 ++++++ 7 files changed, 94 insertions(+), 1 deletion(-)
New commits: commit 570834b55ff7303ca977f0e6d6a03f2d8cb4ee68 Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Mon Dec 9 14:47:09 2019 +0100 Commit: Szymon Kłos <szymon.k...@collabora.com> CommitDate: Tue Dec 10 11:07:52 2019 +0100 jsdialog: apply FillGradient with JSON arg Change-Id: I0ca53a53ff53e66d2f25ad4eb13305edbc3aaa12 Reviewed-on: https://gerrit.libreoffice.org/84749 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Szymon Kłos <szymon.k...@collabora.com> diff --git a/include/svx/svxids.hrc b/include/svx/svxids.hrc index 526518d2a144..2924a1bec218 100644 --- a/include/svx/svxids.hrc +++ b/include/svx/svxids.hrc @@ -327,6 +327,7 @@ class SfxStringItem; #define SID_FRAME_LINESTYLE TypedWhichId<SvxLineItem>( SID_SVX_START + 201 ) #define SID_FRAME_LINECOLOR TypedWhichId<SvxColorItem>( SID_SVX_START + 202 ) #define SID_ATTR_LINE_WIDTH_ARG ( SID_SVX_START + 203 ) +#define SID_FILL_GRADIENT_JSON ( SID_SVX_START + 204 ) #define SID_SEARCHDLG_SEARCHSTRINGS ( SID_SVX_START + 215 ) #define SID_SEARCHDLG_REPLACESTRINGS ( SID_SVX_START + 216 ) #define SID_ATTR_TABLE ( SID_SVX_START + 217 ) diff --git a/include/svx/xgrad.hxx b/include/svx/xgrad.hxx index ec8941292103..a5f60f831896 100644 --- a/include/svx/xgrad.hxx +++ b/include/svx/xgrad.hxx @@ -76,6 +76,7 @@ public: sal_uInt16 GetSteps() const { return nStepCount; } boost::property_tree::ptree dumpAsJSON() const; + static XGradient fromJSON(const OUString& rJSON); }; #endif diff --git a/sc/source/ui/drawfunc/drawsh.cxx b/sc/source/ui/drawfunc/drawsh.cxx index c8a17511143c..70623818ef29 100644 --- a/sc/source/ui/drawfunc/drawsh.cxx +++ b/sc/source/ui/drawfunc/drawsh.cxx @@ -63,6 +63,7 @@ #include <svx/chrtitem.hxx> #include <svx/xlnclit.hxx> #include <svx/xflclit.hxx> +#include <svx/xflgrit.hxx> SFX_IMPL_INTERFACE(ScDrawShell, SfxShell) @@ -110,6 +111,16 @@ namespace } } } + if (SfxItemState::SET == pArgs->GetItemState(SID_FILL_GRADIENT_JSON, false, &pItem)) + { + const SfxStringItem* pJSON = static_cast<const SfxStringItem*>(pItem); + if (pJSON) + { + XGradient aGradient = XGradient::fromJSON(pJSON->GetValue()); + XFillGradientItem aItem(aGradient); + pArgs->Put(aItem); + } + } } } diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx index 5b10ea013a04..3945bf1bf550 100644 --- a/sd/source/ui/view/drviews2.cxx +++ b/sd/source/ui/view/drviews2.cxx @@ -91,6 +91,7 @@ #include <svx/xlnwtit.hxx> #include <svx/chrtitem.hxx> #include <svx/xlnclit.hxx> +#include <svx/xflgrit.hxx> #include <tools/diagnose_ex.h> @@ -589,6 +590,16 @@ namespace } } } + if (SfxItemState::SET == pArgs->GetItemState(SID_FILL_GRADIENT_JSON, false, &pItem)) + { + const SfxStringItem* pJSON = static_cast<const SfxStringItem*>(pItem); + if (pJSON) + { + XGradient aGradient = XGradient::fromJSON(pJSON->GetValue()); + XFillGradientItem aItem(aGradient); + pArgs->Put(aItem); + } + } } } 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 ), diff --git a/sw/source/uibase/shells/drawdlg.cxx b/sw/source/uibase/shells/drawdlg.cxx index a8100523c9e5..4ef0bfafc67f 100644 --- a/sw/source/uibase/shells/drawdlg.cxx +++ b/sw/source/uibase/shells/drawdlg.cxx @@ -39,6 +39,7 @@ #include <svx/xlnwtit.hxx> #include <svx/xflclit.hxx> #include <svx/xfillit0.hxx> +#include <svx/xflgrit.hxx> #include <comphelper/lok.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> @@ -253,6 +254,16 @@ namespace XLineWidthItem aItem(nValue); pArgs->Put(aItem); } + if (SfxItemState::SET == pArgs->GetItemState(SID_FILL_GRADIENT_JSON, false, &pItem)) + { + const SfxStringItem* pJSON = static_cast<const SfxStringItem*>(pItem); + if (pJSON) + { + XGradient aGradient = XGradient::fromJSON(pJSON->GetValue()); + XFillGradientItem aItem(aGradient); + pArgs->Put(aItem); + } + } } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits