Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 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 | |
Dan Sinclair | e778668 | 2017-03-29 15:18:41 -0400 | [diff] [blame] | 22 | #include "fxbarcode/cbc_codabar.h" |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 23 | |
Dan Sinclair | e778668 | 2017-03-29 15:18:41 -0400 | [diff] [blame] | 24 | #include "fxbarcode/oned/BC_OnedCodaBarWriter.h" |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 25 | |
dsinclair | a261534 | 2016-06-16 12:29:07 -0700 | [diff] [blame] | 26 | CBC_Codabar::CBC_Codabar() : CBC_OneCode(new CBC_OnedCodaBarWriter) {} |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 27 | |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 28 | CBC_Codabar::~CBC_Codabar() {} |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 29 | |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 30 | bool CBC_Codabar::SetStartChar(char start) { |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 31 | if (!m_pBCWriter) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 32 | return false; |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 33 | return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get()) |
| 34 | ->SetStartChar(start); |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 35 | } |
| 36 | |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 37 | bool CBC_Codabar::SetEndChar(char end) { |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 38 | if (m_pBCWriter) |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 39 | return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get()) |
| 40 | ->SetEndChar(end); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 41 | return false; |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 42 | } |
| 43 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 44 | bool CBC_Codabar::SetTextLocation(BC_TEXT_LOC location) { |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 45 | return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get()) |
| 46 | ->SetTextLocation(location); |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 47 | } |
| 48 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 49 | bool CBC_Codabar::SetWideNarrowRatio(int32_t ratio) { |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 50 | if (m_pBCWriter) |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 51 | return static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get()) |
| 52 | ->SetWideNarrowRatio(ratio); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 53 | return false; |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 54 | } |
| 55 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 56 | bool CBC_Codabar::Encode(const CFX_WideStringC& contents, |
| 57 | bool isDevice, |
| 58 | int32_t& e) { |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 59 | if (contents.IsEmpty()) { |
| 60 | e = BCExceptionNoContents; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 61 | return false; |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 62 | } |
| 63 | BCFORMAT format = BCFORMAT_CODABAR; |
| 64 | int32_t outWidth = 0; |
| 65 | int32_t outHeight = 0; |
| 66 | CFX_WideString filtercontents = |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 67 | static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) |
| 68 | ->FilterContents(contents); |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 69 | CFX_ByteString byteString = filtercontents.UTF8Encode(); |
| 70 | m_renderContents = filtercontents; |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 71 | uint8_t* data = static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get()) |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 72 | ->Encode(byteString, format, outWidth, outHeight, e); |
Tom Sepez | c8017b2 | 2017-01-31 13:02:10 -0800 | [diff] [blame] | 73 | if (e != BCExceptionNO) |
| 74 | return false; |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 75 | static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 76 | ->RenderResult(filtercontents.AsStringC(), data, outWidth, isDevice, e); |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 77 | FX_Free(data); |
Tom Sepez | c8017b2 | 2017-01-31 13:02:10 -0800 | [diff] [blame] | 78 | if (e != BCExceptionNO) |
| 79 | return false; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 80 | return true; |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 81 | } |
| 82 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 83 | bool CBC_Codabar::RenderDevice(CFX_RenderDevice* device, |
| 84 | const CFX_Matrix* matrix, |
| 85 | int32_t& e) { |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 86 | CFX_WideString renderCon = |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 87 | static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get()) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 88 | ->encodedContents(m_renderContents.AsStringC()); |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 89 | static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) |
thestig | fbe14b9 | 2016-05-02 13:31:10 -0700 | [diff] [blame] | 90 | ->RenderDeviceResult(device, matrix, renderCon.AsStringC(), e); |
Tom Sepez | c8017b2 | 2017-01-31 13:02:10 -0800 | [diff] [blame] | 91 | if (e != BCExceptionNO) |
| 92 | return false; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 93 | return true; |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 94 | } |
| 95 | |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 96 | bool CBC_Codabar::RenderBitmap(CFX_RetainPtr<CFX_DIBitmap>& pOutBitmap, |
| 97 | int32_t& e) { |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 98 | CFX_WideString renderCon = |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 99 | static_cast<CBC_OnedCodaBarWriter*>(m_pBCWriter.get()) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 100 | ->encodedContents(m_renderContents.AsStringC()); |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 101 | static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 102 | ->RenderBitmapResult(pOutBitmap, renderCon.AsStringC(), e); |
Tom Sepez | c8017b2 | 2017-01-31 13:02:10 -0800 | [diff] [blame] | 103 | if (e != BCExceptionNO) |
| 104 | return false; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 105 | return true; |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 106 | } |
| 107 | |
weili | 29b8ad0 | 2016-06-14 18:20:04 -0700 | [diff] [blame] | 108 | BC_TYPE CBC_Codabar::GetType() { |
| 109 | return BC_CODABAR; |
| 110 | } |