7#include "fxjs/cjs_color.h"
11#include "core/fxcrt/span.h"
12#include "core/fxge/cfx_color.h"
13#include "fxjs/cjs_event_context.h"
14#include "fxjs/cjs_object.h"
15#include "fxjs/cjs_runtime.h"
17#include "fxjs/js_define.h"
18#include "v8/include/v8-container.h"
21 {
"black", get_black_static, set_black_static},
22 {
"blue", get_blue_static, set_blue_static},
23 {
"cyan", get_cyan_static, set_cyan_static},
24 {
"dkGray", get_dark_gray_static, set_dark_gray_static},
25 {
"gray", get_gray_static, set_gray_static},
26 {
"green", get_green_static, set_green_static},
27 {
"ltGray", get_light_gray_static, set_light_gray_static},
28 {
"magenta", get_magenta_static, set_magenta_static},
29 {
"red", get_red_static, set_red_static},
30 {
"transparent", get_transparent_static, set_transparent_static},
31 {
"white", get_white_static, set_white_static},
32 {
"yellow", get_yellow_static, set_yellow_static}};
34const JSMethodSpec CJS_Color::MethodSpecs[] = {{
"convert", convert_static},
35 {
"equal", equal_static}};
37uint32_t CJS_Color::ObjDefnID = 0;
38const char CJS_Color::kName[] =
"color";
48 JSConstructor<CJS_Color>, JSDestructor);
49 DefineProps(pEngine, ObjDefnID, PropertySpecs);
50 DefineMethods(pEngine, ObjDefnID, MethodSpecs);
54v8::Local<v8::Array> CJS_Color::ConvertPWLColorToArray(CJS_Runtime* pRuntime,
56 v8::Local<v8::Array> array;
58 case CFX_Color::Type::kTransparent:
59 array = pRuntime->NewArray();
60 pRuntime->PutArrayElement(array, 0, pRuntime->NewString(
"T"));
62 case CFX_Color::Type::kGray:
63 array = pRuntime->NewArray();
64 pRuntime->PutArrayElement(array, 0, pRuntime->NewString(
"G"));
65 pRuntime->PutArrayElement(array, 1, pRuntime->NewNumber(color.fColor1));
67 case CFX_Color::Type::kRGB:
68 array = pRuntime->NewArray();
69 pRuntime->PutArrayElement(array, 0, pRuntime->NewString(
"RGB"));
70 pRuntime->PutArrayElement(array, 1, pRuntime->NewNumber(color.fColor1));
71 pRuntime->PutArrayElement(array, 2, pRuntime->NewNumber(color.fColor2));
72 pRuntime->PutArrayElement(array, 3, pRuntime->NewNumber(color.fColor3));
74 case CFX_Color::Type::kCMYK:
75 array = pRuntime->NewArray();
76 pRuntime->PutArrayElement(array, 0, pRuntime->NewString(
"CMYK"));
77 pRuntime->PutArrayElement(array, 1, pRuntime->NewNumber(color.fColor1));
78 pRuntime->PutArrayElement(array, 2, pRuntime->NewNumber(color.fColor2));
79 pRuntime->PutArrayElement(array, 3, pRuntime->NewNumber(color.fColor3));
80 pRuntime->PutArrayElement(array, 4, pRuntime->NewNumber(color.fColor4));
87CFX_Color CJS_Color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime,
88 v8::Local<v8::Array> array) {
89 size_t nArrayLen = pRuntime->GetArrayLength(array);
94 pRuntime->ToWideString(pRuntime->GetArrayElement(array, 0));
100 d1 =
static_cast<
float>(
101 pRuntime->ToDouble(pRuntime->GetArrayElement(array, 1)));
109 d2 =
static_cast<
float>(
110 pRuntime->ToDouble(pRuntime->GetArrayElement(array, 2)));
113 d3 =
static_cast<
float>(
114 pRuntime->ToDouble(pRuntime->GetArrayElement(array, 3)));
121 d4 =
static_cast<
float>(
122 pRuntime->ToDouble(pRuntime->GetArrayElement(array, 4)));
130CJS_Color::
CJS_Color(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
147CJS_Result CJS_Color::get_transparent(CJS_Runtime* pRuntime) {
148 return GetPropertyHelper(pRuntime, &m_crTransparent);
151CJS_Result CJS_Color::set_transparent(CJS_Runtime* pRuntime,
152 v8::Local<v8::Value> vp) {
153 return SetPropertyHelper(pRuntime, vp, &m_crTransparent);
156CJS_Result CJS_Color::get_black(CJS_Runtime* pRuntime) {
157 return GetPropertyHelper(pRuntime, &m_crBlack);
160CJS_Result CJS_Color::set_black(CJS_Runtime* pRuntime,
161 v8::Local<v8::Value> vp) {
162 return SetPropertyHelper(pRuntime, vp, &m_crBlack);
165CJS_Result CJS_Color::get_white(CJS_Runtime* pRuntime) {
166 return GetPropertyHelper(pRuntime, &m_crWhite);
169CJS_Result CJS_Color::set_white(CJS_Runtime* pRuntime,
170 v8::Local<v8::Value> vp) {
171 return SetPropertyHelper(pRuntime, vp, &m_crWhite);
174CJS_Result CJS_Color::get_red(CJS_Runtime* pRuntime) {
175 return GetPropertyHelper(pRuntime, &m_crRed);
178CJS_Result CJS_Color::set_red(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
179 return SetPropertyHelper(pRuntime, vp, &m_crRed);
182CJS_Result CJS_Color::get_green(CJS_Runtime* pRuntime) {
183 return GetPropertyHelper(pRuntime, &m_crGreen);
186CJS_Result CJS_Color::set_green(CJS_Runtime* pRuntime,
187 v8::Local<v8::Value> vp) {
188 return SetPropertyHelper(pRuntime, vp, &m_crGreen);
191CJS_Result CJS_Color::get_blue(CJS_Runtime* pRuntime) {
192 return GetPropertyHelper(pRuntime, &m_crBlue);
195CJS_Result CJS_Color::set_blue(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
196 return SetPropertyHelper(pRuntime, vp, &m_crBlue);
199CJS_Result CJS_Color::get_cyan(CJS_Runtime* pRuntime) {
200 return GetPropertyHelper(pRuntime, &m_crCyan);
203CJS_Result CJS_Color::set_cyan(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
204 return SetPropertyHelper(pRuntime, vp, &m_crCyan);
207CJS_Result CJS_Color::get_magenta(CJS_Runtime* pRuntime) {
208 return GetPropertyHelper(pRuntime, &m_crMagenta);
211CJS_Result CJS_Color::set_magenta(CJS_Runtime* pRuntime,
212 v8::Local<v8::Value> vp) {
213 return SetPropertyHelper(pRuntime, vp, &m_crMagenta);
216CJS_Result CJS_Color::get_yellow(CJS_Runtime* pRuntime) {
217 return GetPropertyHelper(pRuntime, &m_crYellow);
220CJS_Result CJS_Color::set_yellow(CJS_Runtime* pRuntime,
221 v8::Local<v8::Value> vp) {
222 return SetPropertyHelper(pRuntime, vp, &m_crYellow);
225CJS_Result CJS_Color::get_dark_gray(CJS_Runtime* pRuntime) {
226 return GetPropertyHelper(pRuntime, &m_crDKGray);
229CJS_Result CJS_Color::set_dark_gray(CJS_Runtime* pRuntime,
230 v8::Local<v8::Value> vp) {
231 return SetPropertyHelper(pRuntime, vp, &m_crDKGray);
234CJS_Result CJS_Color::get_gray(CJS_Runtime* pRuntime) {
235 return GetPropertyHelper(pRuntime, &m_crGray);
238CJS_Result CJS_Color::set_gray(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
239 return SetPropertyHelper(pRuntime, vp, &m_crGray);
242CJS_Result CJS_Color::get_light_gray(CJS_Runtime* pRuntime) {
243 return GetPropertyHelper(pRuntime, &m_crLTGray);
246CJS_Result CJS_Color::set_light_gray(CJS_Runtime* pRuntime,
247 v8::Local<v8::Value> vp) {
248 return SetPropertyHelper(pRuntime, vp, &m_crLTGray);
252 v8::Local<v8::Value> array = ConvertPWLColorToArray(pRuntime, *var);
256 return CJS_Result::Success(array);
259CJS_Result CJS_Color::SetPropertyHelper(CJS_Runtime* pRuntime,
260 v8::Local<v8::Value> vp,
268 *var = ConvertArrayToPWLColor(pRuntime, pRuntime->ToArray(vp));
272CJS_Result CJS_Color::convert(CJS_Runtime* pRuntime,
273 pdfium::span<v8::Local<v8::Value>> params) {
274 if (params.size() < 2)
277 if (!fxv8::IsArray(params[0]))
280 WideString sDestSpace = pRuntime->ToWideString(params[1]);
292 ConvertArrayToPWLColor(pRuntime, pRuntime->ToArray(params[0]));
293 v8::Local<v8::Value> array =
294 ConvertPWLColorToArray(pRuntime, color.ConvertColorType(nColorType));
298 return CJS_Result::Success(array);
301CJS_Result CJS_Color::equal(CJS_Runtime* pRuntime,
302 pdfium::span<v8::Local<v8::Value>> params) {
303 if (params.size() < 2)
306 if (!fxv8::IsArray(params[0]) || !fxv8::IsArray(params[1]))
310 ConvertArrayToPWLColor(pRuntime, pRuntime->ToArray(params[0]));
312 ConvertArrayToPWLColor(pRuntime, pRuntime->ToArray(params[1]));
bool operator==(const CFX_Color &c1, const CFX_Color &c2)
static uint32_t GetObjDefnID()
CJS_Color(v8::Local< v8::Object > pObject, CJS_Runtime *pRuntime)
static void DefineJSObjects(CFXJS_Engine *pEngine)
static CJS_Result Success()
static CJS_Result Failure(JSMessage id)
bool EqualsASCII(ByteStringView that) const
CFX_Color ConvertColorType(Type nConvertColorType) const
constexpr CFX_Color(Type type=CFX_Color::Type::kTransparent, float color1=0.0f, float color2=0.0f, float color3=0.0f, float color4=0.0f)
fxcrt::WideString WideString