OLD | NEW |
| (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 2012 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_TwoDimWriter.h" | |
25 #include "include/BC_PDF417Compaction.h" | |
26 #include "include/BC_PDF417.h" | |
27 #include "include/BC_PDF417BarcodeMatrix.h" | |
28 #include "include/BC_CommonBitArray.h" | |
29 #include "include/BC_CommonBitMatrix.h" | |
30 #include "include/BC_PDF417Writer.h" | |
31 CBC_PDF417Writer::CBC_PDF417Writer() | |
32 { | |
33 m_bFixedSize = FALSE; | |
34 } | |
35 CBC_PDF417Writer::~CBC_PDF417Writer() | |
36 { | |
37 m_bTruncated = TRUE; | |
38 } | |
39 FX_BOOL CBC_PDF417Writer:: SetErrorCorrectionLevel(FX_INT32 level) | |
40 { | |
41 if (level < 0 || level > 8) { | |
42 return FALSE; | |
43 } | |
44 m_iCorrectLevel = level; | |
45 return TRUE; | |
46 } | |
47 void CBC_PDF417Writer::SetTruncated(FX_BOOL truncated) | |
48 { | |
49 m_bTruncated = truncated; | |
50 } | |
51 FX_BYTE* CBC_PDF417Writer::Encode(const CFX_ByteString &contents, BCFORMAT forma
t, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 &e) | |
52 { | |
53 if ( format != BCFORMAT_PDF_417) { | |
54 return NULL; | |
55 } | |
56 CFX_WideString encodeContents = contents.UTF8Decode(); | |
57 return Encode(encodeContents, outWidth, outHeight, e ); | |
58 } | |
59 FX_BYTE* CBC_PDF417Writer::Encode(const CFX_ByteString &contents, BCFORMAT forma
t, FX_INT32 &outWidth, FX_INT32 &outHeight, FX_INT32 hints, FX_INT32 &e) | |
60 { | |
61 return NULL; | |
62 } | |
63 FX_BYTE* CBC_PDF417Writer::Encode(const CFX_WideString &contents, FX_INT32 &outW
idth, FX_INT32 &outHeight, FX_INT32 &e) | |
64 { | |
65 CBC_PDF417 encoder; | |
66 FX_INT32 col = (m_Width / m_ModuleWidth - 69) / 17; | |
67 FX_INT32 row = m_Height / (m_ModuleWidth * 20); | |
68 if (row >= 3 && row <= 90 && col >= 1 && col <= 30) { | |
69 encoder.setDimensions(col, col, row, row); | |
70 } else if (col >= 1 && col <= 30) { | |
71 encoder.setDimensions(col, col, 90, 3); | |
72 } else if (row >= 3 && row <= 90) { | |
73 encoder.setDimensions(30, 1, row, row); | |
74 } | |
75 encoder.generateBarcodeLogic(contents, m_iCorrectLevel, e); | |
76 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | |
77 FX_INT32 lineThickness = 2; | |
78 FX_INT32 aspectRatio = 4; | |
79 CBC_BarcodeMatrix* barcodeMatrix = encoder.getBarcodeMatrix(); | |
80 CFX_ByteArray originalScale; | |
81 originalScale.Copy(barcodeMatrix->getScaledMatrix(lineThickness, aspectRatio
* lineThickness)); | |
82 FX_INT32 width = outWidth; | |
83 FX_INT32 height = outHeight; | |
84 outWidth = barcodeMatrix->getWidth(); | |
85 outHeight = barcodeMatrix->getHeight(); | |
86 FX_BOOL rotated = FALSE; | |
87 if ((height > width) ^ (outWidth < outHeight)) { | |
88 rotateArray(originalScale, outHeight, outWidth); | |
89 rotated = TRUE; | |
90 FX_INT32 temp = outHeight; | |
91 outHeight = outWidth; | |
92 outWidth = temp; | |
93 } | |
94 FX_INT32 scaleX = width / outWidth; | |
95 FX_INT32 scaleY = height / outHeight; | |
96 FX_INT32 scale; | |
97 if (scaleX < scaleY) { | |
98 scale = scaleX; | |
99 } else { | |
100 scale = scaleY; | |
101 } | |
102 if (scale > 1) { | |
103 originalScale.RemoveAll(); | |
104 originalScale.Copy(barcodeMatrix->getScaledMatrix(scale * lineThickness,
scale * aspectRatio * lineThickness)); | |
105 if (rotated) { | |
106 rotateArray(originalScale, outHeight, outWidth); | |
107 FX_INT32 temp = outHeight; | |
108 outHeight = outWidth; | |
109 outWidth = temp; | |
110 } | |
111 } | |
112 FX_BYTE* result = (FX_BYTE*)FX_Alloc(FX_BYTE, outHeight * outWidth); | |
113 FXSYS_memcpy32(result, originalScale.GetData(), outHeight * outWidth); | |
114 return result; | |
115 } | |
116 void CBC_PDF417Writer::rotateArray(CFX_ByteArray& bitarray, FX_INT32 height, FX_
INT32 width) | |
117 { | |
118 CFX_ByteArray temp; | |
119 temp.Copy(bitarray); | |
120 for (FX_INT32 ii = 0; ii < height; ii++) { | |
121 FX_INT32 inverseii = height - ii - 1; | |
122 for (FX_INT32 jj = 0; jj < width; jj++) { | |
123 bitarray[jj * height + inverseii] = temp[ii * width + jj]; | |
124 } | |
125 } | |
126 } | |
OLD | NEW |