xref: /aosp_15_r20/external/pdfium/fxbarcode/cbc_codabar.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1*3ac0a46fSAndroid Build Coastguard Worker // Copyright 2016 The PDFium Authors
2*3ac0a46fSAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*3ac0a46fSAndroid Build Coastguard Worker // found in the LICENSE file.
4*3ac0a46fSAndroid Build Coastguard Worker 
5*3ac0a46fSAndroid Build Coastguard Worker // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6*3ac0a46fSAndroid Build Coastguard Worker /*
7*3ac0a46fSAndroid Build Coastguard Worker  * Copyright 2011 ZXing authors
8*3ac0a46fSAndroid Build Coastguard Worker  *
9*3ac0a46fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
10*3ac0a46fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
11*3ac0a46fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
12*3ac0a46fSAndroid Build Coastguard Worker  *
13*3ac0a46fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
14*3ac0a46fSAndroid Build Coastguard Worker  *
15*3ac0a46fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
16*3ac0a46fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
17*3ac0a46fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18*3ac0a46fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
19*3ac0a46fSAndroid Build Coastguard Worker  * limitations under the License.
20*3ac0a46fSAndroid Build Coastguard Worker  */
21*3ac0a46fSAndroid Build Coastguard Worker 
22*3ac0a46fSAndroid Build Coastguard Worker #include "fxbarcode/cbc_codabar.h"
23*3ac0a46fSAndroid Build Coastguard Worker 
24*3ac0a46fSAndroid Build Coastguard Worker #include <memory>
25*3ac0a46fSAndroid Build Coastguard Worker 
26*3ac0a46fSAndroid Build Coastguard Worker #include "core/fxcrt/fx_coordinates.h"
27*3ac0a46fSAndroid Build Coastguard Worker #include "fxbarcode/oned/BC_OnedCodaBarWriter.h"
28*3ac0a46fSAndroid Build Coastguard Worker 
CBC_Codabar()29*3ac0a46fSAndroid Build Coastguard Worker CBC_Codabar::CBC_Codabar()
30*3ac0a46fSAndroid Build Coastguard Worker     : CBC_OneCode(std::make_unique<CBC_OnedCodaBarWriter>()) {}
31*3ac0a46fSAndroid Build Coastguard Worker 
32*3ac0a46fSAndroid Build Coastguard Worker CBC_Codabar::~CBC_Codabar() = default;
33*3ac0a46fSAndroid Build Coastguard Worker 
Encode(WideStringView contents)34*3ac0a46fSAndroid Build Coastguard Worker bool CBC_Codabar::Encode(WideStringView contents) {
35*3ac0a46fSAndroid Build Coastguard Worker   auto* pWriter = GetOnedCodaBarWriter();
36*3ac0a46fSAndroid Build Coastguard Worker   if (!pWriter->CheckContentValidity(contents))
37*3ac0a46fSAndroid Build Coastguard Worker     return false;
38*3ac0a46fSAndroid Build Coastguard Worker 
39*3ac0a46fSAndroid Build Coastguard Worker   m_renderContents = pWriter->FilterContents(contents);
40*3ac0a46fSAndroid Build Coastguard Worker   ByteString byteString = m_renderContents.ToUTF8();
41*3ac0a46fSAndroid Build Coastguard Worker   return pWriter->RenderResult(m_renderContents.AsStringView(),
42*3ac0a46fSAndroid Build Coastguard Worker                                pWriter->Encode(byteString));
43*3ac0a46fSAndroid Build Coastguard Worker }
44*3ac0a46fSAndroid Build Coastguard Worker 
RenderDevice(CFX_RenderDevice * device,const CFX_Matrix & matrix)45*3ac0a46fSAndroid Build Coastguard Worker bool CBC_Codabar::RenderDevice(CFX_RenderDevice* device,
46*3ac0a46fSAndroid Build Coastguard Worker                                const CFX_Matrix& matrix) {
47*3ac0a46fSAndroid Build Coastguard Worker   auto* pWriter = GetOnedCodaBarWriter();
48*3ac0a46fSAndroid Build Coastguard Worker   WideString renderCon =
49*3ac0a46fSAndroid Build Coastguard Worker       pWriter->encodedContents(m_renderContents.AsStringView());
50*3ac0a46fSAndroid Build Coastguard Worker   return pWriter->RenderDeviceResult(device, matrix, renderCon.AsStringView());
51*3ac0a46fSAndroid Build Coastguard Worker }
52*3ac0a46fSAndroid Build Coastguard Worker 
GetType()53*3ac0a46fSAndroid Build Coastguard Worker BC_TYPE CBC_Codabar::GetType() {
54*3ac0a46fSAndroid Build Coastguard Worker   return BC_TYPE::kCodabar;
55*3ac0a46fSAndroid Build Coastguard Worker }
56*3ac0a46fSAndroid Build Coastguard Worker 
GetOnedCodaBarWriter()57*3ac0a46fSAndroid Build Coastguard Worker CBC_OnedCodaBarWriter* CBC_Codabar::GetOnedCodaBarWriter() {
58*3ac0a46fSAndroid Build Coastguard Worker   return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get());
59*3ac0a46fSAndroid Build Coastguard Worker }
60