1 // Copyright 2016 PDFium Authors. All rights reserved.
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 "xfa/fxbarcode/cbc_pdf417i.h"
23 
24 #include "xfa/fxbarcode/pdf417/BC_PDF417Writer.h"
25 
CBC_PDF417I()26 CBC_PDF417I::CBC_PDF417I() : CBC_CodeBase(new CBC_PDF417Writer) {}
27 
~CBC_PDF417I()28 CBC_PDF417I::~CBC_PDF417I() {}
29 
SetErrorCorrectionLevel(int32_t level)30 FX_BOOL CBC_PDF417I::SetErrorCorrectionLevel(int32_t level) {
31   static_cast<CBC_PDF417Writer*>(m_pBCWriter.get())
32       ->SetErrorCorrectionLevel(level);
33   return TRUE;
34 }
35 
SetTruncated(FX_BOOL truncated)36 void CBC_PDF417I::SetTruncated(FX_BOOL truncated) {
37   static_cast<CBC_PDF417Writer*>(m_pBCWriter.get())->SetTruncated(truncated);
38 }
39 
Encode(const CFX_WideStringC & contents,FX_BOOL isDevice,int32_t & e)40 FX_BOOL CBC_PDF417I::Encode(const CFX_WideStringC& contents,
41                             FX_BOOL isDevice,
42                             int32_t& e) {
43   int32_t outWidth = 0;
44   int32_t outHeight = 0;
45   uint8_t* data =
46       static_cast<CBC_PDF417Writer*>(m_pBCWriter.get())
47           ->Encode(CFX_WideString(contents), outWidth, outHeight, e);
48   BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
49   static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
50       ->RenderResult(data, outWidth, outHeight, e);
51   FX_Free(data);
52   BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
53   return TRUE;
54 }
55 
RenderDevice(CFX_RenderDevice * device,const CFX_Matrix * matrix,int32_t & e)56 FX_BOOL CBC_PDF417I::RenderDevice(CFX_RenderDevice* device,
57                                   const CFX_Matrix* matrix,
58                                   int32_t& e) {
59   static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
60       ->RenderDeviceResult(device, matrix);
61   return TRUE;
62 }
63 
RenderBitmap(CFX_DIBitmap * & pOutBitmap,int32_t & e)64 FX_BOOL CBC_PDF417I::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
65   static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
66       ->RenderBitmapResult(pOutBitmap, e);
67   BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
68   return TRUE;
69 }
70 
GetType()71 BC_TYPE CBC_PDF417I::GetType() {
72   return BC_PDF417;
73 }
74