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

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

Issue 1265503005: clang-format all pdfium code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: sigh Created 5 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 "../../include/javascript/JavaScript.h" 7 #include "../../include/javascript/JavaScript.h"
8 #include "../../include/javascript/IJavaScript.h" 8 #include "../../include/javascript/IJavaScript.h"
9 #include "../../include/javascript/JS_Define.h" 9 #include "../../include/javascript/JS_Define.h"
10 #include "../../include/javascript/JS_Object.h" 10 #include "../../include/javascript/JS_Object.h"
11 #include "../../include/javascript/JS_Value.h" 11 #include "../../include/javascript/JS_Value.h"
12 #include "../../include/javascript/color.h" 12 #include "../../include/javascript/color.h"
13 #include "../../include/javascript/JS_EventHandler.h" 13 #include "../../include/javascript/JS_EventHandler.h"
14 #include "../../include/javascript/JS_Context.h" 14 #include "../../include/javascript/JS_Context.h"
15 #include "../../include/javascript/JS_Runtime.h" 15 #include "../../include/javascript/JS_Runtime.h"
16 16
17 static v8::Isolate* GetIsolate(IFXJS_Context* cc) 17 static v8::Isolate* GetIsolate(IFXJS_Context* cc) {
18 { 18 CJS_Context* pContext = (CJS_Context*)cc;
19 » CJS_Context* pContext = (CJS_Context *)cc; 19 ASSERT(pContext != NULL);
20 » ASSERT(pContext != NULL);
21 20
22 » CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 21 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
23 » ASSERT(pRuntime != NULL); 22 ASSERT(pRuntime != NULL);
24 23
25 » return pRuntime->GetIsolate(); 24 return pRuntime->GetIsolate();
26 } 25 }
27 /* -------------------------- color -------------------------- */ 26 /* -------------------------- color -------------------------- */
28 27
29 BEGIN_JS_STATIC_CONST(CJS_Color) 28 BEGIN_JS_STATIC_CONST(CJS_Color)
30 END_JS_STATIC_CONST() 29 END_JS_STATIC_CONST()
31 30
32 BEGIN_JS_STATIC_PROP(CJS_Color) 31 BEGIN_JS_STATIC_PROP(CJS_Color)
33 » JS_STATIC_PROP_ENTRY(black) 32 JS_STATIC_PROP_ENTRY(black)
34 » JS_STATIC_PROP_ENTRY(blue) 33 JS_STATIC_PROP_ENTRY(blue)
35 » JS_STATIC_PROP_ENTRY(cyan) 34 JS_STATIC_PROP_ENTRY(cyan)
36 » JS_STATIC_PROP_ENTRY(dkGray) 35 JS_STATIC_PROP_ENTRY(dkGray)
37 » JS_STATIC_PROP_ENTRY(gray) 36 JS_STATIC_PROP_ENTRY(gray)
38 » JS_STATIC_PROP_ENTRY(green) 37 JS_STATIC_PROP_ENTRY(green)
39 » JS_STATIC_PROP_ENTRY(ltGray) 38 JS_STATIC_PROP_ENTRY(ltGray)
40 » JS_STATIC_PROP_ENTRY(magenta) 39 JS_STATIC_PROP_ENTRY(magenta)
41 » JS_STATIC_PROP_ENTRY(red) 40 JS_STATIC_PROP_ENTRY(red)
42 » JS_STATIC_PROP_ENTRY(transparent) 41 JS_STATIC_PROP_ENTRY(transparent)
43 » JS_STATIC_PROP_ENTRY(white) 42 JS_STATIC_PROP_ENTRY(white)
44 » JS_STATIC_PROP_ENTRY(yellow) 43 JS_STATIC_PROP_ENTRY(yellow)
45 END_JS_STATIC_PROP() 44 END_JS_STATIC_PROP()
46 45
47 BEGIN_JS_STATIC_METHOD(CJS_Color) 46 BEGIN_JS_STATIC_METHOD(CJS_Color)
48 » JS_STATIC_METHOD_ENTRY(convert) 47 JS_STATIC_METHOD_ENTRY(convert)
49 » JS_STATIC_METHOD_ENTRY(equal) 48 JS_STATIC_METHOD_ENTRY(equal)
50 END_JS_STATIC_METHOD() 49 END_JS_STATIC_METHOD()
51 50
52 IMPLEMENT_JS_CLASS(CJS_Color,color) 51 IMPLEMENT_JS_CLASS(CJS_Color, color)
53 52
54 color::color(CJS_Object* pJSObject): CJS_EmbedObj(pJSObject) 53 color::color(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {
55 { 54 m_crTransparent = CPWL_Color(COLORTYPE_TRANSPARENT);
56 » m_crTransparent = CPWL_Color(COLORTYPE_TRANSPARENT); 55 m_crBlack = CPWL_Color(COLORTYPE_GRAY, 0);
57 » m_crBlack = CPWL_Color(COLORTYPE_GRAY, 0); 56 m_crWhite = CPWL_Color(COLORTYPE_GRAY, 1);
58 » m_crWhite = CPWL_Color(COLORTYPE_GRAY, 1); 57 m_crRed = CPWL_Color(COLORTYPE_RGB, 1, 0, 0);
59 » m_crRed = CPWL_Color(COLORTYPE_RGB, 1, 0 ,0); 58 m_crGreen = CPWL_Color(COLORTYPE_RGB, 0, 1, 0);
60 » m_crGreen = CPWL_Color(COLORTYPE_RGB, 0, 1 ,0); 59 m_crBlue = CPWL_Color(COLORTYPE_RGB, 0, 0, 1);
61 » m_crBlue = CPWL_Color(COLORTYPE_RGB, 0, 0 ,1); 60 m_crCyan = CPWL_Color(COLORTYPE_CMYK, 1, 0, 0, 0);
62 » m_crCyan = CPWL_Color(COLORTYPE_CMYK, 1, 0 ,0, 0); 61 m_crMagenta = CPWL_Color(COLORTYPE_CMYK, 0, 1, 0, 0);
63 » m_crMagenta = CPWL_Color(COLORTYPE_CMYK, 0, 1 ,0, 0); 62 m_crYellow = CPWL_Color(COLORTYPE_CMYK, 0, 0, 1, 0);
64 » m_crYellow = CPWL_Color(COLORTYPE_CMYK, 0, 0 ,1, 0); 63 m_crDKGray = CPWL_Color(COLORTYPE_GRAY, 0.25);
65 » m_crDKGray = CPWL_Color(COLORTYPE_GRAY, 0.25); 64 m_crGray = CPWL_Color(COLORTYPE_GRAY, 0.5);
66 » m_crGray = CPWL_Color(COLORTYPE_GRAY, 0.5); 65 m_crLTGray = CPWL_Color(COLORTYPE_GRAY, 0.75);
67 » m_crLTGray = CPWL_Color(COLORTYPE_GRAY, 0.75);
68 } 66 }
69 67
70 color::~color(void) 68 color::~color(void) {}
71 { 69
70 void color::ConvertPWLColorToArray(const CPWL_Color& color, CJS_Array& array) {
71 switch (color.nColorType) {
72 case COLORTYPE_TRANSPARENT:
73 array.SetElement(0, CJS_Value(array.GetIsolate(), "T"));
74 break;
75 case COLORTYPE_GRAY:
76 array.SetElement(0, CJS_Value(array.GetIsolate(), "G"));
77 array.SetElement(1, CJS_Value(array.GetIsolate(), color.fColor1));
78 break;
79 case COLORTYPE_RGB:
80 array.SetElement(0, CJS_Value(array.GetIsolate(), "RGB"));
81 array.SetElement(1, CJS_Value(array.GetIsolate(), color.fColor1));
82 array.SetElement(2, CJS_Value(array.GetIsolate(), color.fColor2));
83 array.SetElement(3, CJS_Value(array.GetIsolate(), color.fColor3));
84 break;
85 case COLORTYPE_CMYK:
86 array.SetElement(0, CJS_Value(array.GetIsolate(), "CMYK"));
87 array.SetElement(1, CJS_Value(array.GetIsolate(), color.fColor1));
88 array.SetElement(2, CJS_Value(array.GetIsolate(), color.fColor2));
89 array.SetElement(3, CJS_Value(array.GetIsolate(), color.fColor3));
90 array.SetElement(4, CJS_Value(array.GetIsolate(), color.fColor4));
91 break;
92 }
72 } 93 }
73 94
74 void color::ConvertPWLColorToArray(const CPWL_Color& color, CJS_Array& array) 95 void color::ConvertArrayToPWLColor(CJS_Array& array, CPWL_Color& color) {
75 { 96 int nArrayLen = array.GetLength();
76 » switch (color.nColorType) 97 if (nArrayLen < 1)
77 » { 98 return;
78 » case COLORTYPE_TRANSPARENT: 99
79 » » array.SetElement(0, CJS_Value(array.GetIsolate(), "T")); 100 CJS_Value value(array.GetIsolate());
80 » » break; 101 array.GetElement(0, value);
81 » case COLORTYPE_GRAY: 102 CFX_ByteString sSpace = value.ToCFXByteString();
82 » » array.SetElement(0, CJS_Value(array.GetIsolate(),"G")); 103
83 » » array.SetElement(1, CJS_Value(array.GetIsolate(),color.fColor1)) ; 104 double d1 = 0;
84 » » break; 105 double d2 = 0;
85 » case COLORTYPE_RGB: 106 double d3 = 0;
86 » » array.SetElement(0, CJS_Value(array.GetIsolate(),"RGB")); 107 double d4 = 0;
87 » » array.SetElement(1, CJS_Value(array.GetIsolate(),color.fColor1)) ; 108
88 » » array.SetElement(2, CJS_Value(array.GetIsolate(),color.fColor2)) ; 109 if (nArrayLen > 1) {
89 » » array.SetElement(3, CJS_Value(array.GetIsolate(),color.fColor3)) ; 110 array.GetElement(1, value);
90 » » break; 111 d1 = value.ToDouble();
91 » case COLORTYPE_CMYK: 112 }
92 » » array.SetElement(0, CJS_Value(array.GetIsolate(),"CMYK")); 113
93 » » array.SetElement(1, CJS_Value(array.GetIsolate(),color.fColor1)) ; 114 if (nArrayLen > 2) {
94 » » array.SetElement(2, CJS_Value(array.GetIsolate(),color.fColor2)) ; 115 array.GetElement(2, value);
95 » » array.SetElement(3, CJS_Value(array.GetIsolate(),color.fColor3)) ; 116 d2 = value.ToDouble();
96 » » array.SetElement(4, CJS_Value(array.GetIsolate(),color.fColor4)) ; 117 }
97 » » break; 118
98 » } 119 if (nArrayLen > 3) {
120 array.GetElement(3, value);
121 d3 = value.ToDouble();
122 }
123
124 if (nArrayLen > 4) {
125 array.GetElement(4, value);
126 d4 = value.ToDouble();
127 }
128
129 if (sSpace == "T") {
130 color = CPWL_Color(COLORTYPE_TRANSPARENT);
131 } else if (sSpace == "G") {
132 color = CPWL_Color(COLORTYPE_GRAY, (FX_FLOAT)d1);
133 } else if (sSpace == "RGB") {
134 color = CPWL_Color(COLORTYPE_RGB, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3);
135 } else if (sSpace == "CMYK") {
136 color = CPWL_Color(COLORTYPE_CMYK, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3,
137 (FX_FLOAT)d4);
138 }
99 } 139 }
100 140
101 void color::ConvertArrayToPWLColor(CJS_Array& array, CPWL_Color& color) 141 #define JS_IMPLEMENT_COLORPROP(prop, var) \
102 { 142 FX_BOOL color::prop(IFXJS_Context* cc, CJS_PropValue& vp, \
103 » int nArrayLen = array.GetLength(); 143 CFX_WideString& sError) { \
104 » if (nArrayLen < 1) return; 144 CJS_Context* pContext = (CJS_Context*)cc; \
105 145 v8::Isolate* isolate = pContext->GetJSRuntime()->GetIsolate(); \
106 » CJS_Value value(array.GetIsolate()); 146 if (vp.IsGetting()) { \
107 » array.GetElement(0, value); 147 CJS_Array array(isolate); \
108 » CFX_ByteString sSpace = value.ToCFXByteString(); 148 ConvertPWLColorToArray(var, array); \
109 149 vp << array; \
110 » double d1 = 0; 150 } else { \
111 » double d2 = 0; 151 CJS_Array array(isolate); \
112 » double d3 = 0; 152 if (!vp.ConvertToArray(array)) \
113 » double d4 = 0; 153 return FALSE; \
114 154 ConvertArrayToPWLColor(array, var); \
115 » if (nArrayLen > 1) 155 } \
116 » { 156 return TRUE; \
117 » » array.GetElement(1, value); 157 }
118 » » d1 = value.ToDouble();
119 » }
120
121 » if (nArrayLen > 2)
122 » {
123 » » array.GetElement(2, value);
124 » » d2 = value.ToDouble();
125 » }
126
127 » if (nArrayLen > 3)
128 » {
129 » » array.GetElement(3, value);
130 » » d3 = value.ToDouble();
131 » }
132
133 » if (nArrayLen > 4)
134 » {
135 » » array.GetElement(4, value);
136 » » d4 = value.ToDouble();
137 » }
138
139 » if (sSpace == "T")
140 » {
141 » » color = CPWL_Color(COLORTYPE_TRANSPARENT);
142 » }
143 » else if (sSpace == "G")
144 » {
145 » » color = CPWL_Color(COLORTYPE_GRAY, (FX_FLOAT)d1);
146 » }
147 » else if (sSpace == "RGB")
148 » {
149 » » color = CPWL_Color(COLORTYPE_RGB, (FX_FLOAT)d1, (FX_FLOAT)d2, (F X_FLOAT)d3);
150 » }
151 » else if (sSpace == "CMYK")
152 » {
153 » » color = CPWL_Color(COLORTYPE_CMYK, (FX_FLOAT)d1, (FX_FLOAT)d2, ( FX_FLOAT)d3, (FX_FLOAT)d4);
154 » }
155 }
156
157 #define JS_IMPLEMENT_COLORPROP(prop, var)\
158 FX_BOOL color::prop(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError )\
159 {\
160 » CJS_Context* pContext = (CJS_Context*)cc;\
161 » v8::Isolate* isolate = pContext->GetJSRuntime()->GetIsolate();\
162 » if (vp.IsGetting())\
163 » {\
164 » » CJS_Array array(isolate);\
165 » » ConvertPWLColorToArray(var, array);\
166 » » vp << array;\
167 » }\
168 » else\
169 » {\
170 » » CJS_Array array(isolate);\
171 » » if (!vp.ConvertToArray(array)) return FALSE;\
172 » » ConvertArrayToPWLColor(array, var);\
173 » }\
174 » return TRUE;\
175 }
176 158
177 JS_IMPLEMENT_COLORPROP(transparent, m_crTransparent) 159 JS_IMPLEMENT_COLORPROP(transparent, m_crTransparent)
178 JS_IMPLEMENT_COLORPROP(black, m_crBlack) 160 JS_IMPLEMENT_COLORPROP(black, m_crBlack)
179 JS_IMPLEMENT_COLORPROP(white, m_crWhite) 161 JS_IMPLEMENT_COLORPROP(white, m_crWhite)
180 JS_IMPLEMENT_COLORPROP(red, m_crRed) 162 JS_IMPLEMENT_COLORPROP(red, m_crRed)
181 JS_IMPLEMENT_COLORPROP(green, m_crGreen) 163 JS_IMPLEMENT_COLORPROP(green, m_crGreen)
182 JS_IMPLEMENT_COLORPROP(blue, m_crBlue) 164 JS_IMPLEMENT_COLORPROP(blue, m_crBlue)
183 JS_IMPLEMENT_COLORPROP(cyan, m_crCyan) 165 JS_IMPLEMENT_COLORPROP(cyan, m_crCyan)
184 JS_IMPLEMENT_COLORPROP(magenta, m_crMagenta) 166 JS_IMPLEMENT_COLORPROP(magenta, m_crMagenta)
185 JS_IMPLEMENT_COLORPROP(yellow, m_crYellow) 167 JS_IMPLEMENT_COLORPROP(yellow, m_crYellow)
186 JS_IMPLEMENT_COLORPROP(dkGray, m_crDKGray) 168 JS_IMPLEMENT_COLORPROP(dkGray, m_crDKGray)
187 JS_IMPLEMENT_COLORPROP(gray, m_crGray) 169 JS_IMPLEMENT_COLORPROP(gray, m_crGray)
188 JS_IMPLEMENT_COLORPROP(ltGray, m_crLTGray) 170 JS_IMPLEMENT_COLORPROP(ltGray, m_crLTGray)
189 171
190 FX_BOOL color::convert(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Valu e& vRet, CFX_WideString& sError) 172 FX_BOOL color::convert(IFXJS_Context* cc,
191 { 173 const CJS_Parameters& params,
192 » v8::Isolate* isolate = GetIsolate(cc); 174 CJS_Value& vRet,
193 » int iSize = params.size(); 175 CFX_WideString& sError) {
194 » if (iSize < 2) return FALSE; 176 v8::Isolate* isolate = GetIsolate(cc);
195 » CJS_Array aSource(isolate); 177 int iSize = params.size();
196 » if (!params[0].ConvertToArray(aSource)) return FALSE; 178 if (iSize < 2)
179 return FALSE;
180 CJS_Array aSource(isolate);
181 if (!params[0].ConvertToArray(aSource))
182 return FALSE;
197 183
198 » CPWL_Color crSource; 184 CPWL_Color crSource;
199 » ConvertArrayToPWLColor(aSource, crSource); 185 ConvertArrayToPWLColor(aSource, crSource);
200 186
201 » CFX_ByteString sDestSpace = params[1].ToCFXByteString(); 187 CFX_ByteString sDestSpace = params[1].ToCFXByteString();
202 » int nColorType = COLORTYPE_TRANSPARENT; 188 int nColorType = COLORTYPE_TRANSPARENT;
203 189
204 » if (sDestSpace == "T") 190 if (sDestSpace == "T") {
205 » { 191 nColorType = COLORTYPE_TRANSPARENT;
206 » » nColorType = COLORTYPE_TRANSPARENT; 192 } else if (sDestSpace == "G") {
207 » } 193 nColorType = COLORTYPE_GRAY;
208 » else if (sDestSpace == "G") 194 } else if (sDestSpace == "RGB") {
209 » { 195 nColorType = COLORTYPE_RGB;
210 » » nColorType = COLORTYPE_GRAY; 196 } else if (sDestSpace == "CMYK") {
211 » } 197 nColorType = COLORTYPE_CMYK;
212 » else if (sDestSpace == "RGB") 198 }
213 » {
214 » » nColorType = COLORTYPE_RGB;
215 » }
216 » else if (sDestSpace == "CMYK")
217 » {
218 » » nColorType = COLORTYPE_CMYK;
219 » }
220 199
221 » CJS_Array aDest(isolate); 200 CJS_Array aDest(isolate);
222 » CPWL_Color crDest = crSource; 201 CPWL_Color crDest = crSource;
223 » crDest.ConvertColorType(nColorType); 202 crDest.ConvertColorType(nColorType);
224 » ConvertPWLColorToArray(crDest, aDest); 203 ConvertPWLColorToArray(crDest, aDest);
225 » vRet = aDest; 204 vRet = aDest;
226 205
227 » return TRUE; 206 return TRUE;
228 } 207 }
229 208
230 FX_BOOL color::equal(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) 209 FX_BOOL color::equal(IFXJS_Context* cc,
231 { 210 const CJS_Parameters& params,
232 » v8::Isolate* isolate = GetIsolate(cc); 211 CJS_Value& vRet,
233 » if (params.size() < 2) return FALSE; 212 CFX_WideString& sError) {
213 v8::Isolate* isolate = GetIsolate(cc);
214 if (params.size() < 2)
215 return FALSE;
234 216
235 » CJS_Array array1(isolate), array2(isolate); 217 CJS_Array array1(isolate), array2(isolate);
236 218
237 » if (!params[0].ConvertToArray(array1)) return FALSE; 219 if (!params[0].ConvertToArray(array1))
238 » if (!params[1].ConvertToArray(array2)) return FALSE; 220 return FALSE;
221 if (!params[1].ConvertToArray(array2))
222 return FALSE;
239 223
240 » CPWL_Color color1; 224 CPWL_Color color1;
241 » CPWL_Color color2; 225 CPWL_Color color2;
242 226
243 » ConvertArrayToPWLColor(array1, color1); 227 ConvertArrayToPWLColor(array1, color1);
244 » ConvertArrayToPWLColor(array2, color2); 228 ConvertArrayToPWLColor(array2, color2);
245 229
246 » color1.ConvertColorType(color2.nColorType); 230 color1.ConvertColorType(color2.nColorType);
247 231
248 » vRet = color1 == color2; 232 vRet = color1 == color2;
249 » return TRUE; 233 return TRUE;
250 } 234 }
251
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698