summaryrefslogtreecommitdiff
path: root/xfa/src/fxbarcode/utils.h
blob: 9639ba850407e4d9a93954f5ac45f185af37f67c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef _BC_UTILS_H_
#define _BC_UTILS_H_
typedef CFX_MapPtrTemplate<FX_LPVOID, int32_t> CFX_PtrToInt32;
FX_BOOL BC_FX_ByteString_Replace(CFX_ByteString &dst, FX_DWORD first, FX_DWORD last, int32_t count, FX_CHAR c);
void BC_FX_ByteString_Append(CFX_ByteString &dst, int32_t count, FX_CHAR c);
void BC_FX_ByteString_Append(CFX_ByteString &dst, const CFX_ByteArray &ba);
typedef FX_BOOL (*BC_PtrArrayCompareCallback)(FX_LPVOID l, FX_LPVOID r);
void BC_FX_PtrArray_Sort(CFX_PtrArray &src, BC_PtrArrayCompareCallback fun);
template<class _Ty>
class CBC_AutoPtr
{
public:
    typedef _Ty element_type;
    explicit CBC_AutoPtr(_Ty *_P = 0)
        : _Owns(_P != 0), _Ptr(_P) {}
    CBC_AutoPtr(const CBC_AutoPtr<_Ty>& _Y)
        : _Owns(_Y._Owns), _Ptr(_Y.release()) {}
    CBC_AutoPtr<_Ty>& operator=(const CBC_AutoPtr<_Ty>& _Y)
    {
        if (this != &_Y) {
            if (_Ptr != _Y.get()) {
                if (_Owns) {
                    delete _Ptr;
                }
                _Owns = _Y._Owns;
            } else if (_Y._Owns) {
                _Owns = TRUE;
            }
            _Ptr = _Y.release();
        }
        return (*this);
    }
    ~CBC_AutoPtr()
    {
        if (_Owns) {
            delete _Ptr;
        }
    }
    _Ty& operator*() const
    {
        return (*get());
    }
    _Ty *operator->() const
    {
        return (get());
    }
    _Ty *get() const
    {
        return (_Ptr);
    }
    _Ty *release() const
    {
        ((CBC_AutoPtr<_Ty> *)this)->_Owns = FALSE;
        return (_Ptr);
    }
private:
    FX_BOOL _Owns;
    _Ty *_Ptr;
};
#if (_FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_)
#include <limits>
#elif (_FX_OS_ == _FX_MACOSX_ || _FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_IOS_)
#include <limits.h>
#endif
#if (_FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_)
#define FXSYS_isnan(x) _isnan(x)
#elif (_FX_OS_ == _FX_MACOSX_ || _FX_OS_ == _FX_IOS_)
#include <math.h>
#define FXSYS_isnan(x) std::isnan(x)
#elif (_FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_ANDROID_)
#include <math.h>
#define FXSYS_isnan(x) isnan(x)
#endif
#if (_FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_)
#define FXSYS_nan() (std::numeric_limits<float>::quiet_NaN())
#elif (_FX_OS_ == _FX_MACOSX_ || _FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_IOS_ || _FX_OS_ == _FX_ANDROID_)
#define FXSYS_nan() NAN
#endif
enum BCFORMAT {
    BCFORMAT_UNSPECIFY = -1,
    BCFORMAT_CODABAR,
    BCFORMAT_CODE_39,
    BCFORMAT_CODE_128,
    BCFORMAT_CODE_128B,
    BCFORMAT_CODE_128C,
    BCFORMAT_EAN_8,
    BCFORMAT_UPC_A,
    BCFORMAT_EAN_13,
    BCFORMAT_PDF_417,
    BCFORMAT_DATAMATRIX,
    BCFORMAT_QR_CODE
};
#define BCFORMAT_ECLEVEL_L 0
#define BCFORMAT_ECLEVEL_M 1
#define BCFORMAT_ECLEVEL_Q 2
#define BCFORMAT_ECLEVEL_H 3
#include <ctype.h>
#define FXSYS_IntMax INT_MAX
#define FXSYS_Isdigit isdigit
#define	BCExceptionNO											           0
#define	BCExceptionNotFound										           1
#define	BCExceptionEndLessThanStart								           2
#define	BCExceptionUnknownDecoder								           3
#define	BCExceptionRotateNotSupported							           4
#define	BCExceptionHeightAndWidthMustBeAtLeast1					           5
#define	BCExceptionRegionMustFitInsideMatrix				               6
#define	BCExceptionCanNotCallGetDimensionOnNonSquareMatrix		           7
#define	BCExceptionFormatException								           8
#define	BCExceptionIllegalArgumentMustMatchVersionSize		               9
#define	BCExceptionChecksumException							          10
#define	BCExceptionIllegalArgumentInvalidFirstDigit			              11
#define	BCExceptionIllegalArgumentInvalidSecondDigit			          12
#define	BCExceptionRuntimeDecodingInvalidISO_IEC				          13
#define	BCExceptionRuntimeDecodingInvalidAlphanumeric			          14
#define	BCExceptionLeftAndTopMustBeNonnegative					          15
#define	BCExceptionIllegalArgument								          16
#define	BCExceptionBadECI										          17
#define	BCExceptionUnSupportedBarcode							          18
#define	BCExceptionUnSupportedString							          19
#define	BCExceptionDigitLengthMustBe8							          20
#define	BCExceptionDataCheckException							          21
#define BCExceptionExtractNumberValueFromBitArray                         22
#define BCExceptionRead											          23
#define BCExceptionRequestedRowIsOutSizeTheImage                          24
#define BCExceptionNoContents                                             26
#define BCExceptionUnSupportEclevel                                       27
#define BCExceptionUnSupportMode								          28
#define BCExceptionReferenceMustBeBetween0And7					          29
#define BCExceptionBadErrorLocation								          30
#define BCExceptionDegreeIsNegative							 	          31
#define BCExceptionDivideByZero									          32
#define BCExceptionCoefficientsSizeIsNull						          33
#define BCExceptionNoCorrectionBytes							          34
#define BCExceptionNoDataBytesProvided						              35
#define BCExceptionR_I_1IsZero									          36
#define BCExceptionAIsZero										          37
#define BCExceptionIsZero										          38
#define BCExceptionDegreeNotMatchRoots					                  39
#define	BCExceptionContentsLengthShouldBetween1and80	                  40
#define	BCExceptionOnlyEncodeCODE_128                                     41
#define	BCExceptionOnlyEncodeCODE_39                                      42
#define	BCExceptionOnlyEncodeEAN_13                                       43
#define	BCExceptionOnlyEncodeEAN_8                                        44
#define	BCExceptionOnlyEncodeITF                                          45
#define	BCExceptionDigitLengthShould13                                    46
#define	BCExceptionDigitLengthMustBe6or8or10or12or14or16or20or24or44      47
#define	BCExceptionOnlyEncodeUPC_A                                        48
#define BCExceptionDigitLengthShouldBe12                                  49
#define BCExceptionValueMustBeEither0or1                                  50
#define BCExceptionReedsolomnDecodeException                              51
#define BCExceptionBadIndexException                                      52
#define BCExceptionBadValueException                                      53
#define BCExceptionBadNumBitsException                                    54
#define BCExceptioncanNotOperatexorOperator                               55
#define BCExceptionVersionMust1_40										  56
#define BCExceptionUnknown												  57
#define BCExceptionNoSuchVersion						    		      58
#define BCExceptionCannotFindBlockInfo									  59
#define BCExceptionDataTooBig							         		  60
#define BCExceptionInvalidQRCode										  61
#define BCExceptionDataTooMany											  62
#define BCExceptionBitsNotEqualCacity								      63
#define BCExceptionUnsupportedMode										  64
#define BCExceptionInvalidateCharacter					                  65
#define BCExceptionBytesNotMatchOffset								      66
#define BCExceptionSizeInBytesDiffer			       					  67
#define BCExceptionInvalidateMaskPattern								  68
#define BCExceptionNullPointer 											  69
#define BCExceptionBadMask 											      70
#define BCExceptionBitSizeNot15										      71
#define BCExceptionBitSizeNot18											  72
#define BCExceptionInvalidateImageData									  73
#define BCExceptionHeight_8BeZero										  74
#define BCExceptionCharacterNotThisMode									  75
#define BCExceptionBitsBytesNotMatch									  76
#define BCExceptionInvalidateData										  77
#define BCExceptionLoadFile												  78
#define BCExceptionPDF417EncodeFail								          79
#define BCExceptionFailToCreateBitmap									  80
#define BCExceptionLoadFontFail											  81
#define BCExceptionOnlyEncodeCODEBAR                                      82
#define BCExceptionCodabarShouldStartWithOneOfABCD                        83
#define BCExceptionCodabarShouldEndWithOneOfTNE                           84
#define BCExceptionCodabarEncodeCharsInvalid                              85
#define BCExceptionOnlyEncodeDATAMATRIX                                   86
#define BCExceptionCharactersOutsideISO88591Encoding                      87
#define BCExceptionIllegalDataCodewords                                   88
#define BCExceptionCannotHandleThisNumberOfDataRegions                    89
#define BCExceptionIllegalStateUnexpectedCase                             90
#define BCExceptionIllegalStateCountMustNotExceed4                        91
#define BCExceptionIllegalStateMessageLengthInvalid                       92
#define BCExceptionIllegalArgumentNotGigits                               93
#define BCExceptionIllegalStateIllegalMode                                94
#define	BCExceptionOnlyEncodePDF417                                       95
#define	BCExceptionNonEncodableCharacterDetected                          96
#define	BCExceptionErrorCorrectionLevelMustBeBetween0And8                 97
#define	BCExceptionNoRecommendationPossible                               98
#define	BCExceptionIllegalArgumentnMustBeAbove0                           99
#define	BCExceptionUnableToFitMessageInColumns                            100
#define	BCExceptionEncodedMessageContainsTooManyCodeWords                 101
#define BCExceptionBitmapSizeError										  102
#define BCExceptionFormatInstance                                         102
#define BCExceptionChecksumInstance                                       103
#define BCExceptiontNotFoundInstance                                      104
#define BCExceptionNotFoundInstance                                       105
#define BCExceptionCannotMetadata                                         106
#define TWO_DIGIT_DATA_LENGTH_SIZE					24
#define THREE_DIGIT_DATA_LENGTH_SIZE				23
#define THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH_SIZE		57
#define FOUR_DIGIT_DATA_LENGTH_SIZE					17
#define BC_EXCEPTION_CHECK_ReturnVoid(e) if (e != BCExceptionNO) return;
#define BC_EXCEPTION_CHECK_ReturnValue(e, v) if (e != BCExceptionNO) return v;
#endif