1 // Copyright 2014 The PDFium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef CORE_FXCRT_FX_SYSTEM_H_ 8 #define CORE_FXCRT_FX_SYSTEM_H_ 9 10 #include <stddef.h> 11 #include <stdint.h> 12 #include <stdio.h> 13 #include <stdlib.h> 14 #include <wchar.h> 15 16 #include "build/build_config.h" 17 #include "core/fxcrt/fx_types.h" 18 19 #if defined(_MSC_VER) && _MSC_VER < 1900 20 #error Sorry, VC++ 2015 or later is required to compile PDFium. 21 #endif // defined(_MSC_VER) && _MSC_VER < 1900 22 23 #if defined(__wasm__) && defined(PDF_ENABLE_V8) 24 #error Cannot compile v8 with wasm. 25 #endif // PDF_ENABLE_V8 26 27 #if BUILDFLAG(IS_WIN) 28 #include <windows.h> 29 #endif // BUILDFLAG(IS_WIN) 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif // __cplusplus 34 35 #define FXSYS_IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001) 36 #define FXSYS_IsFloatBigger(fa, fb) \ 37 ((fa) > (fb) && !FXSYS_IsFloatZero((fa) - (fb))) 38 #define FXSYS_IsFloatSmaller(fa, fb) \ 39 ((fa) < (fb) && !FXSYS_IsFloatZero((fa) - (fb))) 40 #define FXSYS_IsFloatEqual(fa, fb) FXSYS_IsFloatZero((fa) - (fb)) 41 42 // M_PI not universally present on all platforms. 43 #define FXSYS_PI 3.1415926535897932384626433832795f 44 #define FXSYS_BEZIER 0.5522847498308f 45 46 // NOTE: prevent use of the return value from snprintf() since some platforms 47 // have different return values. 48 #define FXSYS_snprintf (void)snprintf 49 #define FXSYS_vsnprintf (void)vsnprintf 50 #define FXSYS_sprintf DO_NOT_USE_SPRINTF_DIE_DIE_DIE 51 #define FXSYS_vsprintf DO_NOT_USE_VSPRINTF_DIE_DIE_DIE 52 53 #if BUILDFLAG(IS_WIN) 54 #define FXSYS_itoa _itoa 55 #define FXSYS_strlwr _strlwr 56 #define FXSYS_strupr _strupr 57 #define FXSYS_stricmp _stricmp 58 #define FXSYS_wcsicmp _wcsicmp 59 #define FXSYS_wcslwr _wcslwr 60 #define FXSYS_wcsupr _wcsupr 61 size_t FXSYS_wcsftime(wchar_t* strDest, 62 size_t maxsize, 63 const wchar_t* format, 64 const struct tm* timeptr); 65 #define FXSYS_SetLastError SetLastError 66 #define FXSYS_GetLastError GetLastError 67 #else // BUILDFLAG(IS_WIN) 68 char* FXSYS_itoa(int value, char* str, int radix); 69 char* FXSYS_strlwr(char* str); 70 char* FXSYS_strupr(char* str); 71 int FXSYS_stricmp(const char* str1, const char* str2); 72 int FXSYS_wcsicmp(const wchar_t* str1, const wchar_t* str2); 73 wchar_t* FXSYS_wcslwr(wchar_t* str); 74 wchar_t* FXSYS_wcsupr(wchar_t* str); 75 #define FXSYS_wcsftime wcsftime 76 void FXSYS_SetLastError(uint32_t err); 77 uint32_t FXSYS_GetLastError(); 78 #endif // BUILDFLAG(IS_WIN) 79 80 int32_t FXSYS_atoi(const char* str); 81 uint32_t FXSYS_atoui(const char* str); 82 int32_t FXSYS_wtoi(const wchar_t* str); 83 int64_t FXSYS_atoi64(const char* str); 84 const char* FXSYS_i64toa(int64_t value, char* str, int radix); 85 int FXSYS_roundf(float f); 86 int FXSYS_round(double d); 87 float FXSYS_sqrt2(float a, float b); 88 89 #ifdef __cplusplus 90 } // extern "C" 91 92 // C++-only section 93 94 // Could be C, but uses C++-style casting. 95 #define FXSYS_UINT16_GET_LSBFIRST(p) \ 96 (static_cast<uint16_t>( \ 97 (static_cast<uint32_t>(static_cast<uint8_t>((p)[1])) << 8) | \ 98 (static_cast<uint32_t>(static_cast<uint8_t>((p)[0]))))) 99 #define FXSYS_UINT16_GET_MSBFIRST(p) \ 100 (static_cast<uint16_t>( \ 101 (static_cast<uint32_t>(static_cast<uint8_t>((p)[0])) << 8) | \ 102 (static_cast<uint32_t>(static_cast<uint8_t>((p)[1]))))) 103 #define FXSYS_UINT32_GET_LSBFIRST(p) \ 104 ((static_cast<uint32_t>(static_cast<uint8_t>((p)[3])) << 24) | \ 105 (static_cast<uint32_t>(static_cast<uint8_t>((p)[2])) << 16) | \ 106 (static_cast<uint32_t>(static_cast<uint8_t>((p)[1])) << 8) | \ 107 (static_cast<uint32_t>(static_cast<uint8_t>((p)[0])))) 108 #define FXSYS_UINT32_GET_MSBFIRST(p) \ 109 ((static_cast<uint32_t>(static_cast<uint8_t>((p)[0])) << 24) | \ 110 (static_cast<uint32_t>(static_cast<uint8_t>((p)[1])) << 16) | \ 111 (static_cast<uint32_t>(static_cast<uint8_t>((p)[2])) << 8) | \ 112 (static_cast<uint32_t>(static_cast<uint8_t>((p)[3])))) 113 #endif // __cplusplus 114 115 #endif // CORE_FXCRT_FX_SYSTEM_H_ 116