1 // Copyright 2014 PDFium Authors. All rights reserved.
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 
30 CBC_QRCoder::CBC_QRCoder() = default;
31 
32 CBC_QRCoder::~CBC_QRCoder() = default;
33 
GetECLevel() const34 const CBC_QRCoderErrorCorrectionLevel* CBC_QRCoder::GetECLevel() const {
35   return m_ecLevel.Get();
36 }
37 
GetVersion() const38 int32_t CBC_QRCoder::GetVersion() const {
39   return m_version;
40 }
41 
GetMatrixWidth() const42 int32_t CBC_QRCoder::GetMatrixWidth() const {
43   return m_matrixWidth;
44 }
45 
GetMaskPattern() const46 int32_t CBC_QRCoder::GetMaskPattern() const {
47   return m_maskPattern;
48 }
49 
GetNumTotalBytes() const50 int32_t CBC_QRCoder::GetNumTotalBytes() const {
51   return m_numTotalBytes;
52 }
53 
GetNumDataBytes() const54 int32_t CBC_QRCoder::GetNumDataBytes() const {
55   return m_numDataBytes;
56 }
57 
GetNumRSBlocks() const58 int32_t CBC_QRCoder::GetNumRSBlocks() const {
59   return m_numRSBlocks;
60 }
61 
GetMatrix() const62 const CBC_CommonByteMatrix* CBC_QRCoder::GetMatrix() const {
63   return m_matrix.get();
64 }
65 
IsValid() const66 bool CBC_QRCoder::IsValid() const {
67   return m_ecLevel && m_version != -1 && m_matrixWidth != -1 &&
68          m_maskPattern != -1 && m_numTotalBytes != -1 && m_numDataBytes != -1 &&
69          m_numECBytes != -1 && m_numRSBlocks != -1 &&
70          IsValidMaskPattern(m_maskPattern) &&
71          m_numTotalBytes == m_numDataBytes + m_numECBytes && m_matrix &&
72          m_matrixWidth == m_matrix->GetWidth() &&
73          m_matrix->GetWidth() == m_matrix->GetHeight();
74 }
75 
SetECLevel(const CBC_QRCoderErrorCorrectionLevel * ecLevel)76 void CBC_QRCoder::SetECLevel(const CBC_QRCoderErrorCorrectionLevel* ecLevel) {
77   m_ecLevel = ecLevel;
78 }
79 
SetVersion(int32_t version)80 void CBC_QRCoder::SetVersion(int32_t version) {
81   m_version = version;
82 }
83 
SetMatrixWidth(int32_t width)84 void CBC_QRCoder::SetMatrixWidth(int32_t width) {
85   m_matrixWidth = width;
86 }
87 
SetMaskPattern(int32_t pattern)88 void CBC_QRCoder::SetMaskPattern(int32_t pattern) {
89   m_maskPattern = pattern;
90 }
91 
SetNumDataBytes(int32_t bytes)92 void CBC_QRCoder::SetNumDataBytes(int32_t bytes) {
93   m_numDataBytes = bytes;
94 }
95 
SetNumTotalBytes(int32_t value)96 void CBC_QRCoder::SetNumTotalBytes(int32_t value) {
97   m_numTotalBytes = value;
98 }
99 
SetNumRSBlocks(int32_t block)100 void CBC_QRCoder::SetNumRSBlocks(int32_t block) {
101   m_numRSBlocks = block;
102 }
103 
SetNumECBytes(int32_t value)104 void CBC_QRCoder::SetNumECBytes(int32_t value) {
105   m_numECBytes = value;
106 }
107 
IsValidMaskPattern(int32_t maskPattern)108 bool CBC_QRCoder::IsValidMaskPattern(int32_t maskPattern) {
109   return maskPattern >= 0 && maskPattern < kNumMaskPatterns;
110 }
111 
SetMatrix(std::unique_ptr<CBC_CommonByteMatrix> pMatrix)112 void CBC_QRCoder::SetMatrix(std::unique_ptr<CBC_CommonByteMatrix> pMatrix) {
113   m_matrix = std::move(pMatrix);
114 }
115