summaryrefslogtreecommitdiff
path: root/fpdfsdk/javascript/color.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-10-24 13:56:29 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-10-24 18:08:51 +0000
commit1b2a18ec4ed99fc2ac56b5fde230bc2b348d9725 (patch)
treea529fbb941a15197b050a0aa88e7a9403ff56152 /fpdfsdk/javascript/color.cpp
parent65f3162c91607071322967ea064a4a11e3904722 (diff)
downloadpdfium-1b2a18ec4ed99fc2ac56b5fde230bc2b348d9725.tar.xz
Remove the CJS_Value To* methods.
This CL removes all of the To* methods on the CJS classes except for ToV8Value. Change-Id: If01263c8cfa557ef7b00f573ddbf68b591d5ae9a Reviewed-on: https://pdfium-review.googlesource.com/16614 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.cpp78
1 files changed, 47 insertions, 31 deletions
diff --git a/fpdfsdk/javascript/color.cpp b/fpdfsdk/javascript/color.cpp
index e730c31588..56baa59019 100644
--- a/fpdfsdk/javascript/color.cpp
+++ b/fpdfsdk/javascript/color.cpp
@@ -82,32 +82,41 @@ CFX_Color color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime,
if (nArrayLen < 1)
return CFX_Color();
- ByteString sSpace = array.GetElement(pRuntime, 0).ToByteString(pRuntime);
- if (sSpace == "T")
+ WideString sSpace =
+ pRuntime->ToWideString(array.GetElement(pRuntime, 0).ToV8Value());
+ if (sSpace == L"T")
return CFX_Color(CFX_Color::kTransparent);
float d1 = 0;
- if (nArrayLen > 1)
- d1 = array.GetElement(pRuntime, 1).ToFloat(pRuntime);
+ if (nArrayLen > 1) {
+ d1 = static_cast<float>(
+ pRuntime->ToDouble(array.GetElement(pRuntime, 1).ToV8Value()));
+ }
- if (sSpace == "G")
+ if (sSpace == L"G")
return CFX_Color(CFX_Color::kGray, d1);
float d2 = 0;
float d3 = 0;
- if (nArrayLen > 2)
- d2 = array.GetElement(pRuntime, 2).ToFloat(pRuntime);
- if (nArrayLen > 3)
- d3 = array.GetElement(pRuntime, 3).ToFloat(pRuntime);
+ if (nArrayLen > 2) {
+ d2 = static_cast<float>(
+ pRuntime->ToDouble(array.GetElement(pRuntime, 2).ToV8Value()));
+ }
+ if (nArrayLen > 3) {
+ d3 = static_cast<float>(
+ pRuntime->ToDouble(array.GetElement(pRuntime, 3).ToV8Value()));
+ }
- if (sSpace == "RGB")
+ if (sSpace == L"RGB")
return CFX_Color(CFX_Color::kRGB, d1, d2, d3);
float d4 = 0;
- if (nArrayLen > 4)
- d4 = array.GetElement(pRuntime, 4).ToFloat(pRuntime);
+ if (nArrayLen > 4) {
+ d4 = static_cast<float>(
+ pRuntime->ToDouble(array.GetElement(pRuntime, 4).ToV8Value()));
+ }
- if (sSpace == "CMYK")
+ if (sSpace == L"CMYK")
return CFX_Color(CFX_Color::kCMYK, d1, d2, d3, d4);
return CFX_Color();
@@ -269,7 +278,11 @@ bool color::set_light_gray(CJS_Runtime* pRuntime,
bool color::GetPropertyHelper(CJS_Runtime* pRuntime,
CJS_Value* vp,
CFX_Color* var) {
- vp->Set(ConvertPWLColorToArray(pRuntime, *var).ToV8Array(pRuntime));
+ CJS_Array array = ConvertPWLColorToArray(pRuntime, *var);
+ if (array.ToV8Value().IsEmpty())
+ vp->Set(pRuntime->NewArray());
+ else
+ vp->Set(array.ToV8Value());
return true;
}
@@ -279,7 +292,8 @@ bool color::SetPropertyHelper(CJS_Runtime* pRuntime,
if (!vp.IsArrayObject())
return false;
- *var = ConvertArrayToPWLColor(pRuntime, vp.ToArray(pRuntime));
+ *var = ConvertArrayToPWLColor(pRuntime,
+ CJS_Array(pRuntime->ToArray(vp.ToV8Value())));
return true;
}
@@ -290,27 +304,29 @@ bool color::convert(CJS_Runtime* pRuntime,
int iSize = params.size();
if (iSize < 2)
return false;
-
if (!params[0].IsArrayObject())
return false;
-
- ByteString sDestSpace = params[1].ToByteString(pRuntime);
+ WideString sDestSpace = pRuntime->ToWideString(params[1].ToV8Value());
int nColorType = CFX_Color::kTransparent;
- if (sDestSpace == "T")
+ if (sDestSpace == L"T")
nColorType = CFX_Color::kTransparent;
- else if (sDestSpace == "G")
+ else if (sDestSpace == L"G")
nColorType = CFX_Color::kGray;
- else if (sDestSpace == "RGB")
+ else if (sDestSpace == L"RGB")
nColorType = CFX_Color::kRGB;
- else if (sDestSpace == "CMYK")
+ else if (sDestSpace == L"CMYK")
nColorType = CFX_Color::kCMYK;
- CFX_Color color =
- ConvertArrayToPWLColor(pRuntime, params[0].ToArray(pRuntime));
- vRet = CJS_Value(
- ConvertPWLColorToArray(pRuntime, color.ConvertColorType(nColorType))
- .ToV8Array(pRuntime));
+ CFX_Color color = ConvertArrayToPWLColor(
+ pRuntime, CJS_Array(pRuntime->ToArray(params[0].ToV8Value())));
+
+ CJS_Array array =
+ ConvertPWLColorToArray(pRuntime, color.ConvertColorType(nColorType));
+ if (array.ToV8Value().IsEmpty())
+ vRet = CJS_Value(pRuntime->NewArray());
+ else
+ vRet = CJS_Value(array.ToV8Value());
return true;
}
@@ -324,10 +340,10 @@ bool color::equal(CJS_Runtime* pRuntime,
if (!params[0].IsArrayObject() || !params[1].IsArrayObject())
return false;
- CFX_Color color1 =
- ConvertArrayToPWLColor(pRuntime, params[0].ToArray(pRuntime));
- CFX_Color color2 =
- ConvertArrayToPWLColor(pRuntime, params[1].ToArray(pRuntime));
+ CFX_Color color1 = ConvertArrayToPWLColor(
+ pRuntime, CJS_Array(pRuntime->ToArray(params[0].ToV8Value())));
+ CFX_Color color2 = ConvertArrayToPWLColor(
+ pRuntime, CJS_Array(pRuntime->ToArray(params[1].ToV8Value())));
color1 = color1.ConvertColorType(color2.nColorType);
vRet = CJS_Value(pRuntime->NewBoolean(color1 == color2));