Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(823)

Side by Side Diff: xfa/fxbarcode/pdf417/BC_PDF417.cpp

Issue 2221023003: Use smart pointers for class owned pointers in xfa/fxbarcode (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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()
385 FX_FLOAT CBC_PDF417::HEIGHT = 2.0f; 385 : m_compact(FALSE),
Lei Zhang 2016/08/09 00:23:43 Just delegate to the ctor below?
Wei Li 2016/08/09 19:31:23 Done.
386 CBC_PDF417::CBC_PDF417() { 386 m_compaction(AUTO),
387 m_compact = FALSE; 387 m_minCols(1),
388 m_compaction = AUTO; 388 m_maxCols(30),
389 m_minCols = 1; 389 m_maxRows(90),
390 m_maxCols = 30; 390 m_minRows(3) {}
391 m_maxRows = 90; 391
392 m_minRows = 3; 392 CBC_PDF417::CBC_PDF417(FX_BOOL compact)
393 m_barcodeMatrix = nullptr; 393 : m_compact(compact),
394 } 394 m_compaction(AUTO),
395 CBC_PDF417::CBC_PDF417(FX_BOOL compact) { 395 m_minCols(1),
396 m_compact = compact; 396 m_maxCols(30),
397 m_compaction = AUTO; 397 m_maxRows(90),
398 m_minCols = 1; 398 m_minRows(3) {}
399 m_maxCols = 30; 399
400 m_maxRows = 90; 400 CBC_PDF417::~CBC_PDF417() {}
401 m_minRows = 3; 401
402 m_barcodeMatrix = nullptr; 402 CBC_BarcodeMatrix* CBC_PDF417::getBarcodeMatrix() {
403 return m_barcodeMatrix.get();
403 } 404 }
404 405
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, 406 void CBC_PDF417::generateBarcodeLogic(CFX_WideString msg,
413 int32_t errorCorrectionLevel, 407 int32_t errorCorrectionLevel,
414 int32_t& e) { 408 int32_t& e) {
415 int32_t errorCorrectionCodeWords = 409 int32_t errorCorrectionCodeWords =
416 CBC_PDF417ErrorCorrection::getErrorCorrectionCodewordCount( 410 CBC_PDF417ErrorCorrection::getErrorCorrectionCodewordCount(
417 errorCorrectionLevel, e); 411 errorCorrectionLevel, e);
418 BC_EXCEPTION_CHECK_ReturnVoid(e); 412 BC_EXCEPTION_CHECK_ReturnVoid(e);
419 CFX_WideString highLevel = 413 CFX_WideString highLevel =
420 CBC_PDF417HighLevelEncoder::encodeHighLevel(msg, m_compaction, e); 414 CBC_PDF417HighLevelEncoder::encodeHighLevel(msg, m_compaction, e);
421 BC_EXCEPTION_CHECK_ReturnVoid(e); 415 BC_EXCEPTION_CHECK_ReturnVoid(e);
(...skipping 15 matching lines...) Expand all
437 sb += (FX_WCHAR)n; 431 sb += (FX_WCHAR)n;
438 sb += highLevel; 432 sb += highLevel;
439 for (int32_t i = 0; i < pad; i++) { 433 for (int32_t i = 0; i < pad; i++) {
440 sb += (FX_WCHAR)900; 434 sb += (FX_WCHAR)900;
441 } 435 }
442 CFX_WideString dataCodewords(sb); 436 CFX_WideString dataCodewords(sb);
443 CFX_WideString ec = CBC_PDF417ErrorCorrection::generateErrorCorrection( 437 CFX_WideString ec = CBC_PDF417ErrorCorrection::generateErrorCorrection(
444 dataCodewords, errorCorrectionLevel, e); 438 dataCodewords, errorCorrectionLevel, e);
445 BC_EXCEPTION_CHECK_ReturnVoid(e); 439 BC_EXCEPTION_CHECK_ReturnVoid(e);
446 CFX_WideString fullCodewords = dataCodewords + ec; 440 CFX_WideString fullCodewords = dataCodewords + ec;
447 m_barcodeMatrix = new CBC_BarcodeMatrix(rows, cols); 441 m_barcodeMatrix.reset(new CBC_BarcodeMatrix(rows, cols));
448 encodeLowLevel(fullCodewords, cols, rows, errorCorrectionLevel, 442 encodeLowLevel(fullCodewords, cols, rows, errorCorrectionLevel,
449 m_barcodeMatrix); 443 m_barcodeMatrix.get());
450 } 444 }
445
451 void CBC_PDF417::setDimensions(int32_t maxCols, 446 void CBC_PDF417::setDimensions(int32_t maxCols,
452 int32_t minCols, 447 int32_t minCols,
453 int32_t maxRows, 448 int32_t maxRows,
454 int32_t minRows) { 449 int32_t minRows) {
455 m_maxCols = maxCols; 450 m_maxCols = maxCols;
456 m_minCols = minCols; 451 m_minCols = minCols;
457 m_maxRows = maxRows; 452 m_maxRows = maxRows;
458 m_minRows = minRows; 453 m_minRows = minRows;
459 } 454 }
455
460 void CBC_PDF417::setCompaction(Compaction compaction) { 456 void CBC_PDF417::setCompaction(Compaction compaction) {
461 m_compaction = compaction; 457 m_compaction = compaction;
462 } 458 }
459
463 void CBC_PDF417::setCompact(FX_BOOL compact) { 460 void CBC_PDF417::setCompact(FX_BOOL compact) {
464 m_compact = compact; 461 m_compact = compact;
465 } 462 }
463
466 int32_t CBC_PDF417::calculateNumberOfRows(int32_t m, int32_t k, int32_t c) { 464 int32_t CBC_PDF417::calculateNumberOfRows(int32_t m, int32_t k, int32_t c) {
467 int32_t r = ((m + 1 + k) / c) + 1; 465 int32_t r = ((m + 1 + k) / c) + 1;
468 if (c * r >= (m + 1 + k + c)) { 466 if (c * r >= (m + 1 + k + c)) {
469 r--; 467 r--;
470 } 468 }
471 return r; 469 return r;
472 } 470 }
471
473 int32_t CBC_PDF417::getNumberOfPadCodewords(int32_t m, 472 int32_t CBC_PDF417::getNumberOfPadCodewords(int32_t m,
474 int32_t k, 473 int32_t k,
475 int32_t c, 474 int32_t c,
476 int32_t r) { 475 int32_t r) {
477 int32_t n = c * r - k; 476 int32_t n = c * r - k;
478 return n > m + 1 ? n - m - 1 : 0; 477 return n > m + 1 ? n - m - 1 : 0;
479 } 478 }
479
480 void CBC_PDF417::encodeChar(int32_t pattern, 480 void CBC_PDF417::encodeChar(int32_t pattern,
481 int32_t len, 481 int32_t len,
482 CBC_BarcodeRow* logic) { 482 CBC_BarcodeRow* logic) {
483 int32_t map = 1 << (len - 1); 483 int32_t map = 1 << (len - 1);
484 FX_BOOL last = ((pattern & map) != 0); 484 FX_BOOL last = ((pattern & map) != 0);
485 int32_t width = 0; 485 int32_t width = 0;
486 for (int32_t i = 0; i < len; i++) { 486 for (int32_t i = 0; i < len; i++) {
487 FX_BOOL black = ((pattern & map) != 0); 487 FX_BOOL black = ((pattern & map) != 0);
488 if (last == black) { 488 if (last == black) {
489 width++; 489 width++;
490 } else { 490 } else {
491 logic->addBar(last, width); 491 logic->addBar(last, width);
492 last = black; 492 last = black;
493 width = 1; 493 width = 1;
494 } 494 }
495 map >>= 1; 495 map >>= 1;
496 } 496 }
497 logic->addBar(last, width); 497 logic->addBar(last, width);
498 } 498 }
499
499 void CBC_PDF417::encodeLowLevel(CFX_WideString fullCodewords, 500 void CBC_PDF417::encodeLowLevel(CFX_WideString fullCodewords,
500 int32_t c, 501 int32_t c,
501 int32_t r, 502 int32_t r,
502 int32_t errorCorrectionLevel, 503 int32_t errorCorrectionLevel,
503 CBC_BarcodeMatrix* logic) { 504 CBC_BarcodeMatrix* logic) {
504 int32_t idx = 0; 505 int32_t idx = 0;
505 for (int32_t y = 0; y < r; y++) { 506 for (int32_t y = 0; y < r; y++) {
506 int32_t cluster = y % 3; 507 int32_t cluster = y % 3;
507 logic->startRow(); 508 logic->startRow();
508 encodeChar(START_PATTERN, 17, logic->getCurrentRow()); 509 encodeChar(START_PATTERN, 17, logic->getCurrentRow());
(...skipping 18 matching lines...) Expand all
527 } 528 }
528 if (m_compact) { 529 if (m_compact) {
529 encodeChar(STOP_PATTERN, 1, logic->getCurrentRow()); 530 encodeChar(STOP_PATTERN, 1, logic->getCurrentRow());
530 } else { 531 } else {
531 pattern = CODEWORD_TABLE[cluster][right]; 532 pattern = CODEWORD_TABLE[cluster][right];
532 encodeChar(pattern, 17, logic->getCurrentRow()); 533 encodeChar(pattern, 17, logic->getCurrentRow());
533 encodeChar(STOP_PATTERN, 18, logic->getCurrentRow()); 534 encodeChar(STOP_PATTERN, 18, logic->getCurrentRow());
534 } 535 }
535 } 536 }
536 } 537 }
538
537 CFX_Int32Array* CBC_PDF417::determineDimensions( 539 CFX_Int32Array* CBC_PDF417::determineDimensions(
538 int32_t sourceCodeWords, 540 int32_t sourceCodeWords,
539 int32_t errorCorrectionCodeWords, 541 int32_t errorCorrectionCodeWords,
540 int32_t& e) { 542 int32_t& e) {
541 FX_FLOAT ratio = 0.0f; 543 FX_FLOAT ratio = 0.0f;
542 CFX_Int32Array* dimension = nullptr; 544 CFX_Int32Array* dimension = nullptr;
543 for (int32_t cols = m_minCols; cols <= m_maxCols; cols++) { 545 for (int32_t cols = m_minCols; cols <= m_maxCols; cols++) {
544 int32_t rows = 546 int32_t rows =
545 calculateNumberOfRows(sourceCodeWords, errorCorrectionCodeWords, cols); 547 calculateNumberOfRows(sourceCodeWords, errorCorrectionCodeWords, cols);
546 if (rows < m_minRows) { 548 if (rows < m_minRows) {
(...skipping 26 matching lines...) Expand all
573 dimension->Add(m_minCols); 575 dimension->Add(m_minCols);
574 dimension->Add(rows); 576 dimension->Add(rows);
575 } 577 }
576 } 578 }
577 if (!dimension) { 579 if (!dimension) {
578 e = BCExceptionUnableToFitMessageInColumns; 580 e = BCExceptionUnableToFitMessageInColumns;
579 return nullptr; 581 return nullptr;
580 } 582 }
581 return dimension; 583 return dimension;
582 } 584 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698