blob: ec7ff4751fe7a26270ea876787982b4501a2075e [file] [log] [blame]
Dan Sinclair1770c022016-03-14 14:14:16 -04001// found in the LICENSE file.
2
3// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
4// Original code is licensed as follows:
5/*
6 * Copyright 2006-2007 Jeremias Maerki.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
Lei Zhang6714ff82017-04-27 13:21:00 -070021#include "fxbarcode/datamatrix/BC_TextEncoder.h"
22
Dan Sinclaire7786682017-03-29 15:18:41 -040023#include "fxbarcode/common/BC_CommonBitMatrix.h"
24#include "fxbarcode/datamatrix/BC_C40Encoder.h"
25#include "fxbarcode/datamatrix/BC_Encoder.h"
26#include "fxbarcode/datamatrix/BC_EncoderContext.h"
27#include "fxbarcode/datamatrix/BC_HighLevelEncoder.h"
28#include "fxbarcode/datamatrix/BC_SymbolInfo.h"
29#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
Lei Zhang60cd0332017-04-27 23:58:03 -070030#include "fxbarcode/utils.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040031
32CBC_TextEncoder::CBC_TextEncoder() {}
33CBC_TextEncoder::~CBC_TextEncoder() {}
34int32_t CBC_TextEncoder::getEncodingMode() {
35 return TEXT_ENCODATION;
36}
Dan Sinclair812e96c2017-03-13 16:43:37 -040037int32_t CBC_TextEncoder::encodeChar(wchar_t c, CFX_WideString& sb, int32_t& e) {
Dan Sinclair1770c022016-03-14 14:14:16 -040038 if (c == ' ') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040039 sb += (wchar_t)'\3';
Dan Sinclair1770c022016-03-14 14:14:16 -040040 return 1;
41 }
42 if (c >= '0' && c <= '9') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040043 sb += (wchar_t)(c - 48 + 4);
Dan Sinclair1770c022016-03-14 14:14:16 -040044 return 1;
45 }
46 if (c >= 'a' && c <= 'z') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040047 sb += (wchar_t)(c - 97 + 14);
Dan Sinclair1770c022016-03-14 14:14:16 -040048 return 1;
49 }
50 if (c <= 0x1f) {
Dan Sinclair812e96c2017-03-13 16:43:37 -040051 sb += (wchar_t)'\0';
Dan Sinclair1770c022016-03-14 14:14:16 -040052 sb += c;
53 return 2;
54 }
55 if (c >= '!' && c <= '/') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040056 sb += (wchar_t)'\1';
57 sb += (wchar_t)(c - 33);
Dan Sinclair1770c022016-03-14 14:14:16 -040058 return 2;
59 }
60 if (c >= ':' && c <= '@') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040061 sb += (wchar_t)'\1';
62 sb += (wchar_t)(c - 58 + 15);
Dan Sinclair1770c022016-03-14 14:14:16 -040063 return 2;
64 }
65 if (c >= '[' && c <= '_') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040066 sb += (wchar_t)'\1';
67 sb += (wchar_t)(c - 91 + 22);
Dan Sinclair1770c022016-03-14 14:14:16 -040068 return 2;
69 }
70 if (c == 0x0060) {
Dan Sinclair812e96c2017-03-13 16:43:37 -040071 sb += (wchar_t)'\2';
72 sb += (wchar_t)(c - 96);
Dan Sinclair1770c022016-03-14 14:14:16 -040073 return 2;
74 }
75 if (c >= 'A' && c <= 'Z') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040076 sb += (wchar_t)'\2';
77 sb += (wchar_t)(c - 65 + 1);
Dan Sinclair1770c022016-03-14 14:14:16 -040078 return 2;
79 }
80 if (c >= '{' && c <= 0x007f) {
Dan Sinclair812e96c2017-03-13 16:43:37 -040081 sb += (wchar_t)'\2';
82 sb += (wchar_t)(c - 123 + 27);
Dan Sinclair1770c022016-03-14 14:14:16 -040083 return 2;
84 }
85 if (c >= 0x0080) {
Dan Sinclair812e96c2017-03-13 16:43:37 -040086 sb += (wchar_t)'\1';
87 sb += (wchar_t)0x001e;
Dan Sinclair1770c022016-03-14 14:14:16 -040088 int32_t len = 2;
Dan Sinclair812e96c2017-03-13 16:43:37 -040089 len += encodeChar((wchar_t)(c - 128), sb, e);
Tom Sepezc8017b22017-01-31 13:02:10 -080090 if (e != BCExceptionNO)
91 return -1;
Dan Sinclair1770c022016-03-14 14:14:16 -040092 return len;
93 }
Lei Zhang6714ff82017-04-27 13:21:00 -070094 e = BCExceptionIllegalArgument;
Dan Sinclair1770c022016-03-14 14:14:16 -040095 return -1;
96}