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