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

Side by Side Diff: xfa/src/fxbarcode/src/BC_OnedCodaBarWriter.cpp

Issue 842043002: Organize barcode codes into modules. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: rebase Created 5 years, 11 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
(Empty)
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 // Original code is licensed as follows:
7 /*
8 * Copyright 2011 ZXing authors
9 *
10 * Licensed under the Apache License, Version 2.0 (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
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 */
22
23 #include "barcode.h"
24 #include "include/BC_Writer.h"
25 #include "include/BC_Reader.h"
26 #include "include/BC_OneDReader.h"
27 #include "include/BC_CommonBitArray.h"
28 #include "include/BC_OneDimWriter.h"
29 #include "include/BC_OnedCodaBarReader.h"
30 #include "include/BC_OnedCodaBarWriter.h"
31 #include "include/BC_CommonBitMatrix.h"
32 const FX_CHAR CBC_OnedCodaBarWriter::START_END_CHARS[] = {'A', 'B', 'C', 'D', 'T ', 'N', '*', 'E', 'a', 'b', 'c', 'd', 't', 'n', 'e'};
33 const FX_CHAR CBC_OnedCodaBarWriter::CONTENT_CHARS[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '$', '/', ':', '+', '.'};
34 CBC_OnedCodaBarWriter::CBC_OnedCodaBarWriter()
35 {
36 m_chStart = 'A';
37 m_chEnd = 'B';
38 m_iWideNarrRatio = 2;
39 }
40 CBC_OnedCodaBarWriter::~CBC_OnedCodaBarWriter()
41 {
42 }
43 FX_BOOL CBC_OnedCodaBarWriter::SetStartChar(FX_CHAR start)
44 {
45 for (FX_INT32 i = 0; i < sizeof(START_END_CHARS) / sizeof(FX_CHAR); i++) {
46 if (START_END_CHARS[i] == start) {
47 m_chStart = start;
48 return TRUE;
49 }
50 }
51 return FALSE;
52 }
53 FX_BOOL CBC_OnedCodaBarWriter::SetEndChar(FX_CHAR end)
54 {
55 for (FX_INT32 i = 0; i < sizeof(START_END_CHARS) / sizeof(FX_CHAR); i++) {
56 if (START_END_CHARS[i] == end) {
57 m_chEnd = end;
58 return TRUE;
59 }
60 }
61 return FALSE;
62 }
63 void CBC_OnedCodaBarWriter::SetDataLength(FX_INT32 length)
64 {
65 m_iDataLenth = length + 2;
66 }
67 FX_BOOL CBC_OnedCodaBarWriter::SetTextLocation(BC_TEXT_LOC location)
68 {
69 if ( location < BC_TEXT_LOC_NONE || location > BC_TEXT_LOC_BELOWEMBED) {
70 return FALSE;
71 }
72 m_locTextLoc = location;
73 return TRUE;
74 }
75 FX_BOOL CBC_OnedCodaBarWriter::SetWideNarrowRatio(FX_INT32 ratio)
76 {
77 if(ratio < 2 || ratio > 3) {
78 return FALSE;
79 }
80 m_iWideNarrRatio = ratio;
81 return TRUE;
82 }
83 FX_BOOL CBC_OnedCodaBarWriter::FindChar(FX_WCHAR ch, FX_BOOL isContent)
84 {
85 if(isContent) {
86 for(FX_INT32 i = 0 ; i < sizeof(CONTENT_CHARS) / sizeof(FX_CHAR) ; i++) {
87 if(ch == (FX_WCHAR)CONTENT_CHARS[i]) {
88 return TRUE;
89 }
90 }
91 for(FX_INT32 j = 0 ; j < sizeof(START_END_CHARS) / sizeof(FX_CHAR) ; j++ ) {
92 if(ch == (FX_WCHAR)START_END_CHARS[j]) {
93 return TRUE;
94 }
95 }
96 return FALSE;
97 } else {
98 for(FX_INT32 i = 0 ; i < sizeof(CONTENT_CHARS) / sizeof(FX_CHAR) ; i++) {
99 if(ch == (FX_WCHAR)CONTENT_CHARS[i]) {
100 return TRUE;
101 }
102 }
103 return FALSE;
104 }
105 }
106 FX_BOOL CBC_OnedCodaBarWriter::CheckContentValidity(FX_WSTR contents)
107 {
108 FX_WCHAR ch;
109 FX_INT32 index = 0;
110 for (index = 0; index < contents.GetLength(); index++) {
111 ch = contents.GetAt(index);
112 if (FindChar(ch, FALSE)) {
113 continue;
114 } else {
115 return FALSE;
116 }
117 }
118 return TRUE;
119 }
120 CFX_WideString CBC_OnedCodaBarWriter::FilterContents(FX_WSTR contents)
121 {
122 CFX_WideString filtercontents;
123 FX_WCHAR ch;
124 for (FX_INT32 index = 0; index < contents.GetLength(); index ++) {
125 ch = contents.GetAt(index);
126 if(ch > 175) {
127 index++;
128 continue;
129 }
130 if (FindChar(ch, TRUE)) {
131 filtercontents += ch;
132 } else {
133 continue;
134 }
135 }
136 return filtercontents;
137 }
138 FX_BYTE *CBC_OnedCodaBarWriter::Encode(const CFX_ByteString &contents, BCFORMAT format, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 &e)
139 {
140 FX_BYTE *ret = Encode(contents, format, outWidth, outHeight, 0 , e);
141 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
142 return ret;
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)
145 {
146 if(format != BCFORMAT_CODABAR) {
147 e = BCExceptionOnlyEncodeCODEBAR;
148 return NULL;
149 }
150 FX_BYTE *ret = CBC_OneDimWriter::Encode(contents, format, outWidth, outHeigh t, hints, e);
151 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
152 return ret;
153 }
154 FX_BYTE* CBC_OnedCodaBarWriter::Encode(const CFX_ByteString &contents, FX_INT32 &outLength, FX_INT32 &e)
155 {
156 CBC_OnedCodaBarReader CodaBarR;
157 CFX_ByteString data = m_chStart + contents + m_chEnd;
158 m_iContentLen = data.GetLength();
159 FX_BYTE *result = FX_Alloc(FX_BYTE, m_iWideNarrRatio * 7 * data.GetLength()) ;
160 FX_CHAR ch;
161 FX_INT32 position = 0;
162 for (FX_INT32 index = 0; index < data.GetLength(); index++) {
163 ch = data.GetAt(index);
164 if (((ch >= 'a') && (ch <= 'z'))) {
165 ch = ch - 32;
166 }
167 switch (ch) {
168 case 'T':
169 ch = 'A';
170 break;
171 case 'N':
172 ch = 'B';
173 break;
174 case '*':
175 ch = 'C';
176 break;
177 case 'E':
178 ch = 'D';
179 break;
180 default:
181 break;
182 }
183 FX_INT32 code = 0;
184 FX_INT32 len = (FX_INT32)strlen(CodaBarR.ALPHABET_STRING);
185 for (FX_INT32 i = 0; i < len; i++) {
186 if (ch == CodaBarR.ALPHABET_STRING[i]) {
187 code = CodaBarR.CHARACTER_ENCODINGS[i];
188 break;
189 }
190 }
191 FX_BYTE color = 1;
192 FX_INT32 counter = 0;
193 FX_INT32 bit = 0;
194 while (bit < 7) {
195 result[position] = color;
196 position++;
197 if (((code >> (6 - bit)) & 1) == 0 || counter == m_iWideNarrRatio - 1) {
198 color = !color;
199 bit++;
200 counter = 0;
201 } else {
202 counter++;
203 }
204 }
205 if (index < data.GetLength() - 1) {
206 result[position] = 0;
207 position ++;
208 }
209 }
210 outLength = position;
211 return result;
212 }
213 CFX_WideString CBC_OnedCodaBarWriter::encodedContents(FX_WSTR contents)
214 {
215 CFX_WideString strStart(m_chStart);
216 CFX_WideString strEnd(m_chEnd);
217 return strStart + contents + strEnd;
218 }
219 void CBC_OnedCodaBarWriter::RenderResult(FX_WSTR contents, FX_BYTE* code, FX_INT 32 codeLength, FX_BOOL isDevice, FX_INT32 &e)
220 {
221 CBC_OneDimWriter::RenderResult(encodedContents(contents), code, codeLength, isDevice, e);
222 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/src/BC_OnedCodaBarReader.cpp ('k') | xfa/src/fxbarcode/src/BC_OnedCode128Reader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698