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
32CBC_X12Encoder::CBC_X12Encoder() = default;
33
34CBC_X12Encoder::~CBC_X12Encoder() = default;
35
39
40bool 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);
52 CBC_HighLevelEncoder::LookAheadTest(context->m_msg, context->m_pos,
54 if (newMode != GetEncodingMode()) {
55 context->SignalEncoderChange(newMode);
56 break;
57 }
58 }
59 }
60 return HandleEOD(context, &buffer);
61}
62
63bool 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) {
73 context->m_pos -= 2;
75 } else if (count == 1) {
76 context->m_pos--;
77 if (available > 1) {
79 }
81 }
82 return true;
83}
84
85int32_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}
static void WriteNextTriplet(CBC_EncoderContext *context, WideString *buffer)
void writeCodeword(wchar_t codeword)
void SignalEncoderChange(CBC_HighLevelEncoder::Encoding encoding)
static const wchar_t X12_UNLATCH
bool Encode(CBC_EncoderContext *context) override
bool HandleEOD(CBC_EncoderContext *context, WideString *buffer) override
CBC_HighLevelEncoder::Encoding GetEncodingMode() override
int32_t EncodeChar(wchar_t c, WideString *sb) override
~CBC_X12Encoder() override
WideString & operator+=(wchar_t ch)
bool FXSYS_IsDecimalDigit(wchar_t c)
bool FXSYS_IsUpperASCII(int32_t c)
fxcrt::WideString WideString
Definition widestring.h:207