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_ASCIIEncoder.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 2006-2007 Jeremias Maerki.
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/datamatrix/BC_ASCIIEncoder.h"
24
25
#
include
"core/fxcrt/fx_extension.h"
26
#
include
"fxbarcode/datamatrix/BC_Encoder.h"
27
#
include
"fxbarcode/datamatrix/BC_EncoderContext.h"
28
#
include
"fxbarcode/datamatrix/BC_HighLevelEncoder.h"
29
#
include
"fxbarcode/datamatrix/BC_SymbolInfo.h"
30
#
include
"third_party/abseil-cpp/absl/types/optional.h"
31
32
namespace
{
33
34
absl::optional<
wchar_t
> EncodeASCIIDigits(
wchar_t
digit1,
wchar_t
digit2) {
35
if
(!
FXSYS_IsDecimalDigit
(
digit1
)
|| !
FXSYS_IsDecimalDigit
(
digit2
)
) {
36
// This could potentially return 0 as a sentinel value. Then this function
37
// can just return wchar_t instead of absl::optional<wchar_t>.
38
return
absl::nullopt;
39
}
40
return
static_cast
<
wchar_t
>((digit1 - 48) * 10 + (digit2 - 48) + 130);
41
}
42
43
size_t DetermineConsecutiveDigitCount(
const
WideString& msg, size_t startpos) {
44
// This is faster in debug builds and helpful for fuzzers.
45
// Access |data| with care.
46
size_t count = 0;
47
const
size_t size = msg.GetLength();
48
const
wchar_t
* data = msg
.
c_str
(
)
;
49
for
(size_t i = startpos; i < size; ++i) {
50
if
(!FXSYS_IsDecimalDigit(data[i]))
51
break
;
52
++count;
53
}
54
return
count;
55
}
56
57
}
// namespace
58
59
CBC_ASCIIEncoder::
CBC_ASCIIEncoder
() =
default
;
60
61
CBC_ASCIIEncoder::~
CBC_ASCIIEncoder
() =
default
;
62
63
CBC_HighLevelEncoder
::
Encoding
CBC_ASCIIEncoder::
GetEncodingMode
() {
64
return
CBC_HighLevelEncoder
::
Encoding
::
ASCII
;
65
}
66
67
bool
CBC_ASCIIEncoder::
Encode
(
CBC_EncoderContext
* context) {
68
size_t n = DetermineConsecutiveDigitCount(context->m_msg, context->m_pos);
69
if
(n >= 2) {
70
absl::optional<
wchar_t
> code = EncodeASCIIDigits(
71
context->m_msg[context->m_pos], context->m_msg[context->m_pos + 1]);
72
if
(!code.has_value())
73
return
false
;
74
75
context->writeCodeword(code.value());
76
context->m_pos += 2;
77
return
true
;
78
}
79
80
wchar_t
c = context
->
getCurrentChar
(
)
;
81
CBC_HighLevelEncoder
::
Encoding
newMode = CBC_HighLevelEncoder::LookAheadTest(
82
context->m_msg, context->m_pos,
GetEncodingMode
(
)
);
83
if
(newMode !=
GetEncodingMode
(
)
) {
84
switch
(newMode) {
85
case
CBC_HighLevelEncoder
::
Encoding
::
BASE256
:
86
context
->
writeCodeword
(
CBC_HighLevelEncoder
::
LATCH_TO_BASE256
)
;
87
break
;
88
case
CBC_HighLevelEncoder
::
Encoding
::
C40
:
89
context
->
writeCodeword
(
CBC_HighLevelEncoder
::
LATCH_TO_C40
)
;
90
break
;
91
case
CBC_HighLevelEncoder
::
Encoding
::
X12
:
92
context
->
writeCodeword
(
CBC_HighLevelEncoder
::
LATCH_TO_ANSIX12
)
;
93
break
;
94
case
CBC_HighLevelEncoder
::
Encoding
::
TEXT
:
95
context
->
writeCodeword
(
CBC_HighLevelEncoder
::
LATCH_TO_TEXT
)
;
96
break
;
97
case
CBC_HighLevelEncoder
::
Encoding
::
EDIFACT
:
98
context
->
writeCodeword
(
CBC_HighLevelEncoder
::
LATCH_TO_EDIFACT
)
;
99
break
;
100
default
:
101
return
false
;
102
}
103
context
->
SignalEncoderChange
(
newMode
)
;
104
return
true
;
105
}
106
107
if
(
CBC_HighLevelEncoder
::
IsExtendedASCII
(
c
)
) {
108
context
->
writeCodeword
(
CBC_HighLevelEncoder
::
UPPER_SHIFT
)
;
109
context
->
writeCodeword
(
static_cast
<
wchar_t
>(c - 128 + 1)
)
;
110
}
else
{
111
context
->
writeCodeword
(
static_cast
<
wchar_t
>(c + 1)
)
;
112
}
113
context->m_pos++;
114
return
true
;
115
}
CBC_ASCIIEncoder::Encode
bool Encode(CBC_EncoderContext *context) override
Definition
BC_ASCIIEncoder.cpp:67
CBC_ASCIIEncoder::~CBC_ASCIIEncoder
~CBC_ASCIIEncoder() override
CBC_ASCIIEncoder::GetEncodingMode
CBC_HighLevelEncoder::Encoding GetEncodingMode() override
Definition
BC_ASCIIEncoder.cpp:63
CBC_ASCIIEncoder::CBC_ASCIIEncoder
CBC_ASCIIEncoder()
CBC_EncoderContext
Definition
BC_EncoderContext.h:16
CBC_EncoderContext::writeCodeword
void writeCodeword(wchar_t codeword)
Definition
BC_EncoderContext.cpp:64
CBC_EncoderContext::getCurrentChar
wchar_t getCurrentChar()
Definition
BC_EncoderContext.cpp:53
CBC_EncoderContext::SignalEncoderChange
void SignalEncoderChange(CBC_HighLevelEncoder::Encoding encoding)
Definition
BC_EncoderContext.cpp:72
CBC_HighLevelEncoder
Definition
BC_HighLevelEncoder.h:12
CBC_HighLevelEncoder::LATCH_TO_TEXT
static const wchar_t LATCH_TO_TEXT
Definition
BC_HighLevelEncoder.h:40
CBC_HighLevelEncoder::LATCH_TO_ANSIX12
static const wchar_t LATCH_TO_ANSIX12
Definition
BC_HighLevelEncoder.h:39
CBC_HighLevelEncoder::LATCH_TO_BASE256
static const wchar_t LATCH_TO_BASE256
Definition
BC_HighLevelEncoder.h:37
CBC_HighLevelEncoder::IsExtendedASCII
static bool IsExtendedASCII(wchar_t ch)
Definition
BC_HighLevelEncoder.cpp:328
CBC_HighLevelEncoder::LATCH_TO_C40
static const wchar_t LATCH_TO_C40
Definition
BC_HighLevelEncoder.h:36
CBC_HighLevelEncoder::UPPER_SHIFT
static const wchar_t UPPER_SHIFT
Definition
BC_HighLevelEncoder.h:38
CBC_HighLevelEncoder::Encoding
Encoding
Definition
BC_HighLevelEncoder.h:14
CBC_HighLevelEncoder::Encoding::BASE256
@ BASE256
CBC_HighLevelEncoder::Encoding::TEXT
@ TEXT
CBC_HighLevelEncoder::Encoding::C40
@ C40
CBC_HighLevelEncoder::Encoding::X12
@ X12
CBC_HighLevelEncoder::Encoding::EDIFACT
@ EDIFACT
CBC_HighLevelEncoder::Encoding::ASCII
@ ASCII
CBC_HighLevelEncoder::LATCH_TO_EDIFACT
static const wchar_t LATCH_TO_EDIFACT
Definition
BC_HighLevelEncoder.h:41
fxcrt::WideString::c_str
const wchar_t * c_str() const
Definition
widestring.h:81
FXSYS_IsDecimalDigit
bool FXSYS_IsDecimalDigit(wchar_t c)
Definition
fx_extension.h:101
qtwebengine
src
3rdparty
chromium
third_party
pdfium
fxbarcode
datamatrix
BC_ASCIIEncoder.cpp
Generated on Thu Nov 14 2024 01:01:42 for Qt by
1.12.0