7#include "fxjs/cjs_color.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 "third_party/base/containers/span.h"
19#include "v8/include/v8-container.h"
22 {
"black", get_black_static, set_black_static},
23 {
"blue", get_blue_static, set_blue_static},
24 {
"cyan", get_cyan_static, set_cyan_static},
25 {
"dkGray", get_dark_gray_static, set_dark_gray_static},
26 {
"gray", get_gray_static, set_gray_static},
27 {
"green", get_green_static, set_green_static},
28 {
"ltGray", get_light_gray_static, set_light_gray_static},
29 {
"magenta", get_magenta_static, set_magenta_static},
30 {
"red", get_red_static, set_red_static},
31 {
"transparent", get_transparent_static, set_transparent_static},
32 {
"white", get_white_static, set_white_static},
33 {
"yellow", get_yellow_static, set_yellow_static}};
35const JSMethodSpec CJS_Color::MethodSpecs[] = {{
"convert", convert_static},
36 {
"equal", equal_static}};
38uint32_t CJS_Color::ObjDefnID = 0;
39const char CJS_Color::kName[] =
"color";
49 JSConstructor<CJS_Color>, JSDestructor);
55v8::Local<v8::Array> CJS_Color::ConvertPWLColorToArray(CJS_Runtime* pRuntime,
57 v8::Local<v8::Array> array;
59 case CFX_Color::Type::kTransparent:
60 array = pRuntime->NewArray();
61 pRuntime->PutArrayElement(array, 0, pRuntime->NewString(
"T"));
63 case CFX_Color::Type::kGray:
64 array = pRuntime->NewArray();
65 pRuntime->PutArrayElement(array, 0, pRuntime->NewString(
"G"));
66 pRuntime->PutArrayElement(array, 1, pRuntime->NewNumber(color.fColor1));
68 case CFX_Color::Type::kRGB:
69 array = pRuntime->NewArray();
70 pRuntime->PutArrayElement(array, 0, pRuntime->NewString(
"RGB"));
71 pRuntime->PutArrayElement(array, 1, pRuntime->NewNumber(color.fColor1));
72 pRuntime->PutArrayElement(array, 2, pRuntime->NewNumber(color.fColor2));
73 pRuntime->PutArrayElement(array, 3, pRuntime->NewNumber(color.fColor3));
75 case CFX_Color::Type::kCMYK:
76 array = pRuntime->NewArray();
77 pRuntime->PutArrayElement(array, 0, pRuntime->NewString(
"CMYK"));
78 pRuntime->PutArrayElement(array, 1, pRuntime->NewNumber(color.fColor1));
79 pRuntime->PutArrayElement(array, 2, pRuntime->NewNumber(color.fColor2));
80 pRuntime->PutArrayElement(array, 3, pRuntime->NewNumber(color.fColor3));
81 pRuntime->PutArrayElement(array, 4, pRuntime->NewNumber(color.fColor4));
88CFX_Color CJS_Color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime,
89 v8::Local<v8::Array> array) {
90 size_t nArrayLen = pRuntime->GetArrayLength(array);
95 pRuntime->ToWideString(pRuntime->GetArrayElement(array, 0));
101 d1 =
static_cast<
float>(
102 pRuntime->ToDouble(pRuntime->GetArrayElement(array, 1)));
110 d2 =
static_cast<
float>(
111 pRuntime->ToDouble(pRuntime->GetArrayElement(array, 2)));
114 d3 =
static_cast<
float>(
115 pRuntime->ToDouble(pRuntime->GetArrayElement(array, 3)));
122 d4 =
static_cast<
float>(
123 pRuntime->ToDouble(pRuntime->GetArrayElement(array, 4)));
131CJS_Color::
CJS_Color(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
148CJS_Result CJS_Color::get_transparent(CJS_Runtime* pRuntime) {
149 return GetPropertyHelper(pRuntime, &m_crTransparent);
152CJS_Result CJS_Color::set_transparent(CJS_Runtime* pRuntime,
153 v8::Local<v8::Value> vp) {
154 return SetPropertyHelper(pRuntime, vp, &m_crTransparent);
157CJS_Result CJS_Color::get_black(CJS_Runtime* pRuntime) {
158 return GetPropertyHelper(pRuntime, &m_crBlack);
161CJS_Result CJS_Color::set_black(CJS_Runtime* pRuntime,
162 v8::Local<v8::Value> vp) {
163 return SetPropertyHelper(pRuntime, vp, &m_crBlack);
166CJS_Result CJS_Color::get_white(CJS_Runtime* pRuntime) {
167 return GetPropertyHelper(pRuntime, &m_crWhite);
170CJS_Result CJS_Color::set_white(CJS_Runtime* pRuntime,
171 v8::Local<v8::Value> vp) {
172 return SetPropertyHelper(pRuntime, vp, &m_crWhite);
175CJS_Result CJS_Color::get_red(CJS_Runtime* pRuntime) {
176 return GetPropertyHelper(pRuntime, &m_crRed);
179CJS_Result CJS_Color::set_red(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
180 return SetPropertyHelper(pRuntime, vp, &m_crRed);
183CJS_Result CJS_Color::get_green(CJS_Runtime* pRuntime) {
184 return GetPropertyHelper(pRuntime, &m_crGreen);
187CJS_Result CJS_Color::set_green(CJS_Runtime* pRuntime,
188 v8::Local<v8::Value> vp) {
189 return SetPropertyHelper(pRuntime, vp, &m_crGreen);
192CJS_Result CJS_Color::get_blue(CJS_Runtime* pRuntime) {
193 return GetPropertyHelper(pRuntime, &m_crBlue);
196CJS_Result CJS_Color::set_blue(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
197 return SetPropertyHelper(pRuntime, vp, &m_crBlue);
200CJS_Result CJS_Color::get_cyan(CJS_Runtime* pRuntime) {
201 return GetPropertyHelper(pRuntime, &m_crCyan);
204CJS_Result CJS_Color::set_cyan(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
205 return SetPropertyHelper(pRuntime, vp, &m_crCyan);
208CJS_Result CJS_Color::get_magenta(CJS_Runtime* pRuntime) {
209 return GetPropertyHelper(pRuntime, &m_crMagenta);
212CJS_Result CJS_Color::set_magenta(CJS_Runtime* pRuntime,
213 v8::Local<v8::Value> vp) {
214 return SetPropertyHelper(pRuntime, vp, &m_crMagenta);
217CJS_Result CJS_Color::get_yellow(CJS_Runtime* pRuntime) {
218 return GetPropertyHelper(pRuntime, &m_crYellow);
221CJS_Result CJS_Color::set_yellow(CJS_Runtime* pRuntime,
222 v8::Local<v8::Value> vp) {
223 return SetPropertyHelper(pRuntime, vp, &m_crYellow);
226CJS_Result CJS_Color::get_dark_gray(CJS_Runtime* pRuntime) {
227 return GetPropertyHelper(pRuntime, &m_crDKGray);
230CJS_Result CJS_Color::set_dark_gray(CJS_Runtime* pRuntime,
231 v8::Local<v8::Value> vp) {
232 return SetPropertyHelper(pRuntime, vp, &m_crDKGray);
235CJS_Result CJS_Color::get_gray(CJS_Runtime* pRuntime) {
236 return GetPropertyHelper(pRuntime, &m_crGray);
239CJS_Result CJS_Color::set_gray(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
240 return SetPropertyHelper(pRuntime, vp, &m_crGray);
243CJS_Result CJS_Color::get_light_gray(CJS_Runtime* pRuntime) {
244 return GetPropertyHelper(pRuntime, &m_crLTGray);
247CJS_Result CJS_Color::set_light_gray(CJS_Runtime* pRuntime,
248 v8::Local<v8::Value> vp) {
249 return SetPropertyHelper(pRuntime, vp, &m_crLTGray);
253 v8::Local<v8::Value> array = ConvertPWLColorToArray(pRuntime, *var);
257 return CJS_Result::Success(array);
260CJS_Result CJS_Color::SetPropertyHelper(CJS_Runtime* pRuntime,
261 v8::Local<v8::Value> vp,
269 *var = ConvertArrayToPWLColor(pRuntime, pRuntime->ToArray(vp));
273CJS_Result CJS_Color::convert(CJS_Runtime* pRuntime,
274 pdfium::span<v8::Local<v8::Value>> params) {
275 if (params.size() < 2)
278 if (!fxv8::IsArray(params[0]))
281 WideString sDestSpace = pRuntime->ToWideString(params[1]);
293 ConvertArrayToPWLColor(pRuntime, pRuntime->ToArray(params[0]));
294 v8::Local<v8::Value> array =
295 ConvertPWLColorToArray(pRuntime, color.ConvertColorType(nColorType));
299 return CJS_Result::Success(array);
302CJS_Result CJS_Color::equal(CJS_Runtime* pRuntime,
303 pdfium::span<v8::Local<v8::Value>> params) {
304 if (params.size() < 2)
307 if (!fxv8::IsArray(params[0]) || !fxv8::IsArray(params[1]))
311 ConvertArrayToPWLColor(pRuntime, pRuntime->ToArray(params[0]));
313 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 void DefineProps(CFXJS_Engine *pEngine, uint32_t nObjDefnID, pdfium::span< const JSPropertySpec > consts)
static void DefineMethods(CFXJS_Engine *pEngine, uint32_t nObjDefnID, pdfium::span< const JSMethodSpec > consts)
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)