From 18470fe5cad25ab73acb45a01e6b77e8fa11c5bc Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 30 Oct 2017 18:03:03 +0000 Subject: Rename color to cjs_color This CL renames color.{cpp|h} to cjs_color.{cpp|h}. Change-Id: I141435da9e4f6ac38bda85126975fca02e12b17c Reviewed-on: https://pdfium-review.googlesource.com/17041 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- fpdfsdk/javascript/cjs_color.cpp | 304 +++++++++++++++++++++++++++++++ fpdfsdk/javascript/cjs_color.h | 115 ++++++++++++ fpdfsdk/javascript/cjs_field.cpp | 2 +- fpdfsdk/javascript/cjs_publicmethods.cpp | 2 +- fpdfsdk/javascript/cjs_runtime.cpp | 2 +- fpdfsdk/javascript/color.cpp | 304 ------------------------------- fpdfsdk/javascript/color.h | 115 ------------ 7 files changed, 422 insertions(+), 422 deletions(-) create mode 100644 fpdfsdk/javascript/cjs_color.cpp create mode 100644 fpdfsdk/javascript/cjs_color.h delete mode 100644 fpdfsdk/javascript/color.cpp delete mode 100644 fpdfsdk/javascript/color.h (limited to 'fpdfsdk') diff --git a/fpdfsdk/javascript/cjs_color.cpp b/fpdfsdk/javascript/cjs_color.cpp new file mode 100644 index 0000000000..0c0d9640d1 --- /dev/null +++ b/fpdfsdk/javascript/cjs_color.cpp @@ -0,0 +1,304 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/javascript/cjs_color.h" + +#include + +#include "fpdfsdk/javascript/JS_Define.h" +#include "fpdfsdk/javascript/cjs_event_context.h" +#include "fpdfsdk/javascript/cjs_eventhandler.h" +#include "fpdfsdk/javascript/cjs_object.h" +#include "fpdfsdk/javascript/cjs_runtime.h" + +const JSPropertySpec CJS_Color::PropertySpecs[] = { + {"black", get_black_static, set_black_static}, + {"blue", get_blue_static, set_blue_static}, + {"cyan", get_cyan_static, set_cyan_static}, + {"dkGray", get_dark_gray_static, set_dark_gray_static}, + {"gray", get_gray_static, set_gray_static}, + {"green", get_green_static, set_green_static}, + {"ltGray", get_light_gray_static, set_light_gray_static}, + {"magenta", get_magenta_static, set_magenta_static}, + {"red", get_red_static, set_red_static}, + {"transparent", get_transparent_static, set_transparent_static}, + {"white", get_white_static, set_white_static}, + {"yellow", get_yellow_static, set_yellow_static}, + {0, 0, 0}}; + +const JSMethodSpec CJS_Color::MethodSpecs[] = {{"convert", convert_static}, + {"equal", equal_static}, + {0, 0}}; + +int CJS_Color::ObjDefnID = -1; + +// static +void CJS_Color::DefineJSObjects(CFXJS_Engine* pEngine) { + ObjDefnID = pEngine->DefineObj("color", FXJSOBJTYPE_STATIC, + JSConstructor, + JSDestructor); + DefineProps(pEngine, ObjDefnID, PropertySpecs); + DefineMethods(pEngine, ObjDefnID, MethodSpecs); +} + +// static +v8::Local color::ConvertPWLColorToArray(CJS_Runtime* pRuntime, + const CFX_Color& color) { + v8::Local array; + switch (color.nColorType) { + case CFX_Color::kTransparent: + array = pRuntime->NewArray(); + pRuntime->PutArrayElement(array, 0, pRuntime->NewString(L"T")); + break; + case CFX_Color::kGray: + array = pRuntime->NewArray(); + pRuntime->PutArrayElement(array, 0, pRuntime->NewString(L"G")); + pRuntime->PutArrayElement(array, 1, pRuntime->NewNumber(color.fColor1)); + break; + case CFX_Color::kRGB: + array = pRuntime->NewArray(); + pRuntime->PutArrayElement(array, 0, pRuntime->NewString(L"RGB")); + pRuntime->PutArrayElement(array, 1, pRuntime->NewNumber(color.fColor1)); + pRuntime->PutArrayElement(array, 2, pRuntime->NewNumber(color.fColor2)); + pRuntime->PutArrayElement(array, 3, pRuntime->NewNumber(color.fColor3)); + break; + case CFX_Color::kCMYK: + array = pRuntime->NewArray(); + pRuntime->PutArrayElement(array, 0, pRuntime->NewString(L"CMYK")); + pRuntime->PutArrayElement(array, 1, pRuntime->NewNumber(color.fColor1)); + pRuntime->PutArrayElement(array, 2, pRuntime->NewNumber(color.fColor2)); + pRuntime->PutArrayElement(array, 3, pRuntime->NewNumber(color.fColor3)); + pRuntime->PutArrayElement(array, 4, pRuntime->NewNumber(color.fColor4)); + break; + } + return array; +} + +// static +CFX_Color color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime, + v8::Local array) { + int nArrayLen = pRuntime->GetArrayLength(array); + if (nArrayLen < 1) + return CFX_Color(); + + WideString sSpace = + pRuntime->ToWideString(pRuntime->GetArrayElement(array, 0)); + if (sSpace == L"T") + return CFX_Color(CFX_Color::kTransparent); + + float d1 = 0; + if (nArrayLen > 1) { + d1 = static_cast( + pRuntime->ToDouble(pRuntime->GetArrayElement(array, 1))); + } + + if (sSpace == L"G") + return CFX_Color(CFX_Color::kGray, d1); + + float d2 = 0; + float d3 = 0; + if (nArrayLen > 2) { + d2 = static_cast( + pRuntime->ToDouble(pRuntime->GetArrayElement(array, 2))); + } + if (nArrayLen > 3) { + d3 = static_cast( + pRuntime->ToDouble(pRuntime->GetArrayElement(array, 3))); + } + + if (sSpace == L"RGB") + return CFX_Color(CFX_Color::kRGB, d1, d2, d3); + + float d4 = 0; + if (nArrayLen > 4) { + d4 = static_cast( + pRuntime->ToDouble(pRuntime->GetArrayElement(array, 4))); + } + if (sSpace == L"CMYK") + return CFX_Color(CFX_Color::kCMYK, d1, d2, d3, d4); + + return CFX_Color(); +} + +color::color(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) { + m_crTransparent = CFX_Color(CFX_Color::kTransparent); + m_crBlack = CFX_Color(CFX_Color::kGray, 0); + m_crWhite = CFX_Color(CFX_Color::kGray, 1); + m_crRed = CFX_Color(CFX_Color::kRGB, 1, 0, 0); + m_crGreen = CFX_Color(CFX_Color::kRGB, 0, 1, 0); + m_crBlue = CFX_Color(CFX_Color::kRGB, 0, 0, 1); + m_crCyan = CFX_Color(CFX_Color::kCMYK, 1, 0, 0, 0); + m_crMagenta = CFX_Color(CFX_Color::kCMYK, 0, 1, 0, 0); + m_crYellow = CFX_Color(CFX_Color::kCMYK, 0, 0, 1, 0); + m_crDKGray = CFX_Color(CFX_Color::kGray, 0.25); + m_crGray = CFX_Color(CFX_Color::kGray, 0.5); + m_crLTGray = CFX_Color(CFX_Color::kGray, 0.75); +} + +color::~color() {} + +CJS_Return color::get_transparent(CJS_Runtime* pRuntime) { + return GetPropertyHelper(pRuntime, &m_crTransparent); +} + +CJS_Return color::set_transparent(CJS_Runtime* pRuntime, + v8::Local vp) { + return SetPropertyHelper(pRuntime, vp, &m_crTransparent); +} + +CJS_Return color::get_black(CJS_Runtime* pRuntime) { + return GetPropertyHelper(pRuntime, &m_crBlack); +} + +CJS_Return color::set_black(CJS_Runtime* pRuntime, v8::Local vp) { + return SetPropertyHelper(pRuntime, vp, &m_crBlack); +} + +CJS_Return color::get_white(CJS_Runtime* pRuntime) { + return GetPropertyHelper(pRuntime, &m_crWhite); +} + +CJS_Return color::set_white(CJS_Runtime* pRuntime, v8::Local vp) { + return SetPropertyHelper(pRuntime, vp, &m_crWhite); +} + +CJS_Return color::get_red(CJS_Runtime* pRuntime) { + return GetPropertyHelper(pRuntime, &m_crRed); +} + +CJS_Return color::set_red(CJS_Runtime* pRuntime, v8::Local vp) { + return SetPropertyHelper(pRuntime, vp, &m_crRed); +} + +CJS_Return color::get_green(CJS_Runtime* pRuntime) { + return GetPropertyHelper(pRuntime, &m_crGreen); +} + +CJS_Return color::set_green(CJS_Runtime* pRuntime, v8::Local vp) { + return SetPropertyHelper(pRuntime, vp, &m_crGreen); +} + +CJS_Return color::get_blue(CJS_Runtime* pRuntime) { + return GetPropertyHelper(pRuntime, &m_crBlue); +} + +CJS_Return color::set_blue(CJS_Runtime* pRuntime, v8::Local vp) { + return SetPropertyHelper(pRuntime, vp, &m_crBlue); +} + +CJS_Return color::get_cyan(CJS_Runtime* pRuntime) { + return GetPropertyHelper(pRuntime, &m_crCyan); +} + +CJS_Return color::set_cyan(CJS_Runtime* pRuntime, v8::Local vp) { + return SetPropertyHelper(pRuntime, vp, &m_crCyan); +} + +CJS_Return color::get_magenta(CJS_Runtime* pRuntime) { + return GetPropertyHelper(pRuntime, &m_crMagenta); +} + +CJS_Return color::set_magenta(CJS_Runtime* pRuntime, v8::Local vp) { + return SetPropertyHelper(pRuntime, vp, &m_crMagenta); +} + +CJS_Return color::get_yellow(CJS_Runtime* pRuntime) { + return GetPropertyHelper(pRuntime, &m_crYellow); +} + +CJS_Return color::set_yellow(CJS_Runtime* pRuntime, v8::Local vp) { + return SetPropertyHelper(pRuntime, vp, &m_crYellow); +} + +CJS_Return color::get_dark_gray(CJS_Runtime* pRuntime) { + return GetPropertyHelper(pRuntime, &m_crDKGray); +} + +CJS_Return color::set_dark_gray(CJS_Runtime* pRuntime, + v8::Local vp) { + return SetPropertyHelper(pRuntime, vp, &m_crDKGray); +} + +CJS_Return color::get_gray(CJS_Runtime* pRuntime) { + return GetPropertyHelper(pRuntime, &m_crGray); +} + +CJS_Return color::set_gray(CJS_Runtime* pRuntime, v8::Local vp) { + return SetPropertyHelper(pRuntime, vp, &m_crGray); +} + +CJS_Return color::get_light_gray(CJS_Runtime* pRuntime) { + return GetPropertyHelper(pRuntime, &m_crLTGray); +} + +CJS_Return color::set_light_gray(CJS_Runtime* pRuntime, + v8::Local vp) { + return SetPropertyHelper(pRuntime, vp, &m_crLTGray); +} + +CJS_Return color::GetPropertyHelper(CJS_Runtime* pRuntime, CFX_Color* var) { + v8::Local array = ConvertPWLColorToArray(pRuntime, *var); + if (array.IsEmpty()) + return CJS_Return(pRuntime->NewArray()); + return CJS_Return(array); +} + +CJS_Return color::SetPropertyHelper(CJS_Runtime* pRuntime, + v8::Local vp, + CFX_Color* var) { + if (vp.IsEmpty() || !vp->IsArray()) + return CJS_Return(false); + + *var = ConvertArrayToPWLColor(pRuntime, pRuntime->ToArray(vp)); + return CJS_Return(true); +} + +CJS_Return color::convert(CJS_Runtime* pRuntime, + const std::vector>& params) { + int iSize = params.size(); + if (iSize < 2) + return CJS_Return(false); + if (params[0].IsEmpty() || !params[0]->IsArray()) + return CJS_Return(false); + + WideString sDestSpace = pRuntime->ToWideString(params[1]); + int nColorType = CFX_Color::kTransparent; + if (sDestSpace == L"T") + nColorType = CFX_Color::kTransparent; + else if (sDestSpace == L"G") + nColorType = CFX_Color::kGray; + else if (sDestSpace == L"RGB") + nColorType = CFX_Color::kRGB; + else if (sDestSpace == L"CMYK") + nColorType = CFX_Color::kCMYK; + + CFX_Color color = + ConvertArrayToPWLColor(pRuntime, pRuntime->ToArray(params[0])); + + v8::Local array = + ConvertPWLColorToArray(pRuntime, color.ConvertColorType(nColorType)); + if (array.IsEmpty()) + return CJS_Return(pRuntime->NewArray()); + return CJS_Return(array); +} + +CJS_Return color::equal(CJS_Runtime* pRuntime, + const std::vector>& params) { + if (params.size() < 2) + return CJS_Return(false); + if (params[0].IsEmpty() || !params[0]->IsArray() || params[1].IsEmpty() || + !params[1]->IsArray()) { + return CJS_Return(false); + } + + CFX_Color color1 = + ConvertArrayToPWLColor(pRuntime, pRuntime->ToArray(params[0])); + CFX_Color color2 = + ConvertArrayToPWLColor(pRuntime, pRuntime->ToArray(params[1])); + + color1 = color1.ConvertColorType(color2.nColorType); + return CJS_Return(pRuntime->NewBoolean(color1 == color2)); +} diff --git a/fpdfsdk/javascript/cjs_color.h b/fpdfsdk/javascript/cjs_color.h new file mode 100644 index 0000000000..1942f3dd38 --- /dev/null +++ b/fpdfsdk/javascript/cjs_color.h @@ -0,0 +1,115 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef FPDFSDK_JAVASCRIPT_CJS_COLOR_H_ +#define FPDFSDK_JAVASCRIPT_CJS_COLOR_H_ + +#include + +#include "fpdfsdk/javascript/JS_Define.h" +#include "fpdfsdk/pwl/cpwl_wnd.h" + +class color : public CJS_EmbedObj { + public: + static v8::Local ConvertPWLColorToArray(CJS_Runtime* pRuntime, + const CFX_Color& color); + static CFX_Color ConvertArrayToPWLColor(CJS_Runtime* pRuntime, + v8::Local array); + + explicit color(CJS_Object* pJSObject); + ~color() override; + + CJS_Return get_black(CJS_Runtime* pRuntime); + CJS_Return set_black(CJS_Runtime* pRuntime, v8::Local vp); + + CJS_Return get_blue(CJS_Runtime* pRuntime); + CJS_Return set_blue(CJS_Runtime* pRuntime, v8::Local vp); + + CJS_Return get_cyan(CJS_Runtime* pRuntime); + CJS_Return set_cyan(CJS_Runtime* pRuntime, v8::Local vp); + + CJS_Return get_dark_gray(CJS_Runtime* pRuntime); + CJS_Return set_dark_gray(CJS_Runtime* pRuntime, v8::Local vp); + + CJS_Return get_gray(CJS_Runtime* pRuntime); + CJS_Return set_gray(CJS_Runtime* pRuntime, v8::Local vp); + + CJS_Return get_green(CJS_Runtime* pRuntime); + CJS_Return set_green(CJS_Runtime* pRuntime, v8::Local vp); + + CJS_Return get_light_gray(CJS_Runtime* pRuntime); + CJS_Return set_light_gray(CJS_Runtime* pRuntime, v8::Local vp); + + CJS_Return get_magenta(CJS_Runtime* pRuntime); + CJS_Return set_magenta(CJS_Runtime* pRuntime, v8::Local vp); + + CJS_Return get_red(CJS_Runtime* pRuntime); + CJS_Return set_red(CJS_Runtime* pRuntime, v8::Local vp); + + CJS_Return get_transparent(CJS_Runtime* pRuntime); + CJS_Return set_transparent(CJS_Runtime* pRuntime, v8::Local vp); + + CJS_Return get_white(CJS_Runtime* pRuntime); + CJS_Return set_white(CJS_Runtime* pRuntime, v8::Local vp); + + CJS_Return get_yellow(CJS_Runtime* pRuntime); + CJS_Return set_yellow(CJS_Runtime* pRuntime, v8::Local vp); + + CJS_Return convert(CJS_Runtime* pRuntime, + const std::vector>& params); + CJS_Return equal(CJS_Runtime* pRuntime, + const std::vector>& params); + + private: + CJS_Return GetPropertyHelper(CJS_Runtime* pRuntime, CFX_Color* val); + CJS_Return SetPropertyHelper(CJS_Runtime* pRuntime, + v8::Local vp, + CFX_Color* val); + + CFX_Color m_crTransparent; + CFX_Color m_crBlack; + CFX_Color m_crWhite; + CFX_Color m_crRed; + CFX_Color m_crGreen; + CFX_Color m_crBlue; + CFX_Color m_crCyan; + CFX_Color m_crMagenta; + CFX_Color m_crYellow; + CFX_Color m_crDKGray; + CFX_Color m_crGray; + CFX_Color m_crLTGray; +}; + +class CJS_Color : public CJS_Object { + public: + static void DefineJSObjects(CFXJS_Engine* pEngine); + + explicit CJS_Color(v8::Local pObject) : CJS_Object(pObject) {} + ~CJS_Color() override {} + + JS_STATIC_PROP(black, black, color); + JS_STATIC_PROP(blue, blue, color); + JS_STATIC_PROP(cyan, cyan, color); + JS_STATIC_PROP(dkGray, dark_gray, color); + JS_STATIC_PROP(gray, gray, color); + JS_STATIC_PROP(green, green, color); + JS_STATIC_PROP(ltGray, light_gray, color); + JS_STATIC_PROP(magenta, magenta, color); + JS_STATIC_PROP(red, red, color); + JS_STATIC_PROP(transparent, transparent, color); + JS_STATIC_PROP(white, white, color); + JS_STATIC_PROP(yellow, yellow, color); + + JS_STATIC_METHOD(convert, color); + JS_STATIC_METHOD(equal, color); + + private: + static int ObjDefnID; + static const JSPropertySpec PropertySpecs[]; + static const JSMethodSpec MethodSpecs[]; +}; + +#endif // FPDFSDK_JAVASCRIPT_CJS_COLOR_H_ diff --git a/fpdfsdk/javascript/cjs_field.cpp b/fpdfsdk/javascript/cjs_field.cpp index 4de5da1747..84c0d6ab10 100644 --- a/fpdfsdk/javascript/cjs_field.cpp +++ b/fpdfsdk/javascript/cjs_field.cpp @@ -15,10 +15,10 @@ #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" #include "fpdfsdk/cpdfsdk_widget.h" +#include "fpdfsdk/javascript/cjs_color.h" #include "fpdfsdk/javascript/cjs_delaydata.h" #include "fpdfsdk/javascript/cjs_document.h" #include "fpdfsdk/javascript/cjs_icon.h" -#include "fpdfsdk/javascript/color.h" namespace { diff --git a/fpdfsdk/javascript/cjs_publicmethods.cpp b/fpdfsdk/javascript/cjs_publicmethods.cpp index c62bf7be67..27bb869f0d 100644 --- a/fpdfsdk/javascript/cjs_publicmethods.cpp +++ b/fpdfsdk/javascript/cjs_publicmethods.cpp @@ -20,12 +20,12 @@ #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/javascript/JS_Define.h" +#include "fpdfsdk/javascript/cjs_color.h" #include "fpdfsdk/javascript/cjs_event_context.h" #include "fpdfsdk/javascript/cjs_eventhandler.h" #include "fpdfsdk/javascript/cjs_field.h" #include "fpdfsdk/javascript/cjs_object.h" #include "fpdfsdk/javascript/cjs_runtime.h" -#include "fpdfsdk/javascript/color.h" #include "fpdfsdk/javascript/resource.h" #include "fpdfsdk/javascript/util.h" diff --git a/fpdfsdk/javascript/cjs_runtime.cpp b/fpdfsdk/javascript/cjs_runtime.cpp index d940f082d3..0eb5233b0e 100644 --- a/fpdfsdk/javascript/cjs_runtime.cpp +++ b/fpdfsdk/javascript/cjs_runtime.cpp @@ -14,6 +14,7 @@ #include "fpdfsdk/javascript/cjs_annot.h" #include "fpdfsdk/javascript/cjs_app.h" #include "fpdfsdk/javascript/cjs_border.h" +#include "fpdfsdk/javascript/cjs_color.h" #include "fpdfsdk/javascript/cjs_display.h" #include "fpdfsdk/javascript/cjs_document.h" #include "fpdfsdk/javascript/cjs_event_context.h" @@ -34,7 +35,6 @@ #include "fpdfsdk/javascript/cjs_style.h" #include "fpdfsdk/javascript/cjs_timerobj.h" #include "fpdfsdk/javascript/cjs_zoomtype.h" -#include "fpdfsdk/javascript/color.h" #include "fpdfsdk/javascript/console.h" #include "fpdfsdk/javascript/event.h" #include "fpdfsdk/javascript/report.h" diff --git a/fpdfsdk/javascript/color.cpp b/fpdfsdk/javascript/color.cpp deleted file mode 100644 index 0f9ed0a4b8..0000000000 --- a/fpdfsdk/javascript/color.cpp +++ /dev/null @@ -1,304 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "fpdfsdk/javascript/color.h" - -#include - -#include "fpdfsdk/javascript/JS_Define.h" -#include "fpdfsdk/javascript/cjs_event_context.h" -#include "fpdfsdk/javascript/cjs_eventhandler.h" -#include "fpdfsdk/javascript/cjs_object.h" -#include "fpdfsdk/javascript/cjs_runtime.h" - -const JSPropertySpec CJS_Color::PropertySpecs[] = { - {"black", get_black_static, set_black_static}, - {"blue", get_blue_static, set_blue_static}, - {"cyan", get_cyan_static, set_cyan_static}, - {"dkGray", get_dark_gray_static, set_dark_gray_static}, - {"gray", get_gray_static, set_gray_static}, - {"green", get_green_static, set_green_static}, - {"ltGray", get_light_gray_static, set_light_gray_static}, - {"magenta", get_magenta_static, set_magenta_static}, - {"red", get_red_static, set_red_static}, - {"transparent", get_transparent_static, set_transparent_static}, - {"white", get_white_static, set_white_static}, - {"yellow", get_yellow_static, set_yellow_static}, - {0, 0, 0}}; - -const JSMethodSpec CJS_Color::MethodSpecs[] = {{"convert", convert_static}, - {"equal", equal_static}, - {0, 0}}; - -int CJS_Color::ObjDefnID = -1; - -// static -void CJS_Color::DefineJSObjects(CFXJS_Engine* pEngine) { - ObjDefnID = pEngine->DefineObj("color", FXJSOBJTYPE_STATIC, - JSConstructor, - JSDestructor); - DefineProps(pEngine, ObjDefnID, PropertySpecs); - DefineMethods(pEngine, ObjDefnID, MethodSpecs); -} - -// static -v8::Local color::ConvertPWLColorToArray(CJS_Runtime* pRuntime, - const CFX_Color& color) { - v8::Local array; - switch (color.nColorType) { - case CFX_Color::kTransparent: - array = pRuntime->NewArray(); - pRuntime->PutArrayElement(array, 0, pRuntime->NewString(L"T")); - break; - case CFX_Color::kGray: - array = pRuntime->NewArray(); - pRuntime->PutArrayElement(array, 0, pRuntime->NewString(L"G")); - pRuntime->PutArrayElement(array, 1, pRuntime->NewNumber(color.fColor1)); - break; - case CFX_Color::kRGB: - array = pRuntime->NewArray(); - pRuntime->PutArrayElement(array, 0, pRuntime->NewString(L"RGB")); - pRuntime->PutArrayElement(array, 1, pRuntime->NewNumber(color.fColor1)); - pRuntime->PutArrayElement(array, 2, pRuntime->NewNumber(color.fColor2)); - pRuntime->PutArrayElement(array, 3, pRuntime->NewNumber(color.fColor3)); - break; - case CFX_Color::kCMYK: - array = pRuntime->NewArray(); - pRuntime->PutArrayElement(array, 0, pRuntime->NewString(L"CMYK")); - pRuntime->PutArrayElement(array, 1, pRuntime->NewNumber(color.fColor1)); - pRuntime->PutArrayElement(array, 2, pRuntime->NewNumber(color.fColor2)); - pRuntime->PutArrayElement(array, 3, pRuntime->NewNumber(color.fColor3)); - pRuntime->PutArrayElement(array, 4, pRuntime->NewNumber(color.fColor4)); - break; - } - return array; -} - -// static -CFX_Color color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime, - v8::Local array) { - int nArrayLen = pRuntime->GetArrayLength(array); - if (nArrayLen < 1) - return CFX_Color(); - - WideString sSpace = - pRuntime->ToWideString(pRuntime->GetArrayElement(array, 0)); - if (sSpace == L"T") - return CFX_Color(CFX_Color::kTransparent); - - float d1 = 0; - if (nArrayLen > 1) { - d1 = static_cast( - pRuntime->ToDouble(pRuntime->GetArrayElement(array, 1))); - } - - if (sSpace == L"G") - return CFX_Color(CFX_Color::kGray, d1); - - float d2 = 0; - float d3 = 0; - if (nArrayLen > 2) { - d2 = static_cast( - pRuntime->ToDouble(pRuntime->GetArrayElement(array, 2))); - } - if (nArrayLen > 3) { - d3 = static_cast( - pRuntime->ToDouble(pRuntime->GetArrayElement(array, 3))); - } - - if (sSpace == L"RGB") - return CFX_Color(CFX_Color::kRGB, d1, d2, d3); - - float d4 = 0; - if (nArrayLen > 4) { - d4 = static_cast( - pRuntime->ToDouble(pRuntime->GetArrayElement(array, 4))); - } - if (sSpace == L"CMYK") - return CFX_Color(CFX_Color::kCMYK, d1, d2, d3, d4); - - return CFX_Color(); -} - -color::color(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) { - m_crTransparent = CFX_Color(CFX_Color::kTransparent); - m_crBlack = CFX_Color(CFX_Color::kGray, 0); - m_crWhite = CFX_Color(CFX_Color::kGray, 1); - m_crRed = CFX_Color(CFX_Color::kRGB, 1, 0, 0); - m_crGreen = CFX_Color(CFX_Color::kRGB, 0, 1, 0); - m_crBlue = CFX_Color(CFX_Color::kRGB, 0, 0, 1); - m_crCyan = CFX_Color(CFX_Color::kCMYK, 1, 0, 0, 0); - m_crMagenta = CFX_Color(CFX_Color::kCMYK, 0, 1, 0, 0); - m_crYellow = CFX_Color(CFX_Color::kCMYK, 0, 0, 1, 0); - m_crDKGray = CFX_Color(CFX_Color::kGray, 0.25); - m_crGray = CFX_Color(CFX_Color::kGray, 0.5); - m_crLTGray = CFX_Color(CFX_Color::kGray, 0.75); -} - -color::~color() {} - -CJS_Return color::get_transparent(CJS_Runtime* pRuntime) { - return GetPropertyHelper(pRuntime, &m_crTransparent); -} - -CJS_Return color::set_transparent(CJS_Runtime* pRuntime, - v8::Local vp) { - return SetPropertyHelper(pRuntime, vp, &m_crTransparent); -} - -CJS_Return color::get_black(CJS_Runtime* pRuntime) { - return GetPropertyHelper(pRuntime, &m_crBlack); -} - -CJS_Return color::set_black(CJS_Runtime* pRuntime, v8::Local vp) { - return SetPropertyHelper(pRuntime, vp, &m_crBlack); -} - -CJS_Return color::get_white(CJS_Runtime* pRuntime) { - return GetPropertyHelper(pRuntime, &m_crWhite); -} - -CJS_Return color::set_white(CJS_Runtime* pRuntime, v8::Local vp) { - return SetPropertyHelper(pRuntime, vp, &m_crWhite); -} - -CJS_Return color::get_red(CJS_Runtime* pRuntime) { - return GetPropertyHelper(pRuntime, &m_crRed); -} - -CJS_Return color::set_red(CJS_Runtime* pRuntime, v8::Local vp) { - return SetPropertyHelper(pRuntime, vp, &m_crRed); -} - -CJS_Return color::get_green(CJS_Runtime* pRuntime) { - return GetPropertyHelper(pRuntime, &m_crGreen); -} - -CJS_Return color::set_green(CJS_Runtime* pRuntime, v8::Local vp) { - return SetPropertyHelper(pRuntime, vp, &m_crGreen); -} - -CJS_Return color::get_blue(CJS_Runtime* pRuntime) { - return GetPropertyHelper(pRuntime, &m_crBlue); -} - -CJS_Return color::set_blue(CJS_Runtime* pRuntime, v8::Local vp) { - return SetPropertyHelper(pRuntime, vp, &m_crBlue); -} - -CJS_Return color::get_cyan(CJS_Runtime* pRuntime) { - return GetPropertyHelper(pRuntime, &m_crCyan); -} - -CJS_Return color::set_cyan(CJS_Runtime* pRuntime, v8::Local vp) { - return SetPropertyHelper(pRuntime, vp, &m_crCyan); -} - -CJS_Return color::get_magenta(CJS_Runtime* pRuntime) { - return GetPropertyHelper(pRuntime, &m_crMagenta); -} - -CJS_Return color::set_magenta(CJS_Runtime* pRuntime, v8::Local vp) { - return SetPropertyHelper(pRuntime, vp, &m_crMagenta); -} - -CJS_Return color::get_yellow(CJS_Runtime* pRuntime) { - return GetPropertyHelper(pRuntime, &m_crYellow); -} - -CJS_Return color::set_yellow(CJS_Runtime* pRuntime, v8::Local vp) { - return SetPropertyHelper(pRuntime, vp, &m_crYellow); -} - -CJS_Return color::get_dark_gray(CJS_Runtime* pRuntime) { - return GetPropertyHelper(pRuntime, &m_crDKGray); -} - -CJS_Return color::set_dark_gray(CJS_Runtime* pRuntime, - v8::Local vp) { - return SetPropertyHelper(pRuntime, vp, &m_crDKGray); -} - -CJS_Return color::get_gray(CJS_Runtime* pRuntime) { - return GetPropertyHelper(pRuntime, &m_crGray); -} - -CJS_Return color::set_gray(CJS_Runtime* pRuntime, v8::Local vp) { - return SetPropertyHelper(pRuntime, vp, &m_crGray); -} - -CJS_Return color::get_light_gray(CJS_Runtime* pRuntime) { - return GetPropertyHelper(pRuntime, &m_crLTGray); -} - -CJS_Return color::set_light_gray(CJS_Runtime* pRuntime, - v8::Local vp) { - return SetPropertyHelper(pRuntime, vp, &m_crLTGray); -} - -CJS_Return color::GetPropertyHelper(CJS_Runtime* pRuntime, CFX_Color* var) { - v8::Local array = ConvertPWLColorToArray(pRuntime, *var); - if (array.IsEmpty()) - return CJS_Return(pRuntime->NewArray()); - return CJS_Return(array); -} - -CJS_Return color::SetPropertyHelper(CJS_Runtime* pRuntime, - v8::Local vp, - CFX_Color* var) { - if (vp.IsEmpty() || !vp->IsArray()) - return CJS_Return(false); - - *var = ConvertArrayToPWLColor(pRuntime, pRuntime->ToArray(vp)); - return CJS_Return(true); -} - -CJS_Return color::convert(CJS_Runtime* pRuntime, - const std::vector>& params) { - int iSize = params.size(); - if (iSize < 2) - return CJS_Return(false); - if (params[0].IsEmpty() || !params[0]->IsArray()) - return CJS_Return(false); - - WideString sDestSpace = pRuntime->ToWideString(params[1]); - int nColorType = CFX_Color::kTransparent; - if (sDestSpace == L"T") - nColorType = CFX_Color::kTransparent; - else if (sDestSpace == L"G") - nColorType = CFX_Color::kGray; - else if (sDestSpace == L"RGB") - nColorType = CFX_Color::kRGB; - else if (sDestSpace == L"CMYK") - nColorType = CFX_Color::kCMYK; - - CFX_Color color = - ConvertArrayToPWLColor(pRuntime, pRuntime->ToArray(params[0])); - - v8::Local array = - ConvertPWLColorToArray(pRuntime, color.ConvertColorType(nColorType)); - if (array.IsEmpty()) - return CJS_Return(pRuntime->NewArray()); - return CJS_Return(array); -} - -CJS_Return color::equal(CJS_Runtime* pRuntime, - const std::vector>& params) { - if (params.size() < 2) - return CJS_Return(false); - if (params[0].IsEmpty() || !params[0]->IsArray() || params[1].IsEmpty() || - !params[1]->IsArray()) { - return CJS_Return(false); - } - - CFX_Color color1 = - ConvertArrayToPWLColor(pRuntime, pRuntime->ToArray(params[0])); - CFX_Color color2 = - ConvertArrayToPWLColor(pRuntime, pRuntime->ToArray(params[1])); - - color1 = color1.ConvertColorType(color2.nColorType); - return CJS_Return(pRuntime->NewBoolean(color1 == color2)); -} diff --git a/fpdfsdk/javascript/color.h b/fpdfsdk/javascript/color.h deleted file mode 100644 index 4a5aa5f025..0000000000 --- a/fpdfsdk/javascript/color.h +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef FPDFSDK_JAVASCRIPT_COLOR_H_ -#define FPDFSDK_JAVASCRIPT_COLOR_H_ - -#include - -#include "fpdfsdk/javascript/JS_Define.h" -#include "fpdfsdk/pwl/cpwl_wnd.h" - -class color : public CJS_EmbedObj { - public: - static v8::Local ConvertPWLColorToArray(CJS_Runtime* pRuntime, - const CFX_Color& color); - static CFX_Color ConvertArrayToPWLColor(CJS_Runtime* pRuntime, - v8::Local array); - - explicit color(CJS_Object* pJSObject); - ~color() override; - - CJS_Return get_black(CJS_Runtime* pRuntime); - CJS_Return set_black(CJS_Runtime* pRuntime, v8::Local vp); - - CJS_Return get_blue(CJS_Runtime* pRuntime); - CJS_Return set_blue(CJS_Runtime* pRuntime, v8::Local vp); - - CJS_Return get_cyan(CJS_Runtime* pRuntime); - CJS_Return set_cyan(CJS_Runtime* pRuntime, v8::Local vp); - - CJS_Return get_dark_gray(CJS_Runtime* pRuntime); - CJS_Return set_dark_gray(CJS_Runtime* pRuntime, v8::Local vp); - - CJS_Return get_gray(CJS_Runtime* pRuntime); - CJS_Return set_gray(CJS_Runtime* pRuntime, v8::Local vp); - - CJS_Return get_green(CJS_Runtime* pRuntime); - CJS_Return set_green(CJS_Runtime* pRuntime, v8::Local vp); - - CJS_Return get_light_gray(CJS_Runtime* pRuntime); - CJS_Return set_light_gray(CJS_Runtime* pRuntime, v8::Local vp); - - CJS_Return get_magenta(CJS_Runtime* pRuntime); - CJS_Return set_magenta(CJS_Runtime* pRuntime, v8::Local vp); - - CJS_Return get_red(CJS_Runtime* pRuntime); - CJS_Return set_red(CJS_Runtime* pRuntime, v8::Local vp); - - CJS_Return get_transparent(CJS_Runtime* pRuntime); - CJS_Return set_transparent(CJS_Runtime* pRuntime, v8::Local vp); - - CJS_Return get_white(CJS_Runtime* pRuntime); - CJS_Return set_white(CJS_Runtime* pRuntime, v8::Local vp); - - CJS_Return get_yellow(CJS_Runtime* pRuntime); - CJS_Return set_yellow(CJS_Runtime* pRuntime, v8::Local vp); - - CJS_Return convert(CJS_Runtime* pRuntime, - const std::vector>& params); - CJS_Return equal(CJS_Runtime* pRuntime, - const std::vector>& params); - - private: - CJS_Return GetPropertyHelper(CJS_Runtime* pRuntime, CFX_Color* val); - CJS_Return SetPropertyHelper(CJS_Runtime* pRuntime, - v8::Local vp, - CFX_Color* val); - - CFX_Color m_crTransparent; - CFX_Color m_crBlack; - CFX_Color m_crWhite; - CFX_Color m_crRed; - CFX_Color m_crGreen; - CFX_Color m_crBlue; - CFX_Color m_crCyan; - CFX_Color m_crMagenta; - CFX_Color m_crYellow; - CFX_Color m_crDKGray; - CFX_Color m_crGray; - CFX_Color m_crLTGray; -}; - -class CJS_Color : public CJS_Object { - public: - static void DefineJSObjects(CFXJS_Engine* pEngine); - - explicit CJS_Color(v8::Local pObject) : CJS_Object(pObject) {} - ~CJS_Color() override {} - - JS_STATIC_PROP(black, black, color); - JS_STATIC_PROP(blue, blue, color); - JS_STATIC_PROP(cyan, cyan, color); - JS_STATIC_PROP(dkGray, dark_gray, color); - JS_STATIC_PROP(gray, gray, color); - JS_STATIC_PROP(green, green, color); - JS_STATIC_PROP(ltGray, light_gray, color); - JS_STATIC_PROP(magenta, magenta, color); - JS_STATIC_PROP(red, red, color); - JS_STATIC_PROP(transparent, transparent, color); - JS_STATIC_PROP(white, white, color); - JS_STATIC_PROP(yellow, yellow, color); - - JS_STATIC_METHOD(convert, color); - JS_STATIC_METHOD(equal, color); - - private: - static int ObjDefnID; - static const JSPropertySpec PropertySpecs[]; - static const JSMethodSpec MethodSpecs[]; -}; - -#endif // FPDFSDK_JAVASCRIPT_COLOR_H_ -- cgit v1.2.3