blob: 8b2b65dee65e5e7e43d05439286be3d49677f896 [file] [log] [blame]
kumarashishg826308d2023-06-23 13:21:22 +00001// Copyright 2016 The PDFium Authors
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -07002// 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/*
7 * Copyright 2011 ZXing authors
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22#include "fxbarcode/cbc_code128.h"
23
24#include <memory>
25
kumarashishg826308d2023-06-23 13:21:22 +000026#include "core/fxcrt/fx_coordinates.h"
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070027#include "fxbarcode/oned/BC_OnedCode128Writer.h"
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070028
29CBC_Code128::CBC_Code128(BC_TYPE type)
kumarashishg826308d2023-06-23 13:21:22 +000030 : CBC_OneCode(std::make_unique<CBC_OnedCode128Writer>(type)) {}
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070031
kumarashishg826308d2023-06-23 13:21:22 +000032CBC_Code128::~CBC_Code128() = default;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070033
Haibo Huang49cc9302020-04-27 16:14:24 -070034bool CBC_Code128::Encode(WideStringView contents) {
kumarashishg826308d2023-06-23 13:21:22 +000035 auto* pWriter = GetOnedCode128Writer();
36 if (!pWriter->CheckContentValidity(contents))
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070037 return false;
38
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070039 WideString content(contents);
kumarashishg826308d2023-06-23 13:21:22 +000040 if (contents.GetLength() % 2 && pWriter->GetType() == BC_TYPE::kCode128C)
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070041 content += '0';
42
Haibo Huang49cc9302020-04-27 16:14:24 -070043 m_renderContents = pWriter->FilterContents(content.AsStringView());
44 ByteString byteString = m_renderContents.ToUTF8();
kumarashishg826308d2023-06-23 13:21:22 +000045 return pWriter->RenderResult(m_renderContents.AsStringView(),
46 pWriter->Encode(byteString));
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070047}
48
49bool CBC_Code128::RenderDevice(CFX_RenderDevice* device,
kumarashishg826308d2023-06-23 13:21:22 +000050 const CFX_Matrix& matrix) {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070051 return GetOnedCode128Writer()->RenderDeviceResult(
52 device, matrix, m_renderContents.AsStringView());
53}
54
55BC_TYPE CBC_Code128::GetType() {
kumarashishg826308d2023-06-23 13:21:22 +000056 return BC_TYPE::kCode128;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070057}
58
59CBC_OnedCode128Writer* CBC_Code128::GetOnedCode128Writer() {
60 return static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get());
61}