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 | |
| 22 | #include "xfa/fxbarcode/cbc_code39.h" |
| 23 | |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 24 | #include "xfa/fxbarcode/oned/BC_OnedCode39Writer.h" |
| 25 | |
dsinclair | a261534 | 2016-06-16 12:29:07 -0700 | [diff] [blame] | 26 | CBC_Code39::CBC_Code39() : CBC_OneCode(new CBC_OnedCode39Writer) {} |
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_Code39::~CBC_Code39() {} |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 29 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame^] | 30 | bool CBC_Code39::Encode(const CFX_WideStringC& contents, |
| 31 | bool isDevice, |
| 32 | int32_t& e) { |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 33 | if (contents.IsEmpty()) { |
| 34 | e = BCExceptionNoContents; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame^] | 35 | return false; |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 36 | } |
| 37 | BCFORMAT format = BCFORMAT_CODE_39; |
| 38 | int32_t outWidth = 0; |
| 39 | int32_t outHeight = 0; |
| 40 | CFX_WideString filtercontents = |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 41 | static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) |
| 42 | ->FilterContents(contents); |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 43 | CFX_WideString renderContents = |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 44 | static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) |
| 45 | ->RenderTextContents(contents); |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 46 | m_renderContents = renderContents; |
| 47 | CFX_ByteString byteString = filtercontents.UTF8Encode(); |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 48 | uint8_t* data = static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 49 | ->Encode(byteString, format, outWidth, outHeight, e); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame^] | 50 | BC_EXCEPTION_CHECK_ReturnValue(e, false); |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 51 | static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 52 | ->RenderResult(renderContents.AsStringC(), data, outWidth, isDevice, e); |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 53 | FX_Free(data); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame^] | 54 | BC_EXCEPTION_CHECK_ReturnValue(e, false); |
| 55 | return true; |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 56 | } |
| 57 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame^] | 58 | bool CBC_Code39::RenderDevice(CFX_RenderDevice* device, |
| 59 | const CFX_Matrix* matrix, |
| 60 | int32_t& e) { |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 61 | CFX_WideString renderCon = |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 62 | static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 63 | ->encodedContents(m_renderContents.AsStringC(), e); |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 64 | static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) |
thestig | fbe14b9 | 2016-05-02 13:31:10 -0700 | [diff] [blame] | 65 | ->RenderDeviceResult(device, matrix, renderCon.AsStringC(), e); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame^] | 66 | BC_EXCEPTION_CHECK_ReturnValue(e, false); |
| 67 | return true; |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 68 | } |
| 69 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame^] | 70 | bool CBC_Code39::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 71 | CFX_WideString renderCon = |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 72 | static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 73 | ->encodedContents(m_renderContents.AsStringC(), e); |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 74 | static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 75 | ->RenderBitmapResult(pOutBitmap, renderCon.AsStringC(), e); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame^] | 76 | BC_EXCEPTION_CHECK_ReturnValue(e, false); |
| 77 | return true; |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 78 | } |
| 79 | |
weili | 29b8ad0 | 2016-06-14 18:20:04 -0700 | [diff] [blame] | 80 | BC_TYPE CBC_Code39::GetType() { |
| 81 | return BC_CODE39; |
| 82 | } |
| 83 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame^] | 84 | bool CBC_Code39::SetTextLocation(BC_TEXT_LOC location) { |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 85 | if (m_pBCWriter) |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 86 | return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) |
| 87 | ->SetTextLocation(location); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame^] | 88 | return false; |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 89 | } |
| 90 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame^] | 91 | bool CBC_Code39::SetWideNarrowRatio(int32_t ratio) { |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 92 | if (m_pBCWriter) |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 93 | return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) |
| 94 | ->SetWideNarrowRatio(ratio); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame^] | 95 | return false; |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 96 | } |