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

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

Issue 2217253002: Remove backpointer to runtime from CJS_Array. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Remove non-const refs 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
« no previous file with comments | « fpdfsdk/javascript/color.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 m_crCyan = CPWL_Color(COLORTYPE_CMYK, 1, 0, 0, 0); 50 m_crCyan = CPWL_Color(COLORTYPE_CMYK, 1, 0, 0, 0);
51 m_crMagenta = CPWL_Color(COLORTYPE_CMYK, 0, 1, 0, 0); 51 m_crMagenta = CPWL_Color(COLORTYPE_CMYK, 0, 1, 0, 0);
52 m_crYellow = CPWL_Color(COLORTYPE_CMYK, 0, 0, 1, 0); 52 m_crYellow = CPWL_Color(COLORTYPE_CMYK, 0, 0, 1, 0);
53 m_crDKGray = CPWL_Color(COLORTYPE_GRAY, 0.25); 53 m_crDKGray = CPWL_Color(COLORTYPE_GRAY, 0.25);
54 m_crGray = CPWL_Color(COLORTYPE_GRAY, 0.5); 54 m_crGray = CPWL_Color(COLORTYPE_GRAY, 0.5);
55 m_crLTGray = CPWL_Color(COLORTYPE_GRAY, 0.75); 55 m_crLTGray = CPWL_Color(COLORTYPE_GRAY, 0.75);
56 } 56 }
57 57
58 color::~color() {} 58 color::~color() {}
59 59
60 void color::ConvertPWLColorToArray(const CPWL_Color& color, CJS_Array& array) { 60 void color::ConvertPWLColorToArray(CJS_Runtime* pRuntime,
61 const CPWL_Color& color,
62 CJS_Array* array) {
61 switch (color.nColorType) { 63 switch (color.nColorType) {
62 case COLORTYPE_TRANSPARENT: 64 case COLORTYPE_TRANSPARENT:
63 array.SetElement(0, CJS_Value(array.GetJSRuntime(), "T")); 65 array->SetElement(pRuntime->GetIsolate(), 0, CJS_Value(pRuntime, "T"));
64 break; 66 break;
65 case COLORTYPE_GRAY: 67 case COLORTYPE_GRAY:
66 array.SetElement(0, CJS_Value(array.GetJSRuntime(), "G")); 68 array->SetElement(pRuntime->GetIsolate(), 0, CJS_Value(pRuntime, "G"));
67 array.SetElement(1, CJS_Value(array.GetJSRuntime(), color.fColor1)); 69 array->SetElement(pRuntime->GetIsolate(), 1,
70 CJS_Value(pRuntime, color.fColor1));
68 break; 71 break;
69 case COLORTYPE_RGB: 72 case COLORTYPE_RGB:
70 array.SetElement(0, CJS_Value(array.GetJSRuntime(), "RGB")); 73 array->SetElement(pRuntime->GetIsolate(), 0, CJS_Value(pRuntime, "RGB"));
71 array.SetElement(1, CJS_Value(array.GetJSRuntime(), color.fColor1)); 74 array->SetElement(pRuntime->GetIsolate(), 1,
72 array.SetElement(2, CJS_Value(array.GetJSRuntime(), color.fColor2)); 75 CJS_Value(pRuntime, color.fColor1));
73 array.SetElement(3, CJS_Value(array.GetJSRuntime(), color.fColor3)); 76 array->SetElement(pRuntime->GetIsolate(), 2,
77 CJS_Value(pRuntime, color.fColor2));
78 array->SetElement(pRuntime->GetIsolate(), 3,
79 CJS_Value(pRuntime, color.fColor3));
74 break; 80 break;
75 case COLORTYPE_CMYK: 81 case COLORTYPE_CMYK:
76 array.SetElement(0, CJS_Value(array.GetJSRuntime(), "CMYK")); 82 array->SetElement(pRuntime->GetIsolate(), 0, CJS_Value(pRuntime, "CMYK"));
77 array.SetElement(1, CJS_Value(array.GetJSRuntime(), color.fColor1)); 83 array->SetElement(pRuntime->GetIsolate(), 1,
78 array.SetElement(2, CJS_Value(array.GetJSRuntime(), color.fColor2)); 84 CJS_Value(pRuntime, color.fColor1));
79 array.SetElement(3, CJS_Value(array.GetJSRuntime(), color.fColor3)); 85 array->SetElement(pRuntime->GetIsolate(), 2,
80 array.SetElement(4, CJS_Value(array.GetJSRuntime(), color.fColor4)); 86 CJS_Value(pRuntime, color.fColor2));
87 array->SetElement(pRuntime->GetIsolate(), 3,
88 CJS_Value(pRuntime, color.fColor3));
89 array->SetElement(pRuntime->GetIsolate(), 4,
90 CJS_Value(pRuntime, color.fColor4));
81 break; 91 break;
82 } 92 }
83 } 93 }
84 94
85 void color::ConvertArrayToPWLColor(CJS_Array& array, CPWL_Color& color) { 95 void color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime,
96 const CJS_Array& array,
97 CPWL_Color* color) {
86 int nArrayLen = array.GetLength(); 98 int nArrayLen = array.GetLength();
87 if (nArrayLen < 1) 99 if (nArrayLen < 1)
88 return; 100 return;
89 101
90 CJS_Value value(array.GetJSRuntime()); 102 CJS_Value value(pRuntime);
91 array.GetElement(0, value); 103 array.GetElement(pRuntime->GetIsolate(), 0, value);
92 CFX_ByteString sSpace = value.ToCFXByteString(); 104 CFX_ByteString sSpace = value.ToCFXByteString();
93 105
94 double d1 = 0; 106 double d1 = 0;
95 double d2 = 0; 107 double d2 = 0;
96 double d3 = 0; 108 double d3 = 0;
97 double d4 = 0; 109 double d4 = 0;
98 110
99 if (nArrayLen > 1) { 111 if (nArrayLen > 1) {
100 array.GetElement(1, value); 112 array.GetElement(pRuntime->GetIsolate(), 1, value);
101 d1 = value.ToDouble(); 113 d1 = value.ToDouble();
102 } 114 }
103 115
104 if (nArrayLen > 2) { 116 if (nArrayLen > 2) {
105 array.GetElement(2, value); 117 array.GetElement(pRuntime->GetIsolate(), 2, value);
106 d2 = value.ToDouble(); 118 d2 = value.ToDouble();
107 } 119 }
108 120
109 if (nArrayLen > 3) { 121 if (nArrayLen > 3) {
110 array.GetElement(3, value); 122 array.GetElement(pRuntime->GetIsolate(), 3, value);
111 d3 = value.ToDouble(); 123 d3 = value.ToDouble();
112 } 124 }
113 125
114 if (nArrayLen > 4) { 126 if (nArrayLen > 4) {
115 array.GetElement(4, value); 127 array.GetElement(pRuntime->GetIsolate(), 4, value);
116 d4 = value.ToDouble(); 128 d4 = value.ToDouble();
117 } 129 }
118 130
119 if (sSpace == "T") { 131 if (sSpace == "T") {
120 color = CPWL_Color(COLORTYPE_TRANSPARENT); 132 *color = CPWL_Color(COLORTYPE_TRANSPARENT);
121 } else if (sSpace == "G") { 133 } else if (sSpace == "G") {
122 color = CPWL_Color(COLORTYPE_GRAY, (FX_FLOAT)d1); 134 *color = CPWL_Color(COLORTYPE_GRAY, (FX_FLOAT)d1);
123 } else if (sSpace == "RGB") { 135 } else if (sSpace == "RGB") {
124 color = CPWL_Color(COLORTYPE_RGB, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3); 136 *color =
137 CPWL_Color(COLORTYPE_RGB, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3);
125 } else if (sSpace == "CMYK") { 138 } else if (sSpace == "CMYK") {
126 color = CPWL_Color(COLORTYPE_CMYK, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3, 139 *color = CPWL_Color(COLORTYPE_CMYK, (FX_FLOAT)d1, (FX_FLOAT)d2,
127 (FX_FLOAT)d4); 140 (FX_FLOAT)d3, (FX_FLOAT)d4);
128 } 141 }
129 } 142 }
130 143
131 #define JS_IMPLEMENT_COLORPROP(prop, var) \ 144 #define JS_IMPLEMENT_COLORPROP(prop, var) \
132 FX_BOOL color::prop(IJS_Context* cc, CJS_PropValue& vp, \ 145 FX_BOOL color::prop(IJS_Context* cc, CJS_PropValue& vp, \
133 CFX_WideString& sError) { \ 146 CFX_WideString& sError) { \
134 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); \ 147 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); \
135 CJS_Array array(pRuntime); \ 148 CJS_Array array; \
136 if (vp.IsGetting()) { \ 149 if (vp.IsGetting()) { \
137 ConvertPWLColorToArray(var, array); \ 150 ConvertPWLColorToArray(pRuntime, var, &array); \
138 vp << array; \ 151 vp << array; \
139 } else { \ 152 } else { \
140 if (!vp.ConvertToArray(array)) \ 153 if (!vp.ConvertToArray(array)) \
141 return FALSE; \ 154 return FALSE; \
142 ConvertArrayToPWLColor(array, var); \ 155 ConvertArrayToPWLColor(pRuntime, array, &var); \
143 } \ 156 } \
144 return TRUE; \ 157 return TRUE; \
145 } 158 }
146 159
147 JS_IMPLEMENT_COLORPROP(transparent, m_crTransparent) 160 JS_IMPLEMENT_COLORPROP(transparent, m_crTransparent)
148 JS_IMPLEMENT_COLORPROP(black, m_crBlack) 161 JS_IMPLEMENT_COLORPROP(black, m_crBlack)
149 JS_IMPLEMENT_COLORPROP(white, m_crWhite) 162 JS_IMPLEMENT_COLORPROP(white, m_crWhite)
150 JS_IMPLEMENT_COLORPROP(red, m_crRed) 163 JS_IMPLEMENT_COLORPROP(red, m_crRed)
151 JS_IMPLEMENT_COLORPROP(green, m_crGreen) 164 JS_IMPLEMENT_COLORPROP(green, m_crGreen)
152 JS_IMPLEMENT_COLORPROP(blue, m_crBlue) 165 JS_IMPLEMENT_COLORPROP(blue, m_crBlue)
153 JS_IMPLEMENT_COLORPROP(cyan, m_crCyan) 166 JS_IMPLEMENT_COLORPROP(cyan, m_crCyan)
154 JS_IMPLEMENT_COLORPROP(magenta, m_crMagenta) 167 JS_IMPLEMENT_COLORPROP(magenta, m_crMagenta)
155 JS_IMPLEMENT_COLORPROP(yellow, m_crYellow) 168 JS_IMPLEMENT_COLORPROP(yellow, m_crYellow)
156 JS_IMPLEMENT_COLORPROP(dkGray, m_crDKGray) 169 JS_IMPLEMENT_COLORPROP(dkGray, m_crDKGray)
157 JS_IMPLEMENT_COLORPROP(gray, m_crGray) 170 JS_IMPLEMENT_COLORPROP(gray, m_crGray)
158 JS_IMPLEMENT_COLORPROP(ltGray, m_crLTGray) 171 JS_IMPLEMENT_COLORPROP(ltGray, m_crLTGray)
159 172
160 FX_BOOL color::convert(IJS_Context* cc, 173 FX_BOOL color::convert(IJS_Context* cc,
161 const std::vector<CJS_Value>& params, 174 const std::vector<CJS_Value>& params,
162 CJS_Value& vRet, 175 CJS_Value& vRet,
163 CFX_WideString& sError) { 176 CFX_WideString& sError) {
164 int iSize = params.size(); 177 int iSize = params.size();
165 if (iSize < 2) 178 if (iSize < 2)
166 return FALSE; 179 return FALSE;
167 180
168 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 181 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
169 CJS_Array aSource(pRuntime); 182 CJS_Array aSource;
170 if (!params[0].ConvertToArray(aSource)) 183 if (!params[0].ConvertToArray(aSource))
171 return FALSE; 184 return FALSE;
172 185
173 CPWL_Color crSource; 186 CPWL_Color crSource;
174 ConvertArrayToPWLColor(aSource, crSource); 187 ConvertArrayToPWLColor(pRuntime, aSource, &crSource);
175 188
176 CFX_ByteString sDestSpace = params[1].ToCFXByteString(); 189 CFX_ByteString sDestSpace = params[1].ToCFXByteString();
177 int nColorType = COLORTYPE_TRANSPARENT; 190 int nColorType = COLORTYPE_TRANSPARENT;
178 191
179 if (sDestSpace == "T") { 192 if (sDestSpace == "T") {
180 nColorType = COLORTYPE_TRANSPARENT; 193 nColorType = COLORTYPE_TRANSPARENT;
181 } else if (sDestSpace == "G") { 194 } else if (sDestSpace == "G") {
182 nColorType = COLORTYPE_GRAY; 195 nColorType = COLORTYPE_GRAY;
183 } else if (sDestSpace == "RGB") { 196 } else if (sDestSpace == "RGB") {
184 nColorType = COLORTYPE_RGB; 197 nColorType = COLORTYPE_RGB;
185 } else if (sDestSpace == "CMYK") { 198 } else if (sDestSpace == "CMYK") {
186 nColorType = COLORTYPE_CMYK; 199 nColorType = COLORTYPE_CMYK;
187 } 200 }
188 201
189 CJS_Array aDest(pRuntime); 202 CJS_Array aDest;
190 CPWL_Color crDest = crSource; 203 CPWL_Color crDest = crSource;
191 crDest.ConvertColorType(nColorType); 204 crDest.ConvertColorType(nColorType);
192 ConvertPWLColorToArray(crDest, aDest); 205 ConvertPWLColorToArray(pRuntime, crDest, &aDest);
193 vRet = aDest; 206 vRet = CJS_Value(pRuntime, aDest);
194 207
195 return TRUE; 208 return TRUE;
196 } 209 }
197 210
198 FX_BOOL color::equal(IJS_Context* cc, 211 FX_BOOL color::equal(IJS_Context* cc,
199 const std::vector<CJS_Value>& params, 212 const std::vector<CJS_Value>& params,
200 CJS_Value& vRet, 213 CJS_Value& vRet,
201 CFX_WideString& sError) { 214 CFX_WideString& sError) {
202 if (params.size() < 2) 215 if (params.size() < 2)
203 return FALSE; 216 return FALSE;
204 217
205 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 218 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
206 CJS_Array array1(pRuntime); 219 CJS_Array array1;
207 CJS_Array array2(pRuntime); 220 CJS_Array array2;
208 if (!params[0].ConvertToArray(array1)) 221 if (!params[0].ConvertToArray(array1))
209 return FALSE; 222 return FALSE;
210 if (!params[1].ConvertToArray(array2)) 223 if (!params[1].ConvertToArray(array2))
211 return FALSE; 224 return FALSE;
212 225
213 CPWL_Color color1; 226 CPWL_Color color1;
214 CPWL_Color color2; 227 CPWL_Color color2;
215 ConvertArrayToPWLColor(array1, color1); 228 ConvertArrayToPWLColor(pRuntime, array1, &color1);
216 ConvertArrayToPWLColor(array2, color2); 229 ConvertArrayToPWLColor(pRuntime, array2, &color2);
217 color1.ConvertColorType(color2.nColorType); 230 color1.ConvertColorType(color2.nColorType);
218 vRet = color1 == color2; 231 vRet = color1 == color2;
219 return TRUE; 232 return TRUE;
220 } 233 }
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/color.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698