1// Copyright 2014 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// Original code is licensed as follows: 7/* 8 * Copyright 2008 ZXing authors 9 * 10 * Licensed under the Apache License, Version 2.0 (the "License"); 11 * you may not use this file except in compliance with the License. 12 * You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software 17 * distributed under the License is distributed on an "AS IS" BASIS, 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 * See the License for the specific language governing permissions and 20 * limitations under the License. 21 */ 22 23#include "xfa/src/fxbarcode/barcode.h" 24#include "xfa/src/fxbarcode/BC_Reader.h" 25#include "BC_OneDReader.h" 26#include "BC_OneDimReader.h" 27#include "BC_OnedEAN13Reader.h" 28#include "BC_OnedUPCAReader.h" 29CBC_OnedUPCAReader::CBC_OnedUPCAReader() { 30 m_ean13Reader = NULL; 31} 32void CBC_OnedUPCAReader::Init() { 33 m_ean13Reader = new CBC_OnedEAN13Reader; 34} 35CBC_OnedUPCAReader::~CBC_OnedUPCAReader() { 36 if (m_ean13Reader != NULL) { 37 delete m_ean13Reader; 38 } 39 m_ean13Reader = NULL; 40} 41CFX_ByteString CBC_OnedUPCAReader::DecodeRow(int32_t rowNumber, 42 CBC_CommonBitArray* row, 43 int32_t hints, 44 int32_t& e) { 45 CFX_ByteString bytestring = 46 m_ean13Reader->DecodeRow(rowNumber, row, hints, e); 47 BC_EXCEPTION_CHECK_ReturnValue(e, ""); 48 CFX_ByteString temp = MaybeReturnResult(bytestring, e); 49 BC_EXCEPTION_CHECK_ReturnValue(e, ""); 50 return temp; 51} 52CFX_ByteString CBC_OnedUPCAReader::DecodeRow(int32_t rowNumber, 53 CBC_CommonBitArray* row, 54 CFX_Int32Array* startGuardRange, 55 int32_t hints, 56 int32_t& e) { 57 CFX_ByteString bytestring = 58 m_ean13Reader->DecodeRow(rowNumber, row, startGuardRange, hints, e); 59 BC_EXCEPTION_CHECK_ReturnValue(e, ""); 60 CFX_ByteString temp = MaybeReturnResult(bytestring, e); 61 BC_EXCEPTION_CHECK_ReturnValue(e, ""); 62 return temp; 63} 64CFX_ByteString CBC_OnedUPCAReader::Decode(CBC_BinaryBitmap* image, int32_t& e) { 65 CFX_ByteString bytestring = m_ean13Reader->Decode(image, e); 66 BC_EXCEPTION_CHECK_ReturnValue(e, ""); 67 CFX_ByteString temp = MaybeReturnResult(bytestring, e); 68 BC_EXCEPTION_CHECK_ReturnValue(e, ""); 69 return temp; 70} 71CFX_ByteString CBC_OnedUPCAReader::Decode(CBC_BinaryBitmap* image, 72 int32_t hints, 73 int32_t& e) { 74 CFX_ByteString bytestring = m_ean13Reader->Decode(image, hints, e); 75 BC_EXCEPTION_CHECK_ReturnValue(e, ""); 76 CFX_ByteString temp = MaybeReturnResult(bytestring, e); 77 BC_EXCEPTION_CHECK_ReturnValue(e, ""); 78 return temp; 79} 80int32_t CBC_OnedUPCAReader::DecodeMiddle(CBC_CommonBitArray* row, 81 CFX_Int32Array* startRange, 82 CFX_ByteString& resultString, 83 int32_t& e) { 84 int32_t temp = m_ean13Reader->DecodeMiddle(row, startRange, resultString, e); 85 BC_EXCEPTION_CHECK_ReturnValue(e, 0); 86 return temp; 87} 88CFX_ByteString CBC_OnedUPCAReader::MaybeReturnResult(CFX_ByteString& result, 89 int32_t& e) { 90 if (result[0] == '0') { 91 result.Delete(0); 92 return result; 93 } else { 94 e = BCExceptionFormatException; 95 return ""; 96 } 97 return ""; 98} 99