| 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 2009 ZXing authors | 8 * Copyright 2009 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"); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 return filtercontents; | 61 return filtercontents; |
| 62 } | 62 } |
| 63 int32_t CBC_OnedEAN13Writer::CalcChecksum(const CFX_ByteString& contents) { | 63 int32_t CBC_OnedEAN13Writer::CalcChecksum(const CFX_ByteString& contents) { |
| 64 int32_t odd = 0; | 64 int32_t odd = 0; |
| 65 int32_t even = 0; | 65 int32_t even = 0; |
| 66 int32_t j = 1; | 66 int32_t j = 1; |
| 67 for (int32_t i = contents.GetLength() - 1; i >= 0; i--) { | 67 for (int32_t i = contents.GetLength() - 1; i >= 0; i--) { |
| 68 if (j % 2) { | 68 if (j % 2) { |
| 69 odd += FXSYS_atoi(contents.Mid(i, 1)); | 69 odd += FXSYS_atoi(contents.Mid(i, 1).c_str()); |
| 70 } else { | 70 } else { |
| 71 even += FXSYS_atoi(contents.Mid(i, 1)); | 71 even += FXSYS_atoi(contents.Mid(i, 1).c_str()); |
| 72 } | 72 } |
| 73 j++; | 73 j++; |
| 74 } | 74 } |
| 75 int32_t checksum = (odd * 3 + even) % 10; | 75 int32_t checksum = (odd * 3 + even) % 10; |
| 76 checksum = (10 - checksum) % 10; | 76 checksum = (10 - checksum) % 10; |
| 77 return (checksum); | 77 return (checksum); |
| 78 } | 78 } |
| 79 uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents, | 79 uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents, |
| 80 BCFORMAT format, | 80 BCFORMAT format, |
| 81 int32_t& outWidth, | 81 int32_t& outWidth, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 100 return ret; | 100 return ret; |
| 101 } | 101 } |
| 102 uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents, | 102 uint8_t* CBC_OnedEAN13Writer::Encode(const CFX_ByteString& contents, |
| 103 int32_t& outLength, | 103 int32_t& outLength, |
| 104 int32_t& e) { | 104 int32_t& e) { |
| 105 if (contents.GetLength() != 13) { | 105 if (contents.GetLength() != 13) { |
| 106 e = BCExceptionDigitLengthShould13; | 106 e = BCExceptionDigitLengthShould13; |
| 107 return NULL; | 107 return NULL; |
| 108 } | 108 } |
| 109 m_iDataLenth = 13; | 109 m_iDataLenth = 13; |
| 110 int32_t firstDigit = FXSYS_atoi(contents.Mid(0, 1)); | 110 int32_t firstDigit = FXSYS_atoi(contents.Mid(0, 1).c_str()); |
| 111 int32_t parities = CBC_OnedEAN13Reader::FIRST_DIGIT_ENCODINGS[firstDigit]; | 111 int32_t parities = CBC_OnedEAN13Reader::FIRST_DIGIT_ENCODINGS[firstDigit]; |
| 112 outLength = m_codeWidth; | 112 outLength = m_codeWidth; |
| 113 uint8_t* result = FX_Alloc(uint8_t, m_codeWidth); | 113 uint8_t* result = FX_Alloc(uint8_t, m_codeWidth); |
| 114 int32_t pos = 0; | 114 int32_t pos = 0; |
| 115 pos += | 115 pos += |
| 116 AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e); | 116 AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e); |
| 117 if (e != BCExceptionNO) { | 117 if (e != BCExceptionNO) { |
| 118 FX_Free(result); | 118 FX_Free(result); |
| 119 return NULL; | 119 return NULL; |
| 120 } | 120 } |
| 121 int32_t i = 0; | 121 int32_t i = 0; |
| 122 for (i = 1; i <= 6; i++) { | 122 for (i = 1; i <= 6; i++) { |
| 123 int32_t digit = FXSYS_atoi(contents.Mid(i, 1)); | 123 int32_t digit = FXSYS_atoi(contents.Mid(i, 1).c_str()); |
| 124 if ((parities >> (6 - i) & 1) == 1) { | 124 if ((parities >> (6 - i) & 1) == 1) { |
| 125 digit += 10; | 125 digit += 10; |
| 126 } | 126 } |
| 127 pos += AppendPattern(result, pos, CBC_OneDimReader::L_AND_G_PATTERNS[digit], | 127 pos += AppendPattern(result, pos, CBC_OneDimReader::L_AND_G_PATTERNS[digit], |
| 128 4, 0, e); | 128 4, 0, e); |
| 129 if (e != BCExceptionNO) { | 129 if (e != BCExceptionNO) { |
| 130 FX_Free(result); | 130 FX_Free(result); |
| 131 return NULL; | 131 return NULL; |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 pos += AppendPattern(result, pos, CBC_OneDimReader::MIDDLE_PATTERN, 5, 0, e); | 134 pos += AppendPattern(result, pos, CBC_OneDimReader::MIDDLE_PATTERN, 5, 0, e); |
| 135 if (e != BCExceptionNO) { | 135 if (e != BCExceptionNO) { |
| 136 FX_Free(result); | 136 FX_Free(result); |
| 137 return NULL; | 137 return NULL; |
| 138 } | 138 } |
| 139 for (i = 7; i <= 12; i++) { | 139 for (i = 7; i <= 12; i++) { |
| 140 int32_t digit = FXSYS_atoi(contents.Mid(i, 1)); | 140 int32_t digit = FXSYS_atoi(contents.Mid(i, 1).c_str()); |
| 141 pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4, 1, | 141 pos += AppendPattern(result, pos, CBC_OneDimReader::L_PATTERNS[digit], 4, 1, |
| 142 e); | 142 e); |
| 143 if (e != BCExceptionNO) { | 143 if (e != BCExceptionNO) { |
| 144 FX_Free(result); | 144 FX_Free(result); |
| 145 return NULL; | 145 return NULL; |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 pos += | 148 pos += |
| 149 AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e); | 149 AppendPattern(result, pos, CBC_OneDimReader::START_END_PATTERN, 3, 1, e); |
| 150 if (e != BCExceptionNO) { | 150 if (e != BCExceptionNO) { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 } | 292 } |
| 293 FX_Free(pCharPos); | 293 FX_Free(pCharPos); |
| 294 } | 294 } |
| 295 void CBC_OnedEAN13Writer::RenderResult(const CFX_WideStringC& contents, | 295 void CBC_OnedEAN13Writer::RenderResult(const CFX_WideStringC& contents, |
| 296 uint8_t* code, | 296 uint8_t* code, |
| 297 int32_t codeLength, | 297 int32_t codeLength, |
| 298 FX_BOOL isDevice, | 298 FX_BOOL isDevice, |
| 299 int32_t& e) { | 299 int32_t& e) { |
| 300 CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e); | 300 CBC_OneDimWriter::RenderResult(contents, code, codeLength, isDevice, e); |
| 301 } | 301 } |
| OLD | NEW |