1 // Copyright 2014 PDFium Authors. All rights reserved. 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 _BC_UTILS_H_ 8 #define _BC_UTILS_H_ 9 typedef CFX_MapPtrTemplate<void*, int32_t> CFX_PtrToInt32; 10 FX_BOOL BC_FX_ByteString_Replace(CFX_ByteString& dst, 11 FX_DWORD first, 12 FX_DWORD last, 13 int32_t count, 14 FX_CHAR c); 15 void BC_FX_ByteString_Append(CFX_ByteString& dst, int32_t count, FX_CHAR c); 16 void BC_FX_ByteString_Append(CFX_ByteString& dst, const CFX_ByteArray& ba); 17 typedef FX_BOOL (*BC_PtrArrayCompareCallback)(void* l, void* r); 18 void BC_FX_PtrArray_Sort(CFX_PtrArray& src, BC_PtrArrayCompareCallback fun); 19 template <class _Ty> 20 class CBC_AutoPtr { 21 public: 22 typedef _Ty element_type; 23 explicit CBC_AutoPtr(_Ty* _P = 0) : _Owns(_P != 0), _Ptr(_P) {} 24 CBC_AutoPtr(const CBC_AutoPtr<_Ty>& _Y) 25 : _Owns(_Y._Owns), _Ptr(_Y.release()) {} 26 CBC_AutoPtr<_Ty>& operator=(const CBC_AutoPtr<_Ty>& _Y) { 27 if (this != &_Y) { 28 if (_Ptr != _Y.get()) { 29 if (_Owns) { 30 delete _Ptr; 31 } 32 _Owns = _Y._Owns; 33 } else if (_Y._Owns) { 34 _Owns = TRUE; 35 } 36 _Ptr = _Y.release(); 37 } 38 return (*this); 39 } 40 ~CBC_AutoPtr() { 41 if (_Owns) { 42 delete _Ptr; 43 } 44 } 45 _Ty& operator*() const { return (*get()); } 46 _Ty* operator->() const { return (get()); } 47 _Ty* get() const { return (_Ptr); } 48 _Ty* release() const { 49 ((CBC_AutoPtr<_Ty>*)this)->_Owns = FALSE; 50 return (_Ptr); 51 } 52 53 private: 54 FX_BOOL _Owns; 55 _Ty* _Ptr; 56 }; 57 #if (_FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_) 58 #include <limits> 59 #elif(_FX_OS_ == _FX_MACOSX_ || _FX_OS_ == _FX_LINUX_DESKTOP_ || \ 60 _FX_OS_ == _FX_IOS_) 61 #include <limits.h> 62 #endif 63 #if (_FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_) 64 #define FXSYS_isnan(x) _isnan(x) 65 #elif(_FX_OS_ == _FX_MACOSX_ || _FX_OS_ == _FX_IOS_) 66 #include <cmath> 67 #define FXSYS_isnan(x) std::isnan(x) 68 #elif(_FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_ANDROID_) 69 #include <math.h> 70 #define FXSYS_isnan(x) isnan(x) 71 #endif 72 #if (_FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_) 73 #define FXSYS_nan() (std::numeric_limits<float>::quiet_NaN()) 74 #elif(_FX_OS_ == _FX_MACOSX_ || _FX_OS_ == _FX_LINUX_DESKTOP_ || \ 75 _FX_OS_ == _FX_IOS_ || _FX_OS_ == _FX_ANDROID_) 76 #define FXSYS_nan() NAN 77 #endif 78 enum BCFORMAT { 79 BCFORMAT_UNSPECIFY = -1, 80 BCFORMAT_CODABAR, 81 BCFORMAT_CODE_39, 82 BCFORMAT_CODE_128, 83 BCFORMAT_CODE_128B, 84 BCFORMAT_CODE_128C, 85 BCFORMAT_EAN_8, 86 BCFORMAT_UPC_A, 87 BCFORMAT_EAN_13, 88 BCFORMAT_PDF_417, 89 BCFORMAT_DATAMATRIX, 90 BCFORMAT_QR_CODE 91 }; 92 #define BCFORMAT_ECLEVEL_L 0 93 #define BCFORMAT_ECLEVEL_M 1 94 #define BCFORMAT_ECLEVEL_Q 2 95 #define BCFORMAT_ECLEVEL_H 3 96 #include <ctype.h> 97 #define FXSYS_IntMax INT_MAX 98 #define FXSYS_Isdigit isdigit 99 #define BCExceptionNO 0 100 #define BCExceptionNotFound 1 101 #define BCExceptionEndLessThanStart 2 102 #define BCExceptionUnknownDecoder 3 103 #define BCExceptionRotateNotSupported 4 104 #define BCExceptionHeightAndWidthMustBeAtLeast1 5 105 #define BCExceptionRegionMustFitInsideMatrix 6 106 #define BCExceptionCanNotCallGetDimensionOnNonSquareMatrix 7 107 #define BCExceptionFormatException 8 108 #define BCExceptionIllegalArgumentMustMatchVersionSize 9 109 #define BCExceptionChecksumException 10 110 #define BCExceptionIllegalArgumentInvalidFirstDigit 11 111 #define BCExceptionIllegalArgumentInvalidSecondDigit 12 112 #define BCExceptionRuntimeDecodingInvalidISO_IEC 13 113 #define BCExceptionRuntimeDecodingInvalidAlphanumeric 14 114 #define BCExceptionLeftAndTopMustBeNonnegative 15 115 #define BCExceptionIllegalArgument 16 116 #define BCExceptionBadECI 17 117 #define BCExceptionUnSupportedBarcode 18 118 #define BCExceptionUnSupportedString 19 119 #define BCExceptionDigitLengthMustBe8 20 120 #define BCExceptionDataCheckException 21 121 #define BCExceptionExtractNumberValueFromBitArray 22 122 #define BCExceptionRead 23 123 #define BCExceptionRequestedRowIsOutSizeTheImage 24 124 #define BCExceptionNoContents 26 125 #define BCExceptionUnSupportEclevel 27 126 #define BCExceptionUnSupportMode 28 127 #define BCExceptionReferenceMustBeBetween0And7 29 128 #define BCExceptionBadErrorLocation 30 129 #define BCExceptionDegreeIsNegative 31 130 #define BCExceptionDivideByZero 32 131 #define BCExceptionCoefficientsSizeIsNull 33 132 #define BCExceptionNoCorrectionBytes 34 133 #define BCExceptionNoDataBytesProvided 35 134 #define BCExceptionR_I_1IsZero 36 135 #define BCExceptionAIsZero 37 136 #define BCExceptionIsZero 38 137 #define BCExceptionDegreeNotMatchRoots 39 138 #define BCExceptionContentsLengthShouldBetween1and80 40 139 #define BCExceptionOnlyEncodeCODE_128 41 140 #define BCExceptionOnlyEncodeCODE_39 42 141 #define BCExceptionOnlyEncodeEAN_13 43 142 #define BCExceptionOnlyEncodeEAN_8 44 143 #define BCExceptionOnlyEncodeITF 45 144 #define BCExceptionDigitLengthShould13 46 145 #define BCExceptionDigitLengthMustBe6or8or10or12or14or16or20or24or44 47 146 #define BCExceptionOnlyEncodeUPC_A 48 147 #define BCExceptionDigitLengthShouldBe12 49 148 #define BCExceptionValueMustBeEither0or1 50 149 #define BCExceptionReedsolomnDecodeException 51 150 #define BCExceptionBadIndexException 52 151 #define BCExceptionBadValueException 53 152 #define BCExceptionBadNumBitsException 54 153 #define BCExceptioncanNotOperatexorOperator 55 154 #define BCExceptionVersionMust1_40 56 155 #define BCExceptionUnknown 57 156 #define BCExceptionNoSuchVersion 58 157 #define BCExceptionCannotFindBlockInfo 59 158 #define BCExceptionDataTooBig 60 159 #define BCExceptionInvalidQRCode 61 160 #define BCExceptionDataTooMany 62 161 #define BCExceptionBitsNotEqualCacity 63 162 #define BCExceptionUnsupportedMode 64 163 #define BCExceptionInvalidateCharacter 65 164 #define BCExceptionBytesNotMatchOffset 66 165 #define BCExceptionSizeInBytesDiffer 67 166 #define BCExceptionInvalidateMaskPattern 68 167 #define BCExceptionNullPointer 69 168 #define BCExceptionBadMask 70 169 #define BCExceptionBitSizeNot15 71 170 #define BCExceptionBitSizeNot18 72 171 #define BCExceptionInvalidateImageData 73 172 #define BCExceptionHeight_8BeZero 74 173 #define BCExceptionCharacterNotThisMode 75 174 #define BCExceptionBitsBytesNotMatch 76 175 #define BCExceptionInvalidateData 77 176 #define BCExceptionLoadFile 78 177 #define BCExceptionPDF417EncodeFail 79 178 #define BCExceptionFailToCreateBitmap 80 179 #define BCExceptionLoadFontFail 81 180 #define BCExceptionOnlyEncodeCODEBAR 82 181 #define BCExceptionCodabarShouldStartWithOneOfABCD 83 182 #define BCExceptionCodabarShouldEndWithOneOfTNE 84 183 #define BCExceptionCodabarEncodeCharsInvalid 85 184 #define BCExceptionOnlyEncodeDATAMATRIX 86 185 #define BCExceptionCharactersOutsideISO88591Encoding 87 186 #define BCExceptionIllegalDataCodewords 88 187 #define BCExceptionCannotHandleThisNumberOfDataRegions 89 188 #define BCExceptionIllegalStateUnexpectedCase 90 189 #define BCExceptionIllegalStateCountMustNotExceed4 91 190 #define BCExceptionIllegalStateMessageLengthInvalid 92 191 #define BCExceptionIllegalArgumentNotGigits 93 192 #define BCExceptionIllegalStateIllegalMode 94 193 #define BCExceptionOnlyEncodePDF417 95 194 #define BCExceptionNonEncodableCharacterDetected 96 195 #define BCExceptionErrorCorrectionLevelMustBeBetween0And8 97 196 #define BCExceptionNoRecommendationPossible 98 197 #define BCExceptionIllegalArgumentnMustBeAbove0 99 198 #define BCExceptionUnableToFitMessageInColumns 100 199 #define BCExceptionEncodedMessageContainsTooManyCodeWords 101 200 #define BCExceptionBitmapSizeError 102 201 #define BCExceptionFormatInstance 102 202 #define BCExceptionChecksumInstance 103 203 #define BCExceptiontNotFoundInstance 104 204 #define BCExceptionNotFoundInstance 105 205 #define BCExceptionCannotMetadata 106 206 #define TWO_DIGIT_DATA_LENGTH_SIZE 24 207 #define THREE_DIGIT_DATA_LENGTH_SIZE 23 208 #define THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH_SIZE 57 209 #define FOUR_DIGIT_DATA_LENGTH_SIZE 17 210 #define BC_EXCEPTION_CHECK_ReturnVoid(e) \ 211 if (e != BCExceptionNO) \ 212 return; 213 #define BC_EXCEPTION_CHECK_ReturnValue(e, v) \ 214 if (e != BCExceptionNO) \ 215 return v; 216 #endif 217