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