blob: bbf4123d4241a36c6953a638734cdde2c85c6c15 [file] [log] [blame]
Dan Sinclaira98600a2016-03-21 15:15:56 -04001// 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_code39.h"
23
Dan Sinclaira98600a2016-03-21 15:15:56 -040024#include "xfa/fxbarcode/oned/BC_OnedCode39Writer.h"
25
dsinclaira2615342016-06-16 12:29:07 -070026CBC_Code39::CBC_Code39() : CBC_OneCode(new CBC_OnedCode39Writer) {}
Dan Sinclaira98600a2016-03-21 15:15:56 -040027
tsepez52d78562016-06-06 12:57:44 -070028CBC_Code39::~CBC_Code39() {}
Dan Sinclaira98600a2016-03-21 15:15:56 -040029
30FX_BOOL CBC_Code39::Encode(const CFX_WideStringC& contents,
31 FX_BOOL isDevice,
32 int32_t& e) {
33 if (contents.IsEmpty()) {
34 e = BCExceptionNoContents;
35 return FALSE;
36 }
37 BCFORMAT format = BCFORMAT_CODE_39;
38 int32_t outWidth = 0;
39 int32_t outHeight = 0;
40 CFX_WideString filtercontents =
tsepez52d78562016-06-06 12:57:44 -070041 static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
42 ->FilterContents(contents);
Dan Sinclaira98600a2016-03-21 15:15:56 -040043 CFX_WideString renderContents =
tsepez52d78562016-06-06 12:57:44 -070044 static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
45 ->RenderTextContents(contents);
Dan Sinclaira98600a2016-03-21 15:15:56 -040046 m_renderContents = renderContents;
47 CFX_ByteString byteString = filtercontents.UTF8Encode();
tsepez52d78562016-06-06 12:57:44 -070048 uint8_t* data = static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
Dan Sinclaira98600a2016-03-21 15:15:56 -040049 ->Encode(byteString, format, outWidth, outHeight, e);
50 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
tsepez52d78562016-06-06 12:57:44 -070051 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
tsepez4c3debb2016-04-08 12:20:38 -070052 ->RenderResult(renderContents.AsStringC(), data, outWidth, isDevice, e);
Dan Sinclaira98600a2016-03-21 15:15:56 -040053 FX_Free(data);
54 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
55 return TRUE;
56}
57
58FX_BOOL CBC_Code39::RenderDevice(CFX_RenderDevice* device,
thestigfbe14b92016-05-02 13:31:10 -070059 const CFX_Matrix* matrix,
Dan Sinclaira98600a2016-03-21 15:15:56 -040060 int32_t& e) {
tsepezfc58ad12016-04-05 12:22:15 -070061 CFX_WideString renderCon =
tsepez52d78562016-06-06 12:57:44 -070062 static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
tsepez4c3debb2016-04-08 12:20:38 -070063 ->encodedContents(m_renderContents.AsStringC(), e);
tsepez52d78562016-06-06 12:57:44 -070064 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
thestigfbe14b92016-05-02 13:31:10 -070065 ->RenderDeviceResult(device, matrix, renderCon.AsStringC(), e);
Dan Sinclaira98600a2016-03-21 15:15:56 -040066 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
67 return TRUE;
68}
69
70FX_BOOL CBC_Code39::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
tsepezfc58ad12016-04-05 12:22:15 -070071 CFX_WideString renderCon =
tsepez52d78562016-06-06 12:57:44 -070072 static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
tsepez4c3debb2016-04-08 12:20:38 -070073 ->encodedContents(m_renderContents.AsStringC(), e);
tsepez52d78562016-06-06 12:57:44 -070074 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
tsepez4c3debb2016-04-08 12:20:38 -070075 ->RenderBitmapResult(pOutBitmap, renderCon.AsStringC(), e);
Dan Sinclaira98600a2016-03-21 15:15:56 -040076 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
77 return TRUE;
78}
79
weili29b8ad02016-06-14 18:20:04 -070080BC_TYPE CBC_Code39::GetType() {
81 return BC_CODE39;
82}
83
Dan Sinclaira98600a2016-03-21 15:15:56 -040084FX_BOOL CBC_Code39::SetTextLocation(BC_TEXT_LOC location) {
85 if (m_pBCWriter)
tsepez52d78562016-06-06 12:57:44 -070086 return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
87 ->SetTextLocation(location);
Dan Sinclaira98600a2016-03-21 15:15:56 -040088 return FALSE;
89}
90
91FX_BOOL CBC_Code39::SetWideNarrowRatio(int32_t ratio) {
92 if (m_pBCWriter)
tsepez52d78562016-06-06 12:57:44 -070093 return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
94 ->SetWideNarrowRatio(ratio);
Dan Sinclaira98600a2016-03-21 15:15:56 -040095 return FALSE;
96}