• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_code128.h"
23 
24 #include "xfa/fxbarcode/oned/BC_OnedCode128Writer.h"
25 
CBC_Code128(BC_TYPE type)26 CBC_Code128::CBC_Code128(BC_TYPE type)
27     : CBC_OneCode(new CBC_OnedCode128Writer(type)) {}
28 
~CBC_Code128()29 CBC_Code128::~CBC_Code128() {}
30 
SetTextLocation(BC_TEXT_LOC location)31 bool CBC_Code128::SetTextLocation(BC_TEXT_LOC location) {
32   if (m_pBCWriter)
33     return static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get())
34         ->SetTextLocation(location);
35   return false;
36 }
37 
Encode(const CFX_WideStringC & contents,bool isDevice,int32_t & e)38 bool CBC_Code128::Encode(const CFX_WideStringC& contents,
39                          bool isDevice,
40                          int32_t& e) {
41   if (contents.IsEmpty()) {
42     e = BCExceptionNoContents;
43     return false;
44   }
45   BCFORMAT format = BCFORMAT_CODE_128;
46   int32_t outWidth = 0;
47   int32_t outHeight = 0;
48   CFX_WideString content(contents);
49   if (contents.GetLength() % 2 &&
50       static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get())->GetType() ==
51           BC_CODE128_C) {
52     content += '0';
53   }
54   CFX_WideString encodeContents =
55       static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get())
56           ->FilterContents(content.AsStringC());
57   m_renderContents = encodeContents;
58   CFX_ByteString byteString = encodeContents.UTF8Encode();
59   uint8_t* data = static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get())
60                       ->Encode(byteString, format, outWidth, outHeight, e);
61   if (e != BCExceptionNO)
62     return false;
63   static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
64       ->RenderResult(encodeContents.AsStringC(), data, outWidth, isDevice, e);
65   FX_Free(data);
66   if (e != BCExceptionNO)
67     return false;
68   return true;
69 }
70 
RenderDevice(CFX_RenderDevice * device,const CFX_Matrix * matrix,int32_t & e)71 bool CBC_Code128::RenderDevice(CFX_RenderDevice* device,
72                                const CFX_Matrix* matrix,
73                                int32_t& e) {
74   static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
75       ->RenderDeviceResult(device, matrix, m_renderContents.AsStringC(), e);
76   if (e != BCExceptionNO)
77     return false;
78   return true;
79 }
80 
RenderBitmap(CFX_DIBitmap * & pOutBitmap,int32_t & e)81 bool CBC_Code128::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
82   static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
83       ->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e);
84   if (e != BCExceptionNO)
85     return false;
86   return true;
87 }
88 
GetType()89 BC_TYPE CBC_Code128::GetType() {
90   return BC_CODE128;
91 }
92 
93