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_pdf417i.h" | 22 #include "xfa/fxbarcode/cbc_pdf417i.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/pdf417/BC_PDF417Reader.h" | 27 #include "xfa/fxbarcode/pdf417/BC_PDF417Reader.h" |
28 #include "xfa/fxbarcode/pdf417/BC_PDF417Writer.h" | 28 #include "xfa/fxbarcode/pdf417/BC_PDF417Writer.h" |
29 | 29 |
30 CBC_PDF417I::CBC_PDF417I() { | 30 CBC_PDF417I::CBC_PDF417I() |
31 m_pBCReader = (CBC_Reader*)new (CBC_PDF417Reader); | 31 : CBC_CodeBase(new CBC_PDF417Reader, new CBC_PDF417Writer) {} |
32 m_pBCWriter = (CBC_Writer*)new (CBC_PDF417Writer); | |
33 } | |
34 | 32 |
35 CBC_PDF417I::~CBC_PDF417I() { | 33 CBC_PDF417I::~CBC_PDF417I() {} |
36 delete (m_pBCReader); | |
37 delete (m_pBCWriter); | |
38 } | |
39 | 34 |
40 FX_BOOL CBC_PDF417I::SetErrorCorrectionLevel(int32_t level) { | 35 FX_BOOL CBC_PDF417I::SetErrorCorrectionLevel(int32_t level) { |
41 ((CBC_PDF417Writer*)m_pBCWriter)->SetErrorCorrectionLevel(level); | 36 static_cast<CBC_PDF417Writer*>(m_pBCWriter.get()) |
| 37 ->SetErrorCorrectionLevel(level); |
42 return TRUE; | 38 return TRUE; |
43 } | 39 } |
44 | 40 |
45 void CBC_PDF417I::SetTruncated(FX_BOOL truncated) { | 41 void CBC_PDF417I::SetTruncated(FX_BOOL truncated) { |
46 ((CBC_PDF417Writer*)m_pBCWriter)->SetTruncated(truncated); | 42 static_cast<CBC_PDF417Writer*>(m_pBCWriter.get())->SetTruncated(truncated); |
47 } | 43 } |
48 | 44 |
49 FX_BOOL CBC_PDF417I::Encode(const CFX_WideStringC& contents, | 45 FX_BOOL CBC_PDF417I::Encode(const CFX_WideStringC& contents, |
50 FX_BOOL isDevice, | 46 FX_BOOL isDevice, |
51 int32_t& e) { | 47 int32_t& e) { |
52 int32_t outWidth = 0; | 48 int32_t outWidth = 0; |
53 int32_t outHeight = 0; | 49 int32_t outHeight = 0; |
54 uint8_t* data = | 50 uint8_t* data = |
55 ((CBC_PDF417Writer*)m_pBCWriter) | 51 static_cast<CBC_PDF417Writer*>(m_pBCWriter.get()) |
56 ->Encode(CFX_WideString(contents), outWidth, outHeight, e); | 52 ->Encode(CFX_WideString(contents), outWidth, outHeight, e); |
57 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); | 53 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
58 ((CBC_TwoDimWriter*)m_pBCWriter)->RenderResult(data, outWidth, outHeight, e); | 54 static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) |
| 55 ->RenderResult(data, outWidth, outHeight, e); |
59 FX_Free(data); | 56 FX_Free(data); |
60 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); | 57 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
61 return TRUE; | 58 return TRUE; |
62 } | 59 } |
63 | 60 |
64 FX_BOOL CBC_PDF417I::RenderDevice(CFX_RenderDevice* device, | 61 FX_BOOL CBC_PDF417I::RenderDevice(CFX_RenderDevice* device, |
65 const CFX_Matrix* matrix, | 62 const CFX_Matrix* matrix, |
66 int32_t& e) { | 63 int32_t& e) { |
67 ((CBC_TwoDimWriter*)m_pBCWriter)->RenderDeviceResult(device, matrix); | 64 static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) |
| 65 ->RenderDeviceResult(device, matrix); |
68 return TRUE; | 66 return TRUE; |
69 } | 67 } |
70 | 68 |
71 FX_BOOL CBC_PDF417I::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { | 69 FX_BOOL CBC_PDF417I::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) { |
72 ((CBC_TwoDimWriter*)m_pBCWriter)->RenderBitmapResult(pOutBitmap, e); | 70 static_cast<CBC_TwoDimWriter*>(m_pBCWriter.get()) |
| 71 ->RenderBitmapResult(pOutBitmap, e); |
73 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); | 72 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); |
74 return TRUE; | 73 return TRUE; |
75 } | 74 } |
76 | 75 |
77 CFX_WideString CBC_PDF417I::Decode(uint8_t* buf, | 76 CFX_WideString CBC_PDF417I::Decode(uint8_t* buf, |
78 int32_t width, | 77 int32_t width, |
79 int32_t height, | 78 int32_t height, |
80 int32_t& e) { | 79 int32_t& e) { |
81 CFX_WideString str; | 80 CFX_WideString str; |
82 return str; | 81 return str; |
83 } | 82 } |
84 | 83 |
85 CFX_WideString CBC_PDF417I::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { | 84 CFX_WideString CBC_PDF417I::Decode(CFX_DIBitmap* pBitmap, int32_t& e) { |
86 CBC_BufferedImageLuminanceSource source(pBitmap); | 85 CBC_BufferedImageLuminanceSource source(pBitmap); |
87 CBC_GlobalHistogramBinarizer binarizer(&source); | 86 CBC_GlobalHistogramBinarizer binarizer(&source); |
88 CBC_BinaryBitmap bitmap(&binarizer); | 87 CBC_BinaryBitmap bitmap(&binarizer); |
89 CFX_ByteString bytestring = m_pBCReader->Decode(&bitmap, 0, e); | 88 CFX_ByteString bytestring = m_pBCReader->Decode(&bitmap, 0, e); |
90 BC_EXCEPTION_CHECK_ReturnValue(e, CFX_WideString()); | 89 BC_EXCEPTION_CHECK_ReturnValue(e, CFX_WideString()); |
91 return CFX_WideString::FromUTF8(bytestring.AsStringC()); | 90 return CFX_WideString::FromUTF8(bytestring.AsStringC()); |
92 } | 91 } |
OLD | NEW |