Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
BC_PDF417Writer.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 2012 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/pdf417/BC_PDF417Writer.h"
24
25
#
include
<
stdint
.
h
>
26
27
#
include
<
algorithm
>
28
#
include
<
utility
>
29
30
#
include
"core/fxcrt/data_vector.h"
31
#
include
"core/fxcrt/stl_util.h"
32
#
include
"fxbarcode/BC_TwoDimWriter.h"
33
#
include
"fxbarcode/pdf417/BC_PDF417.h"
34
#
include
"fxbarcode/pdf417/BC_PDF417BarcodeMatrix.h"
35
36
namespace
{
37
38
void
RotateArray(DataVector<uint8_t>& bitarray, int32_t width, int32_t height) {
39
DataVector<uint8_t> temp = bitarray;
40
for
(int32_t i = 0; i < height; i++) {
41
int32_t inverse_i = height - i - 1;
42
for
(int32_t j = 0; j < width; j++) {
43
bitarray[j * height + inverse_i] = temp[i * width + j];
44
}
45
}
46
}
47
48
}
// namespace
49
50
CBC_PDF417Writer::
CBC_PDF417Writer
() :
CBC_TwoDimWriter
(
false
)
{}
51
52
CBC_PDF417Writer::~
CBC_PDF417Writer
() =
default
;
53
54
bool
CBC_PDF417Writer::
SetErrorCorrectionLevel
(int32_t level) {
55
if
(level < 0 || level > 8) {
56
return
false
;
57
}
58
set_error_correction_level
(level);
59
return
true
;
60
}
61
62
CBC_PDF417Writer::
EncodeResult
CBC_PDF417Writer::
Encode
(
63
WideStringView
contents)
const
{
64
CBC_PDF417
encoder;
65
int32_t col = (m_Width / m_ModuleWidth - 69) / 17;
66
int32_t row = m_Height / (m_ModuleWidth * 20);
67
if
(row >= 3 && row <= 90 && col >= 1 && col <= 30)
68
encoder
.
setDimensions
(
col
,
1
,
row
,
3
)
;
69
else
if
(col >= 1 && col <= 30)
70
encoder
.
setDimensions
(
col
,
col
,
90
,
3
)
;
71
else
if
(row >= 3 && row <= 90)
72
encoder
.
setDimensions
(
30
,
1
,
row
,
row
)
;
73
if
(!encoder
.
GenerateBarcodeLogic
(
contents
,
error_correction_level
()
)
) {
74
return
{DataVector<uint8_t>(), 0, 0};
75
}
76
77
CBC_BarcodeMatrix* barcodeMatrix = encoder
.
getBarcodeMatrix
(
)
;
78
DataVector<uint8_t> matrix_data = barcodeMatrix->toBitArray();
79
int32_t matrix_width = barcodeMatrix->getWidth();
80
int32_t matrix_height = barcodeMatrix->getHeight();
81
82
if
(matrix_width < matrix_height) {
83
RotateArray(matrix_data, matrix_width, matrix_height);
84
std
::swap(matrix_width, matrix_height);
85
}
86
return
{
std
::move(matrix_data), matrix_width, matrix_height};
87
}
88
89
CBC_PDF417Writer::
EncodeResult
::EncodeResult(DataVector<uint8_t> data,
90
int32_t width,
91
int32_t height)
92
: data(std::move(data)),
width
(width),
height
(height) {}
93
94
CBC_PDF417Writer::
EncodeResult
::~
EncodeResult
() =
default
;
CBC_PDF417Writer::~CBC_PDF417Writer
~CBC_PDF417Writer() override
CBC_PDF417Writer::Encode
EncodeResult Encode(WideStringView contents) const
Definition
BC_PDF417Writer.cpp:62
CBC_PDF417Writer::SetErrorCorrectionLevel
bool SetErrorCorrectionLevel(int32_t level) override
Definition
BC_PDF417Writer.cpp:54
CBC_PDF417Writer::CBC_PDF417Writer
CBC_PDF417Writer()
Definition
BC_PDF417Writer.cpp:50
CBC_PDF417
Definition
BC_PDF417.h:18
CBC_PDF417::setDimensions
void setDimensions(int32_t maxCols, int32_t minCols, int32_t maxRows, int32_t minRows)
Definition
BC_PDF417.cpp:418
CBC_PDF417::GenerateBarcodeLogic
bool GenerateBarcodeLogic(WideStringView msg, int32_t errorCorrectionLevel)
Definition
BC_PDF417.cpp:367
CBC_PDF417::getBarcodeMatrix
CBC_BarcodeMatrix * getBarcodeMatrix()
Definition
BC_PDF417.cpp:363
CBC_TwoDimWriter
Definition
BC_TwoDimWriter.h:19
CBC_TwoDimWriter::error_correction_level
int32_t error_correction_level() const
Definition
BC_TwoDimWriter.h:29
CBC_TwoDimWriter::set_error_correction_level
void set_error_correction_level(int32_t level)
Definition
BC_TwoDimWriter.h:32
CBC_TwoDimWriter::CBC_TwoDimWriter
CBC_TwoDimWriter(bool bFixedSize)
Definition
BC_TwoDimWriter.cpp:20
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
WideStringView
fxcrt::WideStringView WideStringView
Definition
string_view_template.h:326
CBC_PDF417Writer::EncodeResult
Definition
BC_PDF417Writer.h:19
CBC_PDF417Writer::EncodeResult::width
int32_t width
Definition
BC_PDF417Writer.h:24
CBC_PDF417Writer::EncodeResult::~EncodeResult
~EncodeResult()
CBC_PDF417Writer::EncodeResult::height
int32_t height
Definition
BC_PDF417Writer.h:25
qtwebengine
src
3rdparty
chromium
third_party
pdfium
fxbarcode
pdf417
BC_PDF417Writer.cpp
Generated on
for Qt by
1.18.0