| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 /* | 6 /* |
| 7 * Copyright 2011 ZXing authors | 7 * Copyright 2011 ZXing authors |
| 8 * | 8 * |
| 9 * Licensed under the Apache License, Version 2.0 (the "License"); | 9 * Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 * you may not use this file except in compliance with 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 | 11 * You may obtain a copy of the License at |
| 12 * | 12 * |
| 13 * http://www.apache.org/licenses/LICENSE-2.0 | 13 * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 * | 14 * |
| 15 * Unless required by applicable law or agreed to in writing, software | 15 * Unless required by applicable law or agreed to in writing, software |
| 16 * distributed under the License is distributed on an "AS IS" BASIS, | 16 * distributed under the License is distributed on an "AS IS" BASIS, |
| 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 * See the License for the specific language governing permissions and | 18 * See the License for the specific language governing permissions and |
| 19 * limitations under the License. | 19 * limitations under the License. |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 #include "xfa/fxbarcode/cbc_ean8.h" | 22 #include "xfa/fxbarcode/cbc_ean8.h" |
| 23 | 23 |
| 24 #include "xfa/fxbarcode/BC_BinaryBitmap.h" | 24 #include "xfa/fxbarcode/BC_BinaryBitmap.h" |
| 25 #include "xfa/fxbarcode/BC_BufferedImageLuminanceSource.h" | 25 #include "xfa/fxbarcode/BC_BufferedImageLuminanceSource.h" |
| 26 #include "xfa/fxbarcode/common/BC_GlobalHistogramBinarizer.h" | 26 #include "xfa/fxbarcode/common/BC_GlobalHistogramBinarizer.h" |
| 27 #include "xfa/fxbarcode/oned/BC_OnedEAN8Reader.h" | 27 #include "xfa/fxbarcode/oned/BC_OnedEAN8Reader.h" |
| 28 #include "xfa/fxbarcode/oned/BC_OnedEAN8Writer.h" | 28 #include "xfa/fxbarcode/oned/BC_OnedEAN8Writer.h" |
| 29 | 29 |
| 30 CBC_EAN8::CBC_EAN8() { | 30 CBC_EAN8::CBC_EAN8() |
| 31 m_pBCReader = (CBC_Reader*)new (CBC_OnedEAN8Reader); | 31 : CBC_OneCode(new CBC_OnedEAN8Reader, new CBC_OnedEAN8Writer) {} |
| 32 m_pBCWriter = (CBC_Writer*)new (CBC_OnedEAN8Writer); | |
| 33 } | |
| 34 | 32 |
| 35 CBC_EAN8::~CBC_EAN8() { | 33 CBC_EAN8::~CBC_EAN8() {} |
| 36 delete (m_pBCReader); | |
| 37 delete (m_pBCWriter); | |
| 38 } | |
| 39 | 34 |
| 40 CFX_WideString CBC_EAN8::Preprocess(const CFX_WideStringC& contents) { | 35 CFX_WideString CBC_EAN8::Preprocess(const CFX_WideStringC& contents) { |
| 41 CFX_WideString encodeContents = | 36 CFX_WideString encodeContents = |
| 42 ((CBC_OnedEAN8Writer*)m_pBCWriter)->FilterContents(contents); | 37 static_cast<CBC_OnedEAN8Writer*>(m_pBCWriter.get()) |
| 38 ->FilterContents(contents); |
| 43 int32_t length = encodeContents.GetLength(); | 39 int32_t length = encodeContents.GetLength(); |
| 44 if (length <= 7) { | 40 if (length <= 7) { |
| 45 for (int32_t i = 0; i < 7 - length; i++) | 41 for (int32_t i = 0; i < 7 - length; i++) |
| 46 encodeContents = FX_WCHAR('0') + encodeContents; | 42 encodeContents = FX_WCHAR('0') + encodeContents; |
| 47 | 43 |
| 48 CFX_ByteString byteString = encodeContents.UTF8Encode(); | 44 CFX_ByteString byteString = encodeContents.UTF8Encode(); |
| 49 int32_t checksum = | 45 int32_t checksum = static_cast<CBC_OnedEAN8Writer*>(m_pBCWriter.get()) |
| 50 ((CBC_OnedEAN8Writer*)m_pBCWriter)->CalcChecksum(byteString); | 46 ->CalcChecksum(byteString); |
| 51 encodeContents += FX_WCHAR(checksum - 0 + '0'); | 47 encodeContents += FX_WCHAR(checksum - 0 + '0'); |
| 52 } | 48 } |
| 53 if (length > 8) | 49 if (length > 8) |
| 54 encodeContents = encodeContents.Mid(0, 8); | 50 encodeContents = encodeContents.Mid(0, 8); |
| 55 | 51 |
| 56 return encodeContents; | 52 return encodeContents; |
| 57 } | 53 } |
| 58 | 54 |
| 59 FX_BOOL CBC_EAN8::Encode(const CFX_WideStringC& contents, | 55 FX_BOOL CBC_EAN8::Encode(const CFX_WideStringC& contents, |
| 60 FX_BOOL isDevice, | 56 FX_BOOL isDevice, |
| 61 int32_t& e) { | 57 int32_t& e) { |
| 62 if (contents.IsEmpty()) { | 58 if (contents.IsEmpty()) { |
| 63 e = BCExceptionNoContents; | 59 e = BCExceptionNoContents; |
| 64 return FALSE; | 60 return FALSE; |
| 65 } | 61 } |
| 66 BCFORMAT format = BCFORMAT_EAN_8; | 62 BCFORMAT format = BCFORMAT_EAN_8; |
| 67 int32_t outWidth = 0; | 63 int32_t outWidth = 0; |
| 68 int32_t outHeight = 0; | 64 int32_t outHeight = 0; |
| 69 CFX_WideString encodeContents = Preprocess(contents); | 65 CFX_WideString encodeContents = Preprocess(contents); |
| 70 CFX_ByteString byteString = encodeContents.UTF8Encode(); | 66 CFX_ByteString byteString = encodeContents.UTF8Encode(); |
| 71 m_renderContents = encodeContents; | 67 m_renderContents = encodeContents; |
| 72 uint8_t* data = static_cast<CBC_OnedEAN8Writer*>(m_pBCWriter) | 68 uint8_t* data = static_cast<CBC_OnedEAN8Writer*>(m_pBCWriter.get()) |
| 73 ->Encode(byteString, format, outWidth, outHeight, e); | 69 ->Encode(byteString, format, outWidth, outHeight, e); |
| 74 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); | 70 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
| 75 ((CBC_OneDimWriter*)m_pBCWriter) | 71 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) |
| 76 ->RenderResult(encodeContents.AsStringC(), data, outWidth, isDevice, e); | 72 ->RenderResult(encodeContents.AsStringC(), data, outWidth, isDevice, e); |
| 77 FX_Free(data); | 73 FX_Free(data); |
| 78 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); | 74 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
| 79 return TRUE; | 75 return TRUE; |
| 80 } | 76 } |
| 81 | 77 |
| 82 FX_BOOL CBC_EAN8::RenderDevice(CFX_RenderDevice* device, | 78 FX_BOOL CBC_EAN8::RenderDevice(CFX_RenderDevice* device, |
| 83 const CFX_Matrix* matrix, | 79 const CFX_Matrix* matrix, |
| 84 int32_t& e) { | 80 int32_t& e) { |
| 85 ((CBC_OneDimWriter*)m_pBCWriter) | 81 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) |
| 86 ->RenderDeviceResult(device, matrix, m_renderContents.AsStringC(), e); | 82 ->RenderDeviceResult(device, matrix, m_renderContents.AsStringC(), e); |
| 87 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); | 83 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
| 88 return TRUE; | 84 return TRUE; |
| 89 } | 85 } |
| 90 | 86 |
| 91 FX_BOOL CBC_EAN8::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { | 87 FX_BOOL CBC_EAN8::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { |
| 92 ((CBC_OneDimWriter*)m_pBCWriter) | 88 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) |
| 93 ->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e); | 89 ->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e); |
| 94 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); | 90 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
| 95 return TRUE; | 91 return TRUE; |
| 96 } | 92 } |
| 97 | 93 |
| 98 CFX_WideString CBC_EAN8::Decode(uint8_t* buf, | 94 CFX_WideString CBC_EAN8::Decode(uint8_t* buf, |
| 99 int32_t width, | 95 int32_t width, |
| 100 int32_t height, | 96 int32_t height, |
| 101 int32_t& e) { | 97 int32_t& e) { |
| 102 CFX_WideString str; | 98 CFX_WideString str; |
| 103 return str; | 99 return str; |
| 104 } | 100 } |
| 105 | 101 |
| 106 CFX_WideString CBC_EAN8::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { | 102 CFX_WideString CBC_EAN8::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { |
| 107 CBC_BufferedImageLuminanceSource source(pBitmap); | 103 CBC_BufferedImageLuminanceSource source(pBitmap); |
| 108 CBC_GlobalHistogramBinarizer binarizer(&source); | 104 CBC_GlobalHistogramBinarizer binarizer(&source); |
| 109 CBC_BinaryBitmap bitmap(&binarizer); | 105 CBC_BinaryBitmap bitmap(&binarizer); |
| 110 CFX_ByteString str = m_pBCReader->Decode(&bitmap, 0, e); | 106 CFX_ByteString str = m_pBCReader->Decode(&bitmap, 0, e); |
| 111 BC_EXCEPTION_CHECK_ReturnValue(e, CFX_WideString()); | 107 BC_EXCEPTION_CHECK_ReturnValue(e, CFX_WideString()); |
| 112 return CFX_WideString::FromUTF8(str.AsStringC()); | 108 return CFX_WideString::FromUTF8(str.AsStringC()); |
| 113 } | 109 } |
| OLD | NEW |