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); |
Tom Sepez | c8017b2 | 2017-01-31 13:02:10 -0800 | [diff] [blame^] | 50 | if (e != BCExceptionNO) |
| 51 | return false; |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 52 | static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 53 | ->RenderResult(renderContents.AsStringC(), data, outWidth, isDevice, e); |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 54 | FX_Free(data); |
Tom Sepez | c8017b2 | 2017-01-31 13:02:10 -0800 | [diff] [blame^] | 55 | if (e != BCExceptionNO) |
| 56 | return false; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 57 | return true; |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 58 | } |
| 59 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 60 | bool CBC_Code39::RenderDevice(CFX_RenderDevice* device, |
| 61 | const CFX_Matrix* matrix, |
| 62 | int32_t& e) { |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 63 | CFX_WideString renderCon = |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 64 | static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 65 | ->encodedContents(m_renderContents.AsStringC(), e); |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 66 | static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) |
thestig | fbe14b9 | 2016-05-02 13:31:10 -0700 | [diff] [blame] | 67 | ->RenderDeviceResult(device, matrix, renderCon.AsStringC(), e); |
Tom Sepez | c8017b2 | 2017-01-31 13:02:10 -0800 | [diff] [blame^] | 68 | if (e != BCExceptionNO) |
| 69 | return false; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 70 | return true; |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 71 | } |
| 72 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 73 | bool CBC_Code39::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 74 | CFX_WideString renderCon = |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 75 | static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 76 | ->encodedContents(m_renderContents.AsStringC(), e); |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 77 | static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 78 | ->RenderBitmapResult(pOutBitmap, renderCon.AsStringC(), e); |
Tom Sepez | c8017b2 | 2017-01-31 13:02:10 -0800 | [diff] [blame^] | 79 | if (e != BCExceptionNO) |
| 80 | return false; |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 81 | return true; |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 82 | } |
| 83 | |
weili | 29b8ad0 | 2016-06-14 18:20:04 -0700 | [diff] [blame] | 84 | BC_TYPE CBC_Code39::GetType() { |
| 85 | return BC_CODE39; |
| 86 | } |
| 87 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 88 | bool CBC_Code39::SetTextLocation(BC_TEXT_LOC location) { |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 89 | if (m_pBCWriter) |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 90 | return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) |
| 91 | ->SetTextLocation(location); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 92 | return false; |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 93 | } |
| 94 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 95 | bool CBC_Code39::SetWideNarrowRatio(int32_t ratio) { |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 96 | if (m_pBCWriter) |
tsepez | 52d7856 | 2016-06-06 12:57:44 -0700 | [diff] [blame] | 97 | return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) |
| 98 | ->SetWideNarrowRatio(ratio); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 99 | return false; |
Dan Sinclair | a98600a | 2016-03-21 15:15:56 -0400 | [diff] [blame] | 100 | } |