cbc_code39.cpp revision 5ae9d0c6fd838a2967cca72aa5751b51dadc2769
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 24#include "xfa/fxbarcode/oned/BC_OnedCode39Writer.h" 25 26CBC_Code39::CBC_Code39() : CBC_OneCode(new CBC_OnedCode39Writer) {} 27 28CBC_Code39::~CBC_Code39() {} 29 30bool CBC_Code39::Encode(const CFX_WideStringC& contents, 31 bool isDevice, 32 int32_t& e) { 33 if (contents.IsEmpty()) { 34 e = BCExceptionNoContents; 35 return false; 36 } 37 BCFORMAT format = BCFORMAT_CODE_39; 38 int32_t outWidth = 0; 39 int32_t outHeight = 0; 40 CFX_WideString filtercontents = 41 static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) 42 ->FilterContents(contents); 43 CFX_WideString renderContents = 44 static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) 45 ->RenderTextContents(contents); 46 m_renderContents = renderContents; 47 CFX_ByteString byteString = filtercontents.UTF8Encode(); 48 uint8_t* data = static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) 49 ->Encode(byteString, format, outWidth, outHeight, e); 50 if (e != BCExceptionNO) 51 return false; 52 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) 53 ->RenderResult(renderContents.AsStringC(), data, outWidth, isDevice, e); 54 FX_Free(data); 55 if (e != BCExceptionNO) 56 return false; 57 return true; 58} 59 60bool CBC_Code39::RenderDevice(CFX_RenderDevice* device, 61 const CFX_Matrix* matrix, 62 int32_t& e) { 63 CFX_WideString renderCon = 64 static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) 65 ->encodedContents(m_renderContents.AsStringC(), e); 66 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) 67 ->RenderDeviceResult(device, matrix, renderCon.AsStringC(), e); 68 if (e != BCExceptionNO) 69 return false; 70 return true; 71} 72 73bool CBC_Code39::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { 74 CFX_WideString renderCon = 75 static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) 76 ->encodedContents(m_renderContents.AsStringC(), e); 77 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) 78 ->RenderBitmapResult(pOutBitmap, renderCon.AsStringC(), e); 79 if (e != BCExceptionNO) 80 return false; 81 return true; 82} 83 84BC_TYPE CBC_Code39::GetType() { 85 return BC_CODE39; 86} 87 88bool CBC_Code39::SetTextLocation(BC_TEXT_LOC location) { 89 if (m_pBCWriter) 90 return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) 91 ->SetTextLocation(location); 92 return false; 93} 94 95bool CBC_Code39::SetWideNarrowRatio(int32_t ratio) { 96 if (m_pBCWriter) 97 return static_cast<CBC_OnedCode39Writer*>(m_pBCWriter.get()) 98 ->SetWideNarrowRatio(ratio); 99 return false; 100} 101