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 "xfa/src/fxbarcode/barcode.h" 24 #include "xfa/src/fxbarcode/common/BC_CommonByteMatrix.h" 25 #include "BC_QRCoderErrorCorrectionLevel.h" 26 #include "BC_QRCoderMode.h" 27 #include "BC_QRCoder.h" 28 CBC_QRCoder::CBC_QRCoder() { 29 m_mode = NULL; 30 m_ecLevel = NULL; 31 m_version = -1; 32 m_matrixWidth = -1; 33 m_maskPattern = -1; 34 m_numTotalBytes = -1; 35 m_numDataBytes = -1; 36 m_numECBytes = -1; 37 m_numRSBlocks = -1; 38 m_matrix = NULL; 39 } 40 CBC_QRCoder::~CBC_QRCoder() { 41 if (m_matrix != NULL) { 42 delete m_matrix; 43 m_matrix = NULL; 44 } 45 m_mode = NULL; 46 m_ecLevel = NULL; 47 m_version = -1; 48 m_matrixWidth = -1; 49 m_maskPattern = -1; 50 m_numTotalBytes = -1; 51 m_numDataBytes = -1; 52 m_numECBytes = -1; 53 m_numRSBlocks = -1; 54 } 55 CBC_QRCoderMode* CBC_QRCoder::GetMode() { 56 return m_mode; 57 } 58 CBC_QRCoderErrorCorrectionLevel* CBC_QRCoder::GetECLevel() { 59 return m_ecLevel; 60 } 61 int32_t CBC_QRCoder::GetVersion() { 62 return m_version; 63 } 64 int32_t CBC_QRCoder::GetMatrixWidth() { 65 return m_matrixWidth; 66 } 67 int32_t CBC_QRCoder::GetMaskPattern() { 68 return m_maskPattern; 69 } 70 int32_t CBC_QRCoder::GetNumTotalBytes() { 71 return m_numTotalBytes; 72 } 73 int32_t CBC_QRCoder::GetNumDataBytes() { 74 return m_numDataBytes; 75 } 76 int32_t CBC_QRCoder::GetNumECBytes() { 77 return m_numECBytes; 78 } 79 int32_t CBC_QRCoder::GetNumRSBlocks() { 80 return m_numRSBlocks; 81 } 82 CBC_CommonByteMatrix* CBC_QRCoder::GetMatrix() { 83 return m_matrix; 84 } 85 int32_t CBC_QRCoder::At(int32_t x, int32_t y, int32_t& e) { 86 int32_t value = m_matrix->Get(x, y); 87 if (!(value == 0 || value == 1)) { 88 e = BCExceptionValueMustBeEither0or1; 89 BC_EXCEPTION_CHECK_ReturnValue(e, 0); 90 } 91 return value; 92 } 93 FX_BOOL CBC_QRCoder::IsValid() { 94 return m_mode != NULL && m_ecLevel != NULL && m_version != -1 && 95 m_matrixWidth != -1 && m_maskPattern != -1 && m_numTotalBytes != -1 && 96 m_numDataBytes != -1 && m_numECBytes != -1 && m_numRSBlocks != -1 && 97 IsValidMaskPattern(m_maskPattern) && 98 m_numTotalBytes == m_numDataBytes + m_numECBytes && m_matrix != NULL && 99 m_matrixWidth == m_matrix->GetWidth() && 100 m_matrix->GetWidth() == m_matrix->GetHeight(); 101 } 102 void CBC_QRCoder::SetMode(CBC_QRCoderMode* value) { 103 m_mode = value; 104 } 105 void CBC_QRCoder::SetECLevel(CBC_QRCoderErrorCorrectionLevel* ecLevel) { 106 m_ecLevel = ecLevel; 107 } 108 void CBC_QRCoder::SetVersion(int32_t version) { 109 m_version = version; 110 } 111 void CBC_QRCoder::SetMatrixWidth(int32_t width) { 112 m_matrixWidth = width; 113 } 114 void CBC_QRCoder::SetMaskPattern(int32_t pattern) { 115 m_maskPattern = pattern; 116 } 117 void CBC_QRCoder::SetNumDataBytes(int32_t bytes) { 118 m_numDataBytes = bytes; 119 } 120 void CBC_QRCoder::SetNumTotalBytes(int32_t value) { 121 m_numTotalBytes = value; 122 } 123 void CBC_QRCoder::SetNumRSBlocks(int32_t block) { 124 m_numRSBlocks = block; 125 } 126 void CBC_QRCoder::SetNumECBytes(int32_t value) { 127 m_numECBytes = value; 128 } 129 FX_BOOL CBC_QRCoder::IsValidMaskPattern(int32_t maskPattern) { 130 return maskPattern >= 0 && maskPattern < NUM_MASK_PATTERNS; 131 } 132 void CBC_QRCoder::SetMatrix(CBC_CommonByteMatrix* value) { 133 m_matrix = value; 134 } 135 const int32_t CBC_QRCoder::NUM_MASK_PATTERNS = 8; 136