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_datamatrix.h"
23
24 #include "xfa/fxbarcode/datamatrix/BC_DataMatrixWriter.h"
25
CBC_DataMatrix()26 CBC_DataMatrix::CBC_DataMatrix() : CBC_CodeBase(new CBC_DataMatrixWriter) {}
27
~CBC_DataMatrix()28 CBC_DataMatrix::~CBC_DataMatrix() {}
29
Encode(const CFX_WideStringC & contents,bool isDevice,int32_t & e)30 bool CBC_DataMatrix::Encode(const CFX_WideStringC& contents,
31 bool isDevice,
32 int32_t& e) {
33 int32_t outWidth = 0;
34 int32_t outHeight = 0;
35 uint8_t* data =
36 static_cast<CBC_DataMatrixWriter*>(m_pBCWriter.get())
37 ->Encode(CFX_WideString(contents), outWidth, outHeight, e);
38 if (e != BCExceptionNO)
39 return false;
40 static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
41 ->RenderResult(data, outWidth, outHeight, e);
42 FX_Free(data);
43 if (e != BCExceptionNO)
44 return false;
45 return true;
46 }
47
RenderDevice(CFX_RenderDevice * device,const CFX_Matrix * matrix,int32_t & e)48 bool CBC_DataMatrix::RenderDevice(CFX_RenderDevice* device,
49 const CFX_Matrix* matrix,
50 int32_t& e) {
51 static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
52 ->RenderDeviceResult(device, matrix);
53 return true;
54 }
55
RenderBitmap(CFX_DIBitmap * & pOutBitmap,int32_t & e)56 bool CBC_DataMatrix::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
57 static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get())
58 ->RenderBitmapResult(pOutBitmap, e);
59 if (e != BCExceptionNO)
60 return false;
61 return true;
62 }
63
GetType()64 BC_TYPE CBC_DataMatrix::GetType() {
65 return BC_DATAMATRIX;
66 }
67