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_X12Encoder.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_X12Encoder.h"
24
25
#
include
"core/fxcrt/fx_extension.h"
26
#
include
"fxbarcode/common/BC_CommonBitMatrix.h"
27
#
include
"fxbarcode/datamatrix/BC_C40Encoder.h"
28
#
include
"fxbarcode/datamatrix/BC_Encoder.h"
29
#
include
"fxbarcode/datamatrix/BC_EncoderContext.h"
30
#
include
"fxbarcode/datamatrix/BC_HighLevelEncoder.h"
31
#
include
"fxbarcode/datamatrix/BC_SymbolInfo.h"
32
33
CBC_X12Encoder::
CBC_X12Encoder
() =
default
;
34
35
CBC_X12Encoder::~
CBC_X12Encoder
() =
default
;
36
37
CBC_HighLevelEncoder
::
Encoding
CBC_X12Encoder::
GetEncodingMode
() {
38
return
CBC_HighLevelEncoder
::
Encoding
::
X12
;
39
}
40
41
bool
CBC_X12Encoder::
Encode
(
CBC_EncoderContext
* context) {
42
WideString buffer;
43
while
(context
->
hasMoreCharacters
(
)
) {
44
wchar_t
c = context
->
getCurrentChar
(
)
;
45
context->m_pos++;
46
if
(
EncodeChar
(
c
,
&buffer
)
<= 0)
47
return
false
;
48
49
size_t count = buffer.GetLength();
50
if
((count % 3) == 0) {
51
WriteNextTriplet
(
context
,
&buffer
)
;
52
CBC_HighLevelEncoder
::
Encoding
newMode =
53
CBC_HighLevelEncoder::LookAheadTest(context->m_msg, context->m_pos,
54
GetEncodingMode
(
)
);
55
if
(newMode !=
GetEncodingMode
(
)
) {
56
context
->
SignalEncoderChange
(
newMode
)
;
57
break
;
58
}
59
}
60
}
61
return
HandleEOD
(
context
,
&buffer
)
;
62
}
63
64
bool
CBC_X12Encoder::
HandleEOD
(
CBC_EncoderContext
* context,
65
WideString* buffer) {
66
if
(!context
->
UpdateSymbolInfo
(
)
)
67
return
false
;
68
69
int32_t available =
70
context->m_symbolInfo->data_capacity() - context->getCodewordCount();
71
size_t count = buffer->GetLength();
72
if
(count == 2) {
73
context
->
writeCodeword
(
CBC_HighLevelEncoder
::
X12_UNLATCH
)
;
74
context->m_pos -= 2;
75
context
->
SignalEncoderChange
(
CBC_HighLevelEncoder
::
Encoding
::
ASCII
)
;
76
}
else
if
(count == 1) {
77
context->m_pos--;
78
if
(available > 1) {
79
context
->
writeCodeword
(
CBC_HighLevelEncoder
::
X12_UNLATCH
)
;
80
}
81
context
->
SignalEncoderChange
(
CBC_HighLevelEncoder
::
Encoding
::
ASCII
)
;
82
}
83
return
true
;
84
}
85
86
int32_t CBC_X12Encoder::
EncodeChar
(
wchar_t
c, WideString* sb) {
87
if
(c ==
'\r'
)
88
*sb
+=
(
wchar_t
)
'\0'
;
89
else
if
(c ==
'*'
)
90
*sb
+=
(
wchar_t
)
'\1'
;
91
else
if
(c ==
'>'
)
92
*sb
+=
(
wchar_t
)
'\2'
;
93
else
if
(c ==
' '
)
94
*sb
+=
(
wchar_t
)
'\3'
;
95
else
if
(
FXSYS_IsDecimalDigit
(
c
)
)
96
*sb
+=
(
wchar_t
)(c - 48 + 4);
97
else
if
(
FXSYS_IsUpperASCII
(
c
)
)
98
*sb
+=
(
wchar_t
)(c - 65 + 14);
99
else
100
return
0;
101
return
1;
102
}
CBC_C40Encoder::WriteNextTriplet
static void WriteNextTriplet(CBC_EncoderContext *context, WideString *buffer)
Definition
BC_C40Encoder.cpp:104
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::UpdateSymbolInfo
bool UpdateSymbolInfo()
Definition
BC_EncoderContext.cpp:89
CBC_EncoderContext::hasMoreCharacters
bool hasMoreCharacters()
Definition
BC_EncoderContext.cpp:81
CBC_EncoderContext::SignalEncoderChange
void SignalEncoderChange(CBC_HighLevelEncoder::Encoding encoding)
Definition
BC_EncoderContext.cpp:72
CBC_HighLevelEncoder
Definition
BC_HighLevelEncoder.h:12
CBC_HighLevelEncoder::Encoding
Encoding
Definition
BC_HighLevelEncoder.h:14
CBC_HighLevelEncoder::Encoding::X12
@ X12
CBC_HighLevelEncoder::Encoding::ASCII
@ ASCII
CBC_HighLevelEncoder::X12_UNLATCH
static const wchar_t X12_UNLATCH
Definition
BC_HighLevelEncoder.h:43
CBC_X12Encoder::Encode
bool Encode(CBC_EncoderContext *context) override
Definition
BC_X12Encoder.cpp:41
CBC_X12Encoder::HandleEOD
bool HandleEOD(CBC_EncoderContext *context, WideString *buffer) override
Definition
BC_X12Encoder.cpp:64
CBC_X12Encoder::CBC_X12Encoder
CBC_X12Encoder()
CBC_X12Encoder::GetEncodingMode
CBC_HighLevelEncoder::Encoding GetEncodingMode() override
Definition
BC_X12Encoder.cpp:37
CBC_X12Encoder::EncodeChar
int32_t EncodeChar(wchar_t c, WideString *sb) override
Definition
BC_X12Encoder.cpp:86
CBC_X12Encoder::~CBC_X12Encoder
~CBC_X12Encoder() override
fxcrt::WideString::operator+=
WideString & operator+=(wchar_t ch)
Definition
widestring.cpp:519
FXSYS_IsDecimalDigit
bool FXSYS_IsDecimalDigit(wchar_t c)
Definition
fx_extension.h:101
FXSYS_IsUpperASCII
bool FXSYS_IsUpperASCII(int32_t c)
Definition
fx_extension.h:51
qtwebengine
src
3rdparty
chromium
third_party
pdfium
fxbarcode
datamatrix
BC_X12Encoder.cpp
Generated on Thu Nov 14 2024 01:01:51 for Qt by
1.12.0