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

Side by Side Diff: xfa/src/fxbarcode/src/BC_DefaultPlacement.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
« no previous file with comments | « xfa/src/fxbarcode/src/BC_DataMatrixWriter.cpp ('k') | xfa/src/fxbarcode/src/BC_Dimension.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2006 Jeremias Maerki.
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_Encoder.h"
25 #include "include/BC_DefaultPlacement.h"
26 CBC_DefaultPlacement::CBC_DefaultPlacement(CFX_WideString codewords, FX_INT32 nu mcols, FX_INT32 numrows)
27 {
28 m_codewords = codewords;
29 m_numcols = numcols;
30 m_numrows = numrows;
31 m_bits.SetSize(numcols * numrows);
32 for (FX_INT32 i = 0; i < numcols * numrows; i++) {
33 m_bits[i] = (FX_BYTE) 2;
34 }
35 }
36 CBC_DefaultPlacement::~CBC_DefaultPlacement()
37 {
38 m_bits.RemoveAll();
39 }
40 FX_INT32 CBC_DefaultPlacement::getNumrows()
41 {
42 return m_numrows;
43 }
44 FX_INT32 CBC_DefaultPlacement::getNumcols()
45 {
46 return m_numcols;
47 }
48 CFX_ByteArray& CBC_DefaultPlacement::getBits()
49 {
50 return m_bits;
51 }
52 FX_BOOL CBC_DefaultPlacement::getBit(FX_INT32 col, FX_INT32 row)
53 {
54 return m_bits[row * m_numcols + col] == 1;
55 }
56 void CBC_DefaultPlacement::setBit(FX_INT32 col, FX_INT32 row, FX_BOOL bit)
57 {
58 m_bits[row * m_numcols + col] = bit ? (FX_BYTE) 1 : (FX_BYTE) 0;
59 }
60 FX_BOOL CBC_DefaultPlacement::hasBit(FX_INT32 col, FX_INT32 row)
61 {
62 return m_bits[row * m_numcols + col] != 2;
63 }
64 void CBC_DefaultPlacement::place()
65 {
66 FX_INT32 pos = 0;
67 FX_INT32 row = 4;
68 FX_INT32 col = 0;
69 do {
70 if ((row == m_numrows) && (col == 0)) {
71 corner1(pos++);
72 }
73 if ((row == m_numrows - 2) && (col == 0) && ((m_numcols % 4) != 0)) {
74 corner2(pos++);
75 }
76 if ((row == m_numrows - 2) && (col == 0) && (m_numcols % 8 == 4)) {
77 corner3(pos++);
78 }
79 if ((row == m_numrows + 4) && (col == 2) && ((m_numcols % 8) == 0)) {
80 corner4(pos++);
81 }
82 do {
83 if ((row < m_numrows) && (col >= 0) && !hasBit(col, row)) {
84 utah(row, col, pos++);
85 }
86 row -= 2;
87 col += 2;
88 } while (row >= 0 && (col < m_numcols));
89 row++;
90 col += 3;
91 do {
92 if ((row >= 0) && (col < m_numcols) && !hasBit(col, row)) {
93 utah(row, col, pos++);
94 }
95 row += 2;
96 col -= 2;
97 } while ((row < m_numrows) && (col >= 0));
98 row += 3;
99 col++;
100 } while ((row < m_numrows) || (col < m_numcols));
101 if (!hasBit(m_numcols - 1, m_numrows - 1)) {
102 setBit(m_numcols - 1, m_numrows - 1, TRUE);
103 setBit(m_numcols - 2, m_numrows - 2, TRUE);
104 }
105 }
106 void CBC_DefaultPlacement::module(FX_INT32 row, FX_INT32 col, FX_INT32 pos, FX_I NT32 bit)
107 {
108 if (row < 0) {
109 row += m_numrows;
110 col += 4 - ((m_numrows + 4) % 8);
111 }
112 if (col < 0) {
113 col += m_numcols;
114 row += 4 - ((m_numcols + 4) % 8);
115 }
116 FX_INT32 v = m_codewords.GetAt(pos);
117 v &= 1 << (8 - bit);
118 setBit(col, row, v != 0);
119 }
120 void CBC_DefaultPlacement::utah(FX_INT32 row, FX_INT32 col, FX_INT32 pos)
121 {
122 module(row - 2, col - 2, pos, 1);
123 module(row - 2, col - 1, pos, 2);
124 module(row - 1, col - 2, pos, 3);
125 module(row - 1, col - 1, pos, 4);
126 module(row - 1, col, pos, 5);
127 module(row, col - 2, pos, 6);
128 module(row, col - 1, pos, 7);
129 module(row, col, pos, 8);
130 }
131 void CBC_DefaultPlacement::corner1(FX_INT32 pos)
132 {
133 module(m_numrows - 1, 0, pos, 1);
134 module(m_numrows - 1, 1, pos, 2);
135 module(m_numrows - 1, 2, pos, 3);
136 module(0, m_numcols - 2, pos, 4);
137 module(0, m_numcols - 1, pos, 5);
138 module(1, m_numcols - 1, pos, 6);
139 module(2, m_numcols - 1, pos, 7);
140 module(3, m_numcols - 1, pos, 8);
141 }
142 void CBC_DefaultPlacement::corner2(FX_INT32 pos)
143 {
144 module(m_numrows - 3, 0, pos, 1);
145 module(m_numrows - 2, 0, pos, 2);
146 module(m_numrows - 1, 0, pos, 3);
147 module(0, m_numcols - 4, pos, 4);
148 module(0, m_numcols - 3, pos, 5);
149 module(0, m_numcols - 2, pos, 6);
150 module(0, m_numcols - 1, pos, 7);
151 module(1, m_numcols - 1, pos, 8);
152 }
153 void CBC_DefaultPlacement::corner3(FX_INT32 pos)
154 {
155 module(m_numrows - 3, 0, pos, 1);
156 module(m_numrows - 2, 0, pos, 2);
157 module(m_numrows - 1, 0, pos, 3);
158 module(0, m_numcols - 2, pos, 4);
159 module(0, m_numcols - 1, pos, 5);
160 module(1, m_numcols - 1, pos, 6);
161 module(2, m_numcols - 1, pos, 7);
162 module(3, m_numcols - 1, pos, 8);
163 }
164 void CBC_DefaultPlacement::corner4(FX_INT32 pos)
165 {
166 module(m_numrows - 1, 0, pos, 1);
167 module(m_numrows - 1, m_numcols - 1, pos, 2);
168 module(0, m_numcols - 3, pos, 3);
169 module(0, m_numcols - 2, pos, 4);
170 module(0, m_numcols - 1, pos, 5);
171 module(1, m_numcols - 3, pos, 6);
172 module(1, m_numcols - 2, pos, 7);
173 module(1, m_numcols - 1, pos, 8);
174 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/src/BC_DataMatrixWriter.cpp ('k') | xfa/src/fxbarcode/src/BC_Dimension.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698