blob: 4072f32712b210d8eab31cb4110f7b086ad6d8e4 [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
Dan Sinclaire7786682017-03-29 15:18:41 -040022#include "fxbarcode/cbc_codabar.h"
Dan Sinclaira98600a2016-03-21 15:15:56 -040023
Dan Sinclaire7786682017-03-29 15:18:41 -040024#include "fxbarcode/oned/BC_OnedCodaBarWriter.h"
Dan Sinclaira98600a2016-03-21 15:15:56 -040025
dsinclaira2615342016-06-16 12:29:07 -070026CBC_Codabar::CBC_Codabar() : CBC_OneCode(new CBC_OnedCodaBarWriter) {}
Dan Sinclaira98600a2016-03-21 15:15:56 -040027
tsepez52d78562016-06-06 12:57:44 -070028CBC_Codabar::~CBC_Codabar() {}
Dan Sinclaira98600a2016-03-21 15:15:56 -040029
Dan Sinclair812e96c2017-03-13 16:43:37 -040030bool CBC_Codabar::SetStartChar(char start) {
tsepez52d78562016-06-06 12:57:44 -070031 if (!m_pBCWriter)
tsepezd19e9122016-11-02 15:43:18 -070032 return false;
tsepez52d78562016-06-06 12:57:44 -070033 return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
34 ->SetStartChar(start);
Dan Sinclaira98600a2016-03-21 15:15:56 -040035}
36
Dan Sinclair812e96c2017-03-13 16:43:37 -040037bool CBC_Codabar::SetEndChar(char end) {
Dan Sinclaira98600a2016-03-21 15:15:56 -040038 if (m_pBCWriter)
tsepez52d78562016-06-06 12:57:44 -070039 return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
40 ->SetEndChar(end);
tsepezd19e9122016-11-02 15:43:18 -070041 return false;
Dan Sinclaira98600a2016-03-21 15:15:56 -040042}
43
tsepezd19e9122016-11-02 15:43:18 -070044bool CBC_Codabar::SetTextLocation(BC_TEXT_LOC location) {
tsepez52d78562016-06-06 12:57:44 -070045 return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
46 ->SetTextLocation(location);
Dan Sinclaira98600a2016-03-21 15:15:56 -040047}
48
tsepezd19e9122016-11-02 15:43:18 -070049bool CBC_Codabar::SetWideNarrowRatio(int32_t ratio) {
Dan Sinclaira98600a2016-03-21 15:15:56 -040050 if (m_pBCWriter)
tsepez52d78562016-06-06 12:57:44 -070051 return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
52 ->SetWideNarrowRatio(ratio);
tsepezd19e9122016-11-02 15:43:18 -070053 return false;
Dan Sinclaira98600a2016-03-21 15:15:56 -040054}
55
tsepezd19e9122016-11-02 15:43:18 -070056bool CBC_Codabar::Encode(const CFX_WideStringC& contents,
57 bool isDevice,
58 int32_t& e) {
Dan Sinclaira98600a2016-03-21 15:15:56 -040059 if (contents.IsEmpty()) {
60 e = BCExceptionNoContents;
tsepezd19e9122016-11-02 15:43:18 -070061 return false;
Dan Sinclaira98600a2016-03-21 15:15:56 -040062 }
63 BCFORMAT format = BCFORMAT_CODABAR;
64 int32_t outWidth = 0;
65 int32_t outHeight = 0;
66 CFX_WideString filtercontents =
tsepez52d78562016-06-06 12:57:44 -070067 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
68 ->FilterContents(contents);
Dan Sinclaira98600a2016-03-21 15:15:56 -040069 CFX_ByteString byteString = filtercontents.UTF8Encode();
70 m_renderContents = filtercontents;
tsepez52d78562016-06-06 12:57:44 -070071 uint8_t* data = static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
Dan Sinclaira98600a2016-03-21 15:15:56 -040072 ->Encode(byteString, format, outWidth, outHeight, e);
Tom Sepezc8017b22017-01-31 13:02:10 -080073 if (e != BCExceptionNO)
74 return false;
tsepez52d78562016-06-06 12:57:44 -070075 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
tsepez4c3debb2016-04-08 12:20:38 -070076 ->RenderResult(filtercontents.AsStringC(), data, outWidth, isDevice, e);
Dan Sinclaira98600a2016-03-21 15:15:56 -040077 FX_Free(data);
Tom Sepezc8017b22017-01-31 13:02:10 -080078 if (e != BCExceptionNO)
79 return false;
tsepezd19e9122016-11-02 15:43:18 -070080 return true;
Dan Sinclaira98600a2016-03-21 15:15:56 -040081}
82
tsepezd19e9122016-11-02 15:43:18 -070083bool CBC_Codabar::RenderDevice(CFX_RenderDevice* device,
84 const CFX_Matrix* matrix,
85 int32_t& e) {
Dan Sinclaira98600a2016-03-21 15:15:56 -040086 CFX_WideString renderCon =
tsepez52d78562016-06-06 12:57:44 -070087 static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
tsepez4c3debb2016-04-08 12:20:38 -070088 ->encodedContents(m_renderContents.AsStringC());
tsepez52d78562016-06-06 12:57:44 -070089 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
thestigfbe14b92016-05-02 13:31:10 -070090 ->RenderDeviceResult(device, matrix, renderCon.AsStringC(), e);
Tom Sepezc8017b22017-01-31 13:02:10 -080091 if (e != BCExceptionNO)
92 return false;
tsepezd19e9122016-11-02 15:43:18 -070093 return true;
Dan Sinclaira98600a2016-03-21 15:15:56 -040094}
95
Tom Sepezf0799fe2017-03-28 09:31:32 -070096bool CBC_Codabar::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap,
97 int32_t& e) {
Dan Sinclaira98600a2016-03-21 15:15:56 -040098 CFX_WideString renderCon =
tsepez52d78562016-06-06 12:57:44 -070099 static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get())
tsepez4c3debb2016-04-08 12:20:38 -0700100 ->encodedContents(m_renderContents.AsStringC());
tsepez52d78562016-06-06 12:57:44 -0700101 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get())
tsepez4c3debb2016-04-08 12:20:38 -0700102 ->RenderBitmapResult(pOutBitmap, renderCon.AsStringC(), e);
Tom Sepezc8017b22017-01-31 13:02:10 -0800103 if (e != BCExceptionNO)
104 return false;
tsepezd19e9122016-11-02 15:43:18 -0700105 return true;
Dan Sinclaira98600a2016-03-21 15:15:56 -0400106}
107
weili29b8ad02016-06-14 18:20:04 -0700108BC_TYPE CBC_Codabar::GetType() {
109 return BC_CODABAR;
110}