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
33CBC_X12Encoder::CBC_X12Encoder() = default;
34
35CBC_X12Encoder::~CBC_X12Encoder() = default;
36
40
41bool 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);
53 CBC_HighLevelEncoder::LookAheadTest(context->m_msg, context->m_pos,
55 if (newMode != GetEncodingMode()) {
56 context->SignalEncoderChange(newMode);
57 break;
58 }
59 }
60 }
61 return HandleEOD(context, &buffer);
62}
63
64bool 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) {
74 context->m_pos -= 2;
76 } else if (count == 1) {
77 context->m_pos--;
78 if (available > 1) {
80 }
82 }
83 return true;
84}
85
86int32_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}
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)