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

Side by Side Diff: xfa/src/fxbarcode/oned/BC_OnedCodaBarWriter.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 2011 ZXing authors 8 * Copyright 2011 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");
(...skipping 24 matching lines...) Expand all
35 { 35 {
36 m_chStart = 'A'; 36 m_chStart = 'A';
37 m_chEnd = 'B'; 37 m_chEnd = 'B';
38 m_iWideNarrRatio = 2; 38 m_iWideNarrRatio = 2;
39 } 39 }
40 CBC_OnedCodaBarWriter::~CBC_OnedCodaBarWriter() 40 CBC_OnedCodaBarWriter::~CBC_OnedCodaBarWriter()
41 { 41 {
42 } 42 }
43 FX_BOOL CBC_OnedCodaBarWriter::SetStartChar(FX_CHAR start) 43 FX_BOOL CBC_OnedCodaBarWriter::SetStartChar(FX_CHAR start)
44 { 44 {
45 for (FX_INT32 i = 0; i < sizeof(START_END_CHARS) / sizeof(FX_CHAR); i++) { 45 for (int32_t i = 0; i < sizeof(START_END_CHARS) / sizeof(FX_CHAR); i++) {
46 if (START_END_CHARS[i] == start) { 46 if (START_END_CHARS[i] == start) {
47 m_chStart = start; 47 m_chStart = start;
48 return TRUE; 48 return TRUE;
49 } 49 }
50 } 50 }
51 return FALSE; 51 return FALSE;
52 } 52 }
53 FX_BOOL CBC_OnedCodaBarWriter::SetEndChar(FX_CHAR end) 53 FX_BOOL CBC_OnedCodaBarWriter::SetEndChar(FX_CHAR end)
54 { 54 {
55 for (FX_INT32 i = 0; i < sizeof(START_END_CHARS) / sizeof(FX_CHAR); i++) { 55 for (int32_t i = 0; i < sizeof(START_END_CHARS) / sizeof(FX_CHAR); i++) {
56 if (START_END_CHARS[i] == end) { 56 if (START_END_CHARS[i] == end) {
57 m_chEnd = end; 57 m_chEnd = end;
58 return TRUE; 58 return TRUE;
59 } 59 }
60 } 60 }
61 return FALSE; 61 return FALSE;
62 } 62 }
63 void CBC_OnedCodaBarWriter::SetDataLength(FX_INT32 length) 63 void CBC_OnedCodaBarWriter::SetDataLength(int32_t length)
64 { 64 {
65 m_iDataLenth = length + 2; 65 m_iDataLenth = length + 2;
66 } 66 }
67 FX_BOOL CBC_OnedCodaBarWriter::SetTextLocation(BC_TEXT_LOC location) 67 FX_BOOL CBC_OnedCodaBarWriter::SetTextLocation(BC_TEXT_LOC location)
68 { 68 {
69 if ( location < BC_TEXT_LOC_NONE || location > BC_TEXT_LOC_BELOWEMBED) { 69 if ( location < BC_TEXT_LOC_NONE || location > BC_TEXT_LOC_BELOWEMBED) {
70 return FALSE; 70 return FALSE;
71 } 71 }
72 m_locTextLoc = location; 72 m_locTextLoc = location;
73 return TRUE; 73 return TRUE;
74 } 74 }
75 FX_BOOL CBC_OnedCodaBarWriter::SetWideNarrowRatio(FX_INT32 ratio) 75 FX_BOOL CBC_OnedCodaBarWriter::SetWideNarrowRatio(int32_t ratio)
76 { 76 {
77 if(ratio < 2 || ratio > 3) { 77 if(ratio < 2 || ratio > 3) {
78 return FALSE; 78 return FALSE;
79 } 79 }
80 m_iWideNarrRatio = ratio; 80 m_iWideNarrRatio = ratio;
81 return TRUE; 81 return TRUE;
82 } 82 }
83 FX_BOOL CBC_OnedCodaBarWriter::FindChar(FX_WCHAR ch, FX_BOOL isContent) 83 FX_BOOL CBC_OnedCodaBarWriter::FindChar(FX_WCHAR ch, FX_BOOL isContent)
84 { 84 {
85 if(isContent) { 85 if(isContent) {
86 for(FX_INT32 i = 0 ; i < sizeof(CONTENT_CHARS) / sizeof(FX_CHAR) ; i++) { 86 for(int32_t i = 0 ; i < sizeof(CONTENT_CHARS) / sizeof(FX_CHAR) ; i++) {
87 if(ch == (FX_WCHAR)CONTENT_CHARS[i]) { 87 if(ch == (FX_WCHAR)CONTENT_CHARS[i]) {
88 return TRUE; 88 return TRUE;
89 } 89 }
90 } 90 }
91 for(FX_INT32 j = 0 ; j < sizeof(START_END_CHARS) / sizeof(FX_CHAR) ; j++ ) { 91 for(int32_t j = 0 ; j < sizeof(START_END_CHARS) / sizeof(FX_CHAR) ; j++) {
92 if(ch == (FX_WCHAR)START_END_CHARS[j]) { 92 if(ch == (FX_WCHAR)START_END_CHARS[j]) {
93 return TRUE; 93 return TRUE;
94 } 94 }
95 } 95 }
96 return FALSE; 96 return FALSE;
97 } else { 97 } else {
98 for(FX_INT32 i = 0 ; i < sizeof(CONTENT_CHARS) / sizeof(FX_CHAR) ; i++) { 98 for(int32_t i = 0 ; i < sizeof(CONTENT_CHARS) / sizeof(FX_CHAR) ; i++) {
99 if(ch == (FX_WCHAR)CONTENT_CHARS[i]) { 99 if(ch == (FX_WCHAR)CONTENT_CHARS[i]) {
100 return TRUE; 100 return TRUE;
101 } 101 }
102 } 102 }
103 return FALSE; 103 return FALSE;
104 } 104 }
105 } 105 }
106 FX_BOOL CBC_OnedCodaBarWriter::CheckContentValidity(FX_WSTR contents) 106 FX_BOOL CBC_OnedCodaBarWriter::CheckContentValidity(FX_WSTR contents)
107 { 107 {
108 FX_WCHAR ch; 108 FX_WCHAR ch;
109 FX_INT32 index = 0; 109 int32_t index = 0;
110 for (index = 0; index < contents.GetLength(); index++) { 110 for (index = 0; index < contents.GetLength(); index++) {
111 ch = contents.GetAt(index); 111 ch = contents.GetAt(index);
112 if (FindChar(ch, FALSE)) { 112 if (FindChar(ch, FALSE)) {
113 continue; 113 continue;
114 } else { 114 } else {
115 return FALSE; 115 return FALSE;
116 } 116 }
117 } 117 }
118 return TRUE; 118 return TRUE;
119 } 119 }
120 CFX_WideString CBC_OnedCodaBarWriter::FilterContents(FX_WSTR contents) 120 CFX_WideString CBC_OnedCodaBarWriter::FilterContents(FX_WSTR contents)
121 { 121 {
122 CFX_WideString filtercontents; 122 CFX_WideString filtercontents;
123 FX_WCHAR ch; 123 FX_WCHAR ch;
124 for (FX_INT32 index = 0; index < contents.GetLength(); index ++) { 124 for (int32_t index = 0; index < contents.GetLength(); index ++) {
125 ch = contents.GetAt(index); 125 ch = contents.GetAt(index);
126 if(ch > 175) { 126 if(ch > 175) {
127 index++; 127 index++;
128 continue; 128 continue;
129 } 129 }
130 if (FindChar(ch, TRUE)) { 130 if (FindChar(ch, TRUE)) {
131 filtercontents += ch; 131 filtercontents += ch;
132 } else { 132 } else {
133 continue; 133 continue;
134 } 134 }
135 } 135 }
136 return filtercontents; 136 return filtercontents;
137 } 137 }
138 FX_BYTE *CBC_OnedCodaBarWriter::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 &e) 138 uint8_t *CBC_OnedCodaBarWriter::Encode(const CFX_ByteString &contents, BCFORMAT format, int32_t &outWidth, int32_t &outHeight, int32_t &e)
139 { 139 {
140 FX_BYTE *ret = Encode(contents, format, outWidth, outHeight, 0 , e); 140 uint8_t *ret = Encode(contents, format, outWidth, outHeight, 0 , e);
141 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 141 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
142 return ret; 142 return ret;
143 } 143 }
144 FX_BYTE *CBC_OnedCodaBarWriter::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 hints, FX_INT32 &e) 144 uint8_t *CBC_OnedCodaBarWriter::Encode(const CFX_ByteString &contents, BCFORMAT format, int32_t &outWidth, int32_t &outHeight, int32_t hints, int32_t &e)
145 { 145 {
146 if(format != BCFORMAT_CODABAR) { 146 if(format != BCFORMAT_CODABAR) {
147 e = BCExceptionOnlyEncodeCODEBAR; 147 e = BCExceptionOnlyEncodeCODEBAR;
148 return NULL; 148 return NULL;
149 } 149 }
150 FX_BYTE *ret = CBC_OneDimWriter::Encode(contents, format, outWidth, outHeigh t, hints, e); 150 uint8_t *ret = CBC_OneDimWriter::Encode(contents, format, outWidth, outHeigh t, hints, e);
151 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 151 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
152 return ret; 152 return ret;
153 } 153 }
154 FX_BYTE* CBC_OnedCodaBarWriter::Encode(const CFX_ByteString &contents, FX_INT32 &outLength, FX_INT32 &e) 154 uint8_t* CBC_OnedCodaBarWriter::Encode(const CFX_ByteString &contents, int32_t & outLength, int32_t &e)
155 { 155 {
156 CBC_OnedCodaBarReader CodaBarR; 156 CBC_OnedCodaBarReader CodaBarR;
157 CFX_ByteString data = m_chStart + contents + m_chEnd; 157 CFX_ByteString data = m_chStart + contents + m_chEnd;
158 m_iContentLen = data.GetLength(); 158 m_iContentLen = data.GetLength();
159 FX_BYTE *result = FX_Alloc(FX_BYTE, m_iWideNarrRatio * 7 * data.GetLength()) ; 159 uint8_t *result = FX_Alloc(uint8_t, m_iWideNarrRatio * 7 * data.GetLength()) ;
160 FX_CHAR ch; 160 FX_CHAR ch;
161 FX_INT32 position = 0; 161 int32_t position = 0;
162 for (FX_INT32 index = 0; index < data.GetLength(); index++) { 162 for (int32_t index = 0; index < data.GetLength(); index++) {
163 ch = data.GetAt(index); 163 ch = data.GetAt(index);
164 if (((ch >= 'a') && (ch <= 'z'))) { 164 if (((ch >= 'a') && (ch <= 'z'))) {
165 ch = ch - 32; 165 ch = ch - 32;
166 } 166 }
167 switch (ch) { 167 switch (ch) {
168 case 'T': 168 case 'T':
169 ch = 'A'; 169 ch = 'A';
170 break; 170 break;
171 case 'N': 171 case 'N':
172 ch = 'B'; 172 ch = 'B';
173 break; 173 break;
174 case '*': 174 case '*':
175 ch = 'C'; 175 ch = 'C';
176 break; 176 break;
177 case 'E': 177 case 'E':
178 ch = 'D'; 178 ch = 'D';
179 break; 179 break;
180 default: 180 default:
181 break; 181 break;
182 } 182 }
183 FX_INT32 code = 0; 183 int32_t code = 0;
184 FX_INT32 len = (FX_INT32)strlen(CodaBarR.ALPHABET_STRING); 184 int32_t len = (int32_t)strlen(CodaBarR.ALPHABET_STRING);
185 for (FX_INT32 i = 0; i < len; i++) { 185 for (int32_t i = 0; i < len; i++) {
186 if (ch == CodaBarR.ALPHABET_STRING[i]) { 186 if (ch == CodaBarR.ALPHABET_STRING[i]) {
187 code = CodaBarR.CHARACTER_ENCODINGS[i]; 187 code = CodaBarR.CHARACTER_ENCODINGS[i];
188 break; 188 break;
189 } 189 }
190 } 190 }
191 FX_BYTE color = 1; 191 uint8_t color = 1;
192 FX_INT32 counter = 0; 192 int32_t counter = 0;
193 FX_INT32 bit = 0; 193 int32_t bit = 0;
194 while (bit < 7) { 194 while (bit < 7) {
195 result[position] = color; 195 result[position] = color;
196 position++; 196 position++;
197 if (((code >> (6 - bit)) & 1) == 0 || counter == m_iWideNarrRatio - 1) { 197 if (((code >> (6 - bit)) & 1) == 0 || counter == m_iWideNarrRatio - 1) {
198 color = !color; 198 color = !color;
199 bit++; 199 bit++;
200 counter = 0; 200 counter = 0;
201 } else { 201 } else {
202 counter++; 202 counter++;
203 } 203 }
204 } 204 }
205 if (index < data.GetLength() - 1) { 205 if (index < data.GetLength() - 1) {
206 result[position] = 0; 206 result[position] = 0;
207 position ++; 207 position ++;
208 } 208 }
209 } 209 }
210 outLength = position; 210 outLength = position;
211 return result; 211 return result;
212 } 212 }
213 CFX_WideString CBC_OnedCodaBarWriter::encodedContents(FX_WSTR contents) 213 CFX_WideString CBC_OnedCodaBarWriter::encodedContents(FX_WSTR contents)
214 { 214 {
215 CFX_WideString strStart(m_chStart); 215 CFX_WideString strStart(m_chStart);
216 CFX_WideString strEnd(m_chEnd); 216 CFX_WideString strEnd(m_chEnd);
217 return strStart + contents + strEnd; 217 return strStart + contents + strEnd;
218 } 218 }
219 void CBC_OnedCodaBarWriter::RenderResult(FX_WSTR contents, FX_BYTE* code, FX_INT 32 codeLength, FX_BOOL isDevice, FX_INT32 &e) 219 void CBC_OnedCodaBarWriter::RenderResult(FX_WSTR contents, uint8_t* code, int32_ t codeLength, FX_BOOL isDevice, int32_t &e)
220 { 220 {
221 CBC_OneDimWriter::RenderResult(encodedContents(contents), code, codeLength, isDevice, e); 221 CBC_OneDimWriter::RenderResult(encodedContents(contents), code, codeLength, isDevice, e);
222 } 222 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/oned/BC_OnedCodaBarWriter.h ('k') | xfa/src/fxbarcode/oned/BC_OnedCode128Reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698