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 2007 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 "BC_QRCoderErrorCorrectionLevel.h"
25 CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::L = NULL;
26 CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::M = NULL;
27 CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::Q = NULL;
28 CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::H = NULL;
CBC_QRCoderErrorCorrectionLevel(int32_t ordinal,int32_t bits,FX_CHAR * name)29 CBC_QRCoderErrorCorrectionLevel::CBC_QRCoderErrorCorrectionLevel(
30     int32_t ordinal,
31     int32_t bits,
32     FX_CHAR* name) {
33   m_name += name;
34   m_ordinal = ordinal;
35   m_bits = bits;
36 }
~CBC_QRCoderErrorCorrectionLevel()37 CBC_QRCoderErrorCorrectionLevel::~CBC_QRCoderErrorCorrectionLevel() {}
Initialize()38 void CBC_QRCoderErrorCorrectionLevel::Initialize() {
39   L = new CBC_QRCoderErrorCorrectionLevel(0, 0x01, (FX_CHAR*)"L");
40   M = new CBC_QRCoderErrorCorrectionLevel(1, 0x00, (FX_CHAR*)"M");
41   Q = new CBC_QRCoderErrorCorrectionLevel(2, 0x03, (FX_CHAR*)"Q");
42   H = new CBC_QRCoderErrorCorrectionLevel(3, 0x02, (FX_CHAR*)"H");
43 }
Finalize()44 void CBC_QRCoderErrorCorrectionLevel::Finalize() {
45   delete L;
46   delete M;
47   delete Q;
48   delete H;
49 }
Ordinal()50 int32_t CBC_QRCoderErrorCorrectionLevel::Ordinal() {
51   return m_ordinal;
52 }
GetBits()53 int32_t CBC_QRCoderErrorCorrectionLevel::GetBits() {
54   return m_bits;
55 }
GetName()56 CFX_ByteString CBC_QRCoderErrorCorrectionLevel::GetName() {
57   return m_name;
58 }
ForBits(int32_t bits)59 CBC_QRCoderErrorCorrectionLevel* CBC_QRCoderErrorCorrectionLevel::ForBits(
60     int32_t bits) {
61   switch (bits) {
62     case 0x00:
63       return M;
64     case 0x01:
65       return L;
66     case 0x02:
67       return H;
68     case 0x03:
69       return Q;
70     default:
71       return NULL;
72   }
73 }
Destroy()74 void CBC_QRCoderErrorCorrectionLevel::Destroy() {
75   if (L) {
76     delete CBC_QRCoderErrorCorrectionLevel::L;
77     L = NULL;
78   }
79   if (M) {
80     delete CBC_QRCoderErrorCorrectionLevel::M;
81     M = NULL;
82   }
83   if (H) {
84     delete CBC_QRCoderErrorCorrectionLevel::H;
85     H = NULL;
86   }
87   if (Q) {
88     delete CBC_QRCoderErrorCorrectionLevel::Q;
89     Q = NULL;
90   }
91 }
92