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

Side by Side Diff: xfa/src/fxbarcode/src/BC_X12Encoder.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
« no previous file with comments | « xfa/src/fxbarcode/src/BC_Writer.cpp ('k') | xfa/src/fxbarcode/src/barcode.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2006-2007 Jeremias Maerki.
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_Encoder.h"
25 #include "include/BC_CommonBitMatrix.h"
26 #include "include/BC_Dimension.h"
27 #include "include/BC_SymbolShapeHint.h"
28 #include "include/BC_SymbolInfo.h"
29 #include "include/BC_EncoderContext.h"
30 #include "include/BC_HighLevelEncoder.h"
31 #include "include/BC_C40Encoder.h"
32 #include "include/BC_X12Encoder.h"
33 CBC_X12Encoder::CBC_X12Encoder()
34 {
35 }
36 CBC_X12Encoder::~CBC_X12Encoder()
37 {
38 }
39 FX_INT32 CBC_X12Encoder::getEncodingMode()
40 {
41 return X12_ENCODATION;
42 }
43 void CBC_X12Encoder::Encode(CBC_EncoderContext &context, FX_INT32 &e)
44 {
45 CFX_WideString buffer;
46 while (context.hasMoreCharacters()) {
47 FX_WCHAR c = context.getCurrentChar();
48 context.m_pos++;
49 encodeChar(c, buffer, e);
50 if (e != BCExceptionNO) {
51 return;
52 }
53 FX_INT32 count = buffer.GetLength();
54 if ((count % 3) == 0) {
55 writeNextTriplet(context, buffer);
56 FX_INT32 newMode = CBC_HighLevelEncoder::lookAheadTest(context.m_msg , context.m_pos, getEncodingMode());
57 if (newMode != getEncodingMode()) {
58 context.signalEncoderChange(newMode);
59 break;
60 }
61 }
62 }
63 handleEOD(context, buffer, e);
64 }
65 void CBC_X12Encoder::handleEOD(CBC_EncoderContext &context, CFX_WideString &buff er, FX_INT32 &e)
66 {
67 context.updateSymbolInfo(e);
68 if (e != BCExceptionNO) {
69 return;
70 }
71 FX_INT32 available = context.m_symbolInfo->m_dataCapacity - context.getCodew ordCount();
72 FX_INT32 count = buffer.GetLength();
73 if (count == 2) {
74 context.writeCodeword(CBC_HighLevelEncoder::X12_UNLATCH);
75 context.m_pos -= 2;
76 context.signalEncoderChange(ASCII_ENCODATION);
77 } else if (count == 1) {
78 context.m_pos--;
79 if (available > 1) {
80 context.writeCodeword(CBC_HighLevelEncoder::X12_UNLATCH);
81 }
82 context.signalEncoderChange(ASCII_ENCODATION);
83 }
84 }
85 FX_INT32 CBC_X12Encoder::encodeChar(FX_WCHAR c, CFX_WideString &sb, FX_INT32 &e)
86 {
87 if (c == '\r') {
88 sb += (FX_WCHAR)'\0';
89 } else if (c == '*') {
90 sb += (FX_WCHAR)'\1';
91 } else if (c == '>') {
92 sb += (FX_WCHAR)'\2';
93 } else if (c == ' ') {
94 sb += (FX_WCHAR)'\3';
95 } else if (c >= '0' && c <= '9') {
96 sb += (FX_WCHAR) (c - 48 + 4);
97 } else if (c >= 'A' && c <= 'Z') {
98 sb += (FX_WCHAR) (c - 65 + 14);
99 } else {
100 CBC_HighLevelEncoder::illegalCharacter(c, e);
101 BC_EXCEPTION_CHECK_ReturnValue(e, -1);
102 }
103 return 1;
104 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/src/BC_Writer.cpp ('k') | xfa/src/fxbarcode/src/barcode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698