summaryrefslogtreecommitdiff
path: root/fxjs/xfa/cjx_object.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-12-12 18:54:48 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-12-12 18:54:48 +0000
commitebcbb85ea364605baf8e382ad66793bf1b4db029 (patch)
tree2c546368c63f65d7786a1ab9c818cb07b80d599c /fxjs/xfa/cjx_object.cpp
parent4b004930490e416a2a404deee5de4b97e649a1c1 (diff)
downloadpdfium-ebcbb85ea364605baf8e382ad66793bf1b4db029.tar.xz
Move Script_Som_Border{Width|Color} to CJX_Object
The CJX_Node isn't the root of the CJX hierarchy. This causes issues now that CJX_Object has child objects which don't inherit from CJX_Node. This CL moves Script_Som_Border{Width|Color} from CJX_Node to CJX_Object. Change-Id: I07ba9ef2af675993c9f4d14cb74f48252a907569 Reviewed-on: https://pdfium-review.googlesource.com/20990 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fxjs/xfa/cjx_object.cpp')
-rw-r--r--fxjs/xfa/cjx_object.cpp83
1 files changed, 82 insertions, 1 deletions
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index 4ba1d39394..5b21730df2 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -6,7 +6,7 @@
#include "fxjs/xfa/cjx_object.h"
-#include <utility>
+#include <tuple>
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/xml/cfx_xmltext.h"
@@ -57,6 +57,37 @@ void XFA_DefaultFreeData(void* pData) {}
XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = {XFA_DefaultFreeData,
nullptr};
+std::tuple<int32_t, int32_t, int32_t> StrToRGB(const WideString& strRGB) {
+ int32_t r = 0;
+ int32_t g = 0;
+ int32_t b = 0;
+
+ size_t iIndex = 0;
+ for (size_t i = 0; i < strRGB.GetLength(); ++i) {
+ wchar_t ch = strRGB[i];
+ if (ch == L',')
+ ++iIndex;
+ if (iIndex > 2)
+ break;
+
+ int32_t iValue = ch - L'0';
+ if (iValue >= 0 && iValue <= 9) {
+ switch (iIndex) {
+ case 0:
+ r = r * 10 + iValue;
+ break;
+ case 1:
+ g = g * 10 + iValue;
+ break;
+ default:
+ b = b * 10 + iValue;
+ break;
+ }
+ }
+ }
+ return {r, g, b};
+}
+
} // namespace
struct XFA_MAPDATABLOCK {
@@ -893,3 +924,53 @@ void CJX_Object::Script_Attribute_Integer(CFXJSE_Value* pValue,
}
pValue->SetInteger(GetInteger(eAttribute));
}
+
+void CJX_Object::Script_Som_BorderColor(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ if (!widget_data_)
+ return;
+
+ CXFA_BorderData borderData = widget_data_->GetBorderData(true);
+ int32_t iSize = borderData.CountEdges();
+ if (bSetting) {
+ int32_t r = 0;
+ int32_t g = 0;
+ int32_t b = 0;
+ std::tie(r, g, b) = StrToRGB(pValue->ToWideString());
+ FX_ARGB rgb = ArgbEncode(100, r, g, b);
+ for (int32_t i = 0; i < iSize; ++i)
+ borderData.GetEdgeData(i).SetColor(rgb);
+
+ return;
+ }
+
+ FX_ARGB color = borderData.GetEdgeData(0).GetColor();
+ int32_t a;
+ int32_t r;
+ int32_t g;
+ int32_t b;
+ std::tie(a, r, g, b) = ArgbDecode(color);
+ pValue->SetString(
+ WideString::Format(L"%d,%d,%d", r, g, b).UTF8Encode().AsStringView());
+}
+
+void CJX_Object::Script_Som_BorderWidth(CFXJSE_Value* pValue,
+ bool bSetting,
+ XFA_Attribute eAttribute) {
+ if (!widget_data_)
+ return;
+
+ CXFA_BorderData borderData = widget_data_->GetBorderData(true);
+ if (bSetting) {
+ CXFA_Measurement thickness = borderData.GetEdgeData(0).GetMSThickness();
+ pValue->SetString(thickness.ToString().UTF8Encode().AsStringView());
+ return;
+ }
+
+ WideString wsThickness = pValue->ToWideString();
+ for (int32_t i = 0; i < borderData.CountEdges(); ++i) {
+ borderData.GetEdgeData(i).SetMSThickness(
+ CXFA_Measurement(wsThickness.AsStringView()));
+ }
+}