Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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 | |
Lei Zhang | 6714ff8 | 2017-04-27 13:21:00 -0700 | [diff] [blame] | 21 | #include "fxbarcode/datamatrix/BC_TextEncoder.h" |
| 22 | |
Dan Sinclair | e778668 | 2017-03-29 15:18:41 -0400 | [diff] [blame] | 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/datamatrix/BC_SymbolShapeHint.h" |
Lei Zhang | 60cd033 | 2017-04-27 23:58:03 -0700 | [diff] [blame^] | 30 | #include "fxbarcode/utils.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 31 | |
| 32 | CBC_TextEncoder::CBC_TextEncoder() {} |
| 33 | CBC_TextEncoder::~CBC_TextEncoder() {} |
| 34 | int32_t CBC_TextEncoder::getEncodingMode() { |
| 35 | return TEXT_ENCODATION; |
| 36 | } |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 37 | int32_t CBC_TextEncoder::encodeChar(wchar_t c, CFX_WideString& sb, int32_t& e) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 38 | if (c == ' ') { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 39 | sb += (wchar_t)'\3'; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 40 | return 1; |
| 41 | } |
| 42 | if (c >= '0' && c <= '9') { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 43 | sb += (wchar_t)(c - 48 + 4); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 44 | return 1; |
| 45 | } |
| 46 | if (c >= 'a' && c <= 'z') { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 47 | sb += (wchar_t)(c - 97 + 14); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 48 | return 1; |
| 49 | } |
| 50 | if (c <= 0x1f) { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 51 | sb += (wchar_t)'\0'; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 52 | sb += c; |
| 53 | return 2; |
| 54 | } |
| 55 | if (c >= '!' && c <= '/') { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 56 | sb += (wchar_t)'\1'; |
| 57 | sb += (wchar_t)(c - 33); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 58 | return 2; |
| 59 | } |
| 60 | if (c >= ':' && c <= '@') { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 61 | sb += (wchar_t)'\1'; |
| 62 | sb += (wchar_t)(c - 58 + 15); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 63 | return 2; |
| 64 | } |
| 65 | if (c >= '[' && c <= '_') { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 66 | sb += (wchar_t)'\1'; |
| 67 | sb += (wchar_t)(c - 91 + 22); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 68 | return 2; |
| 69 | } |
| 70 | if (c == 0x0060) { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 71 | sb += (wchar_t)'\2'; |
| 72 | sb += (wchar_t)(c - 96); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 73 | return 2; |
| 74 | } |
| 75 | if (c >= 'A' && c <= 'Z') { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 76 | sb += (wchar_t)'\2'; |
| 77 | sb += (wchar_t)(c - 65 + 1); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 78 | return 2; |
| 79 | } |
| 80 | if (c >= '{' && c <= 0x007f) { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 81 | sb += (wchar_t)'\2'; |
| 82 | sb += (wchar_t)(c - 123 + 27); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 83 | return 2; |
| 84 | } |
| 85 | if (c >= 0x0080) { |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 86 | sb += (wchar_t)'\1'; |
| 87 | sb += (wchar_t)0x001e; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 88 | int32_t len = 2; |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 89 | len += encodeChar((wchar_t)(c - 128), sb, e); |
Tom Sepez | c8017b2 | 2017-01-31 13:02:10 -0800 | [diff] [blame] | 90 | if (e != BCExceptionNO) |
| 91 | return -1; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 92 | return len; |
| 93 | } |
Lei Zhang | 6714ff8 | 2017-04-27 13:21:00 -0700 | [diff] [blame] | 94 | e = BCExceptionIllegalArgument; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 95 | return -1; |
| 96 | } |