OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 // Original code is licensed as follows: | 6 // Original code is licensed as follows: |
7 /* | 7 /* |
8 * Copyright 2006-2007 Jeremias Maerki. | 8 * Copyright 2006-2007 Jeremias Maerki. |
9 * | 9 * |
10 * Licensed under the Apache License, Version 2.0 (the "License"); | 10 * Licensed under the Apache License, Version 2.0 (the "License"); |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "BC_EncoderContext.h" | 29 #include "BC_EncoderContext.h" |
30 #include "BC_HighLevelEncoder.h" | 30 #include "BC_HighLevelEncoder.h" |
31 #include "BC_C40Encoder.h" | 31 #include "BC_C40Encoder.h" |
32 #include "BC_X12Encoder.h" | 32 #include "BC_X12Encoder.h" |
33 CBC_X12Encoder::CBC_X12Encoder() | 33 CBC_X12Encoder::CBC_X12Encoder() |
34 { | 34 { |
35 } | 35 } |
36 CBC_X12Encoder::~CBC_X12Encoder() | 36 CBC_X12Encoder::~CBC_X12Encoder() |
37 { | 37 { |
38 } | 38 } |
39 FX_INT32 CBC_X12Encoder::getEncodingMode() | 39 int32_t CBC_X12Encoder::getEncodingMode() |
40 { | 40 { |
41 return X12_ENCODATION; | 41 return X12_ENCODATION; |
42 } | 42 } |
43 void CBC_X12Encoder::Encode(CBC_EncoderContext &context, FX_INT32 &e) | 43 void CBC_X12Encoder::Encode(CBC_EncoderContext &context, int32_t &e) |
44 { | 44 { |
45 CFX_WideString buffer; | 45 CFX_WideString buffer; |
46 while (context.hasMoreCharacters()) { | 46 while (context.hasMoreCharacters()) { |
47 FX_WCHAR c = context.getCurrentChar(); | 47 FX_WCHAR c = context.getCurrentChar(); |
48 context.m_pos++; | 48 context.m_pos++; |
49 encodeChar(c, buffer, e); | 49 encodeChar(c, buffer, e); |
50 if (e != BCExceptionNO) { | 50 if (e != BCExceptionNO) { |
51 return; | 51 return; |
52 } | 52 } |
53 FX_INT32 count = buffer.GetLength(); | 53 int32_t count = buffer.GetLength(); |
54 if ((count % 3) == 0) { | 54 if ((count % 3) == 0) { |
55 writeNextTriplet(context, buffer); | 55 writeNextTriplet(context, buffer); |
56 FX_INT32 newMode = CBC_HighLevelEncoder::lookAheadTest(context.m_msg
, context.m_pos, getEncodingMode()); | 56 int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(context.m_msg,
context.m_pos, getEncodingMode()); |
57 if (newMode != getEncodingMode()) { | 57 if (newMode != getEncodingMode()) { |
58 context.signalEncoderChange(newMode); | 58 context.signalEncoderChange(newMode); |
59 break; | 59 break; |
60 } | 60 } |
61 } | 61 } |
62 } | 62 } |
63 handleEOD(context, buffer, e); | 63 handleEOD(context, buffer, e); |
64 } | 64 } |
65 void CBC_X12Encoder::handleEOD(CBC_EncoderContext &context, CFX_WideString &buff
er, FX_INT32 &e) | 65 void CBC_X12Encoder::handleEOD(CBC_EncoderContext &context, CFX_WideString &buff
er, int32_t &e) |
66 { | 66 { |
67 context.updateSymbolInfo(e); | 67 context.updateSymbolInfo(e); |
68 if (e != BCExceptionNO) { | 68 if (e != BCExceptionNO) { |
69 return; | 69 return; |
70 } | 70 } |
71 FX_INT32 available = context.m_symbolInfo->m_dataCapacity - context.getCodew
ordCount(); | 71 int32_t available = context.m_symbolInfo->m_dataCapacity - context.getCodewo
rdCount(); |
72 FX_INT32 count = buffer.GetLength(); | 72 int32_t count = buffer.GetLength(); |
73 if (count == 2) { | 73 if (count == 2) { |
74 context.writeCodeword(CBC_HighLevelEncoder::X12_UNLATCH); | 74 context.writeCodeword(CBC_HighLevelEncoder::X12_UNLATCH); |
75 context.m_pos -= 2; | 75 context.m_pos -= 2; |
76 context.signalEncoderChange(ASCII_ENCODATION); | 76 context.signalEncoderChange(ASCII_ENCODATION); |
77 } else if (count == 1) { | 77 } else if (count == 1) { |
78 context.m_pos--; | 78 context.m_pos--; |
79 if (available > 1) { | 79 if (available > 1) { |
80 context.writeCodeword(CBC_HighLevelEncoder::X12_UNLATCH); | 80 context.writeCodeword(CBC_HighLevelEncoder::X12_UNLATCH); |
81 } | 81 } |
82 context.signalEncoderChange(ASCII_ENCODATION); | 82 context.signalEncoderChange(ASCII_ENCODATION); |
83 } | 83 } |
84 } | 84 } |
85 FX_INT32 CBC_X12Encoder::encodeChar(FX_WCHAR c, CFX_WideString &sb, FX_INT32 &e) | 85 int32_t CBC_X12Encoder::encodeChar(FX_WCHAR c, CFX_WideString &sb, int32_t &e) |
86 { | 86 { |
87 if (c == '\r') { | 87 if (c == '\r') { |
88 sb += (FX_WCHAR)'\0'; | 88 sb += (FX_WCHAR)'\0'; |
89 } else if (c == '*') { | 89 } else if (c == '*') { |
90 sb += (FX_WCHAR)'\1'; | 90 sb += (FX_WCHAR)'\1'; |
91 } else if (c == '>') { | 91 } else if (c == '>') { |
92 sb += (FX_WCHAR)'\2'; | 92 sb += (FX_WCHAR)'\2'; |
93 } else if (c == ' ') { | 93 } else if (c == ' ') { |
94 sb += (FX_WCHAR)'\3'; | 94 sb += (FX_WCHAR)'\3'; |
95 } else if (c >= '0' && c <= '9') { | 95 } else if (c >= '0' && c <= '9') { |
96 sb += (FX_WCHAR) (c - 48 + 4); | 96 sb += (FX_WCHAR) (c - 48 + 4); |
97 } else if (c >= 'A' && c <= 'Z') { | 97 } else if (c >= 'A' && c <= 'Z') { |
98 sb += (FX_WCHAR) (c - 65 + 14); | 98 sb += (FX_WCHAR) (c - 65 + 14); |
99 } else { | 99 } else { |
100 CBC_HighLevelEncoder::illegalCharacter(c, e); | 100 CBC_HighLevelEncoder::illegalCharacter(c, e); |
101 BC_EXCEPTION_CHECK_ReturnValue(e, -1); | 101 BC_EXCEPTION_CHECK_ReturnValue(e, -1); |
102 } | 102 } |
103 return 1; | 103 return 1; |
104 } | 104 } |
OLD | NEW |