| 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } | 207 } |
| 208 m_iWideNarrRatio = ratio; | 208 m_iWideNarrRatio = ratio; |
| 209 return TRUE; | 209 return TRUE; |
| 210 } | 210 } |
| 211 uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents, | 211 uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents, |
| 212 BCFORMAT format, | 212 BCFORMAT format, |
| 213 int32_t& outWidth, | 213 int32_t& outWidth, |
| 214 int32_t& outHeight, | 214 int32_t& outHeight, |
| 215 int32_t& e) { | 215 int32_t& e) { |
| 216 uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); | 216 uint8_t* ret = Encode(contents, format, outWidth, outHeight, 0, e); |
| 217 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 217 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 218 return ret; | 218 return ret; |
| 219 } | 219 } |
| 220 uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents, | 220 uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents, |
| 221 BCFORMAT format, | 221 BCFORMAT format, |
| 222 int32_t& outWidth, | 222 int32_t& outWidth, |
| 223 int32_t& outHeight, | 223 int32_t& outHeight, |
| 224 int32_t hints, | 224 int32_t hints, |
| 225 int32_t& e) { | 225 int32_t& e) { |
| 226 if (format != BCFORMAT_CODE_39) { | 226 if (format != BCFORMAT_CODE_39) { |
| 227 e = BCExceptionOnlyEncodeCODE_39; | 227 e = BCExceptionOnlyEncodeCODE_39; |
| 228 return NULL; | 228 return nullptr; |
| 229 } | 229 } |
| 230 uint8_t* ret = | 230 uint8_t* ret = |
| 231 CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e); | 231 CBC_OneDimWriter::Encode(contents, format, outWidth, outHeight, hints, e); |
| 232 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 232 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 233 return ret; | 233 return ret; |
| 234 } | 234 } |
| 235 void CBC_OnedCode39Writer::ToIntArray(int32_t a, int32_t* toReturn) { | 235 void CBC_OnedCode39Writer::ToIntArray(int32_t a, int32_t* toReturn) { |
| 236 for (int32_t i = 0; i < 9; i++) { | 236 for (int32_t i = 0; i < 9; i++) { |
| 237 toReturn[i] = (a & (1 << i)) == 0 ? 1 : m_iWideNarrRatio; | 237 toReturn[i] = (a & (1 << i)) == 0 ? 1 : m_iWideNarrRatio; |
| 238 } | 238 } |
| 239 } | 239 } |
| 240 FX_CHAR CBC_OnedCode39Writer::CalcCheckSum(const CFX_ByteString& contents, | 240 FX_CHAR CBC_OnedCode39Writer::CalcCheckSum(const CFX_ByteString& contents, |
| 241 int32_t& e) { | 241 int32_t& e) { |
| 242 int32_t length = contents.GetLength(); | 242 int32_t length = contents.GetLength(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 checksum = checksum % 43; | 266 checksum = checksum % 43; |
| 267 return CBC_OnedCode39Reader::CHECKSUM_STRING[checksum]; | 267 return CBC_OnedCode39Reader::CHECKSUM_STRING[checksum]; |
| 268 } | 268 } |
| 269 uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents, | 269 uint8_t* CBC_OnedCode39Writer::Encode(const CFX_ByteString& contents, |
| 270 int32_t& outlength, | 270 int32_t& outlength, |
| 271 int32_t& e) { | 271 int32_t& e) { |
| 272 FX_CHAR checksum = CalcCheckSum(contents, e); | 272 FX_CHAR checksum = CalcCheckSum(contents, e); |
| 273 if (checksum == '*') { | 273 if (checksum == '*') { |
| 274 return NULL; | 274 return nullptr; |
| 275 } | 275 } |
| 276 int32_t widths[9] = {0}; | 276 int32_t widths[9] = {0}; |
| 277 int32_t wideStrideNum = 3; | 277 int32_t wideStrideNum = 3; |
| 278 int32_t narrStrideNum = 9 - wideStrideNum; | 278 int32_t narrStrideNum = 9 - wideStrideNum; |
| 279 CFX_ByteString encodedContents = contents; | 279 CFX_ByteString encodedContents = contents; |
| 280 if (m_bCalcChecksum) { | 280 if (m_bCalcChecksum) { |
| 281 encodedContents += checksum; | 281 encodedContents += checksum; |
| 282 } | 282 } |
| 283 m_iContentLen = encodedContents.GetLength(); | 283 m_iContentLen = encodedContents.GetLength(); |
| 284 int32_t codeWidth = (wideStrideNum * m_iWideNarrRatio + narrStrideNum) * 2 + | 284 int32_t codeWidth = (wideStrideNum * m_iWideNarrRatio + narrStrideNum) * 2 + |
| 285 1 + m_iContentLen; | 285 1 + m_iContentLen; |
| 286 int32_t len = (int32_t)strlen(CBC_OnedCode39Reader::ALPHABET_STRING); | 286 int32_t len = (int32_t)strlen(CBC_OnedCode39Reader::ALPHABET_STRING); |
| 287 for (int32_t j = 0; j < m_iContentLen; j++) { | 287 for (int32_t j = 0; j < m_iContentLen; j++) { |
| 288 for (int32_t i = 0; i < len; i++) { | 288 for (int32_t i = 0; i < len; i++) { |
| 289 if (CBC_OnedCode39Reader::ALPHABET_STRING[i] == encodedContents[j]) { | 289 if (CBC_OnedCode39Reader::ALPHABET_STRING[i] == encodedContents[j]) { |
| 290 ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[i], widths); | 290 ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[i], widths); |
| 291 for (int32_t k = 0; k < 9; k++) { | 291 for (int32_t k = 0; k < 9; k++) { |
| 292 codeWidth += widths[k]; | 292 codeWidth += widths[k]; |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 } | 295 } |
| 296 } | 296 } |
| 297 outlength = codeWidth; | 297 outlength = codeWidth; |
| 298 uint8_t* result = FX_Alloc(uint8_t, codeWidth); | 298 uint8_t* result = FX_Alloc(uint8_t, codeWidth); |
| 299 ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[39], widths); | 299 ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[39], widths); |
| 300 int32_t pos = AppendPattern(result, 0, widths, 9, 1, e); | 300 int32_t pos = AppendPattern(result, 0, widths, 9, 1, e); |
| 301 if (e != BCExceptionNO) { | 301 if (e != BCExceptionNO) { |
| 302 FX_Free(result); | 302 FX_Free(result); |
| 303 return NULL; | 303 return nullptr; |
| 304 } | 304 } |
| 305 int32_t narrowWhite[] = {1}; | 305 int32_t narrowWhite[] = {1}; |
| 306 pos += AppendPattern(result, pos, narrowWhite, 1, 0, e); | 306 pos += AppendPattern(result, pos, narrowWhite, 1, 0, e); |
| 307 if (e != BCExceptionNO) { | 307 if (e != BCExceptionNO) { |
| 308 FX_Free(result); | 308 FX_Free(result); |
| 309 return NULL; | 309 return nullptr; |
| 310 } | 310 } |
| 311 for (int32_t l = m_iContentLen - 1; l >= 0; l--) { | 311 for (int32_t l = m_iContentLen - 1; l >= 0; l--) { |
| 312 for (int32_t i = 0; i < len; i++) { | 312 for (int32_t i = 0; i < len; i++) { |
| 313 if (CBC_OnedCode39Reader::ALPHABET_STRING[i] == encodedContents[l]) { | 313 if (CBC_OnedCode39Reader::ALPHABET_STRING[i] == encodedContents[l]) { |
| 314 ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[i], widths); | 314 ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[i], widths); |
| 315 pos += AppendPattern(result, pos, widths, 9, 1, e); | 315 pos += AppendPattern(result, pos, widths, 9, 1, e); |
| 316 if (e != BCExceptionNO) { | 316 if (e != BCExceptionNO) { |
| 317 FX_Free(result); | 317 FX_Free(result); |
| 318 return NULL; | 318 return nullptr; |
| 319 } | 319 } |
| 320 } | 320 } |
| 321 } | 321 } |
| 322 pos += AppendPattern(result, pos, narrowWhite, 1, 0, e); | 322 pos += AppendPattern(result, pos, narrowWhite, 1, 0, e); |
| 323 if (e != BCExceptionNO) { | 323 if (e != BCExceptionNO) { |
| 324 FX_Free(result); | 324 FX_Free(result); |
| 325 return NULL; | 325 return nullptr; |
| 326 } | 326 } |
| 327 } | 327 } |
| 328 ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[39], widths); | 328 ToIntArray(CBC_OnedCode39Reader::CHARACTER_ENCODINGS[39], widths); |
| 329 pos += AppendPattern(result, pos, widths, 9, 1, e); | 329 pos += AppendPattern(result, pos, widths, 9, 1, e); |
| 330 if (e != BCExceptionNO) { | 330 if (e != BCExceptionNO) { |
| 331 FX_Free(result); | 331 FX_Free(result); |
| 332 return NULL; | 332 return nullptr; |
| 333 } | 333 } |
| 334 for (int32_t i = 0; i < codeWidth / 2; i++) { | 334 for (int32_t i = 0; i < codeWidth / 2; i++) { |
| 335 result[i] ^= result[codeWidth - 1 - i]; | 335 result[i] ^= result[codeWidth - 1 - i]; |
| 336 result[codeWidth - 1 - i] ^= result[i]; | 336 result[codeWidth - 1 - i] ^= result[i]; |
| 337 result[i] ^= result[codeWidth - 1 - i]; | 337 result[i] ^= result[codeWidth - 1 - i]; |
| 338 } | 338 } |
| 339 return result; | 339 return result; |
| 340 } | 340 } |
| 341 CFX_WideString CBC_OnedCode39Writer::encodedContents( | 341 CFX_WideString CBC_OnedCode39Writer::encodedContents( |
| 342 const CFX_WideStringC& contents, | 342 const CFX_WideStringC& contents, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 356 void CBC_OnedCode39Writer::RenderResult(const CFX_WideStringC& contents, | 356 void CBC_OnedCode39Writer::RenderResult(const CFX_WideStringC& contents, |
| 357 uint8_t* code, | 357 uint8_t* code, |
| 358 int32_t codeLength, | 358 int32_t codeLength, |
| 359 FX_BOOL isDevice, | 359 FX_BOOL isDevice, |
| 360 int32_t& e) { | 360 int32_t& e) { |
| 361 CFX_WideString encodedCon = encodedContents(contents, e); | 361 CFX_WideString encodedCon = encodedContents(contents, e); |
| 362 BC_EXCEPTION_CHECK_ReturnVoid(e); | 362 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 363 CBC_OneDimWriter::RenderResult(encodedCon.AsStringC(), code, codeLength, | 363 CBC_OneDimWriter::RenderResult(encodedCon.AsStringC(), code, codeLength, |
| 364 isDevice, e); | 364 isDevice, e); |
| 365 } | 365 } |
| OLD | NEW |