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 Jeremias Maerki in part, and ZXing Authors in part | 8 * Copyright 2006 Jeremias Maerki in part, and ZXing Authors in part |
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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 0x13e32, 0x17e72, 0x1df8a, 0x19f0a, 0x1bf1a, 0x11e0a, 0x13e1a, 0x17e3a, | 373 0x13e32, 0x17e72, 0x1df8a, 0x19f0a, 0x1bf1a, 0x11e0a, 0x13e1a, 0x17e3a, |
374 0x1035c, 0x1034e, 0x10758, 0x183ae, 0x1074c, 0x10746, 0x1032e, 0x1076e, | 374 0x1035c, 0x1034e, 0x10758, 0x183ae, 0x1074c, 0x10746, 0x1032e, 0x1076e, |
375 0x10f50, 0x187ac, 0x10f48, 0x187a6, 0x10f44, 0x10f42, 0x1072c, 0x10f6c, | 375 0x10f50, 0x187ac, 0x10f48, 0x187a6, 0x10f44, 0x10f42, 0x1072c, 0x10f6c, |
376 0x10726, 0x10f66, 0x18fa8, 0x1c7d6, 0x18fa4, 0x18fa2, 0x10f28, 0x18796, | 376 0x10726, 0x10f66, 0x18fa8, 0x1c7d6, 0x18fa4, 0x18fa2, 0x10f28, 0x18796, |
377 0x11f68, 0x18fb6, 0x11f64, 0x10f22, 0x11f62, 0x10716, 0x10f36, 0x11f76, | 377 0x11f68, 0x18fb6, 0x11f64, 0x10f22, 0x11f62, 0x10716, 0x10f36, 0x11f76, |
378 0x1cfd4, 0x1cfd2, 0x18f94, 0x19fb4, 0x18f92, 0x19fb2, 0x10f14, 0x11f34, | 378 0x1cfd4, 0x1cfd2, 0x18f94, 0x19fb4, 0x18f92, 0x19fb2, 0x10f14, 0x11f34, |
379 0x10f12, 0x13f74, 0x11f32, 0x13f72, 0x1cfca, 0x18f8a, 0x19f9a, 0x10f0a, | 379 0x10f12, 0x13f74, 0x11f32, 0x13f72, 0x1cfca, 0x18f8a, 0x19f9a, 0x10f0a, |
380 0x11f1a, 0x13f3a, 0x103ac, 0x103a6, 0x107a8, 0x183d6, 0x107a4, 0x107a2, | 380 0x11f1a, 0x13f3a, 0x103ac, 0x103a6, 0x107a8, 0x183d6, 0x107a4, 0x107a2, |
381 0x10396, 0x107b6, 0x187d4, 0x187d2, 0x10794, 0x10fb4, 0x10792, 0x10fb2, | 381 0x10396, 0x107b6, 0x187d4, 0x187d2, 0x10794, 0x10fb4, 0x10792, 0x10fb2, |
382 0x1c7ea}}; | 382 0x1c7ea}}; |
383 FX_FLOAT CBC_PDF417::PREFERRED_RATIO = 3.0f; | 383 |
384 FX_FLOAT CBC_PDF417::DEFAULT_MODULE_WIDTH = 0.357f; | 384 CBC_PDF417::CBC_PDF417() : CBC_PDF417(FALSE) {} |
385 FX_FLOAT CBC_PDF417::HEIGHT = 2.0f; | 385 |
386 CBC_PDF417::CBC_PDF417() { | 386 CBC_PDF417::CBC_PDF417(FX_BOOL compact) |
387 m_compact = FALSE; | 387 : m_compact(compact), |
388 m_compaction = AUTO; | 388 m_compaction(AUTO), |
389 m_minCols = 1; | 389 m_minCols(1), |
390 m_maxCols = 30; | 390 m_maxCols(30), |
391 m_maxRows = 90; | 391 m_maxRows(90), |
392 m_minRows = 3; | 392 m_minRows(3) {} |
393 m_barcodeMatrix = nullptr; | 393 |
394 } | 394 CBC_PDF417::~CBC_PDF417() {} |
395 CBC_PDF417::CBC_PDF417(FX_BOOL compact) { | 395 |
396 m_compact = compact; | 396 CBC_BarcodeMatrix* CBC_PDF417::getBarcodeMatrix() { |
397 m_compaction = AUTO; | 397 return m_barcodeMatrix.get(); |
398 m_minCols = 1; | |
399 m_maxCols = 30; | |
400 m_maxRows = 90; | |
401 m_minRows = 3; | |
402 m_barcodeMatrix = nullptr; | |
403 } | 398 } |
404 | 399 |
405 CBC_PDF417::~CBC_PDF417() { | |
406 delete m_barcodeMatrix; | |
407 } | |
408 | |
409 CBC_BarcodeMatrix* CBC_PDF417::getBarcodeMatrix() { | |
410 return m_barcodeMatrix; | |
411 } | |
412 void CBC_PDF417::generateBarcodeLogic(CFX_WideString msg, | 400 void CBC_PDF417::generateBarcodeLogic(CFX_WideString msg, |
413 int32_t errorCorrectionLevel, | 401 int32_t errorCorrectionLevel, |
414 int32_t& e) { | 402 int32_t& e) { |
415 int32_t errorCorrectionCodeWords = | 403 int32_t errorCorrectionCodeWords = |
416 CBC_PDF417ErrorCorrection::getErrorCorrectionCodewordCount( | 404 CBC_PDF417ErrorCorrection::getErrorCorrectionCodewordCount( |
417 errorCorrectionLevel, e); | 405 errorCorrectionLevel, e); |
418 BC_EXCEPTION_CHECK_ReturnVoid(e); | 406 BC_EXCEPTION_CHECK_ReturnVoid(e); |
419 CFX_WideString highLevel = | 407 CFX_WideString highLevel = |
420 CBC_PDF417HighLevelEncoder::encodeHighLevel(msg, m_compaction, e); | 408 CBC_PDF417HighLevelEncoder::encodeHighLevel(msg, m_compaction, e); |
421 BC_EXCEPTION_CHECK_ReturnVoid(e); | 409 BC_EXCEPTION_CHECK_ReturnVoid(e); |
(...skipping 15 matching lines...) Expand all Loading... |
437 sb += (FX_WCHAR)n; | 425 sb += (FX_WCHAR)n; |
438 sb += highLevel; | 426 sb += highLevel; |
439 for (int32_t i = 0; i < pad; i++) { | 427 for (int32_t i = 0; i < pad; i++) { |
440 sb += (FX_WCHAR)900; | 428 sb += (FX_WCHAR)900; |
441 } | 429 } |
442 CFX_WideString dataCodewords(sb); | 430 CFX_WideString dataCodewords(sb); |
443 CFX_WideString ec = CBC_PDF417ErrorCorrection::generateErrorCorrection( | 431 CFX_WideString ec = CBC_PDF417ErrorCorrection::generateErrorCorrection( |
444 dataCodewords, errorCorrectionLevel, e); | 432 dataCodewords, errorCorrectionLevel, e); |
445 BC_EXCEPTION_CHECK_ReturnVoid(e); | 433 BC_EXCEPTION_CHECK_ReturnVoid(e); |
446 CFX_WideString fullCodewords = dataCodewords + ec; | 434 CFX_WideString fullCodewords = dataCodewords + ec; |
447 m_barcodeMatrix = new CBC_BarcodeMatrix(rows, cols); | 435 m_barcodeMatrix.reset(new CBC_BarcodeMatrix(rows, cols)); |
448 encodeLowLevel(fullCodewords, cols, rows, errorCorrectionLevel, | 436 encodeLowLevel(fullCodewords, cols, rows, errorCorrectionLevel, |
449 m_barcodeMatrix); | 437 m_barcodeMatrix.get()); |
450 } | 438 } |
| 439 |
451 void CBC_PDF417::setDimensions(int32_t maxCols, | 440 void CBC_PDF417::setDimensions(int32_t maxCols, |
452 int32_t minCols, | 441 int32_t minCols, |
453 int32_t maxRows, | 442 int32_t maxRows, |
454 int32_t minRows) { | 443 int32_t minRows) { |
455 m_maxCols = maxCols; | 444 m_maxCols = maxCols; |
456 m_minCols = minCols; | 445 m_minCols = minCols; |
457 m_maxRows = maxRows; | 446 m_maxRows = maxRows; |
458 m_minRows = minRows; | 447 m_minRows = minRows; |
459 } | 448 } |
| 449 |
460 void CBC_PDF417::setCompaction(Compaction compaction) { | 450 void CBC_PDF417::setCompaction(Compaction compaction) { |
461 m_compaction = compaction; | 451 m_compaction = compaction; |
462 } | 452 } |
| 453 |
463 void CBC_PDF417::setCompact(FX_BOOL compact) { | 454 void CBC_PDF417::setCompact(FX_BOOL compact) { |
464 m_compact = compact; | 455 m_compact = compact; |
465 } | 456 } |
| 457 |
466 int32_t CBC_PDF417::calculateNumberOfRows(int32_t m, int32_t k, int32_t c) { | 458 int32_t CBC_PDF417::calculateNumberOfRows(int32_t m, int32_t k, int32_t c) { |
467 int32_t r = ((m + 1 + k) / c) + 1; | 459 int32_t r = ((m + 1 + k) / c) + 1; |
468 if (c * r >= (m + 1 + k + c)) { | 460 if (c * r >= (m + 1 + k + c)) { |
469 r--; | 461 r--; |
470 } | 462 } |
471 return r; | 463 return r; |
472 } | 464 } |
| 465 |
473 int32_t CBC_PDF417::getNumberOfPadCodewords(int32_t m, | 466 int32_t CBC_PDF417::getNumberOfPadCodewords(int32_t m, |
474 int32_t k, | 467 int32_t k, |
475 int32_t c, | 468 int32_t c, |
476 int32_t r) { | 469 int32_t r) { |
477 int32_t n = c * r - k; | 470 int32_t n = c * r - k; |
478 return n > m + 1 ? n - m - 1 : 0; | 471 return n > m + 1 ? n - m - 1 : 0; |
479 } | 472 } |
| 473 |
480 void CBC_PDF417::encodeChar(int32_t pattern, | 474 void CBC_PDF417::encodeChar(int32_t pattern, |
481 int32_t len, | 475 int32_t len, |
482 CBC_BarcodeRow* logic) { | 476 CBC_BarcodeRow* logic) { |
483 int32_t map = 1 << (len - 1); | 477 int32_t map = 1 << (len - 1); |
484 FX_BOOL last = ((pattern & map) != 0); | 478 FX_BOOL last = ((pattern & map) != 0); |
485 int32_t width = 0; | 479 int32_t width = 0; |
486 for (int32_t i = 0; i < len; i++) { | 480 for (int32_t i = 0; i < len; i++) { |
487 FX_BOOL black = ((pattern & map) != 0); | 481 FX_BOOL black = ((pattern & map) != 0); |
488 if (last == black) { | 482 if (last == black) { |
489 width++; | 483 width++; |
490 } else { | 484 } else { |
491 logic->addBar(last, width); | 485 logic->addBar(last, width); |
492 last = black; | 486 last = black; |
493 width = 1; | 487 width = 1; |
494 } | 488 } |
495 map >>= 1; | 489 map >>= 1; |
496 } | 490 } |
497 logic->addBar(last, width); | 491 logic->addBar(last, width); |
498 } | 492 } |
| 493 |
499 void CBC_PDF417::encodeLowLevel(CFX_WideString fullCodewords, | 494 void CBC_PDF417::encodeLowLevel(CFX_WideString fullCodewords, |
500 int32_t c, | 495 int32_t c, |
501 int32_t r, | 496 int32_t r, |
502 int32_t errorCorrectionLevel, | 497 int32_t errorCorrectionLevel, |
503 CBC_BarcodeMatrix* logic) { | 498 CBC_BarcodeMatrix* logic) { |
504 int32_t idx = 0; | 499 int32_t idx = 0; |
505 for (int32_t y = 0; y < r; y++) { | 500 for (int32_t y = 0; y < r; y++) { |
506 int32_t cluster = y % 3; | 501 int32_t cluster = y % 3; |
507 logic->startRow(); | 502 logic->startRow(); |
508 encodeChar(START_PATTERN, 17, logic->getCurrentRow()); | 503 encodeChar(START_PATTERN, 17, logic->getCurrentRow()); |
(...skipping 18 matching lines...) Expand all Loading... |
527 } | 522 } |
528 if (m_compact) { | 523 if (m_compact) { |
529 encodeChar(STOP_PATTERN, 1, logic->getCurrentRow()); | 524 encodeChar(STOP_PATTERN, 1, logic->getCurrentRow()); |
530 } else { | 525 } else { |
531 pattern = CODEWORD_TABLE[cluster][right]; | 526 pattern = CODEWORD_TABLE[cluster][right]; |
532 encodeChar(pattern, 17, logic->getCurrentRow()); | 527 encodeChar(pattern, 17, logic->getCurrentRow()); |
533 encodeChar(STOP_PATTERN, 18, logic->getCurrentRow()); | 528 encodeChar(STOP_PATTERN, 18, logic->getCurrentRow()); |
534 } | 529 } |
535 } | 530 } |
536 } | 531 } |
| 532 |
537 CFX_Int32Array* CBC_PDF417::determineDimensions( | 533 CFX_Int32Array* CBC_PDF417::determineDimensions( |
538 int32_t sourceCodeWords, | 534 int32_t sourceCodeWords, |
539 int32_t errorCorrectionCodeWords, | 535 int32_t errorCorrectionCodeWords, |
540 int32_t& e) { | 536 int32_t& e) { |
541 FX_FLOAT ratio = 0.0f; | 537 FX_FLOAT ratio = 0.0f; |
542 CFX_Int32Array* dimension = nullptr; | 538 CFX_Int32Array* dimension = nullptr; |
543 for (int32_t cols = m_minCols; cols <= m_maxCols; cols++) { | 539 for (int32_t cols = m_minCols; cols <= m_maxCols; cols++) { |
544 int32_t rows = | 540 int32_t rows = |
545 calculateNumberOfRows(sourceCodeWords, errorCorrectionCodeWords, cols); | 541 calculateNumberOfRows(sourceCodeWords, errorCorrectionCodeWords, cols); |
546 if (rows < m_minRows) { | 542 if (rows < m_minRows) { |
(...skipping 26 matching lines...) Expand all Loading... |
573 dimension->Add(m_minCols); | 569 dimension->Add(m_minCols); |
574 dimension->Add(rows); | 570 dimension->Add(rows); |
575 } | 571 } |
576 } | 572 } |
577 if (!dimension) { | 573 if (!dimension) { |
578 e = BCExceptionUnableToFitMessageInColumns; | 574 e = BCExceptionUnableToFitMessageInColumns; |
579 return nullptr; | 575 return nullptr; |
580 } | 576 } |
581 return dimension; | 577 return dimension; |
582 } | 578 } |
OLD | NEW |