OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "color.h" | 7 #include "color.h" |
8 | 8 |
9 #include "../../include/javascript/IJavaScript.h" | 9 #include "../../include/javascript/IJavaScript.h" |
10 #include "JS_Define.h" | 10 #include "JS_Define.h" |
11 #include "JS_Object.h" | 11 #include "JS_Object.h" |
12 #include "JS_Value.h" | 12 #include "JS_Value.h" |
13 #include "JS_EventHandler.h" | 13 #include "JS_EventHandler.h" |
14 #include "JS_Context.h" | 14 #include "JS_Context.h" |
15 #include "JS_Runtime.h" | 15 #include "JS_Runtime.h" |
16 | 16 |
17 static v8::Isolate* GetIsolate(IJS_Context* cc) { | |
18 CJS_Context* pContext = (CJS_Context*)cc; | |
19 ASSERT(pContext != NULL); | |
20 | |
21 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | |
22 ASSERT(pRuntime != NULL); | |
23 | |
24 return pRuntime->GetIsolate(); | |
25 } | |
26 /* -------------------------- color -------------------------- */ | 17 /* -------------------------- color -------------------------- */ |
27 | 18 |
28 BEGIN_JS_STATIC_CONST(CJS_Color) | 19 BEGIN_JS_STATIC_CONST(CJS_Color) |
29 END_JS_STATIC_CONST() | 20 END_JS_STATIC_CONST() |
30 | 21 |
31 BEGIN_JS_STATIC_PROP(CJS_Color) | 22 BEGIN_JS_STATIC_PROP(CJS_Color) |
32 JS_STATIC_PROP_ENTRY(black) | 23 JS_STATIC_PROP_ENTRY(black) |
33 JS_STATIC_PROP_ENTRY(blue) | 24 JS_STATIC_PROP_ENTRY(blue) |
34 JS_STATIC_PROP_ENTRY(cyan) | 25 JS_STATIC_PROP_ENTRY(cyan) |
35 JS_STATIC_PROP_ENTRY(dkGray) | 26 JS_STATIC_PROP_ENTRY(dkGray) |
(...skipping 28 matching lines...) Expand all Loading... |
64 m_crGray = CPWL_Color(COLORTYPE_GRAY, 0.5); | 55 m_crGray = CPWL_Color(COLORTYPE_GRAY, 0.5); |
65 m_crLTGray = CPWL_Color(COLORTYPE_GRAY, 0.75); | 56 m_crLTGray = CPWL_Color(COLORTYPE_GRAY, 0.75); |
66 } | 57 } |
67 | 58 |
68 color::~color() { | 59 color::~color() { |
69 } | 60 } |
70 | 61 |
71 void color::ConvertPWLColorToArray(const CPWL_Color& color, CJS_Array& array) { | 62 void color::ConvertPWLColorToArray(const CPWL_Color& color, CJS_Array& array) { |
72 switch (color.nColorType) { | 63 switch (color.nColorType) { |
73 case COLORTYPE_TRANSPARENT: | 64 case COLORTYPE_TRANSPARENT: |
74 array.SetElement(0, CJS_Value(array.GetIsolate(), "T")); | 65 array.SetElement(0, CJS_Value(array.GetJSRuntime(), "T")); |
75 break; | 66 break; |
76 case COLORTYPE_GRAY: | 67 case COLORTYPE_GRAY: |
77 array.SetElement(0, CJS_Value(array.GetIsolate(), "G")); | 68 array.SetElement(0, CJS_Value(array.GetJSRuntime(), "G")); |
78 array.SetElement(1, CJS_Value(array.GetIsolate(), color.fColor1)); | 69 array.SetElement(1, CJS_Value(array.GetJSRuntime(), color.fColor1)); |
79 break; | 70 break; |
80 case COLORTYPE_RGB: | 71 case COLORTYPE_RGB: |
81 array.SetElement(0, CJS_Value(array.GetIsolate(), "RGB")); | 72 array.SetElement(0, CJS_Value(array.GetJSRuntime(), "RGB")); |
82 array.SetElement(1, CJS_Value(array.GetIsolate(), color.fColor1)); | 73 array.SetElement(1, CJS_Value(array.GetJSRuntime(), color.fColor1)); |
83 array.SetElement(2, CJS_Value(array.GetIsolate(), color.fColor2)); | 74 array.SetElement(2, CJS_Value(array.GetJSRuntime(), color.fColor2)); |
84 array.SetElement(3, CJS_Value(array.GetIsolate(), color.fColor3)); | 75 array.SetElement(3, CJS_Value(array.GetJSRuntime(), color.fColor3)); |
85 break; | 76 break; |
86 case COLORTYPE_CMYK: | 77 case COLORTYPE_CMYK: |
87 array.SetElement(0, CJS_Value(array.GetIsolate(), "CMYK")); | 78 array.SetElement(0, CJS_Value(array.GetJSRuntime(), "CMYK")); |
88 array.SetElement(1, CJS_Value(array.GetIsolate(), color.fColor1)); | 79 array.SetElement(1, CJS_Value(array.GetJSRuntime(), color.fColor1)); |
89 array.SetElement(2, CJS_Value(array.GetIsolate(), color.fColor2)); | 80 array.SetElement(2, CJS_Value(array.GetJSRuntime(), color.fColor2)); |
90 array.SetElement(3, CJS_Value(array.GetIsolate(), color.fColor3)); | 81 array.SetElement(3, CJS_Value(array.GetJSRuntime(), color.fColor3)); |
91 array.SetElement(4, CJS_Value(array.GetIsolate(), color.fColor4)); | 82 array.SetElement(4, CJS_Value(array.GetJSRuntime(), color.fColor4)); |
92 break; | 83 break; |
93 } | 84 } |
94 } | 85 } |
95 | 86 |
96 void color::ConvertArrayToPWLColor(CJS_Array& array, CPWL_Color& color) { | 87 void color::ConvertArrayToPWLColor(CJS_Array& array, CPWL_Color& color) { |
97 int nArrayLen = array.GetLength(); | 88 int nArrayLen = array.GetLength(); |
98 if (nArrayLen < 1) | 89 if (nArrayLen < 1) |
99 return; | 90 return; |
100 | 91 |
101 CJS_Value value(array.GetIsolate()); | 92 CJS_Value value(array.GetJSRuntime()); |
102 array.GetElement(0, value); | 93 array.GetElement(0, value); |
103 CFX_ByteString sSpace = value.ToCFXByteString(); | 94 CFX_ByteString sSpace = value.ToCFXByteString(); |
104 | 95 |
105 double d1 = 0; | 96 double d1 = 0; |
106 double d2 = 0; | 97 double d2 = 0; |
107 double d3 = 0; | 98 double d3 = 0; |
108 double d4 = 0; | 99 double d4 = 0; |
109 | 100 |
110 if (nArrayLen > 1) { | 101 if (nArrayLen > 1) { |
111 array.GetElement(1, value); | 102 array.GetElement(1, value); |
(...skipping 20 matching lines...) Expand all Loading... |
132 } else if (sSpace == "G") { | 123 } else if (sSpace == "G") { |
133 color = CPWL_Color(COLORTYPE_GRAY, (FX_FLOAT)d1); | 124 color = CPWL_Color(COLORTYPE_GRAY, (FX_FLOAT)d1); |
134 } else if (sSpace == "RGB") { | 125 } else if (sSpace == "RGB") { |
135 color = CPWL_Color(COLORTYPE_RGB, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3); | 126 color = CPWL_Color(COLORTYPE_RGB, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3); |
136 } else if (sSpace == "CMYK") { | 127 } else if (sSpace == "CMYK") { |
137 color = CPWL_Color(COLORTYPE_CMYK, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3, | 128 color = CPWL_Color(COLORTYPE_CMYK, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3, |
138 (FX_FLOAT)d4); | 129 (FX_FLOAT)d4); |
139 } | 130 } |
140 } | 131 } |
141 | 132 |
142 #define JS_IMPLEMENT_COLORPROP(prop, var) \ | 133 #define JS_IMPLEMENT_COLORPROP(prop, var) \ |
143 FX_BOOL color::prop(IJS_Context* cc, CJS_PropValue& vp, \ | 134 FX_BOOL color::prop(IJS_Context* cc, CJS_PropValue& vp, \ |
144 CFX_WideString& sError) { \ | 135 CFX_WideString& sError) { \ |
145 CJS_Context* pContext = (CJS_Context*)cc; \ | 136 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); \ |
146 v8::Isolate* isolate = pContext->GetJSRuntime()->GetIsolate(); \ | 137 CJS_Array array(pRuntime); \ |
147 if (vp.IsGetting()) { \ | 138 if (vp.IsGetting()) { \ |
148 CJS_Array array(isolate); \ | 139 ConvertPWLColorToArray(var, array); \ |
149 ConvertPWLColorToArray(var, array); \ | 140 vp << array; \ |
150 vp << array; \ | 141 } else { \ |
151 } else { \ | 142 if (!vp.ConvertToArray(array)) \ |
152 CJS_Array array(isolate); \ | 143 return FALSE; \ |
153 if (!vp.ConvertToArray(array)) \ | 144 ConvertArrayToPWLColor(array, var); \ |
154 return FALSE; \ | 145 } \ |
155 ConvertArrayToPWLColor(array, var); \ | 146 return TRUE; \ |
156 } \ | |
157 return TRUE; \ | |
158 } | 147 } |
159 | 148 |
160 JS_IMPLEMENT_COLORPROP(transparent, m_crTransparent) | 149 JS_IMPLEMENT_COLORPROP(transparent, m_crTransparent) |
161 JS_IMPLEMENT_COLORPROP(black, m_crBlack) | 150 JS_IMPLEMENT_COLORPROP(black, m_crBlack) |
162 JS_IMPLEMENT_COLORPROP(white, m_crWhite) | 151 JS_IMPLEMENT_COLORPROP(white, m_crWhite) |
163 JS_IMPLEMENT_COLORPROP(red, m_crRed) | 152 JS_IMPLEMENT_COLORPROP(red, m_crRed) |
164 JS_IMPLEMENT_COLORPROP(green, m_crGreen) | 153 JS_IMPLEMENT_COLORPROP(green, m_crGreen) |
165 JS_IMPLEMENT_COLORPROP(blue, m_crBlue) | 154 JS_IMPLEMENT_COLORPROP(blue, m_crBlue) |
166 JS_IMPLEMENT_COLORPROP(cyan, m_crCyan) | 155 JS_IMPLEMENT_COLORPROP(cyan, m_crCyan) |
167 JS_IMPLEMENT_COLORPROP(magenta, m_crMagenta) | 156 JS_IMPLEMENT_COLORPROP(magenta, m_crMagenta) |
168 JS_IMPLEMENT_COLORPROP(yellow, m_crYellow) | 157 JS_IMPLEMENT_COLORPROP(yellow, m_crYellow) |
169 JS_IMPLEMENT_COLORPROP(dkGray, m_crDKGray) | 158 JS_IMPLEMENT_COLORPROP(dkGray, m_crDKGray) |
170 JS_IMPLEMENT_COLORPROP(gray, m_crGray) | 159 JS_IMPLEMENT_COLORPROP(gray, m_crGray) |
171 JS_IMPLEMENT_COLORPROP(ltGray, m_crLTGray) | 160 JS_IMPLEMENT_COLORPROP(ltGray, m_crLTGray) |
172 | 161 |
173 FX_BOOL color::convert(IJS_Context* cc, | 162 FX_BOOL color::convert(IJS_Context* cc, |
174 const CJS_Parameters& params, | 163 const CJS_Parameters& params, |
175 CJS_Value& vRet, | 164 CJS_Value& vRet, |
176 CFX_WideString& sError) { | 165 CFX_WideString& sError) { |
177 v8::Isolate* isolate = GetIsolate(cc); | |
178 int iSize = params.size(); | 166 int iSize = params.size(); |
179 if (iSize < 2) | 167 if (iSize < 2) |
180 return FALSE; | 168 return FALSE; |
181 CJS_Array aSource(isolate); | 169 |
| 170 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 171 CJS_Array aSource(pRuntime); |
182 if (!params[0].ConvertToArray(aSource)) | 172 if (!params[0].ConvertToArray(aSource)) |
183 return FALSE; | 173 return FALSE; |
184 | 174 |
185 CPWL_Color crSource; | 175 CPWL_Color crSource; |
186 ConvertArrayToPWLColor(aSource, crSource); | 176 ConvertArrayToPWLColor(aSource, crSource); |
187 | 177 |
188 CFX_ByteString sDestSpace = params[1].ToCFXByteString(); | 178 CFX_ByteString sDestSpace = params[1].ToCFXByteString(); |
189 int nColorType = COLORTYPE_TRANSPARENT; | 179 int nColorType = COLORTYPE_TRANSPARENT; |
190 | 180 |
191 if (sDestSpace == "T") { | 181 if (sDestSpace == "T") { |
192 nColorType = COLORTYPE_TRANSPARENT; | 182 nColorType = COLORTYPE_TRANSPARENT; |
193 } else if (sDestSpace == "G") { | 183 } else if (sDestSpace == "G") { |
194 nColorType = COLORTYPE_GRAY; | 184 nColorType = COLORTYPE_GRAY; |
195 } else if (sDestSpace == "RGB") { | 185 } else if (sDestSpace == "RGB") { |
196 nColorType = COLORTYPE_RGB; | 186 nColorType = COLORTYPE_RGB; |
197 } else if (sDestSpace == "CMYK") { | 187 } else if (sDestSpace == "CMYK") { |
198 nColorType = COLORTYPE_CMYK; | 188 nColorType = COLORTYPE_CMYK; |
199 } | 189 } |
200 | 190 |
201 CJS_Array aDest(isolate); | 191 CJS_Array aDest(pRuntime); |
202 CPWL_Color crDest = crSource; | 192 CPWL_Color crDest = crSource; |
203 crDest.ConvertColorType(nColorType); | 193 crDest.ConvertColorType(nColorType); |
204 ConvertPWLColorToArray(crDest, aDest); | 194 ConvertPWLColorToArray(crDest, aDest); |
205 vRet = aDest; | 195 vRet = aDest; |
206 | 196 |
207 return TRUE; | 197 return TRUE; |
208 } | 198 } |
209 | 199 |
210 FX_BOOL color::equal(IJS_Context* cc, | 200 FX_BOOL color::equal(IJS_Context* cc, |
211 const CJS_Parameters& params, | 201 const CJS_Parameters& params, |
212 CJS_Value& vRet, | 202 CJS_Value& vRet, |
213 CFX_WideString& sError) { | 203 CFX_WideString& sError) { |
214 v8::Isolate* isolate = GetIsolate(cc); | |
215 if (params.size() < 2) | 204 if (params.size() < 2) |
216 return FALSE; | 205 return FALSE; |
217 | 206 |
218 CJS_Array array1(isolate), array2(isolate); | 207 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
219 | 208 CJS_Array array1(pRuntime); |
| 209 CJS_Array array2(pRuntime); |
220 if (!params[0].ConvertToArray(array1)) | 210 if (!params[0].ConvertToArray(array1)) |
221 return FALSE; | 211 return FALSE; |
222 if (!params[1].ConvertToArray(array2)) | 212 if (!params[1].ConvertToArray(array2)) |
223 return FALSE; | 213 return FALSE; |
224 | 214 |
225 CPWL_Color color1; | 215 CPWL_Color color1; |
226 CPWL_Color color2; | 216 CPWL_Color color2; |
227 | |
228 ConvertArrayToPWLColor(array1, color1); | 217 ConvertArrayToPWLColor(array1, color1); |
229 ConvertArrayToPWLColor(array2, color2); | 218 ConvertArrayToPWLColor(array2, color2); |
230 | |
231 color1.ConvertColorType(color2.nColorType); | 219 color1.ConvertColorType(color2.nColorType); |
232 | |
233 vRet = color1 == color2; | 220 vRet = color1 == color2; |
234 return TRUE; | 221 return TRUE; |
235 } | 222 } |
OLD | NEW |