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

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

Issue 1803723002: Move xfa/src up to xfa/. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master 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 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 "xfa/src/fxbarcode/BC_BinaryBitmap.h"
24 #include "xfa/src/fxbarcode/BC_Dimension.h"
25 #include "xfa/src/fxbarcode/BC_TwoDimWriter.h"
26 #include "xfa/src/fxbarcode/BC_UtilCodingConvert.h"
27 #include "xfa/src/fxbarcode/BC_Writer.h"
28 #include "xfa/src/fxbarcode/common/BC_CommonBitMatrix.h"
29 #include "xfa/src/fxbarcode/common/BC_CommonByteMatrix.h"
30 #include "xfa/src/fxbarcode/datamatrix/BC_ASCIIEncoder.h"
31 #include "xfa/src/fxbarcode/datamatrix/BC_Base256Encoder.h"
32 #include "xfa/src/fxbarcode/datamatrix/BC_C40Encoder.h"
33 #include "xfa/src/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h"
34 #include "xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.h"
35 #include "xfa/src/fxbarcode/datamatrix/BC_DefaultPlacement.h"
36 #include "xfa/src/fxbarcode/datamatrix/BC_EdifactEncoder.h"
37 #include "xfa/src/fxbarcode/datamatrix/BC_Encoder.h"
38 #include "xfa/src/fxbarcode/datamatrix/BC_EncoderContext.h"
39 #include "xfa/src/fxbarcode/datamatrix/BC_ErrorCorrection.h"
40 #include "xfa/src/fxbarcode/datamatrix/BC_HighLevelEncoder.h"
41 #include "xfa/src/fxbarcode/datamatrix/BC_SymbolInfo.h"
42 #include "xfa/src/fxbarcode/datamatrix/BC_SymbolShapeHint.h"
43 #include "xfa/src/fxbarcode/datamatrix/BC_TextEncoder.h"
44 #include "xfa/src/fxbarcode/datamatrix/BC_X12Encoder.h"
45
46 CBC_DataMatrixWriter::CBC_DataMatrixWriter() {}
47 CBC_DataMatrixWriter::~CBC_DataMatrixWriter() {}
48 FX_BOOL CBC_DataMatrixWriter::SetErrorCorrectionLevel(int32_t level) {
49 m_iCorrectLevel = level;
50 return TRUE;
51 }
52 uint8_t* CBC_DataMatrixWriter::Encode(const CFX_WideString& contents,
53 int32_t& outWidth,
54 int32_t& outHeight,
55 int32_t& e) {
56 if (outWidth < 0 || outHeight < 0) {
57 e = BCExceptionHeightAndWidthMustBeAtLeast1;
58 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
59 }
60 CBC_SymbolShapeHint::SymbolShapeHint shape =
61 CBC_SymbolShapeHint::FORCE_SQUARE;
62 CBC_Dimension* minSize = NULL;
63 CBC_Dimension* maxSize = NULL;
64 CFX_WideString ecLevel;
65 CFX_WideString encoded = CBC_HighLevelEncoder::encodeHighLevel(
66 contents, ecLevel, shape, minSize, maxSize, e);
67 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
68 CBC_SymbolInfo* symbolInfo = CBC_SymbolInfo::lookup(
69 encoded.GetLength(), shape, minSize, maxSize, TRUE, e);
70 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
71 CFX_WideString codewords =
72 CBC_ErrorCorrection::encodeECC200(encoded, symbolInfo, e);
73 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
74 CBC_DefaultPlacement* placement =
75 new CBC_DefaultPlacement(codewords, symbolInfo->getSymbolDataWidth(e),
76 symbolInfo->getSymbolDataHeight(e));
77 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
78 placement->place();
79 CBC_CommonByteMatrix* bytematrix = encodeLowLevel(placement, symbolInfo, e);
80 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
81 outWidth = bytematrix->GetWidth();
82 outHeight = bytematrix->GetHeight();
83 uint8_t* result = FX_Alloc2D(uint8_t, outWidth, outHeight);
84 FXSYS_memcpy(result, bytematrix->GetArray(), outWidth * outHeight);
85 delete bytematrix;
86 delete placement;
87 return result;
88 }
89 CBC_CommonByteMatrix* CBC_DataMatrixWriter::encodeLowLevel(
90 CBC_DefaultPlacement* placement,
91 CBC_SymbolInfo* symbolInfo,
92 int32_t& e) {
93 int32_t symbolWidth = symbolInfo->getSymbolDataWidth(e);
94 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
95 int32_t symbolHeight = symbolInfo->getSymbolDataHeight(e);
96 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
97 CBC_CommonByteMatrix* matrix = new CBC_CommonByteMatrix(
98 symbolInfo->getSymbolWidth(e), symbolInfo->getSymbolHeight(e));
99 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
100 matrix->Init();
101 int32_t matrixY = 0;
102 for (int32_t y = 0; y < symbolHeight; y++) {
103 int32_t matrixX;
104 if ((y % symbolInfo->m_matrixHeight) == 0) {
105 matrixX = 0;
106 for (int32_t x = 0; x < symbolInfo->getSymbolWidth(e); x++) {
107 matrix->Set(matrixX, matrixY, (x % 2) == 0);
108 matrixX++;
109 }
110 matrixY++;
111 }
112 matrixX = 0;
113 for (int32_t x = 0; x < symbolWidth; x++) {
114 if ((x % symbolInfo->m_matrixWidth) == 0) {
115 matrix->Set(matrixX, matrixY, TRUE);
116 matrixX++;
117 }
118 matrix->Set(matrixX, matrixY, placement->getBit(x, y));
119 matrixX++;
120 if ((x % symbolInfo->m_matrixWidth) == symbolInfo->m_matrixWidth - 1) {
121 matrix->Set(matrixX, matrixY, (y % 2) == 0);
122 matrixX++;
123 }
124 }
125 matrixY++;
126 if ((y % symbolInfo->m_matrixHeight) == symbolInfo->m_matrixHeight - 1) {
127 matrixX = 0;
128 for (int32_t x = 0; x < symbolInfo->getSymbolWidth(e); x++) {
129 matrix->Set(matrixX, matrixY, TRUE);
130 matrixX++;
131 }
132 matrixY++;
133 }
134 }
135 return matrix;
136 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/datamatrix/BC_DataMatrixWriter.h ('k') | xfa/src/fxbarcode/datamatrix/BC_DefaultPlacement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698