Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: fpdfsdk/javascript/color.cpp

Issue 2227673005: Remove backpointer to CJS_Runtime from CJS_Value (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "fpdfsdk/javascript/color.h" 7 #include "fpdfsdk/javascript/color.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 void color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime, 95 void color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime,
96 const CJS_Array& array, 96 const CJS_Array& array,
97 CPWL_Color* color) { 97 CPWL_Color* color) {
98 int nArrayLen = array.GetLength(); 98 int nArrayLen = array.GetLength();
99 if (nArrayLen < 1) 99 if (nArrayLen < 1)
100 return; 100 return;
101 101
102 CJS_Value value(pRuntime); 102 CJS_Value value(pRuntime);
103 array.GetElement(pRuntime->GetIsolate(), 0, value); 103 array.GetElement(pRuntime->GetIsolate(), 0, value);
104 CFX_ByteString sSpace = value.ToCFXByteString(); 104 CFX_ByteString sSpace = value.ToCFXByteString(pRuntime->GetIsolate());
105 105
106 double d1 = 0; 106 double d1 = 0;
107 double d2 = 0; 107 double d2 = 0;
108 double d3 = 0; 108 double d3 = 0;
109 double d4 = 0; 109 double d4 = 0;
110 110
111 if (nArrayLen > 1) { 111 if (nArrayLen > 1) {
112 array.GetElement(pRuntime->GetIsolate(), 1, value); 112 array.GetElement(pRuntime->GetIsolate(), 1, value);
113 d1 = value.ToDouble(); 113 d1 = value.ToDouble(pRuntime->GetIsolate());
114 } 114 }
115 115
116 if (nArrayLen > 2) { 116 if (nArrayLen > 2) {
117 array.GetElement(pRuntime->GetIsolate(), 2, value); 117 array.GetElement(pRuntime->GetIsolate(), 2, value);
118 d2 = value.ToDouble(); 118 d2 = value.ToDouble(pRuntime->GetIsolate());
119 } 119 }
120 120
121 if (nArrayLen > 3) { 121 if (nArrayLen > 3) {
122 array.GetElement(pRuntime->GetIsolate(), 3, value); 122 array.GetElement(pRuntime->GetIsolate(), 3, value);
123 d3 = value.ToDouble(); 123 d3 = value.ToDouble(pRuntime->GetIsolate());
124 } 124 }
125 125
126 if (nArrayLen > 4) { 126 if (nArrayLen > 4) {
127 array.GetElement(pRuntime->GetIsolate(), 4, value); 127 array.GetElement(pRuntime->GetIsolate(), 4, value);
128 d4 = value.ToDouble(); 128 d4 = value.ToDouble(pRuntime->GetIsolate());
129 } 129 }
130 130
131 if (sSpace == "T") { 131 if (sSpace == "T") {
132 *color = CPWL_Color(COLORTYPE_TRANSPARENT); 132 *color = CPWL_Color(COLORTYPE_TRANSPARENT);
133 } else if (sSpace == "G") { 133 } else if (sSpace == "G") {
134 *color = CPWL_Color(COLORTYPE_GRAY, (FX_FLOAT)d1); 134 *color = CPWL_Color(COLORTYPE_GRAY, (FX_FLOAT)d1);
135 } else if (sSpace == "RGB") { 135 } else if (sSpace == "RGB") {
136 *color = 136 *color =
137 CPWL_Color(COLORTYPE_RGB, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3); 137 CPWL_Color(COLORTYPE_RGB, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3);
138 } else if (sSpace == "CMYK") { 138 } else if (sSpace == "CMYK") {
139 *color = CPWL_Color(COLORTYPE_CMYK, (FX_FLOAT)d1, (FX_FLOAT)d2, 139 *color = CPWL_Color(COLORTYPE_CMYK, (FX_FLOAT)d1, (FX_FLOAT)d2,
140 (FX_FLOAT)d3, (FX_FLOAT)d4); 140 (FX_FLOAT)d3, (FX_FLOAT)d4);
141 } 141 }
142 } 142 }
143 143
144 #define JS_IMPLEMENT_COLORPROP(prop, var) \ 144 #define JS_IMPLEMENT_COLORPROP(prop, var) \
145 FX_BOOL color::prop(IJS_Context* cc, CJS_PropValue& vp, \ 145 FX_BOOL color::prop(IJS_Context* cc, CJS_PropValue& vp, \
146 CFX_WideString& sError) { \ 146 CFX_WideString& sError) { \
147 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); \ 147 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); \
148 CJS_Array array; \ 148 CJS_Array array; \
149 if (vp.IsGetting()) { \ 149 if (vp.IsGetting()) { \
150 ConvertPWLColorToArray(pRuntime, var, &array); \ 150 ConvertPWLColorToArray(pRuntime, var, &array); \
151 vp << array; \ 151 vp << array; \
152 } else { \ 152 } else { \
153 if (!vp.ConvertToArray(array)) \ 153 if (!vp.GetJSValue()->ConvertToArray(pRuntime->GetIsolate(), array)) \
154 return FALSE; \ 154 return FALSE; \
155 ConvertArrayToPWLColor(pRuntime, array, &var); \ 155 ConvertArrayToPWLColor(pRuntime, 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(IJS_Context* cc, 173 FX_BOOL color::convert(IJS_Context* cc,
174 const std::vector<CJS_Value>& params, 174 const std::vector<CJS_Value>& params,
175 CJS_Value& vRet, 175 CJS_Value& vRet,
176 CFX_WideString& sError) { 176 CFX_WideString& sError) {
177 int iSize = params.size(); 177 int iSize = params.size();
178 if (iSize < 2) 178 if (iSize < 2)
179 return FALSE; 179 return FALSE;
180 180
181 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 181 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
182 CJS_Array aSource; 182 CJS_Array aSource;
183 if (!params[0].ConvertToArray(aSource)) 183 if (!params[0].ConvertToArray(pRuntime->GetIsolate(), aSource))
184 return FALSE; 184 return FALSE;
185 185
186 CPWL_Color crSource; 186 CPWL_Color crSource;
187 ConvertArrayToPWLColor(pRuntime, aSource, &crSource); 187 ConvertArrayToPWLColor(pRuntime, aSource, &crSource);
188 188
189 CFX_ByteString sDestSpace = params[1].ToCFXByteString(); 189 CFX_ByteString sDestSpace = params[1].ToCFXByteString(pRuntime->GetIsolate());
190 int nColorType = COLORTYPE_TRANSPARENT; 190 int nColorType = COLORTYPE_TRANSPARENT;
191 191
192 if (sDestSpace == "T") { 192 if (sDestSpace == "T") {
193 nColorType = COLORTYPE_TRANSPARENT; 193 nColorType = COLORTYPE_TRANSPARENT;
194 } else if (sDestSpace == "G") { 194 } else if (sDestSpace == "G") {
195 nColorType = COLORTYPE_GRAY; 195 nColorType = COLORTYPE_GRAY;
196 } else if (sDestSpace == "RGB") { 196 } else if (sDestSpace == "RGB") {
197 nColorType = COLORTYPE_RGB; 197 nColorType = COLORTYPE_RGB;
198 } else if (sDestSpace == "CMYK") { 198 } else if (sDestSpace == "CMYK") {
199 nColorType = COLORTYPE_CMYK; 199 nColorType = COLORTYPE_CMYK;
(...skipping 11 matching lines...) Expand all
211 FX_BOOL color::equal(IJS_Context* cc, 211 FX_BOOL color::equal(IJS_Context* cc,
212 const std::vector<CJS_Value>& params, 212 const std::vector<CJS_Value>& params,
213 CJS_Value& vRet, 213 CJS_Value& vRet,
214 CFX_WideString& sError) { 214 CFX_WideString& sError) {
215 if (params.size() < 2) 215 if (params.size() < 2)
216 return FALSE; 216 return FALSE;
217 217
218 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 218 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
219 CJS_Array array1; 219 CJS_Array array1;
220 CJS_Array array2; 220 CJS_Array array2;
221 if (!params[0].ConvertToArray(array1)) 221 if (!params[0].ConvertToArray(pRuntime->GetIsolate(), array1))
222 return FALSE; 222 return FALSE;
223 if (!params[1].ConvertToArray(array2)) 223 if (!params[1].ConvertToArray(pRuntime->GetIsolate(), array2))
224 return FALSE; 224 return FALSE;
225 225
226 CPWL_Color color1; 226 CPWL_Color color1;
227 CPWL_Color color2; 227 CPWL_Color color2;
228 ConvertArrayToPWLColor(pRuntime, array1, &color1); 228 ConvertArrayToPWLColor(pRuntime, array1, &color1);
229 ConvertArrayToPWLColor(pRuntime, array2, &color2); 229 ConvertArrayToPWLColor(pRuntime, array2, &color2);
230 color1.ConvertColorType(color2.nColorType); 230 color1.ConvertColorType(color2.nColorType);
231 vRet = color1 == color2; 231 vRet = CJS_Value(pRuntime, color1 == color2);
232 return TRUE; 232 return TRUE;
233 } 233 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698