blob: a521acb6c3bc6c7ebe4b05b69b18ade292444e19 [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
Dan Sinclaire7786682017-03-29 15:18:41 -040023#include "fxbarcode/BC_Dimension.h"
24#include "fxbarcode/common/BC_CommonBitMatrix.h"
25#include "fxbarcode/datamatrix/BC_C40Encoder.h"
26#include "fxbarcode/datamatrix/BC_Encoder.h"
27#include "fxbarcode/datamatrix/BC_EncoderContext.h"
28#include "fxbarcode/datamatrix/BC_HighLevelEncoder.h"
29#include "fxbarcode/datamatrix/BC_SymbolInfo.h"
30#include "fxbarcode/datamatrix/BC_SymbolShapeHint.h"
31#include "fxbarcode/datamatrix/BC_TextEncoder.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040032
33CBC_TextEncoder::CBC_TextEncoder() {}
34CBC_TextEncoder::~CBC_TextEncoder() {}
35int32_t CBC_TextEncoder::getEncodingMode() {
36 return TEXT_ENCODATION;
37}
Dan Sinclair812e96c2017-03-13 16:43:37 -040038int32_t CBC_TextEncoder::encodeChar(wchar_t c, CFX_WideString& sb, int32_t& e) {
Dan Sinclair1770c022016-03-14 14:14:16 -040039 if (c == ' ') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040040 sb += (wchar_t)'\3';
Dan Sinclair1770c022016-03-14 14:14:16 -040041 return 1;
42 }
43 if (c >= '0' && c <= '9') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040044 sb += (wchar_t)(c - 48 + 4);
Dan Sinclair1770c022016-03-14 14:14:16 -040045 return 1;
46 }
47 if (c >= 'a' && c <= 'z') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040048 sb += (wchar_t)(c - 97 + 14);
Dan Sinclair1770c022016-03-14 14:14:16 -040049 return 1;
50 }
51 if (c <= 0x1f) {
Dan Sinclair812e96c2017-03-13 16:43:37 -040052 sb += (wchar_t)'\0';
Dan Sinclair1770c022016-03-14 14:14:16 -040053 sb += c;
54 return 2;
55 }
56 if (c >= '!' && c <= '/') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040057 sb += (wchar_t)'\1';
58 sb += (wchar_t)(c - 33);
Dan Sinclair1770c022016-03-14 14:14:16 -040059 return 2;
60 }
61 if (c >= ':' && c <= '@') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040062 sb += (wchar_t)'\1';
63 sb += (wchar_t)(c - 58 + 15);
Dan Sinclair1770c022016-03-14 14:14:16 -040064 return 2;
65 }
66 if (c >= '[' && c <= '_') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040067 sb += (wchar_t)'\1';
68 sb += (wchar_t)(c - 91 + 22);
Dan Sinclair1770c022016-03-14 14:14:16 -040069 return 2;
70 }
71 if (c == 0x0060) {
Dan Sinclair812e96c2017-03-13 16:43:37 -040072 sb += (wchar_t)'\2';
73 sb += (wchar_t)(c - 96);
Dan Sinclair1770c022016-03-14 14:14:16 -040074 return 2;
75 }
76 if (c >= 'A' && c <= 'Z') {
Dan Sinclair812e96c2017-03-13 16:43:37 -040077 sb += (wchar_t)'\2';
78 sb += (wchar_t)(c - 65 + 1);
Dan Sinclair1770c022016-03-14 14:14:16 -040079 return 2;
80 }
81 if (c >= '{' && c <= 0x007f) {
Dan Sinclair812e96c2017-03-13 16:43:37 -040082 sb += (wchar_t)'\2';
83 sb += (wchar_t)(c - 123 + 27);
Dan Sinclair1770c022016-03-14 14:14:16 -040084 return 2;
85 }
86 if (c >= 0x0080) {
Dan Sinclair812e96c2017-03-13 16:43:37 -040087 sb += (wchar_t)'\1';
88 sb += (wchar_t)0x001e;
Dan Sinclair1770c022016-03-14 14:14:16 -040089 int32_t len = 2;
Dan Sinclair812e96c2017-03-13 16:43:37 -040090 len += encodeChar((wchar_t)(c - 128), sb, e);
Tom Sepezc8017b22017-01-31 13:02:10 -080091 if (e != BCExceptionNO)
92 return -1;
Dan Sinclair1770c022016-03-14 14:14:16 -040093 return len;
94 }
95 CBC_HighLevelEncoder::illegalCharacter(c, e);
96 return -1;
97}