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 "core/fxcrt/fx_basic.h" | 7 #include "core/fxcrt/fx_basic.h" |
8 #include "core/fxcrt/fx_ext.h" | 8 #include "core/fxcrt/fx_ext.h" |
9 | 9 |
10 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 10 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 | 78 |
79 int* pInt = static_cast<int*>(pData); | 79 int* pInt = static_cast<int*>(pData); |
80 *pInt = value; | 80 *pInt = value; |
81 return true; | 81 return true; |
82 } | 82 } |
83 | 83 |
84 static const FX_FLOAT fraction_scales[] = { | 84 static const FX_FLOAT fraction_scales[] = { |
85 0.1f, 0.01f, 0.001f, 0.0001f, | 85 0.1f, 0.01f, 0.001f, 0.0001f, |
86 0.00001f, 0.000001f, 0.0000001f, 0.00000001f, | 86 0.00001f, 0.000001f, 0.0000001f, 0.00000001f, |
87 0.000000001f, 0.0000000001f, 0.00000000001f}; | 87 0.000000001f, 0.0000000001f, 0.00000000001f}; |
88 | |
88 int FXSYS_FractionalScaleCount() { | 89 int FXSYS_FractionalScaleCount() { |
89 return FX_ArraySize(fraction_scales); | 90 return FX_ArraySize(fraction_scales); |
90 } | 91 } |
91 | 92 |
92 FX_FLOAT FXSYS_FractionalScale(size_t scale_factor, int value) { | 93 FX_FLOAT FXSYS_FractionalScale(size_t scale_factor, int value) { |
93 return fraction_scales[scale_factor] * value; | 94 return fraction_scales[scale_factor] * value; |
94 } | 95 } |
95 | 96 |
96 FX_FLOAT FX_atof(const CFX_ByteStringC& strc) { | 97 FX_FLOAT FX_atof(const CFX_ByteStringC& strc) { |
97 if (strc.IsEmpty()) | 98 if (strc.IsEmpty()) |
98 return 0.0; | 99 return 0.0; |
99 | 100 |
100 int cc = 0; | 101 int cc = 0; |
101 bool bNegative = false; | 102 bool bNegative = false; |
102 int len = strc.GetLength(); | 103 int len = strc.GetLength(); |
103 if (strc[0] == '+') { | 104 if (strc[0] == '+') { |
104 cc++; | 105 cc++; |
105 } else if (strc[0] == '-') { | 106 } else if (strc[0] == '-') { |
106 bNegative = TRUE; | 107 bNegative = TRUE; |
107 cc++; | 108 cc++; |
108 } | 109 } |
109 while (cc < len) { | 110 while (cc < len) { |
110 if (strc[cc] != '+' && strc[cc] != '-') { | 111 if (strc[cc] != '+' && strc[cc] != '-') |
111 break; | 112 break; |
112 } | |
113 cc++; | 113 cc++; |
114 } | 114 } |
115 FX_FLOAT value = 0; | 115 FX_FLOAT value = 0; |
116 while (cc < len) { | 116 while (cc < len) { |
117 if (strc[cc] == '.') { | 117 if (strc[cc] == '.') |
118 break; | 118 break; |
119 } | |
120 value = value * 10 + FXSYS_toDecimalDigit(strc.CharAt(cc)); | 119 value = value * 10 + FXSYS_toDecimalDigit(strc.CharAt(cc)); |
121 cc++; | 120 cc++; |
122 } | 121 } |
123 int scale = 0; | 122 int scale = 0; |
124 if (cc < len && strc[cc] == '.') { | 123 if (cc < len && strc[cc] == '.') { |
125 cc++; | 124 cc++; |
126 while (cc < len) { | 125 while (cc < len) { |
127 value += | 126 value += |
128 FXSYS_FractionalScale(scale, FXSYS_toDecimalDigit(strc.CharAt(cc))); | 127 FXSYS_FractionalScale(scale, FXSYS_toDecimalDigit(strc.CharAt(cc))); |
129 scale++; | 128 scale++; |
130 if (scale == FXSYS_FractionalScaleCount()) | 129 if (scale == FXSYS_FractionalScaleCount()) |
131 break; | 130 break; |
132 cc++; | 131 cc++; |
133 } | 132 } |
134 } | 133 } |
135 return bNegative ? -value : value; | 134 return bNegative ? -value : value; |
136 } | 135 } |
137 | 136 |
138 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900 | 137 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900 |
139 void FXSYS_snprintf(char* str, | 138 void FXSYS_snprintf(char* str, |
140 size_t size, | 139 size_t size, |
141 _Printf_format_string_ const char* fmt, | 140 _Printf_format_string_ const char* fmt, |
142 ...) { | 141 ...) { |
143 va_list ap; | 142 va_list ap; |
144 va_start(ap, fmt); | 143 va_start(ap, fmt); |
145 FXSYS_vsnprintf(str, size, fmt, ap); | 144 FXSYS_vsnprintf(str, size, fmt, ap); |
146 va_end(ap); | 145 va_end(ap); |
147 } | 146 } |
147 | |
148 void FXSYS_vsnprintf(char* str, size_t size, const char* fmt, va_list ap) { | 148 void FXSYS_vsnprintf(char* str, size_t size, const char* fmt, va_list ap) { |
149 (void)_vsnprintf(str, size, fmt, ap); | 149 (void)_vsnprintf(str, size, fmt, ap); |
150 if (size) { | 150 if (size) |
151 str[size - 1] = 0; | 151 str[size - 1] = 0; |
152 } | |
153 } | 152 } |
154 #endif // _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900 | 153 #endif // _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900 |
155 | 154 |
156 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 155 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
157 class CFindFileData { | 156 class CFindFileData { |
158 public: | 157 public: |
159 virtual ~CFindFileData() {} | 158 virtual ~CFindFileData() {} |
160 HANDLE m_Handle; | 159 HANDLE m_Handle; |
161 FX_BOOL m_bEnd; | 160 bool m_bEnd; |
162 }; | 161 }; |
163 | 162 |
164 class CFindFileDataA : public CFindFileData { | 163 class CFindFileDataA : public CFindFileData { |
165 public: | 164 public: |
166 ~CFindFileDataA() override {} | 165 ~CFindFileDataA() override {} |
167 WIN32_FIND_DATAA m_FindData; | 166 WIN32_FIND_DATAA m_FindData; |
168 }; | 167 }; |
169 | 168 |
170 class CFindFileDataW : public CFindFileData { | 169 class CFindFileDataW : public CFindFileData { |
171 public: | 170 public: |
172 ~CFindFileDataW() override {} | 171 ~CFindFileDataW() override {} |
173 WIN32_FIND_DATAW m_FindData; | 172 WIN32_FIND_DATAW m_FindData; |
174 }; | 173 }; |
175 #endif | 174 #endif |
176 | 175 |
177 void* FX_OpenFolder(const FX_CHAR* path) { | 176 void* FX_OpenFolder(const FX_CHAR* path) { |
178 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 177 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
179 std::unique_ptr<CFindFileDataA> pData(new CFindFileDataA); | 178 std::unique_ptr<CFindFileDataA> pData(new CFindFileDataA); |
180 pData->m_Handle = FindFirstFileExA((CFX_ByteString(path) + "/*.*").c_str(), | 179 pData->m_Handle = FindFirstFileExA((CFX_ByteString(path) + "/*.*").c_str(), |
181 FindExInfoStandard, &pData->m_FindData, | 180 FindExInfoStandard, &pData->m_FindData, |
182 FindExSearchNameMatch, nullptr, 0); | 181 FindExSearchNameMatch, nullptr, 0); |
183 if (pData->m_Handle == INVALID_HANDLE_VALUE) | 182 if (pData->m_Handle == INVALID_HANDLE_VALUE) |
184 return nullptr; | 183 return nullptr; |
185 | 184 |
186 pData->m_bEnd = FALSE; | 185 pData->m_bEnd = false; |
187 return pData.release(); | 186 return pData.release(); |
188 #else | 187 #else |
189 DIR* dir = opendir(path); | 188 DIR* dir = opendir(path); |
190 return dir; | 189 return dir; |
191 #endif | 190 #endif |
192 } | 191 } |
193 | 192 |
194 void* FX_OpenFolder(const FX_WCHAR* path) { | 193 bool FX_GetNextFile(void* handle, CFX_ByteString& filename, bool& bFolder) { |
195 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 194 if (!handle) |
196 std::unique_ptr<CFindFileDataW> pData(new CFindFileDataW); | 195 return false; |
197 pData->m_Handle = FindFirstFileExW((CFX_WideString(path) + L"/*.*").c_str(), | |
198 FindExInfoStandard, &pData->m_FindData, | |
199 FindExSearchNameMatch, nullptr, 0); | |
200 if (pData->m_Handle == INVALID_HANDLE_VALUE) | |
201 return nullptr; | |
202 | 196 |
203 pData->m_bEnd = FALSE; | |
204 return pData.release(); | |
205 #else | |
206 DIR* dir = opendir(CFX_ByteString::FromUnicode(path).c_str()); | |
207 return dir; | |
208 #endif | |
209 } | |
210 FX_BOOL FX_GetNextFile(void* handle, | |
211 CFX_ByteString& filename, | |
212 FX_BOOL& bFolder) { | |
213 if (!handle) { | |
214 return FALSE; | |
215 } | |
216 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 197 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
dsinclair
2016/10/12 20:43:23
Can we duplicate the method signature inside the #
npm
2016/10/12 22:13:19
Cleaner: created typedef for file handle.
| |
217 CFindFileDataA* pData = (CFindFileDataA*)handle; | 198 CFindFileDataA* pData = (CFindFileDataA*)handle; |
218 if (pData->m_bEnd) | 199 if (pData->m_bEnd) |
219 return FALSE; | 200 return false; |
220 | 201 |
221 filename = pData->m_FindData.cFileName; | 202 filename = pData->m_FindData.cFileName; |
222 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; | 203 bFolder = |
204 (pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; | |
223 if (!FindNextFileA(pData->m_Handle, &pData->m_FindData)) | 205 if (!FindNextFileA(pData->m_Handle, &pData->m_FindData)) |
224 pData->m_bEnd = TRUE; | 206 pData->m_bEnd = true; |
225 return TRUE; | 207 return true; |
226 #elif defined(__native_client__) | 208 #elif defined(__native_client__) |
dsinclair
2016/10/12 20:43:23
Do we even support building under __native_client_
npm
2016/10/12 22:13:19
Deleted... Tom?
| |
227 abort(); | 209 abort(); |
228 return FALSE; | 210 return false; |
229 #else | 211 #else |
230 struct dirent* de = readdir((DIR*)handle); | 212 struct dirent* de = readdir((DIR*)handle); |
231 if (!de) { | 213 if (!de) |
232 return FALSE; | 214 return false; |
233 } | |
234 filename = de->d_name; | 215 filename = de->d_name; |
235 bFolder = de->d_type == DT_DIR; | 216 bFolder = de->d_type == DT_DIR; |
236 return TRUE; | 217 return true; |
237 #endif | 218 #endif |
238 } | 219 } |
239 FX_BOOL FX_GetNextFile(void* handle, | 220 |
240 CFX_WideString& filename, | |
241 FX_BOOL& bFolder) { | |
242 if (!handle) { | |
243 return FALSE; | |
244 } | |
245 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | |
246 CFindFileDataW* pData = (CFindFileDataW*)handle; | |
247 if (pData->m_bEnd) { | |
248 return FALSE; | |
249 } | |
250 filename = pData->m_FindData.cFileName; | |
251 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; | |
252 if (!FindNextFileW(pData->m_Handle, &pData->m_FindData)) { | |
253 pData->m_bEnd = TRUE; | |
254 } | |
255 return TRUE; | |
256 #elif defined(__native_client__) | |
257 abort(); | |
258 return FALSE; | |
259 #else | |
260 struct dirent* de = readdir((DIR*)handle); | |
261 if (!de) { | |
262 return FALSE; | |
263 } | |
264 filename = CFX_WideString::FromLocal(de->d_name); | |
265 bFolder = de->d_type == DT_DIR; | |
266 return TRUE; | |
267 #endif | |
268 } | |
269 void FX_CloseFolder(void* handle) { | 221 void FX_CloseFolder(void* handle) { |
270 if (!handle) { | 222 if (!handle) |
271 return; | 223 return; |
272 } | 224 |
273 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 225 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
274 CFindFileData* pData = (CFindFileData*)handle; | 226 CFindFileData* pData = (CFindFileData*)handle; |
275 FindClose(pData->m_Handle); | 227 FindClose(pData->m_Handle); |
276 delete pData; | 228 delete pData; |
277 #else | 229 #else |
278 closedir((DIR*)handle); | 230 closedir((DIR*)handle); |
279 #endif | 231 #endif |
280 } | 232 } |
233 | |
281 FX_WCHAR FX_GetFolderSeparator() { | 234 FX_WCHAR FX_GetFolderSeparator() { |
282 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 235 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
283 return '\\'; | 236 return '\\'; |
284 #else | 237 #else |
285 return '/'; | 238 return '/'; |
286 #endif | 239 #endif |
287 } | 240 } |
288 | 241 |
289 CFX_Matrix_3by3 CFX_Matrix_3by3::Inverse() { | 242 CFX_Matrix_3by3 CFX_Matrix_3by3::Inverse() { |
290 FX_FLOAT det = | 243 FX_FLOAT det = |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 if (nbits < 8 && nbits + bitCount <= 8) { | 276 if (nbits < 8 && nbits + bitCount <= 8) { |
324 bitShift = 8 - nbits - bitCount; | 277 bitShift = 8 - nbits - bitCount; |
325 bitMask = (1 << nbits) - 1; | 278 bitMask = (1 << nbits) - 1; |
326 dstShift = 0; | 279 dstShift = 0; |
327 } else { | 280 } else { |
328 bitShift = 0; | 281 bitShift = 0; |
329 int bitOffset = 8 - bitCount; | 282 int bitOffset = 8 - bitCount; |
330 bitMask = (1 << std::min(bitOffset, nbits)) - 1; | 283 bitMask = (1 << std::min(bitOffset, nbits)) - 1; |
331 dstShift = nbits - bitOffset; | 284 dstShift = nbits - bitOffset; |
332 } | 285 } |
333 uint32_t result = (uint32_t)(*dataPtr++ >> bitShift & bitMask) << dstShift; | 286 uint32_t result = |
287 static_cast<uint32_t>((*dataPtr++ >> bitShift & bitMask) << dstShift); | |
334 while (dstShift >= 8) { | 288 while (dstShift >= 8) { |
335 dstShift -= 8; | 289 dstShift -= 8; |
336 result |= *dataPtr++ << dstShift; | 290 result |= *dataPtr++ << dstShift; |
337 } | 291 } |
338 if (dstShift > 0) { | 292 if (dstShift > 0) { |
339 bitShift = 8 - dstShift; | 293 bitShift = 8 - dstShift; |
340 bitMask = (1 << dstShift) - 1; | 294 bitMask = (1 << dstShift) - 1; |
341 result |= *dataPtr++ >> bitShift & bitMask; | 295 result |= *dataPtr++ >> bitShift & bitMask; |
342 } | 296 } |
343 return result; | 297 return result; |
344 } | 298 } |
OLD | NEW |