OLD | NEW |
(Empty) | |
| 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/BC_BinaryBitmap.h" |
| 25 #include "xfa/fxbarcode/BC_BufferedImageLuminanceSource.h" |
| 26 #include "xfa/fxbarcode/common/BC_GlobalHistogramBinarizer.h" |
| 27 #include "xfa/fxbarcode/oned/BC_OnedCode39Reader.h" |
| 28 #include "xfa/fxbarcode/oned/BC_OnedCode39Writer.h" |
| 29 |
| 30 CBC_Code39::CBC_Code39() { |
| 31 m_pBCReader = (CBC_Reader*)new (CBC_OnedCode39Reader); |
| 32 m_pBCWriter = (CBC_Writer*)new (CBC_OnedCode39Writer); |
| 33 } |
| 34 |
| 35 CBC_Code39::CBC_Code39(FX_BOOL usingCheckDigit) { |
| 36 m_pBCReader = (CBC_Reader*)new CBC_OnedCode39Reader(usingCheckDigit); |
| 37 m_pBCWriter = (CBC_Writer*)new CBC_OnedCode39Writer; |
| 38 } |
| 39 |
| 40 CBC_Code39::CBC_Code39(FX_BOOL usingCheckDigit, FX_BOOL extendedMode) { |
| 41 m_pBCReader = |
| 42 (CBC_Reader*)new CBC_OnedCode39Reader(usingCheckDigit, extendedMode); |
| 43 m_pBCWriter = (CBC_Writer*)new CBC_OnedCode39Writer(extendedMode); |
| 44 } |
| 45 |
| 46 CBC_Code39::~CBC_Code39() { |
| 47 delete (m_pBCReader); |
| 48 delete (m_pBCWriter); |
| 49 } |
| 50 |
| 51 FX_BOOL CBC_Code39::Encode(const CFX_WideStringC& contents, |
| 52 FX_BOOL isDevice, |
| 53 int32_t& e) { |
| 54 if (contents.IsEmpty()) { |
| 55 e = BCExceptionNoContents; |
| 56 return FALSE; |
| 57 } |
| 58 BCFORMAT format = BCFORMAT_CODE_39; |
| 59 int32_t outWidth = 0; |
| 60 int32_t outHeight = 0; |
| 61 CFX_WideString filtercontents = |
| 62 ((CBC_OnedCode39Writer*)m_pBCWriter)->FilterContents(contents); |
| 63 CFX_WideString renderContents = |
| 64 ((CBC_OnedCode39Writer*)m_pBCWriter)->RenderTextContents(contents); |
| 65 m_renderContents = renderContents; |
| 66 CFX_ByteString byteString = filtercontents.UTF8Encode(); |
| 67 uint8_t* data = static_cast<CBC_OnedCode39Writer*>(m_pBCWriter) |
| 68 ->Encode(byteString, format, outWidth, outHeight, e); |
| 69 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
| 70 ((CBC_OneDimWriter*)m_pBCWriter) |
| 71 ->RenderResult(renderContents, data, outWidth, isDevice, e); |
| 72 FX_Free(data); |
| 73 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
| 74 return TRUE; |
| 75 } |
| 76 |
| 77 FX_BOOL CBC_Code39::RenderDevice(CFX_RenderDevice* device, |
| 78 const CFX_Matrix* matirx, |
| 79 int32_t& e) { |
| 80 CFX_WideString renderCon = ((CBC_OnedCode39Writer*)m_pBCWriter) |
| 81 ->encodedContents(m_renderContents, e); |
| 82 ((CBC_OneDimWriter*)m_pBCWriter) |
| 83 ->RenderDeviceResult(device, matirx, renderCon, e); |
| 84 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
| 85 return TRUE; |
| 86 } |
| 87 |
| 88 FX_BOOL CBC_Code39::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { |
| 89 CFX_WideString renderCon = ((CBC_OnedCode39Writer*)m_pBCWriter) |
| 90 ->encodedContents(m_renderContents, e); |
| 91 ((CBC_OneDimWriter*)m_pBCWriter) |
| 92 ->RenderBitmapResult(pOutBitmap, renderCon, e); |
| 93 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
| 94 return TRUE; |
| 95 } |
| 96 |
| 97 CFX_WideString CBC_Code39::Decode(uint8_t* buf, |
| 98 int32_t width, |
| 99 int32_t hight, |
| 100 int32_t& e) { |
| 101 CFX_WideString str; |
| 102 return str; |
| 103 } |
| 104 |
| 105 CFX_WideString CBC_Code39::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { |
| 106 CBC_BufferedImageLuminanceSource source(pBitmap); |
| 107 CBC_GlobalHistogramBinarizer binarizer(&source); |
| 108 CBC_BinaryBitmap bitmap(&binarizer); |
| 109 CFX_ByteString str = m_pBCReader->Decode(&bitmap, 0, e); |
| 110 BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L"")); |
| 111 return CFX_WideString::FromUTF8(str, str.GetLength()); |
| 112 } |
| 113 |
| 114 FX_BOOL CBC_Code39::SetTextLocation(BC_TEXT_LOC location) { |
| 115 if (m_pBCWriter) |
| 116 return ((CBC_OnedCode39Writer*)m_pBCWriter)->SetTextLocation(location); |
| 117 return FALSE; |
| 118 } |
| 119 |
| 120 FX_BOOL CBC_Code39::SetWideNarrowRatio(int32_t ratio) { |
| 121 if (m_pBCWriter) |
| 122 return ((CBC_OnedCode39Writer*)m_pBCWriter)->SetWideNarrowRatio(ratio); |
| 123 return FALSE; |
| 124 } |
OLD | NEW |