blob: af45ad406332b7ac546c49afd7b76545329f56bf [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
tsepezd19e9122016-11-02 15:43:18 -070030bool CBC_Code39::Encode(const CFX_WideStringC& contents,
31 bool isDevice,
32 int32_t& e) {
Dan Sinclaira98600a2016-03-21 15:15:56 -040033 if (contents.IsEmpty()) {
34 e = BCExceptionNoContents;
tsepezd19e9122016-11-02 15:43:18 -070035 return false;
Dan Sinclaira98600a2016-03-21 15:15:56 -040036 }
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);
Tom Sepezc8017b22017-01-31 13:02:10 -080050 if (e != BCExceptionNO)
51 return false;
tsepez52d78562016-06-06 12:57:44 -070052 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
tsepez4c3debb2016-04-08 12:20:38 -070053 ->RenderResult(renderContents.AsStringC(), data, outWidth, isDevice, e);
Dan Sinclaira98600a2016-03-21 15:15:56 -040054 FX_Free(data);
Tom Sepezc8017b22017-01-31 13:02:10 -080055 if (e != BCExceptionNO)
56 return false;
tsepezd19e9122016-11-02 15:43:18 -070057 return true;
Dan Sinclaira98600a2016-03-21 15:15:56 -040058}
59
tsepezd19e9122016-11-02 15:43:18 -070060bool CBC_Code39::RenderDevice(CFX_RenderDevice* device,
61 const CFX_Matrix* matrix,
62 int32_t& e) {
tsepezfc58ad12016-04-05 12:22:15 -070063 CFX_WideString renderCon =
tsepez52d78562016-06-06 12:57:44 -070064 static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
tsepez4c3debb2016-04-08 12:20:38 -070065 ->encodedContents(m_renderContents.AsStringC(), e);
tsepez52d78562016-06-06 12:57:44 -070066 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
thestigfbe14b92016-05-02 13:31:10 -070067 ->RenderDeviceResult(device, matrix, renderCon.AsStringC(), e);
Tom Sepezc8017b22017-01-31 13:02:10 -080068 if (e != BCExceptionNO)
69 return false;
tsepezd19e9122016-11-02 15:43:18 -070070 return true;
Dan Sinclaira98600a2016-03-21 15:15:56 -040071}
72
tsepezd19e9122016-11-02 15:43:18 -070073bool CBC_Code39::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
tsepezfc58ad12016-04-05 12:22:15 -070074 CFX_WideString renderCon =
tsepez52d78562016-06-06 12:57:44 -070075 static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
tsepez4c3debb2016-04-08 12:20:38 -070076 ->encodedContents(m_renderContents.AsStringC(), e);
tsepez52d78562016-06-06 12:57:44 -070077 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
tsepez4c3debb2016-04-08 12:20:38 -070078 ->RenderBitmapResult(pOutBitmap, renderCon.AsStringC(), e);
Tom Sepezc8017b22017-01-31 13:02:10 -080079 if (e != BCExceptionNO)
80 return false;
tsepezd19e9122016-11-02 15:43:18 -070081 return true;
Dan Sinclaira98600a2016-03-21 15:15:56 -040082}
83
weili29b8ad02016-06-14 18:20:04 -070084BC_TYPE CBC_Code39::GetType() {
85 return BC_CODE39;
86}
87
tsepezd19e9122016-11-02 15:43:18 -070088bool CBC_Code39::SetTextLocation(BC_TEXT_LOC location) {
Dan Sinclaira98600a2016-03-21 15:15:56 -040089 if (m_pBCWriter)
tsepez52d78562016-06-06 12:57:44 -070090 return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
91 ->SetTextLocation(location);
tsepezd19e9122016-11-02 15:43:18 -070092 return false;
Dan Sinclaira98600a2016-03-21 15:15:56 -040093}
94
tsepezd19e9122016-11-02 15:43:18 -070095bool CBC_Code39::SetWideNarrowRatio(int32_t ratio) {
Dan Sinclaira98600a2016-03-21 15:15:56 -040096 if (m_pBCWriter)
tsepez52d78562016-06-06 12:57:44 -070097 return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get())
98 ->SetWideNarrowRatio(ratio);
tsepezd19e9122016-11-02 15:43:18 -070099 return false;
Dan Sinclaira98600a2016-03-21 15:15:56 -0400100}