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

Side by Side Diff: xfa/src/fxbarcode/src/BC_DataMatrixWriter.cpp

Issue 842043002: Organize barcode codes into modules. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: rebase Created 5 years, 11 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 2014 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 // Original code is licensed as follows:
7 /*
8 * Copyright 2008 ZXing authors
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 */
22
23 #include "barcode.h"
24 #include "include/BC_Writer.h"
25 #include "include/BC_TwoDimWriter.h"
26 #include "include/BC_Encoder.h"
27 #include "include/BC_DefaultPlacement.h"
28 #include "include/BC_BinaryBitmap.h"
29 #include "include/BC_CommonBitMatrix.h"
30 #include "include/BC_SymbolShapeHint.h"
31 #include "include/BC_SymbolInfo.h"
32 #include "include/BC_DataMatrixSymbolInfo144.h"
33 #include "include/BC_ErrorCorrection.h"
34 #include "include/BC_Dimension.h"
35 #include "include/BC_EncoderContext.h"
36 #include "include/BC_C40Encoder.h"
37 #include "include/BC_TextEncoder.h"
38 #include "include/BC_X12Encoder.h"
39 #include "include/BC_EdifactEncoder.h"
40 #include "include/BC_Base256Encoder.h"
41 #include "include/BC_ASCIIEncoder.h"
42 #include "include/BC_HighLevelEncoder.h"
43 #include "include/BC_CommonByteMatrix.h"
44 #include "include/BC_DataMatrixWriter.h"
45 #include "include/BC_UtilCodingConvert.h"
46 CBC_DataMatrixWriter::CBC_DataMatrixWriter()
47 {
48 }
49 CBC_DataMatrixWriter::~CBC_DataMatrixWriter()
50 {
51 }
52 FX_BOOL CBC_DataMatrixWriter::SetErrorCorrectionLevel (FX_INT32 level)
53 {
54 m_iCorrectLevel = level;
55 return TRUE;
56 }
57 FX_BYTE* CBC_DataMatrixWriter::Encode(const CFX_WideString &contents, FX_INT32 & outWidth, FX_INT32 &outHeight, FX_INT32 &e)
58 {
59 if (outWidth < 0 || outHeight < 0) {
60 e = BCExceptionHeightAndWidthMustBeAtLeast1;
61 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
62 }
63 CBC_SymbolShapeHint::SymbolShapeHint shape = CBC_SymbolShapeHint::FORCE_SQUA RE;
64 CBC_Dimension* minSize = NULL;
65 CBC_Dimension* maxSize = NULL;
66 CFX_WideString ecLevel;
67 CFX_WideString encoded = CBC_HighLevelEncoder::encodeHighLevel(contents, ecL evel, shape, minSize, maxSize, e);
68 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
69 CBC_SymbolInfo* symbolInfo = CBC_SymbolInfo::lookup(encoded.GetLength(), sha pe, minSize, maxSize, TRUE, e);
70 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
71 CFX_WideString codewords = CBC_ErrorCorrection::encodeECC200(encoded, symbol Info, e);
72 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
73 CBC_DefaultPlacement* placement = FX_NEW CBC_DefaultPlacement(codewords, sym bolInfo->getSymbolDataWidth(e), symbolInfo->getSymbolDataHeight(e));
74 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
75 placement->place();
76 CBC_CommonByteMatrix* bytematrix = encodeLowLevel(placement, symbolInfo, e);
77 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
78 outWidth = bytematrix->GetWidth();
79 outHeight = bytematrix->GetHeight();
80 FX_BYTE* result = FX_Alloc(FX_BYTE, outWidth * outHeight);
81 FXSYS_memcpy32(result, bytematrix->GetArray(), outWidth * outHeight);
82 delete bytematrix;
83 delete placement;
84 return result;
85 }
86 FX_BYTE *CBC_DataMatrixWriter::Encode(const CFX_ByteString &contents, BCFORMAT f ormat, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 &e)
87 {
88 return NULL;
89 }
90 FX_BYTE *CBC_DataMatrixWriter::Encode(const CFX_ByteString &contents, BCFORMAT f ormat, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 hints, FX_INT32 &e)
91 {
92 return NULL;
93 }
94 CBC_CommonByteMatrix* CBC_DataMatrixWriter::encodeLowLevel(CBC_DefaultPlacement* placement, CBC_SymbolInfo* symbolInfo, FX_INT32 &e)
95 {
96 FX_INT32 symbolWidth = symbolInfo->getSymbolDataWidth(e);
97 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
98 FX_INT32 symbolHeight = symbolInfo->getSymbolDataHeight(e);
99 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
100 CBC_CommonByteMatrix* matrix = FX_NEW CBC_CommonByteMatrix(symbolInfo->getSy mbolWidth(e), symbolInfo->getSymbolHeight(e));
101 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
102 matrix->Init();
103 FX_INT32 matrixY = 0;
104 for (FX_INT32 y = 0; y < symbolHeight; y++) {
105 FX_INT32 matrixX;
106 if ((y % symbolInfo->m_matrixHeight) == 0) {
107 matrixX = 0;
108 for (FX_INT32 x = 0; x < symbolInfo->getSymbolWidth(e); x++) {
109 matrix->Set(matrixX, matrixY, (x % 2) == 0);
110 matrixX++;
111 }
112 matrixY++;
113 }
114 matrixX = 0;
115 for (FX_INT32 x = 0; x < symbolWidth; x++) {
116 if ((x % symbolInfo->m_matrixWidth) == 0) {
117 matrix->Set(matrixX, matrixY, TRUE);
118 matrixX++;
119 }
120 matrix->Set(matrixX, matrixY, placement->getBit(x, y));
121 matrixX++;
122 if ((x % symbolInfo->m_matrixWidth) == symbolInfo->m_matrixWidth - 1 ) {
123 matrix->Set(matrixX, matrixY, (y % 2) == 0);
124 matrixX++;
125 }
126 }
127 matrixY++;
128 if ((y % symbolInfo->m_matrixHeight) == symbolInfo->m_matrixHeight - 1) {
129 matrixX = 0;
130 for (FX_INT32 x = 0; x < symbolInfo->getSymbolWidth(e); x++) {
131 matrix->Set(matrixX, matrixY, TRUE);
132 matrixX++;
133 }
134 matrixY++;
135 }
136 }
137 return matrix;
138 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/src/BC_DataMatrixVersion.cpp ('k') | xfa/src/fxbarcode/src/BC_DefaultPlacement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698