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