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_code39.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_OnedCode39Writer.h"
28*3ac0a46fSAndroid Build Coastguard Worker
CBC_Code39()29*3ac0a46fSAndroid Build Coastguard Worker CBC_Code39::CBC_Code39()
30*3ac0a46fSAndroid Build Coastguard Worker : CBC_OneCode(std::make_unique<CBC_OnedCode39Writer>()) {}
31*3ac0a46fSAndroid Build Coastguard Worker
32*3ac0a46fSAndroid Build Coastguard Worker CBC_Code39::~CBC_Code39() = default;
33*3ac0a46fSAndroid Build Coastguard Worker
Encode(WideStringView contents)34*3ac0a46fSAndroid Build Coastguard Worker bool CBC_Code39::Encode(WideStringView contents) {
35*3ac0a46fSAndroid Build Coastguard Worker auto* pWriter = GetOnedCode39Writer();
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 WideString filtercontents = pWriter->FilterContents(contents);
40*3ac0a46fSAndroid Build Coastguard Worker m_renderContents = pWriter->RenderTextContents(contents);
41*3ac0a46fSAndroid Build Coastguard Worker ByteString byteString = filtercontents.ToUTF8();
42*3ac0a46fSAndroid Build Coastguard Worker return pWriter->RenderResult(m_renderContents.AsStringView(),
43*3ac0a46fSAndroid Build Coastguard Worker pWriter->Encode(byteString));
44*3ac0a46fSAndroid Build Coastguard Worker }
45*3ac0a46fSAndroid Build Coastguard Worker
RenderDevice(CFX_RenderDevice * device,const CFX_Matrix & matrix)46*3ac0a46fSAndroid Build Coastguard Worker bool CBC_Code39::RenderDevice(CFX_RenderDevice* device,
47*3ac0a46fSAndroid Build Coastguard Worker const CFX_Matrix& matrix) {
48*3ac0a46fSAndroid Build Coastguard Worker auto* pWriter = GetOnedCode39Writer();
49*3ac0a46fSAndroid Build Coastguard Worker WideString renderCon;
50*3ac0a46fSAndroid Build Coastguard Worker if (!pWriter->encodedContents(m_renderContents.AsStringView(), &renderCon))
51*3ac0a46fSAndroid Build Coastguard Worker return false;
52*3ac0a46fSAndroid Build Coastguard Worker return pWriter->RenderDeviceResult(device, matrix, renderCon.AsStringView());
53*3ac0a46fSAndroid Build Coastguard Worker }
54*3ac0a46fSAndroid Build Coastguard Worker
GetType()55*3ac0a46fSAndroid Build Coastguard Worker BC_TYPE CBC_Code39::GetType() {
56*3ac0a46fSAndroid Build Coastguard Worker return BC_TYPE::kCode39;
57*3ac0a46fSAndroid Build Coastguard Worker }
58*3ac0a46fSAndroid Build Coastguard Worker
GetOnedCode39Writer()59*3ac0a46fSAndroid Build Coastguard Worker CBC_OnedCode39Writer* CBC_Code39::GetOnedCode39Writer() {
60*3ac0a46fSAndroid Build Coastguard Worker return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get());
61*3ac0a46fSAndroid Build Coastguard Worker }
62