cbc_pdf417i.cpp revision 33357cad1fd1321a2b38d2963e2585f27ce980a2
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
26CBC_PDF417I::CBC_PDF417I() : CBC_CodeBase(new CBC_PDF417Writer) {}
27
28CBC_PDF417I::~CBC_PDF417I() {}
29
30bool CBC_PDF417I::SetErrorCorrectionLevel(int32_t level) {
31  static_cast<CBC_PDF417Writer*>(m_pBCWriter.get())
32      ->SetErrorCorrectionLevel(level);
33  return true;
34}
35
36void CBC_PDF417I::SetTruncated(bool truncated) {
37  static_cast<CBC_PDF417Writer*>(m_pBCWriter.get())->SetTruncated(truncated);
38}
39
40bool CBC_PDF417I::Encode(const CFX_WideStringC& contents,
41                         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  if (e != BCExceptionNO)
49    return false;
50  static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
51      ->RenderResult(data, outWidth, outHeight, e);
52  FX_Free(data);
53  if (e != BCExceptionNO)
54    return false;
55  return true;
56}
57
58bool CBC_PDF417I::RenderDevice(CFX_RenderDevice* device,
59                               const CFX_Matrix* matrix,
60                               int32_t& e) {
61  static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
62      ->RenderDeviceResult(device, matrix);
63  return true;
64}
65
66bool CBC_PDF417I::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
67  static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
68      ->RenderBitmapResult(pOutBitmap, e);
69  if (e != BCExceptionNO)
70    return false;
71  return true;
72}
73
74BC_TYPE CBC_PDF417I::GetType() {
75  return BC_PDF417;
76}
77