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 2010 ZXing authors | 8 * Copyright 2010 ZXing authors |
9 * | 9 * |
10 * Licensed under the Apache License, Version 2.0 (the "License"); | 10 * Licensed under the Apache License, Version 2.0 (the "License"); |
11 * you may not use this file except in compliance with 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 | 12 * You may obtain a copy of the License at |
13 * | 13 * |
14 * http://www.apache.org/licenses/LICENSE-2.0 | 14 * http://www.apache.org/licenses/LICENSE-2.0 |
15 * | 15 * |
16 * Unless required by applicable law or agreed to in writing, software | 16 * Unless required by applicable law or agreed to in writing, software |
17 * distributed under the License is distributed on an "AS IS" BASIS, | 17 * distributed under the License is distributed on an "AS IS" BASIS, |
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
19 * See the License for the specific language governing permissions and | 19 * See the License for the specific language governing permissions and |
20 * limitations under the License. | 20 * limitations under the License. |
21 */ | 21 */ |
22 | 22 |
23 #include "core/fxge/include/cfx_gemodule.h" | 23 #include "core/fxge/include/cfx_gemodule.h" |
24 #include "xfa/fxbarcode/BC_Writer.h" | 24 #include "xfa/fxbarcode/BC_Writer.h" |
25 #include "xfa/fxbarcode/oned/BC_OneDimWriter.h" | 25 #include "xfa/fxbarcode/oned/BC_OneDimWriter.h" |
26 #include "xfa/fxbarcode/oned/BC_OnedEAN13Writer.h" | 26 #include "xfa/fxbarcode/oned/BC_OnedEAN13Writer.h" |
27 #include "xfa/fxbarcode/oned/BC_OnedUPCAWriter.h" | 27 #include "xfa/fxbarcode/oned/BC_OnedUPCAWriter.h" |
28 | 28 |
29 CBC_OnedUPCAWriter::CBC_OnedUPCAWriter() { | 29 CBC_OnedUPCAWriter::CBC_OnedUPCAWriter() { |
30 m_subWriter = nullptr; | |
31 m_bLeftPadding = TRUE; | 30 m_bLeftPadding = TRUE; |
32 m_bRightPadding = TRUE; | 31 m_bRightPadding = TRUE; |
33 } | 32 } |
| 33 |
34 void CBC_OnedUPCAWriter::Init() { | 34 void CBC_OnedUPCAWriter::Init() { |
35 m_subWriter = new CBC_OnedEAN13Writer; | 35 m_subWriter.reset(new CBC_OnedEAN13Writer); |
36 } | 36 } |
37 CBC_OnedUPCAWriter::~CBC_OnedUPCAWriter() { | 37 |
38 delete m_subWriter; | 38 CBC_OnedUPCAWriter::~CBC_OnedUPCAWriter() {} |
39 } | |
40 | 39 |
41 FX_BOOL CBC_OnedUPCAWriter::CheckContentValidity( | 40 FX_BOOL CBC_OnedUPCAWriter::CheckContentValidity( |
42 const CFX_WideStringC& contents) { | 41 const CFX_WideStringC& contents) { |
43 for (FX_STRSIZE i = 0; i < contents.GetLength(); ++i) { | 42 for (FX_STRSIZE i = 0; i < contents.GetLength(); ++i) { |
44 if (contents.GetAt(i) < '0' || contents.GetAt(i) > '9') | 43 if (contents.GetAt(i) < '0' || contents.GetAt(i) > '9') |
45 return FALSE; | 44 return FALSE; |
46 } | 45 } |
47 return TRUE; | 46 return TRUE; |
48 } | 47 } |
49 | 48 |
50 CFX_WideString CBC_OnedUPCAWriter::FilterContents( | 49 CFX_WideString CBC_OnedUPCAWriter::FilterContents( |
51 const CFX_WideStringC& contents) { | 50 const CFX_WideStringC& contents) { |
52 CFX_WideString filtercontents; | 51 CFX_WideString filtercontents; |
53 FX_WCHAR ch; | 52 FX_WCHAR ch; |
54 for (int32_t i = 0; i < contents.GetLength(); i++) { | 53 for (int32_t i = 0; i < contents.GetLength(); i++) { |
55 ch = contents.GetAt(i); | 54 ch = contents.GetAt(i); |
56 if (ch > 175) { | 55 if (ch > 175) { |
57 i++; | 56 i++; |
58 continue; | 57 continue; |
59 } | 58 } |
60 if (ch >= '0' && ch <= '9') { | 59 if (ch >= '0' && ch <= '9') { |
61 filtercontents += ch; | 60 filtercontents += ch; |
62 } | 61 } |
63 } | 62 } |
64 return filtercontents; | 63 return filtercontents; |
65 } | 64 } |
| 65 |
66 int32_t CBC_OnedUPCAWriter::CalcChecksum(const CFX_ByteString& contents) { | 66 int32_t CBC_OnedUPCAWriter::CalcChecksum(const CFX_ByteString& contents) { |
67 int32_t odd = 0; | 67 int32_t odd = 0; |
68 int32_t even = 0; | 68 int32_t even = 0; |
69 int32_t j = 1; | 69 int32_t j = 1; |
70 for (int32_t i = contents.GetLength() - 1; i >= 0; i--) { | 70 for (int32_t i = contents.GetLength() - 1; i >= 0; i--) { |
71 if (j % 2) { | 71 if (j % 2) { |
72 odd += FXSYS_atoi(contents.Mid(i, 1).c_str()); | 72 odd += FXSYS_atoi(contents.Mid(i, 1).c_str()); |
73 } else { | 73 } else { |
74 even += FXSYS_atoi(contents.Mid(i, 1).c_str()); | 74 even += FXSYS_atoi(contents.Mid(i, 1).c_str()); |
75 } | 75 } |
76 j++; | 76 j++; |
77 } | 77 } |
78 int32_t checksum = (odd * 3 + even) % 10; | 78 int32_t checksum = (odd * 3 + even) % 10; |
79 checksum = (10 - checksum) % 10; | 79 checksum = (10 - checksum) % 10; |
80 return (checksum); | 80 return (checksum); |
81 } | 81 } |
| 82 |
82 uint8_t* CBC_OnedUPCAWriter::Encode(const CFX_ByteString& contents, | 83 uint8_t* CBC_OnedUPCAWriter::Encode(const CFX_ByteString& contents, |
83 BCFORMAT format, | 84 BCFORMAT format, |
84 int32_t& outWidth, | 85 int32_t& outWidth, |
85 int32_t& outHeight, | 86 int32_t& outHeight, |
86 int32_t& e) { | 87 int32_t& e) { |
87 uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); | 88 uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); |
88 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); | 89 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
89 return ret; | 90 return ret; |
90 } | 91 } |
| 92 |
91 uint8_t* CBC_OnedUPCAWriter::Encode(const CFX_ByteString& contents, | 93 uint8_t* CBC_OnedUPCAWriter::Encode(const CFX_ByteString& contents, |
92 BCFORMAT format, | 94 BCFORMAT format, |
93 int32_t& outWidth, | 95 int32_t& outWidth, |
94 int32_t& outHeight, | 96 int32_t& outHeight, |
95 int32_t hints, | 97 int32_t hints, |
96 int32_t& e) { | 98 int32_t& e) { |
97 if (format != BCFORMAT_UPC_A) { | 99 if (format != BCFORMAT_UPC_A) { |
98 e = BCExceptionOnlyEncodeUPC_A; | 100 e = BCExceptionOnlyEncodeUPC_A; |
99 return nullptr; | 101 return nullptr; |
100 } | 102 } |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 FX_Free(pCharPos); | 279 FX_Free(pCharPos); |
278 } | 280 } |
279 | 281 |
280 void CBC_OnedUPCAWriter::RenderResult(const CFX_WideStringC& contents, | 282 void CBC_OnedUPCAWriter::RenderResult(const CFX_WideStringC& contents, |
281 uint8_t* code, | 283 uint8_t* code, |
282 int32_t codeLength, | 284 int32_t codeLength, |
283 FX_BOOL isDevice, | 285 FX_BOOL isDevice, |
284 int32_t& e) { | 286 int32_t& e) { |
285 CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e); | 287 CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e); |
286 } | 288 } |
OLD | NEW |