Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: xfa/src/fxbarcode/oned/BC_OnedCode128Writer.cpp

Issue 1172793002: Merge to XFA: Use stdint.h types throughout PDFium. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Original code is licensed as follows: 6 // Original code is licensed as follows:
7 /* 7 /*
8 * Copyright 2010 ZXing authors 8 * Copyright 2010 ZXing authors
9 * 9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License. 11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at 12 * You may obtain a copy of the License at
13 * 13 *
14 * http://www.apache.org/licenses/LICENSE-2.0 14 * http://www.apache.org/licenses/LICENSE-2.0
15 * 15 *
16 * Unless required by applicable law or agreed to in writing, software 16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, 17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and 19 * See the License for the specific language governing permissions and
20 * limitations under the License. 20 * limitations under the License.
21 */ 21 */
22 22
23 #include "../barcode.h" 23 #include "../barcode.h"
24 #include "../BC_Writer.h" 24 #include "../BC_Writer.h"
25 #include "../BC_Reader.h" 25 #include "../BC_Reader.h"
26 #include "BC_OneDReader.h" 26 #include "BC_OneDReader.h"
27 #include "BC_OneDimWriter.h" 27 #include "BC_OneDimWriter.h"
28 #include "BC_OnedCode128Reader.h" 28 #include "BC_OnedCode128Reader.h"
29 #include "BC_OnedCode128Writer.h" 29 #include "BC_OnedCode128Writer.h"
30 const FX_INT32 CBC_OnedCode128Writer::CODE_CODE_B = 100; 30 const int32_t CBC_OnedCode128Writer::CODE_CODE_B = 100;
31 const FX_INT32 CBC_OnedCode128Writer::CODE_CODE_C = 99; 31 const int32_t CBC_OnedCode128Writer::CODE_CODE_C = 99;
32 const FX_INT32 CBC_OnedCode128Writer::CODE_START_B = 104; 32 const int32_t CBC_OnedCode128Writer::CODE_START_B = 104;
33 const FX_INT32 CBC_OnedCode128Writer::CODE_START_C = 105; 33 const int32_t CBC_OnedCode128Writer::CODE_START_C = 105;
34 const FX_INT32 CBC_OnedCode128Writer::CODE_STOP = 106; 34 const int32_t CBC_OnedCode128Writer::CODE_STOP = 106;
35 CBC_OnedCode128Writer::CBC_OnedCode128Writer() 35 CBC_OnedCode128Writer::CBC_OnedCode128Writer()
36 { 36 {
37 m_codeFormat = BC_CODE128_B; 37 m_codeFormat = BC_CODE128_B;
38 } 38 }
39 CBC_OnedCode128Writer::CBC_OnedCode128Writer(BC_TYPE type) 39 CBC_OnedCode128Writer::CBC_OnedCode128Writer(BC_TYPE type)
40 { 40 {
41 m_codeFormat = type; 41 m_codeFormat = type;
42 } 42 }
43 CBC_OnedCode128Writer::~CBC_OnedCode128Writer() 43 CBC_OnedCode128Writer::~CBC_OnedCode128Writer()
44 { 44 {
45 } 45 }
46 BC_TYPE CBC_OnedCode128Writer::GetType() 46 BC_TYPE CBC_OnedCode128Writer::GetType()
47 { 47 {
48 return m_codeFormat; 48 return m_codeFormat;
49 } 49 }
50 FX_BOOL CBC_OnedCode128Writer::CheckContentValidity(FX_WSTR contents) 50 FX_BOOL CBC_OnedCode128Writer::CheckContentValidity(FX_WSTR contents)
51 { 51 {
52 FX_BOOL ret = TRUE; 52 FX_BOOL ret = TRUE;
53 FX_INT32 position = 0; 53 int32_t position = 0;
54 FX_INT32 patternIndex = -1; 54 int32_t patternIndex = -1;
55 if (m_codeFormat == BC_CODE128_B || m_codeFormat == BC_CODE128_C) { 55 if (m_codeFormat == BC_CODE128_B || m_codeFormat == BC_CODE128_C) {
56 while (position < contents.GetLength()) { 56 while (position < contents.GetLength()) {
57 patternIndex = (FX_INT32)contents.GetAt(position); 57 patternIndex = (int32_t)contents.GetAt(position);
58 if (patternIndex >= 32 && patternIndex <= 126 && patternIndex != 34) { 58 if (patternIndex >= 32 && patternIndex <= 126 && patternIndex != 34) {
59 position++; 59 position++;
60 continue; 60 continue;
61 } else { 61 } else {
62 ret = FALSE; 62 ret = FALSE;
63 break; 63 break;
64 } 64 }
65 position ++; 65 position ++;
66 } 66 }
67 } else { 67 } else {
68 ret = FALSE; 68 ret = FALSE;
69 } 69 }
70 return ret; 70 return ret;
71 } 71 }
72 CFX_WideString CBC_OnedCode128Writer::FilterContents(FX_WSTR contents) 72 CFX_WideString CBC_OnedCode128Writer::FilterContents(FX_WSTR contents)
73 { 73 {
74 CFX_WideString filterChineseChar; 74 CFX_WideString filterChineseChar;
75 FX_WCHAR ch; 75 FX_WCHAR ch;
76 for (FX_INT32 i = 0; i < contents.GetLength(); i++) { 76 for (int32_t i = 0; i < contents.GetLength(); i++) {
77 ch = contents.GetAt(i); 77 ch = contents.GetAt(i);
78 if(ch > 175) { 78 if(ch > 175) {
79 i++; 79 i++;
80 continue; 80 continue;
81 } 81 }
82 filterChineseChar += ch; 82 filterChineseChar += ch;
83 } 83 }
84 CFX_WideString filtercontents; 84 CFX_WideString filtercontents;
85 if (m_codeFormat == BC_CODE128_B) { 85 if (m_codeFormat == BC_CODE128_B) {
86 for (FX_INT32 i = 0; i < filterChineseChar.GetLength(); i++) { 86 for (int32_t i = 0; i < filterChineseChar.GetLength(); i++) {
87 ch = filterChineseChar.GetAt(i); 87 ch = filterChineseChar.GetAt(i);
88 if (ch >= 32 && ch <= 126) { 88 if (ch >= 32 && ch <= 126) {
89 filtercontents += ch; 89 filtercontents += ch;
90 } else { 90 } else {
91 continue; 91 continue;
92 } 92 }
93 } 93 }
94 } else if (m_codeFormat == BC_CODE128_C) { 94 } else if (m_codeFormat == BC_CODE128_C) {
95 for (FX_INT32 i = 0; i < filterChineseChar.GetLength(); i++) { 95 for (int32_t i = 0; i < filterChineseChar.GetLength(); i++) {
96 ch = filterChineseChar.GetAt(i); 96 ch = filterChineseChar.GetAt(i);
97 if (ch >= 32 && ch <= 106) { 97 if (ch >= 32 && ch <= 106) {
98 filtercontents += ch; 98 filtercontents += ch;
99 } else { 99 } else {
100 continue; 100 continue;
101 } 101 }
102 } 102 }
103 } else { 103 } else {
104 filtercontents = contents; 104 filtercontents = contents;
105 } 105 }
106 return filtercontents; 106 return filtercontents;
107 } 107 }
108 FX_BOOL CBC_OnedCode128Writer::SetTextLocation(BC_TEXT_LOC location) 108 FX_BOOL CBC_OnedCode128Writer::SetTextLocation(BC_TEXT_LOC location)
109 { 109 {
110 if ( location < BC_TEXT_LOC_NONE || location > BC_TEXT_LOC_BELOWEMBED) { 110 if ( location < BC_TEXT_LOC_NONE || location > BC_TEXT_LOC_BELOWEMBED) {
111 return FALSE; 111 return FALSE;
112 } 112 }
113 m_locTextLoc = location; 113 m_locTextLoc = location;
114 return TRUE; 114 return TRUE;
115 } 115 }
116 FX_BYTE *CBC_OnedCode128Writer::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 hints, FX_INT32 &e) 116 uint8_t *CBC_OnedCode128Writer::Encode(const CFX_ByteString &contents, BCFORMAT format, int32_t &outWidth, int32_t &outHeight, int32_t hints, int32_t &e)
117 { 117 {
118 if(format != BCFORMAT_CODE_128) { 118 if(format != BCFORMAT_CODE_128) {
119 e = BCExceptionOnlyEncodeCODE_128; 119 e = BCExceptionOnlyEncodeCODE_128;
120 return NULL; 120 return NULL;
121 } 121 }
122 FX_BYTE *ret = CBC_OneDimWriter::Encode(contents, format, outWidth, outHeigh t, hints, e); 122 uint8_t *ret = CBC_OneDimWriter::Encode(contents, format, outWidth, outHeigh t, hints, e);
123 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 123 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
124 return ret; 124 return ret;
125 } 125 }
126 FX_BYTE *CBC_OnedCode128Writer::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 &e) 126 uint8_t *CBC_OnedCode128Writer::Encode(const CFX_ByteString &contents, BCFORMAT format, int32_t &outWidth, int32_t &outHeight, int32_t &e)
127 { 127 {
128 FX_BYTE *ret = Encode(contents, format, outWidth, outHeight, 0, e); 128 uint8_t *ret = Encode(contents, format, outWidth, outHeight, 0, e);
129 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 129 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
130 return ret; 130 return ret;
131 } 131 }
132 FX_BOOL CBC_OnedCode128Writer::IsDigits(const CFX_ByteString &contents, FX_INT32 start, FX_INT32 length) 132 FX_BOOL CBC_OnedCode128Writer::IsDigits(const CFX_ByteString &contents, int32_t start, int32_t length)
133 { 133 {
134 FX_INT32 end = start + length; 134 int32_t end = start + length;
135 for (FX_INT32 i = start; i < end; i++) { 135 for (int32_t i = start; i < end; i++) {
136 if (contents[i] < '0' || contents[i] > '9') { 136 if (contents[i] < '0' || contents[i] > '9') {
137 return FALSE; 137 return FALSE;
138 } 138 }
139 } 139 }
140 return TRUE; 140 return TRUE;
141 } 141 }
142 FX_BYTE *CBC_OnedCode128Writer::Encode(const CFX_ByteString &contents, FX_INT32 &outLength, FX_INT32 &e) 142 uint8_t *CBC_OnedCode128Writer::Encode(const CFX_ByteString &contents, int32_t & outLength, int32_t &e)
143 { 143 {
144 FX_INT32 length = contents.GetLength(); 144 int32_t length = contents.GetLength();
145 if(contents.GetLength() < 1 || contents.GetLength() > 80) { 145 if(contents.GetLength() < 1 || contents.GetLength() > 80) {
146 e = BCExceptionContentsLengthShouldBetween1and80; 146 e = BCExceptionContentsLengthShouldBetween1and80;
147 return NULL; 147 return NULL;
148 } 148 }
149 CFX_PtrArray patterns; 149 CFX_PtrArray patterns;
150 FX_INT32 checkSum = 0; 150 int32_t checkSum = 0;
151 if (m_codeFormat == BC_CODE128_B) { 151 if (m_codeFormat == BC_CODE128_B) {
152 checkSum = Encode128B(contents, patterns); 152 checkSum = Encode128B(contents, patterns);
153 } else if (m_codeFormat == BC_CODE128_C) { 153 } else if (m_codeFormat == BC_CODE128_C) {
154 checkSum = Encode128C(contents, patterns); 154 checkSum = Encode128C(contents, patterns);
155 } else { 155 } else {
156 e = BCExceptionFormatException; 156 e = BCExceptionFormatException;
157 return NULL; 157 return NULL;
158 } 158 }
159 checkSum %= 103; 159 checkSum %= 103;
160 patterns.Add((FX_INT32*)CBC_OnedCode128Reader::CODE_PATTERNS[checkSum]); 160 patterns.Add((int32_t*)CBC_OnedCode128Reader::CODE_PATTERNS[checkSum]);
161 patterns.Add((FX_INT32*)CBC_OnedCode128Reader::CODE_PATTERNS[CODE_STOP]); 161 patterns.Add((int32_t*)CBC_OnedCode128Reader::CODE_PATTERNS[CODE_STOP]);
162 m_iContentLen = contents.GetLength() + 3; 162 m_iContentLen = contents.GetLength() + 3;
163 FX_INT32 codeWidth = 0; 163 int32_t codeWidth = 0;
164 for(FX_INT32 k = 0; k < patterns.GetSize(); k++) { 164 for(int32_t k = 0; k < patterns.GetSize(); k++) {
165 FX_INT32 *pattern = (FX_INT32*)patterns[k]; 165 int32_t *pattern = (int32_t*)patterns[k];
166 for(FX_INT32 j = 0; j < 7; j++) { 166 for(int32_t j = 0; j < 7; j++) {
167 codeWidth += pattern[j]; 167 codeWidth += pattern[j];
168 } 168 }
169 } 169 }
170 outLength = codeWidth; 170 outLength = codeWidth;
171 FX_BYTE *result = FX_Alloc(FX_BYTE, outLength); 171 uint8_t *result = FX_Alloc(uint8_t, outLength);
172 FX_INT32 pos = 0; 172 int32_t pos = 0;
173 for(FX_INT32 j = 0; j < patterns.GetSize(); j++) { 173 for(int32_t j = 0; j < patterns.GetSize(); j++) {
174 FX_INT32* pattern = (FX_INT32*)patterns[j]; 174 int32_t* pattern = (int32_t*)patterns[j];
175 pos += AppendPattern(result, pos, pattern, 7, 1, e); 175 pos += AppendPattern(result, pos, pattern, 7, 1, e);
176 if (e != BCExceptionNO) { 176 if (e != BCExceptionNO) {
177 FX_Free (result); 177 FX_Free (result);
178 return NULL; 178 return NULL;
179 } 179 }
180 } 180 }
181 return result; 181 return result;
182 } 182 }
183 FX_INT32 CBC_OnedCode128Writer::Encode128B(const CFX_ByteString &contents, CFX_ PtrArray &patterns) 183 int32_t CBC_OnedCode128Writer::Encode128B(const CFX_ByteString &contents, CFX_P trArray &patterns)
184 { 184 {
185 FX_INT32 checkSum = 0; 185 int32_t checkSum = 0;
186 FX_INT32 checkWeight = 1; 186 int32_t checkWeight = 1;
187 FX_INT32 position = 0; 187 int32_t position = 0;
188 patterns.Add((FX_INT32*)CBC_OnedCode128Reader::CODE_PATTERNS[CODE_START_B]); 188 patterns.Add((int32_t*)CBC_OnedCode128Reader::CODE_PATTERNS[CODE_START_B]);
189 checkSum += CODE_START_B * checkWeight; 189 checkSum += CODE_START_B * checkWeight;
190 while (position < contents.GetLength()) { 190 while (position < contents.GetLength()) {
191 FX_INT32 patternIndex = 0; 191 int32_t patternIndex = 0;
192 patternIndex = contents[position] - ' '; 192 patternIndex = contents[position] - ' ';
193 position += 1; 193 position += 1;
194 patterns.Add((FX_INT32*)CBC_OnedCode128Reader::CODE_PATTERNS[patternInde x]); 194 patterns.Add((int32_t*)CBC_OnedCode128Reader::CODE_PATTERNS[patternIndex ]);
195 checkSum += patternIndex * checkWeight; 195 checkSum += patternIndex * checkWeight;
196 if (position != 0) { 196 if (position != 0) {
197 checkWeight++; 197 checkWeight++;
198 } 198 }
199 } 199 }
200 return checkSum; 200 return checkSum;
201 } 201 }
202 FX_INT32 CBC_OnedCode128Writer::Encode128C(const CFX_ByteString &contents, CFX_ PtrArray &patterns) 202 int32_t CBC_OnedCode128Writer::Encode128C(const CFX_ByteString &contents, CFX_P trArray &patterns)
203 { 203 {
204 FX_INT32 checkSum = 0; 204 int32_t checkSum = 0;
205 FX_INT32 checkWeight = 1; 205 int32_t checkWeight = 1;
206 FX_INT32 position = 0; 206 int32_t position = 0;
207 patterns.Add((FX_INT32*)CBC_OnedCode128Reader::CODE_PATTERNS[CODE_START_C]); 207 patterns.Add((int32_t*)CBC_OnedCode128Reader::CODE_PATTERNS[CODE_START_C]);
208 checkSum += CODE_START_C * checkWeight; 208 checkSum += CODE_START_C * checkWeight;
209 while (position < contents.GetLength()) { 209 while (position < contents.GetLength()) {
210 FX_INT32 patternIndex = 0; 210 int32_t patternIndex = 0;
211 FX_CHAR ch = contents.GetAt(position); 211 FX_CHAR ch = contents.GetAt(position);
212 if (ch < '0' || ch > '9') { 212 if (ch < '0' || ch > '9') {
213 patternIndex = (FX_INT32)ch; 213 patternIndex = (int32_t)ch;
214 position++; 214 position++;
215 } else { 215 } else {
216 patternIndex = FXSYS_atoi(contents.Mid(position, 2)); 216 patternIndex = FXSYS_atoi(contents.Mid(position, 2));
217 if (contents.GetAt(position + 1) < '0' || contents.GetAt(position + 1) > '9') { 217 if (contents.GetAt(position + 1) < '0' || contents.GetAt(position + 1) > '9') {
218 position += 1; 218 position += 1;
219 } else { 219 } else {
220 position += 2; 220 position += 2;
221 } 221 }
222 } 222 }
223 patterns.Add((FX_INT32*)CBC_OnedCode128Reader::CODE_PATTERNS[patternInde x]); 223 patterns.Add((int32_t*)CBC_OnedCode128Reader::CODE_PATTERNS[patternIndex ]);
224 checkSum += patternIndex * checkWeight; 224 checkSum += patternIndex * checkWeight;
225 if (position != 0) { 225 if (position != 0) {
226 checkWeight++; 226 checkWeight++;
227 } 227 }
228 } 228 }
229 return checkSum; 229 return checkSum;
230 } 230 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/oned/BC_OnedCode128Writer.h ('k') | xfa/src/fxbarcode/oned/BC_OnedCode39Reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698