blob: 53f92c3d28cd0d63a244df3fad4990fba4184bf7 [file] [log] [blame]
Dan Sinclair1770c022016-03-14 14:14:16 -04001// 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
Lei Zhang6714ff82017-04-27 13:21:00 -070023#include "fxbarcode/datamatrix/BC_TextEncoder.h"
24
Dan Sinclaire7786682017-03-29 15:18:41 -040025#include "fxbarcode/BC_Dimension.h"
26#include "fxbarcode/common/BC_CommonBitMatrix.h"
27#include "fxbarcode/datamatrix/BC_C40Encoder.h"
28#include "fxbarcode/datamatrix/BC_Encoder.h"
29#include "fxbarcode/datamatrix/BC_EncoderContext.h"
30#include "fxbarcode/datamatrix/BC_HighLevelEncoder.h"
31#include "fxbarcode/datamatrix/BC_SymbolInfo.h"
32#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040033
34CBC_TextEncoder::CBC_TextEncoder() {}
35CBC_TextEncoder::~CBC_TextEncoder() {}
36int32_t CBC_TextEncoder::getEncodingMode() {
37 return TEXT_ENCODATION;
38}
Dan Sinclair812e96c2017-03-13 16:43:37 -040039int32_t CBC_TextEncoder::encodeChar(wchar_t c, CFX_WideString& sb, int32_t& e) {
Dan Sinclair1770c022016-03-14 14:14:16 -040040 if (c == ' ') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040041 sb += (wchar_t)'\3';
Dan Sinclair1770c022016-03-14 14:14:16 -040042 return 1;
43 }
44 if (c >= '0' && c <= '9') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040045 sb += (wchar_t)(c - 48 + 4);
Dan Sinclair1770c022016-03-14 14:14:16 -040046 return 1;
47 }
48 if (c >= 'a' && c <= 'z') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040049 sb += (wchar_t)(c - 97 + 14);
Dan Sinclair1770c022016-03-14 14:14:16 -040050 return 1;
51 }
52 if (c <= 0x1f) {
Dan Sinclair812e96c2017-03-13 16:43:37 -040053 sb += (wchar_t)'\0';
Dan Sinclair1770c022016-03-14 14:14:16 -040054 sb += c;
55 return 2;
56 }
57 if (c >= '!' && c <= '/') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040058 sb += (wchar_t)'\1';
59 sb += (wchar_t)(c - 33);
Dan Sinclair1770c022016-03-14 14:14:16 -040060 return 2;
61 }
62 if (c >= ':' && c <= '@') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040063 sb += (wchar_t)'\1';
64 sb += (wchar_t)(c - 58 + 15);
Dan Sinclair1770c022016-03-14 14:14:16 -040065 return 2;
66 }
67 if (c >= '[' && c <= '_') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040068 sb += (wchar_t)'\1';
69 sb += (wchar_t)(c - 91 + 22);
Dan Sinclair1770c022016-03-14 14:14:16 -040070 return 2;
71 }
72 if (c == 0x0060) {
Dan Sinclair812e96c2017-03-13 16:43:37 -040073 sb += (wchar_t)'\2';
74 sb += (wchar_t)(c - 96);
Dan Sinclair1770c022016-03-14 14:14:16 -040075 return 2;
76 }
77 if (c >= 'A' && c <= 'Z') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040078 sb += (wchar_t)'\2';
79 sb += (wchar_t)(c - 65 + 1);
Dan Sinclair1770c022016-03-14 14:14:16 -040080 return 2;
81 }
82 if (c >= '{' && c <= 0x007f) {
Dan Sinclair812e96c2017-03-13 16:43:37 -040083 sb += (wchar_t)'\2';
84 sb += (wchar_t)(c - 123 + 27);
Dan Sinclair1770c022016-03-14 14:14:16 -040085 return 2;
86 }
87 if (c >= 0x0080) {
Dan Sinclair812e96c2017-03-13 16:43:37 -040088 sb += (wchar_t)'\1';
89 sb += (wchar_t)0x001e;
Dan Sinclair1770c022016-03-14 14:14:16 -040090 int32_t len = 2;
Dan Sinclair812e96c2017-03-13 16:43:37 -040091 len += encodeChar((wchar_t)(c - 128), sb, e);
Tom Sepezc8017b22017-01-31 13:02:10 -080092 if (e != BCExceptionNO)
93 return -1;
Dan Sinclair1770c022016-03-14 14:14:16 -040094 return len;
95 }
Lei Zhang6714ff82017-04-27 13:21:00 -070096 e = BCExceptionIllegalArgument;
Dan Sinclair1770c022016-03-14 14:14:16 -040097 return -1;
98}