| 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(IFXJS_Context* cc) { | 17 static v8::Isolate* GetIsolate(IJS_Context* cc) { |
| 18 CJS_Context* pContext = (CJS_Context*)cc; | 18 CJS_Context* pContext = (CJS_Context*)cc; |
| 19 ASSERT(pContext != NULL); | 19 ASSERT(pContext != NULL); |
| 20 | 20 |
| 21 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 21 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 22 ASSERT(pRuntime != NULL); | 22 ASSERT(pRuntime != NULL); |
| 23 | 23 |
| 24 return pRuntime->GetIsolate(); | 24 return pRuntime->GetIsolate(); |
| 25 } | 25 } |
| 26 /* -------------------------- color -------------------------- */ | 26 /* -------------------------- color -------------------------- */ |
| 27 | 27 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 color = CPWL_Color(COLORTYPE_GRAY, (FX_FLOAT)d1); | 133 color = CPWL_Color(COLORTYPE_GRAY, (FX_FLOAT)d1); |
| 134 } else if (sSpace == "RGB") { | 134 } else if (sSpace == "RGB") { |
| 135 color = CPWL_Color(COLORTYPE_RGB, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3); | 135 color = CPWL_Color(COLORTYPE_RGB, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3); |
| 136 } else if (sSpace == "CMYK") { | 136 } else if (sSpace == "CMYK") { |
| 137 color = CPWL_Color(COLORTYPE_CMYK, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3, | 137 color = CPWL_Color(COLORTYPE_CMYK, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3, |
| 138 (FX_FLOAT)d4); | 138 (FX_FLOAT)d4); |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 #define JS_IMPLEMENT_COLORPROP(prop, var) \ | 142 #define JS_IMPLEMENT_COLORPROP(prop, var) \ |
| 143 FX_BOOL color::prop(IFXJS_Context* cc, CJS_PropValue& vp, \ | 143 FX_BOOL color::prop(IJS_Context* cc, CJS_PropValue& vp, \ |
| 144 CFX_WideString& sError) { \ | 144 CFX_WideString& sError) { \ |
| 145 CJS_Context* pContext = (CJS_Context*)cc; \ | 145 CJS_Context* pContext = (CJS_Context*)cc; \ |
| 146 v8::Isolate* isolate = pContext->GetJSRuntime()->GetIsolate(); \ | 146 v8::Isolate* isolate = pContext->GetJSRuntime()->GetIsolate(); \ |
| 147 if (vp.IsGetting()) { \ | 147 if (vp.IsGetting()) { \ |
| 148 CJS_Array array(isolate); \ | 148 CJS_Array array(isolate); \ |
| 149 ConvertPWLColorToArray(var, array); \ | 149 ConvertPWLColorToArray(var, array); \ |
| 150 vp << array; \ | 150 vp << array; \ |
| 151 } else { \ | 151 } else { \ |
| 152 CJS_Array array(isolate); \ | 152 CJS_Array array(isolate); \ |
| 153 if (!vp.ConvertToArray(array)) \ | 153 if (!vp.ConvertToArray(array)) \ |
| 154 return FALSE; \ | 154 return FALSE; \ |
| 155 ConvertArrayToPWLColor(array, var); \ | 155 ConvertArrayToPWLColor(array, var); \ |
| 156 } \ | 156 } \ |
| 157 return TRUE; \ | 157 return TRUE; \ |
| 158 } | 158 } |
| 159 | 159 |
| 160 JS_IMPLEMENT_COLORPROP(transparent, m_crTransparent) | 160 JS_IMPLEMENT_COLORPROP(transparent, m_crTransparent) |
| 161 JS_IMPLEMENT_COLORPROP(black, m_crBlack) | 161 JS_IMPLEMENT_COLORPROP(black, m_crBlack) |
| 162 JS_IMPLEMENT_COLORPROP(white, m_crWhite) | 162 JS_IMPLEMENT_COLORPROP(white, m_crWhite) |
| 163 JS_IMPLEMENT_COLORPROP(red, m_crRed) | 163 JS_IMPLEMENT_COLORPROP(red, m_crRed) |
| 164 JS_IMPLEMENT_COLORPROP(green, m_crGreen) | 164 JS_IMPLEMENT_COLORPROP(green, m_crGreen) |
| 165 JS_IMPLEMENT_COLORPROP(blue, m_crBlue) | 165 JS_IMPLEMENT_COLORPROP(blue, m_crBlue) |
| 166 JS_IMPLEMENT_COLORPROP(cyan, m_crCyan) | 166 JS_IMPLEMENT_COLORPROP(cyan, m_crCyan) |
| 167 JS_IMPLEMENT_COLORPROP(magenta, m_crMagenta) | 167 JS_IMPLEMENT_COLORPROP(magenta, m_crMagenta) |
| 168 JS_IMPLEMENT_COLORPROP(yellow, m_crYellow) | 168 JS_IMPLEMENT_COLORPROP(yellow, m_crYellow) |
| 169 JS_IMPLEMENT_COLORPROP(dkGray, m_crDKGray) | 169 JS_IMPLEMENT_COLORPROP(dkGray, m_crDKGray) |
| 170 JS_IMPLEMENT_COLORPROP(gray, m_crGray) | 170 JS_IMPLEMENT_COLORPROP(gray, m_crGray) |
| 171 JS_IMPLEMENT_COLORPROP(ltGray, m_crLTGray) | 171 JS_IMPLEMENT_COLORPROP(ltGray, m_crLTGray) |
| 172 | 172 |
| 173 FX_BOOL color::convert(IFXJS_Context* cc, | 173 FX_BOOL color::convert(IJS_Context* cc, |
| 174 const CJS_Parameters& params, | 174 const CJS_Parameters& params, |
| 175 CJS_Value& vRet, | 175 CJS_Value& vRet, |
| 176 CFX_WideString& sError) { | 176 CFX_WideString& sError) { |
| 177 v8::Isolate* isolate = GetIsolate(cc); | 177 v8::Isolate* isolate = GetIsolate(cc); |
| 178 int iSize = params.size(); | 178 int iSize = params.size(); |
| 179 if (iSize < 2) | 179 if (iSize < 2) |
| 180 return FALSE; | 180 return FALSE; |
| 181 CJS_Array aSource(isolate); | 181 CJS_Array aSource(isolate); |
| 182 if (!params[0].ConvertToArray(aSource)) | 182 if (!params[0].ConvertToArray(aSource)) |
| 183 return FALSE; | 183 return FALSE; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 200 | 200 |
| 201 CJS_Array aDest(isolate); | 201 CJS_Array aDest(isolate); |
| 202 CPWL_Color crDest = crSource; | 202 CPWL_Color crDest = crSource; |
| 203 crDest.ConvertColorType(nColorType); | 203 crDest.ConvertColorType(nColorType); |
| 204 ConvertPWLColorToArray(crDest, aDest); | 204 ConvertPWLColorToArray(crDest, aDest); |
| 205 vRet = aDest; | 205 vRet = aDest; |
| 206 | 206 |
| 207 return TRUE; | 207 return TRUE; |
| 208 } | 208 } |
| 209 | 209 |
| 210 FX_BOOL color::equal(IFXJS_Context* cc, | 210 FX_BOOL color::equal(IJS_Context* cc, |
| 211 const CJS_Parameters& params, | 211 const CJS_Parameters& params, |
| 212 CJS_Value& vRet, | 212 CJS_Value& vRet, |
| 213 CFX_WideString& sError) { | 213 CFX_WideString& sError) { |
| 214 v8::Isolate* isolate = GetIsolate(cc); | 214 v8::Isolate* isolate = GetIsolate(cc); |
| 215 if (params.size() < 2) | 215 if (params.size() < 2) |
| 216 return FALSE; | 216 return FALSE; |
| 217 | 217 |
| 218 CJS_Array array1(isolate), array2(isolate); | 218 CJS_Array array1(isolate), array2(isolate); |
| 219 | 219 |
| 220 if (!params[0].ConvertToArray(array1)) | 220 if (!params[0].ConvertToArray(array1)) |
| 221 return FALSE; | 221 return FALSE; |
| 222 if (!params[1].ConvertToArray(array2)) | 222 if (!params[1].ConvertToArray(array2)) |
| 223 return FALSE; | 223 return FALSE; |
| 224 | 224 |
| 225 CPWL_Color color1; | 225 CPWL_Color color1; |
| 226 CPWL_Color color2; | 226 CPWL_Color color2; |
| 227 | 227 |
| 228 ConvertArrayToPWLColor(array1, color1); | 228 ConvertArrayToPWLColor(array1, color1); |
| 229 ConvertArrayToPWLColor(array2, color2); | 229 ConvertArrayToPWLColor(array2, color2); |
| 230 | 230 |
| 231 color1.ConvertColorType(color2.nColorType); | 231 color1.ConvertColorType(color2.nColorType); |
| 232 | 232 |
| 233 vRet = color1 == color2; | 233 vRet = color1 == color2; |
| 234 return TRUE; | 234 return TRUE; |
| 235 } | 235 } |
| OLD | NEW |