| 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_code128.h" | 22 #include "xfa/fxbarcode/cbc_code128.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_OnedCode128Reader.h" | 27 #include "xfa/fxbarcode/oned/BC_OnedCode128Reader.h" |
| 28 #include "xfa/fxbarcode/oned/BC_OnedCode128Writer.h" | 28 #include "xfa/fxbarcode/oned/BC_OnedCode128Writer.h" |
| 29 | 29 |
| 30 CBC_Code128::CBC_Code128(BC_TYPE type) { | 30 CBC_Code128::CBC_Code128(BC_TYPE type) |
| 31 m_pBCReader = (CBC_Reader*)new (CBC_OnedCode128Reader); | 31 : CBC_OneCode(new CBC_OnedCode128Reader, new CBC_OnedCode128Writer(type)) {} |
| 32 m_pBCWriter = (CBC_Writer*)new CBC_OnedCode128Writer(type); | |
| 33 } | |
| 34 | 32 |
| 35 CBC_Code128::~CBC_Code128() { | 33 CBC_Code128::~CBC_Code128() {} |
| 36 delete (m_pBCReader); | |
| 37 delete (m_pBCWriter); | |
| 38 } | |
| 39 | 34 |
| 40 FX_BOOL CBC_Code128::SetTextLocation(BC_TEXT_LOC location) { | 35 FX_BOOL CBC_Code128::SetTextLocation(BC_TEXT_LOC location) { |
| 41 if (m_pBCWriter) | 36 if (m_pBCWriter) |
| 42 return ((CBC_OnedCode128Writer*)m_pBCWriter)->SetTextLocation(location); | 37 return static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get()) |
| 38 ->SetTextLocation(location); |
| 43 return FALSE; | 39 return FALSE; |
| 44 } | 40 } |
| 45 | 41 |
| 46 FX_BOOL CBC_Code128::Encode(const CFX_WideStringC& contents, | 42 FX_BOOL CBC_Code128::Encode(const CFX_WideStringC& contents, |
| 47 FX_BOOL isDevice, | 43 FX_BOOL isDevice, |
| 48 int32_t& e) { | 44 int32_t& e) { |
| 49 if (contents.IsEmpty()) { | 45 if (contents.IsEmpty()) { |
| 50 e = BCExceptionNoContents; | 46 e = BCExceptionNoContents; |
| 51 return FALSE; | 47 return FALSE; |
| 52 } | 48 } |
| 53 BCFORMAT format = BCFORMAT_CODE_128; | 49 BCFORMAT format = BCFORMAT_CODE_128; |
| 54 int32_t outWidth = 0; | 50 int32_t outWidth = 0; |
| 55 int32_t outHeight = 0; | 51 int32_t outHeight = 0; |
| 56 CFX_WideString content(contents); | 52 CFX_WideString content(contents); |
| 57 if (contents.GetLength() % 2 && | 53 if (contents.GetLength() % 2 && |
| 58 ((CBC_OnedCode128Writer*)m_pBCWriter)->GetType() == BC_CODE128_C) { | 54 static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get())->GetType() == |
| 55 BC_CODE128_C) { |
| 59 content += '0'; | 56 content += '0'; |
| 60 } | 57 } |
| 61 CFX_WideString encodeContents = ((CBC_OnedCode128Writer*)m_pBCWriter) | 58 CFX_WideString encodeContents = |
| 62 ->FilterContents(content.AsStringC()); | 59 static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get()) |
| 60 ->FilterContents(content.AsStringC()); |
| 63 m_renderContents = encodeContents; | 61 m_renderContents = encodeContents; |
| 64 CFX_ByteString byteString = encodeContents.UTF8Encode(); | 62 CFX_ByteString byteString = encodeContents.UTF8Encode(); |
| 65 uint8_t* data = static_cast<CBC_OnedCode128Writer*>(m_pBCWriter) | 63 uint8_t* data = static_cast<CBC_OnedCode128Writer*>(m_pBCWriter.get()) |
| 66 ->Encode(byteString, format, outWidth, outHeight, e); | 64 ->Encode(byteString, format, outWidth, outHeight, e); |
| 67 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); | 65 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
| 68 ((CBC_OneDimWriter*)m_pBCWriter) | 66 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) |
| 69 ->RenderResult(encodeContents.AsStringC(), data, outWidth, isDevice, e); | 67 ->RenderResult(encodeContents.AsStringC(), data, outWidth, isDevice, e); |
| 70 FX_Free(data); | 68 FX_Free(data); |
| 71 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); | 69 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
| 72 return TRUE; | 70 return TRUE; |
| 73 } | 71 } |
| 74 | 72 |
| 75 FX_BOOL CBC_Code128::RenderDevice(CFX_RenderDevice* device, | 73 FX_BOOL CBC_Code128::RenderDevice(CFX_RenderDevice* device, |
| 76 const CFX_Matrix* matrix, | 74 const CFX_Matrix* matrix, |
| 77 int32_t& e) { | 75 int32_t& e) { |
| 78 ((CBC_OneDimWriter*)m_pBCWriter) | 76 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) |
| 79 ->RenderDeviceResult(device, matrix, m_renderContents.AsStringC(), e); | 77 ->RenderDeviceResult(device, matrix, m_renderContents.AsStringC(), e); |
| 80 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); | 78 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
| 81 return TRUE; | 79 return TRUE; |
| 82 } | 80 } |
| 83 | 81 |
| 84 FX_BOOL CBC_Code128::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { | 82 FX_BOOL CBC_Code128::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { |
| 85 ((CBC_OneDimWriter*)m_pBCWriter) | 83 static_cast<CBC_OneDimWriter*>(m_pBCWriter.get()) |
| 86 ->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e); | 84 ->RenderBitmapResult(pOutBitmap, m_renderContents.AsStringC(), e); |
| 87 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); | 85 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
| 88 return TRUE; | 86 return TRUE; |
| 89 } | 87 } |
| 90 | 88 |
| 91 CFX_WideString CBC_Code128::Decode(uint8_t* buf, | 89 CFX_WideString CBC_Code128::Decode(uint8_t* buf, |
| 92 int32_t width, | 90 int32_t width, |
| 93 int32_t height, | 91 int32_t height, |
| 94 int32_t& e) { | 92 int32_t& e) { |
| 95 CFX_WideString str; | 93 CFX_WideString str; |
| 96 return str; | 94 return str; |
| 97 } | 95 } |
| 98 | 96 |
| 99 CFX_WideString CBC_Code128::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { | 97 CFX_WideString CBC_Code128::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { |
| 100 CBC_BufferedImageLuminanceSource source(pBitmap); | 98 CBC_BufferedImageLuminanceSource source(pBitmap); |
| 101 CBC_GlobalHistogramBinarizer binarizer(&source); | 99 CBC_GlobalHistogramBinarizer binarizer(&source); |
| 102 CBC_BinaryBitmap bitmap(&binarizer); | 100 CBC_BinaryBitmap bitmap(&binarizer); |
| 103 CFX_ByteString str = m_pBCReader->Decode(&bitmap, 0, e); | 101 CFX_ByteString str = m_pBCReader->Decode(&bitmap, 0, e); |
| 104 BC_EXCEPTION_CHECK_ReturnValue(e, CFX_WideString()); | 102 BC_EXCEPTION_CHECK_ReturnValue(e, CFX_WideString()); |
| 105 return CFX_WideString::FromUTF8(str.AsStringC()); | 103 return CFX_WideString::FromUTF8(str.AsStringC()); |
| 106 } | 104 } |
| OLD | NEW |