kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 1 | // Copyright 2016 The PDFium Authors |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 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 | /* |
| 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 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 26 | #include "core/fxcrt/fx_coordinates.h" |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 27 | #include "fxbarcode/oned/BC_OnedCode128Writer.h" |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 28 | |
| 29 | CBC_Code128::CBC_Code128(BC_TYPE type) |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 30 | : CBC_OneCode(std::make_unique<CBC_OnedCode128Writer>(type)) {} |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 31 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 32 | CBC_Code128::~CBC_Code128() = default; |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 33 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 34 | bool CBC_Code128::Encode(WideStringView contents) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 35 | auto* pWriter = GetOnedCode128Writer(); |
| 36 | if (!pWriter->CheckContentValidity(contents)) |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 37 | return false; |
| 38 | |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 39 | WideString content(contents); |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 40 | if (contents.GetLength() % 2 && pWriter->GetType() == BC_TYPE::kCode128C) |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 41 | content += '0'; |
| 42 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 43 | m_renderContents = pWriter->FilterContents(content.AsStringView()); |
| 44 | ByteString byteString = m_renderContents.ToUTF8(); |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 45 | return pWriter->RenderResult(m_renderContents.AsStringView(), |
| 46 | pWriter->Encode(byteString)); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | bool CBC_Code128::RenderDevice(CFX_RenderDevice* device, |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 50 | const CFX_Matrix& matrix) { |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 51 | return GetOnedCode128Writer()->RenderDeviceResult( |
| 52 | device, matrix, m_renderContents.AsStringView()); |
| 53 | } |
| 54 | |
| 55 | BC_TYPE CBC_Code128::GetType() { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 56 | return BC_TYPE::kCode128; |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | CBC_OnedCode128Writer* CBC_Code128::GetOnedCode128Writer() { |
| 60 | return static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get()); |
| 61 | } |