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