1 // Copyright 2014 The PDFium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 // Original code is licensed as follows: 7 /* 8 * Copyright 2008 ZXing authors 9 * 10 * Licensed under the Apache License, Version 2.0 (the "License"); 11 * you may not use this file except in compliance with the License. 12 * You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software 17 * distributed under the License is distributed on an "AS IS" BASIS, 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 * See the License for the specific language governing permissions and 20 * limitations under the License. 21 */ 22 23 #include <utility> 24 25 #include "fxbarcode/common/BC_CommonByteMatrix.h" 26 #include "fxbarcode/qrcode/BC_QRCoder.h" 27 #include "fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h" 28 #include "fxbarcode/qrcode/BC_QRCoderMode.h" 29 #include "third_party/base/numerics/safe_conversions.h" 30 31 CBC_QRCoder::CBC_QRCoder() = default; 32 33 CBC_QRCoder::~CBC_QRCoder() = default; 34 GetECLevel() const35const CBC_QRCoderErrorCorrectionLevel* CBC_QRCoder::GetECLevel() const { 36 return m_ecLevel; 37 } 38 GetVersion() const39int32_t CBC_QRCoder::GetVersion() const { 40 return m_version; 41 } 42 GetMatrixWidth() const43int32_t CBC_QRCoder::GetMatrixWidth() const { 44 return m_matrixWidth; 45 } 46 GetMaskPattern() const47int32_t CBC_QRCoder::GetMaskPattern() const { 48 return m_maskPattern; 49 } 50 GetNumTotalBytes() const51int32_t CBC_QRCoder::GetNumTotalBytes() const { 52 return m_numTotalBytes; 53 } 54 GetNumDataBytes() const55int32_t CBC_QRCoder::GetNumDataBytes() const { 56 return m_numDataBytes; 57 } 58 GetNumRSBlocks() const59int32_t CBC_QRCoder::GetNumRSBlocks() const { 60 return m_numRSBlocks; 61 } 62 TakeMatrix()63std::unique_ptr<CBC_CommonByteMatrix> CBC_QRCoder::TakeMatrix() { 64 return std::move(m_matrix); 65 } 66 IsValid() const67bool CBC_QRCoder::IsValid() const { 68 return m_ecLevel && m_version != -1 && m_matrixWidth != -1 && 69 m_maskPattern != -1 && m_numTotalBytes != -1 && m_numDataBytes != -1 && 70 m_numECBytes != -1 && m_numRSBlocks != -1 && 71 IsValidMaskPattern(m_maskPattern) && 72 m_numTotalBytes == m_numDataBytes + m_numECBytes && m_matrix && 73 m_matrixWidth == 74 pdfium::base::checked_cast<int32_t>(m_matrix->GetWidth()) && 75 m_matrix->GetWidth() == m_matrix->GetHeight(); 76 } 77 SetECLevel(const CBC_QRCoderErrorCorrectionLevel * ecLevel)78void CBC_QRCoder::SetECLevel(const CBC_QRCoderErrorCorrectionLevel* ecLevel) { 79 m_ecLevel = ecLevel; 80 } 81 SetVersion(int32_t version)82void CBC_QRCoder::SetVersion(int32_t version) { 83 m_version = version; 84 } 85 SetMatrixWidth(int32_t width)86void CBC_QRCoder::SetMatrixWidth(int32_t width) { 87 m_matrixWidth = width; 88 } 89 SetMaskPattern(int32_t pattern)90void CBC_QRCoder::SetMaskPattern(int32_t pattern) { 91 m_maskPattern = pattern; 92 } 93 SetNumDataBytes(int32_t bytes)94void CBC_QRCoder::SetNumDataBytes(int32_t bytes) { 95 m_numDataBytes = bytes; 96 } 97 SetNumTotalBytes(int32_t value)98void CBC_QRCoder::SetNumTotalBytes(int32_t value) { 99 m_numTotalBytes = value; 100 } 101 SetNumRSBlocks(int32_t block)102void CBC_QRCoder::SetNumRSBlocks(int32_t block) { 103 m_numRSBlocks = block; 104 } 105 SetNumECBytes(int32_t value)106void CBC_QRCoder::SetNumECBytes(int32_t value) { 107 m_numECBytes = value; 108 } 109 IsValidMaskPattern(int32_t maskPattern)110bool CBC_QRCoder::IsValidMaskPattern(int32_t maskPattern) { 111 return maskPattern >= 0 && maskPattern < kNumMaskPatterns; 112 } 113 SetMatrix(std::unique_ptr<CBC_CommonByteMatrix> pMatrix)114void CBC_QRCoder::SetMatrix(std::unique_ptr<CBC_CommonByteMatrix> pMatrix) { 115 m_matrix = std::move(pMatrix); 116 } 117