Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
BC_QRCodeWriter.cpp
Go to the documentation of this file.
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 "fxbarcode/qrcode/BC_QRCodeWriter.h"
24
25#include <stdint.h>
26
27#include <memory>
28
29#include "core/fxcrt/data_vector.h"
30#include "fxbarcode/common/BC_CommonByteMatrix.h"
31#include "fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h"
32#include "fxbarcode/qrcode/BC_QRCoder.h"
33#include "fxbarcode/qrcode/BC_QRCoderEncoder.h"
34#include "fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h"
35#include "fxbarcode/qrcode/BC_QRCoderMode.h"
36#include "fxbarcode/qrcode/BC_QRCoderVersion.h"
37
38CBC_QRCodeWriter::CBC_QRCodeWriter() : CBC_TwoDimWriter(true) {}
39
40CBC_QRCodeWriter::~CBC_QRCodeWriter() = default;
41
42bool CBC_QRCodeWriter::SetErrorCorrectionLevel(int32_t level) {
43 if (level < 0 || level > 3) {
44 return false;
45 }
47 return true;
48}
49
50DataVector<uint8_t> CBC_QRCodeWriter::Encode(WideStringView contents,
51 int32_t ecLevel,
52 int32_t* pOutWidth,
53 int32_t* pOutHeight) {
55 switch (ecLevel) {
56 case 0:
58 break;
59 case 1:
61 break;
62 case 2:
64 break;
65 case 3:
67 break;
68 default:
69 return DataVector<uint8_t>();
70 }
71 CBC_QRCoder qr;
72 if (!CBC_QRCoderEncoder::Encode(contents, ec, &qr))
73 return DataVector<uint8_t>();
74
75 *pOutWidth = qr.GetMatrixWidth();
76 *pOutHeight = qr.GetMatrixWidth();
77 std::unique_ptr<CBC_CommonByteMatrix> matrix = qr.TakeMatrix();
78 return matrix->TakeArray();
79}
bool SetErrorCorrectionLevel(int32_t level) override
~CBC_QRCodeWriter() override
DataVector< uint8_t > Encode(WideStringView contents, int32_t ecLevel, int32_t *pOutWidth, int32_t *pOutHeight)
static bool Encode(WideStringView content, const CBC_QRCoderErrorCorrectionLevel *ecLevel, CBC_QRCoder *qrCode)
static CBC_QRCoderErrorCorrectionLevel * Q
static CBC_QRCoderErrorCorrectionLevel * H
static CBC_QRCoderErrorCorrectionLevel * L
static CBC_QRCoderErrorCorrectionLevel * M
int32_t GetMatrixWidth() const
void set_error_correction_level(int32_t level)
CBC_TwoDimWriter(bool bFixedSize)