| 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"); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 CBC_OnedCode128Writer::CBC_OnedCode128Writer() { | 73 CBC_OnedCode128Writer::CBC_OnedCode128Writer() { |
| 74 m_codeFormat = BC_CODE128_B; | 74 m_codeFormat = BC_CODE128_B; |
| 75 } | 75 } |
| 76 CBC_OnedCode128Writer::CBC_OnedCode128Writer(BC_TYPE type) { | 76 CBC_OnedCode128Writer::CBC_OnedCode128Writer(BC_TYPE type) { |
| 77 m_codeFormat = type; | 77 m_codeFormat = type; |
| 78 } | 78 } |
| 79 CBC_OnedCode128Writer::~CBC_OnedCode128Writer() {} | 79 CBC_OnedCode128Writer::~CBC_OnedCode128Writer() {} |
| 80 BC_TYPE CBC_OnedCode128Writer::GetType() { | 80 BC_TYPE CBC_OnedCode128Writer::GetType() { |
| 81 return m_codeFormat; | 81 return m_codeFormat; |
| 82 } | 82 } |
| 83 FX_BOOL CBC_OnedCode128Writer::CheckContentValidity( | 83 bool CBC_OnedCode128Writer::CheckContentValidity( |
| 84 const CFX_WideStringC& contents) { | 84 const CFX_WideStringC& contents) { |
| 85 FX_BOOL ret = TRUE; | 85 bool ret = true; |
| 86 int32_t position = 0; | 86 int32_t position = 0; |
| 87 int32_t patternIndex = -1; | 87 int32_t patternIndex = -1; |
| 88 if (m_codeFormat == BC_CODE128_B || m_codeFormat == BC_CODE128_C) { | 88 if (m_codeFormat == BC_CODE128_B || m_codeFormat == BC_CODE128_C) { |
| 89 while (position < contents.GetLength()) { | 89 while (position < contents.GetLength()) { |
| 90 patternIndex = (int32_t)contents.GetAt(position); | 90 patternIndex = (int32_t)contents.GetAt(position); |
| 91 if (patternIndex < 32 || patternIndex > 126 || patternIndex == 34) { | 91 if (patternIndex < 32 || patternIndex > 126 || patternIndex == 34) { |
| 92 ret = FALSE; | 92 ret = false; |
| 93 break; | 93 break; |
| 94 } | 94 } |
| 95 position++; | 95 position++; |
| 96 } | 96 } |
| 97 } else { | 97 } else { |
| 98 ret = FALSE; | 98 ret = false; |
| 99 } | 99 } |
| 100 return ret; | 100 return ret; |
| 101 } | 101 } |
| 102 CFX_WideString CBC_OnedCode128Writer::FilterContents( | 102 CFX_WideString CBC_OnedCode128Writer::FilterContents( |
| 103 const CFX_WideStringC& contents) { | 103 const CFX_WideStringC& contents) { |
| 104 CFX_WideString filterChineseChar; | 104 CFX_WideString filterChineseChar; |
| 105 FX_WCHAR ch; | 105 FX_WCHAR ch; |
| 106 for (int32_t i = 0; i < contents.GetLength(); i++) { | 106 for (int32_t i = 0; i < contents.GetLength(); i++) { |
| 107 ch = contents.GetAt(i); | 107 ch = contents.GetAt(i); |
| 108 if (ch > 175) { | 108 if (ch > 175) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 128 filtercontents += ch; | 128 filtercontents += ch; |
| 129 } else { | 129 } else { |
| 130 continue; | 130 continue; |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 } else { | 133 } else { |
| 134 filtercontents = contents; | 134 filtercontents = contents; |
| 135 } | 135 } |
| 136 return filtercontents; | 136 return filtercontents; |
| 137 } | 137 } |
| 138 FX_BOOL CBC_OnedCode128Writer::SetTextLocation(BC_TEXT_LOC location) { | 138 bool CBC_OnedCode128Writer::SetTextLocation(BC_TEXT_LOC location) { |
| 139 if (location < BC_TEXT_LOC_NONE || location > BC_TEXT_LOC_BELOWEMBED) { | 139 if (location < BC_TEXT_LOC_NONE || location > BC_TEXT_LOC_BELOWEMBED) { |
| 140 return FALSE; | 140 return false; |
| 141 } | 141 } |
| 142 m_locTextLoc = location; | 142 m_locTextLoc = location; |
| 143 return TRUE; | 143 return true; |
| 144 } | 144 } |
| 145 uint8_t* CBC_OnedCode128Writer::Encode(const CFX_ByteString& contents, | 145 uint8_t* CBC_OnedCode128Writer::Encode(const CFX_ByteString& contents, |
| 146 BCFORMAT format, | 146 BCFORMAT format, |
| 147 int32_t& outWidth, | 147 int32_t& outWidth, |
| 148 int32_t& outHeight, | 148 int32_t& outHeight, |
| 149 int32_t hints, | 149 int32_t hints, |
| 150 int32_t& e) { | 150 int32_t& e) { |
| 151 if (format != BCFORMAT_CODE_128) { | 151 if (format != BCFORMAT_CODE_128) { |
| 152 e = BCExceptionOnlyEncodeCODE_128; | 152 e = BCExceptionOnlyEncodeCODE_128; |
| 153 return nullptr; | 153 return nullptr; |
| 154 } | 154 } |
| 155 uint8_t* ret = | 155 uint8_t* ret = |
| 156 CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e); | 156 CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e); |
| 157 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); | 157 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 158 return ret; | 158 return ret; |
| 159 } | 159 } |
| 160 uint8_t* CBC_OnedCode128Writer::Encode(const CFX_ByteString& contents, | 160 uint8_t* CBC_OnedCode128Writer::Encode(const CFX_ByteString& contents, |
| 161 BCFORMAT format, | 161 BCFORMAT format, |
| 162 int32_t& outWidth, | 162 int32_t& outWidth, |
| 163 int32_t& outHeight, | 163 int32_t& outHeight, |
| 164 int32_t& e) { | 164 int32_t& e) { |
| 165 uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); | 165 uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); |
| 166 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); | 166 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 167 return ret; | 167 return ret; |
| 168 } | 168 } |
| 169 FX_BOOL CBC_OnedCode128Writer::IsDigits(const CFX_ByteString& contents, | 169 bool CBC_OnedCode128Writer::IsDigits(const CFX_ByteString& contents, |
| 170 int32_t start, | 170 int32_t start, |
| 171 int32_t length) { | 171 int32_t length) { |
| 172 int32_t end = start + length; | 172 int32_t end = start + length; |
| 173 for (int32_t i = start; i < end; i++) { | 173 for (int32_t i = start; i < end; i++) { |
| 174 if (contents[i] < '0' || contents[i] > '9') { | 174 if (contents[i] < '0' || contents[i] > '9') { |
| 175 return FALSE; | 175 return false; |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 return TRUE; | 178 return true; |
| 179 } | 179 } |
| 180 | 180 |
| 181 uint8_t* CBC_OnedCode128Writer::Encode(const CFX_ByteString& contents, | 181 uint8_t* CBC_OnedCode128Writer::Encode(const CFX_ByteString& contents, |
| 182 int32_t& outLength, | 182 int32_t& outLength, |
| 183 int32_t& e) { | 183 int32_t& e) { |
| 184 if (contents.GetLength() < 1 || contents.GetLength() > 80) { | 184 if (contents.GetLength() < 1 || contents.GetLength() > 80) { |
| 185 e = BCExceptionContentsLengthShouldBetween1and80; | 185 e = BCExceptionContentsLengthShouldBetween1and80; |
| 186 return nullptr; | 186 return nullptr; |
| 187 } | 187 } |
| 188 CFX_ArrayTemplate<const int32_t*> patterns; | 188 CFX_ArrayTemplate<const int32_t*> patterns; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 patterns->Add(CODE_PATTERNS[patternIndex]); | 267 patterns->Add(CODE_PATTERNS[patternIndex]); |
| 268 checkSum += patternIndex * checkWeight; | 268 checkSum += patternIndex * checkWeight; |
| 269 if (position != 0) { | 269 if (position != 0) { |
| 270 checkWeight++; | 270 checkWeight++; |
| 271 } | 271 } |
| 272 } | 272 } |
| 273 return checkSum; | 273 return checkSum; |
| 274 } | 274 } |
| OLD | NEW |