summaryrefslogtreecommitdiff
path: root/fpdfsdk/javascript/color.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-10-23 09:40:59 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-10-23 17:56:28 +0000
commitc970895f94cf76eb738d0a583ae139fecdd85268 (patch)
tree85a46f604e7294cf4402aff67d3338fe031611f4 /fpdfsdk/javascript/color.cpp
parent97dab80731a15a6bd74cdc3caf11f97c3a3be5ed (diff)
downloadpdfium-c970895f94cf76eb738d0a583ae139fecdd85268.tar.xz
Cleanup CJS_Valuechromium/3248
This CL removes unused methods; renames Attach to Set and generally cleans up the CJS_Value classes. Change-Id: I858082100908f3bc51f4b58c11ceda3357fadc70 Reviewed-on: https://pdfium-review.googlesource.com/16430 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/javascript/color.cpp')
-rw-r--r--fpdfsdk/javascript/color.cpp84
1 files changed, 31 insertions, 53 deletions
diff --git a/fpdfsdk/javascript/color.cpp b/fpdfsdk/javascript/color.cpp
index f1dc26efec..575a86c4e6 100644
--- a/fpdfsdk/javascript/color.cpp
+++ b/fpdfsdk/javascript/color.cpp
@@ -89,45 +89,29 @@ void color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime,
if (nArrayLen < 1)
return;
- CJS_Value value(pRuntime);
- array.GetElement(pRuntime, 0, value);
- ByteString sSpace = value.ToCFXByteString(pRuntime);
-
- double d1 = 0;
- double d2 = 0;
- double d3 = 0;
- double d4 = 0;
-
- if (nArrayLen > 1) {
- array.GetElement(pRuntime, 1, value);
- d1 = value.ToDouble(pRuntime);
- }
-
- if (nArrayLen > 2) {
- array.GetElement(pRuntime, 2, value);
- d2 = value.ToDouble(pRuntime);
- }
-
- if (nArrayLen > 3) {
- array.GetElement(pRuntime, 3, value);
- d3 = value.ToDouble(pRuntime);
- }
-
- if (nArrayLen > 4) {
- array.GetElement(pRuntime, 4, value);
- d4 = value.ToDouble(pRuntime);
- }
-
- if (sSpace == "T") {
+ float d1 = 0;
+ float d2 = 0;
+ float d3 = 0;
+ float d4 = 0;
+
+ if (nArrayLen > 1)
+ d1 = array.GetElement(pRuntime, 1).ToFloat(pRuntime);
+ if (nArrayLen > 2)
+ d2 = array.GetElement(pRuntime, 2).ToFloat(pRuntime);
+ if (nArrayLen > 3)
+ d3 = array.GetElement(pRuntime, 3).ToFloat(pRuntime);
+ if (nArrayLen > 4)
+ d4 = array.GetElement(pRuntime, 4).ToFloat(pRuntime);
+
+ ByteString sSpace = array.GetElement(pRuntime, 0).ToByteString(pRuntime);
+ if (sSpace == "T")
*color = CFX_Color(CFX_Color::kTransparent);
- } else if (sSpace == "G") {
- *color = CFX_Color(CFX_Color::kGray, (float)d1);
- } else if (sSpace == "RGB") {
- *color = CFX_Color(CFX_Color::kRGB, (float)d1, (float)d2, (float)d3);
- } else if (sSpace == "CMYK") {
- *color =
- CFX_Color(CFX_Color::kCMYK, (float)d1, (float)d2, (float)d3, (float)d4);
- }
+ else if (sSpace == "G")
+ *color = CFX_Color(CFX_Color::kGray, d1);
+ else if (sSpace == "RGB")
+ *color = CFX_Color(CFX_Color::kRGB, d1, d2, d3);
+ else if (sSpace == "CMYK")
+ *color = CFX_Color(CFX_Color::kCMYK, d1, d2, d3, d4);
}
bool color::get_transparent(CJS_Runtime* pRuntime,
@@ -286,11 +270,10 @@ bool color::GetPropertyHelper(CJS_Runtime* pRuntime,
bool color::SetPropertyHelper(CJS_Runtime* pRuntime,
const CJS_PropValue& vp,
CFX_Color* var) {
- CJS_Array array;
- if (!vp.GetJSValue()->ConvertToArray(pRuntime, array))
+ if (!vp.GetJSValue()->IsArrayObject())
return false;
- ConvertArrayToPWLColor(pRuntime, array, var);
+ ConvertArrayToPWLColor(pRuntime, vp.GetJSValue()->ToArray(pRuntime), var);
return true;
}
@@ -302,14 +285,13 @@ bool color::convert(CJS_Runtime* pRuntime,
if (iSize < 2)
return false;
- CJS_Array aSource;
- if (!params[0].ConvertToArray(pRuntime, aSource))
+ if (!params[0].IsArrayObject())
return false;
CFX_Color crSource;
- ConvertArrayToPWLColor(pRuntime, aSource, &crSource);
+ ConvertArrayToPWLColor(pRuntime, params[0].ToArray(pRuntime), &crSource);
- ByteString sDestSpace = params[1].ToCFXByteString(pRuntime);
+ ByteString sDestSpace = params[1].ToByteString(pRuntime);
int nColorType = CFX_Color::kTransparent;
if (sDestSpace == "T") {
@@ -336,18 +318,14 @@ bool color::equal(CJS_Runtime* pRuntime,
WideString& sError) {
if (params.size() < 2)
return false;
-
- CJS_Array array1;
- CJS_Array array2;
- if (!params[0].ConvertToArray(pRuntime, array1))
- return false;
- if (!params[1].ConvertToArray(pRuntime, array2))
+ if (!params[0].IsArrayObject() || !params[1].IsArrayObject())
return false;
CFX_Color color1;
CFX_Color color2;
- ConvertArrayToPWLColor(pRuntime, array1, &color1);
- ConvertArrayToPWLColor(pRuntime, array2, &color2);
+ ConvertArrayToPWLColor(pRuntime, params[0].ToArray(pRuntime), &color1);
+ ConvertArrayToPWLColor(pRuntime, params[1].ToArray(pRuntime), &color2);
+
color1 = color1.ConvertColorType(color2.nColorType);
vRet = CJS_Value(pRuntime, color1 == color2);
return true;