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_codabar.h"
23
24 #include "xfa/fxbarcode/oned/BC_OnedCodaBarWriter.h"
25
CBC_Codabar()26 CBC_Codabar::CBC_Codabar() : CBC_OneCode(new CBC_OnedCodaBarWriter) {}
27
~CBC_Codabar()28 CBC_Codabar::~CBC_Codabar() {}
29
SetStartChar(FX_CHAR start)30 FX_BOOL CBC_Codabar::SetStartChar(FX_CHAR start) {
31 if (!m_pBCWriter)
32 return FALSE;
33 return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
34 ->SetStartChar(start);
35 }
36
SetEndChar(FX_CHAR end)37 FX_BOOL CBC_Codabar::SetEndChar(FX_CHAR end) {
38 if (m_pBCWriter)
39 return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
40 ->SetEndChar(end);
41 return FALSE;
42 }
43
SetTextLocation(BC_TEXT_LOC location)44 FX_BOOL CBC_Codabar::SetTextLocation(BC_TEXT_LOC location) {
45 return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
46 ->SetTextLocation(location);
47 }
48
SetWideNarrowRatio(int32_t ratio)49 FX_BOOL CBC_Codabar::SetWideNarrowRatio(int32_t ratio) {
50 if (m_pBCWriter)
51 return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
52 ->SetWideNarrowRatio(ratio);
53 return FALSE;
54 }
55
Encode(const CFX_WideStringC & contents,FX_BOOL isDevice,int32_t & e)56 FX_BOOL CBC_Codabar::Encode(const CFX_WideStringC& contents,
57 FX_BOOL isDevice,
58 int32_t& e) {
59 if (contents.IsEmpty()) {
60 e = BCExceptionNoContents;
61 return FALSE;
62 }
63 BCFORMAT format = BCFORMAT_CODABAR;
64 int32_t outWidth = 0;
65 int32_t outHeight = 0;
66 CFX_WideString filtercontents =
67 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
68 ->FilterContents(contents);
69 CFX_ByteString byteString = filtercontents.UTF8Encode();
70 m_renderContents = filtercontents;
71 uint8_t* data = static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
72 ->Encode(byteString, format, outWidth, outHeight, e);
73 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
74 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
75 ->RenderResult(filtercontents.AsStringC(), data, outWidth, isDevice, e);
76 FX_Free(data);
77 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
78 return TRUE;
79 }
80
RenderDevice(CFX_RenderDevice * device,const CFX_Matrix * matrix,int32_t & e)81 FX_BOOL CBC_Codabar::RenderDevice(CFX_RenderDevice* device,
82 const CFX_Matrix* matrix,
83 int32_t& e) {
84 CFX_WideString renderCon =
85 static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
86 ->encodedContents(m_renderContents.AsStringC());
87 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
88 ->RenderDeviceResult(device, matrix, renderCon.AsStringC(), e);
89 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
90 return TRUE;
91 }
92
RenderBitmap(CFX_DIBitmap * & pOutBitmap,int32_t & e)93 FX_BOOL CBC_Codabar::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
94 CFX_WideString renderCon =
95 static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
96 ->encodedContents(m_renderContents.AsStringC());
97 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
98 ->RenderBitmapResult(pOutBitmap, renderCon.AsStringC(), e);
99 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
100 return TRUE;
101 }
102
GetType()103 BC_TYPE CBC_Codabar::GetType() {
104 return BC_CODABAR;
105 }
106