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

Side by Side Diff: xfa/src/fxbarcode/src/BC_ASCIIEncoder.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/qrcode/BC_QRGridSampler.cpp ('k') | xfa/src/fxbarcode/src/BC_BarCode.cpp » ('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_Dimension.h"
26 #include "include/BC_SymbolShapeHint.h"
27 #include "include/BC_SymbolInfo.h"
28 #include "include/BC_EncoderContext.h"
29 #include "include/BC_HighLevelEncoder.h"
30 #include "include/BC_ASCIIEncoder.h"
31 CBC_ASCIIEncoder::CBC_ASCIIEncoder()
32 {
33 }
34 CBC_ASCIIEncoder::~CBC_ASCIIEncoder()
35 {
36 }
37 FX_INT32 CBC_ASCIIEncoder::getEncodingMode()
38 {
39 return ASCII_ENCODATION;
40 }
41 void CBC_ASCIIEncoder::Encode(CBC_EncoderContext &context, FX_INT32 &e)
42 {
43 FX_INT32 n = CBC_HighLevelEncoder::determineConsecutiveDigitCount(context.m_ msg, context.m_pos);
44 if (n >= 2) {
45 FX_WCHAR code = encodeASCIIDigits(context.m_msg.GetAt(context.m_pos), co ntext.m_msg.GetAt(context.m_pos + 1), e);
46 if (e != BCExceptionNO) {
47 return;
48 }
49 context.writeCodeword(code);
50 context.m_pos += 2;
51 } else {
52 FX_WCHAR c = context.getCurrentChar();
53 FX_INT32 newMode = CBC_HighLevelEncoder::lookAheadTest(context.m_msg, co ntext.m_pos, getEncodingMode());
54 if (newMode != getEncodingMode()) {
55 switch (newMode) {
56 case BASE256_ENCODATION:
57 context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_BASE256 );
58 context.signalEncoderChange(BASE256_ENCODATION);
59 return;
60 case C40_ENCODATION:
61 context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_C40);
62 context.signalEncoderChange(C40_ENCODATION);
63 return;
64 case X12_ENCODATION:
65 context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_ANSIX12 );
66 context.signalEncoderChange(X12_ENCODATION);
67 break;
68 case TEXT_ENCODATION:
69 context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_TEXT);
70 context.signalEncoderChange(TEXT_ENCODATION);
71 break;
72 case EDIFACT_ENCODATION:
73 context.writeCodeword(CBC_HighLevelEncoder::LATCH_TO_EDIFACT );
74 context.signalEncoderChange(EDIFACT_ENCODATION);
75 break;
76 default:
77 e = BCExceptionIllegalStateIllegalMode;
78 return;
79 }
80 } else if (CBC_HighLevelEncoder::isExtendedASCII(c)) {
81 context.writeCodeword(CBC_HighLevelEncoder::UPPER_SHIFT);
82 context.writeCodeword((FX_WCHAR) (c - 128 + 1));
83 context.m_pos++;
84 } else {
85 context.writeCodeword((FX_WCHAR) (c + 1));
86 context.m_pos++;
87 }
88 }
89 }
90 FX_WCHAR CBC_ASCIIEncoder::encodeASCIIDigits(FX_WCHAR digit1, FX_WCHAR digit2, F X_INT32 &e)
91 {
92 if (CBC_HighLevelEncoder::isDigit(digit1) && CBC_HighLevelEncoder::isDigit(d igit2)) {
93 FX_INT32 num = (digit1 - 48) * 10 + (digit2 - 48);
94 FX_WCHAR a = (FX_WCHAR) (num + 130);
95 return (FX_WCHAR) (num + 130);
96 }
97 e = BCExceptionIllegalArgumentNotGigits;
98 return 0;
99 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/qrcode/BC_QRGridSampler.cpp ('k') | xfa/src/fxbarcode/src/BC_BarCode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698