Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Side by Side Diff: xfa/fxbarcode/cbc_ean8.cpp

Issue 1816133002: Move xfa/include/fxbarcode/BC_Barcode.h to xfa/fxbarcode. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_ean8.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_OnedEAN8Reader.h"
28 #include "xfa/fxbarcode/oned/BC_OnedEAN8Writer.h"
29
30 CBC_EAN8::CBC_EAN8() {
31 m_pBCReader = (CBC_Reader*)new (CBC_OnedEAN8Reader);
32 m_pBCWriter = (CBC_Writer*)new (CBC_OnedEAN8Writer);
33 }
34
35 CBC_EAN8::~CBC_EAN8() {
36 delete (m_pBCReader);
37 delete (m_pBCWriter);
38 }
39
40 CFX_WideString CBC_EAN8::Preprocess(const CFX_WideStringC& contents) {
41 CFX_WideString encodeContents =
42 ((CBC_OnedEAN8Writer*)m_pBCWriter)->FilterContents(contents);
43 int32_t length = encodeContents.GetLength();
44 if (length <= 7) {
45 for (int32_t i = 0; i < 7 - length; i++)
46 encodeContents = FX_WCHAR('0') + encodeContents;
47
48 CFX_ByteString byteString = encodeContents.UTF8Encode();
49 int32_t checksum =
50 ((CBC_OnedEAN8Writer*)m_pBCWriter)->CalcChecksum(byteString);
51 encodeContents += FX_WCHAR(checksum - 0 + '0');
52 }
53 if (length > 8)
54 encodeContents = encodeContents.Mid(0, 8);
55
56 return encodeContents;
57 }
58
59 FX_BOOL CBC_EAN8::Encode(const CFX_WideStringC& contents,
60 FX_BOOL isDevice,
61 int32_t& e) {
62 if (contents.IsEmpty()) {
63 e = BCExceptionNoContents;
64 return FALSE;
65 }
66 BCFORMAT format = BCFORMAT_EAN_8;
67 int32_t outWidth = 0;
68 int32_t outHeight = 0;
69 CFX_WideString encodeContents = Preprocess(contents);
70 CFX_ByteString byteString = encodeContents.UTF8Encode();
71 m_renderContents = encodeContents;
72 uint8_t* data = static_cast<CBC_OnedEAN8Writer*>(m_pBCWriter)
73 ->Encode(byteString, format, outWidth, outHeight, e);
74 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
75 ((CBC_OneDimWriter*)m_pBCWriter)
76 ->RenderResult(encodeContents, data, outWidth, isDevice, e);
77 FX_Free(data);
78 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
79 return TRUE;
80 }
81
82 FX_BOOL CBC_EAN8::RenderDevice(CFX_RenderDevice* device,
83 const CFX_Matrix* matirx,
84 int32_t& e) {
85 ((CBC_OneDimWriter*)m_pBCWriter)
86 ->RenderDeviceResult(device, matirx, m_renderContents, e);
87 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
88 return TRUE;
89 }
90
91 FX_BOOL CBC_EAN8::RenderBitmap(CFX_DIBitmap*& pOutBitmap, int32_t& e) {
92 ((CBC_OneDimWriter*)m_pBCWriter)
93 ->RenderBitmapResult(pOutBitmap, m_renderContents, e);
94 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
95 return TRUE;
96 }
97
98 CFX_WideString CBC_EAN8::Decode(uint8_t* buf,
99 int32_t width,
100 int32_t hight,
101 int32_t& e) {
102 CFX_WideString str;
103 return str;
104 }
105
106 CFX_WideString CBC_EAN8::Decode(CFX_DIBitmap* pBitmap, int32_t& e) {
107 CBC_BufferedImageLuminanceSource source(pBitmap);
108 CBC_GlobalHistogramBinarizer binarizer(&source);
109 CBC_BinaryBitmap bitmap(&binarizer);
110 CFX_ByteString str = m_pBCReader->Decode(&bitmap, 0, e);
111 BC_EXCEPTION_CHECK_ReturnValue(e, FX_WSTRC(L""));
112 return CFX_WideString::FromUTF8(str, str.GetLength());
113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698