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