• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // 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 
21 #include "fxbarcode/datamatrix/BC_TextEncoder.h"
22 
23 #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/utils.h"
30 
CBC_TextEncoder()31 CBC_TextEncoder::CBC_TextEncoder() {}
~CBC_TextEncoder()32 CBC_TextEncoder::~CBC_TextEncoder() {}
getEncodingMode()33 int32_t CBC_TextEncoder::getEncodingMode() {
34   return TEXT_ENCODATION;
35 }
encodeChar(wchar_t c,WideString & sb,int32_t & e)36 int32_t CBC_TextEncoder::encodeChar(wchar_t c, WideString& sb, int32_t& e) {
37   if (c == ' ') {
38     sb += (wchar_t)'\3';
39     return 1;
40   }
41   if (c >= '0' && c <= '9') {
42     sb += (wchar_t)(c - 48 + 4);
43     return 1;
44   }
45   if (c >= 'a' && c <= 'z') {
46     sb += (wchar_t)(c - 97 + 14);
47     return 1;
48   }
49   if (c <= 0x1f) {
50     sb += (wchar_t)'\0';
51     sb += c;
52     return 2;
53   }
54   if (c >= '!' && c <= '/') {
55     sb += (wchar_t)'\1';
56     sb += (wchar_t)(c - 33);
57     return 2;
58   }
59   if (c >= ':' && c <= '@') {
60     sb += (wchar_t)'\1';
61     sb += (wchar_t)(c - 58 + 15);
62     return 2;
63   }
64   if (c >= '[' && c <= '_') {
65     sb += (wchar_t)'\1';
66     sb += (wchar_t)(c - 91 + 22);
67     return 2;
68   }
69   if (c == 0x0060) {
70     sb += (wchar_t)'\2';
71     sb += (wchar_t)(c - 96);
72     return 2;
73   }
74   if (c >= 'A' && c <= 'Z') {
75     sb += (wchar_t)'\2';
76     sb += (wchar_t)(c - 65 + 1);
77     return 2;
78   }
79   if (c >= '{' && c <= 0x007f) {
80     sb += (wchar_t)'\2';
81     sb += (wchar_t)(c - 123 + 27);
82     return 2;
83   }
84   if (c >= 0x0080) {
85     sb += (wchar_t)'\1';
86     sb += (wchar_t)0x001e;
87     int32_t len = 2;
88     len += encodeChar((wchar_t)(c - 128), sb, e);
89     if (e != BCExceptionNO)
90       return -1;
91     return len;
92   }
93   e = BCExceptionIllegalArgument;
94   return -1;
95 }
96