Skip to content

Commit 7a025f6

Browse files
committed
2D matrix symbols with custom module width should maintain aspect ratio
1 parent 1e84b62 commit 7a025f6

File tree

5 files changed

+179
-15
lines changed

5 files changed

+179
-15
lines changed

src/main/java/uk/org/okapibarcode/backend/MaxiCode.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ protected void encode() {
398398
}
399399
}
400400
pattern[i] = bin2pat(bin);
401-
row_height[i] = 1;
401+
row_height[i] = moduleWidth;
402402
}
403403
}
404404

@@ -907,27 +907,31 @@ protected void plotSymbol() {
907907

908908
resetPlotElements();
909909

910-
symbol_height = 72;
911-
symbol_width = 74;
910+
// this is a very different symbology, but for consistency with all of the other
911+
// 2D matrix symbologies, we scale the symbol up by the module width (the hexagons
912+
// are considered "modules" in the MaxiCode spec)
913+
int m = moduleWidth;
914+
symbol_height = 72 * m;
915+
symbol_width = 74 * m;
912916

913917
// hexagons
914918
for (int row = 0; row < 33; row++) {
915919
for (int col = 0; col < 30; col++) {
916920
if (grid[row][col]) {
917-
double x = (2.46 * col) + 1.23;
921+
double x = ((2.46 * col) + 1.23) * m;
918922
if ((row & 1) != 0) {
919-
x += 1.23;
923+
x += 1.23 * m;
920924
}
921-
double y = (2.135 * row) + 1.43;
922-
hexagons.add(new Hexagon(x, y));
925+
double y = ((2.135 * row) + 1.43) * m;
926+
hexagons.add(new Hexagon(x, y, m));
923927
}
924928
}
925929
}
926930

927931
// circles
928932
double[] radii = { 10.85, 8.97, 7.10, 5.22, 3.31, 1.43 };
929933
for (int i = 0; i < radii.length; i++) {
930-
target.add(new Circle(35.76, 35.60, radii[i]));
934+
target.add(new Circle(35.76 * m, 35.60 * m, radii[i] * m));
931935
}
932936
}
933937

src/main/java/uk/org/okapibarcode/graphics/Hexagon.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ public final class Hexagon {
3535
public final double[] pointX = new double[6];
3636
public final double[] pointY = new double[6];
3737

38-
public Hexagon(double centreX, double centreY) {
38+
public Hexagon(double centreX, double centreY, int factor) {
3939
this.centreX = centreX;
4040
this.centreY = centreY;
4141
for (int i = 0; i < 6; i++) {
42-
pointX[i] = centreX + (OFFSET_X[i] * INK_SPREAD);
43-
pointY[i] = centreY + (OFFSET_Y[i] * INK_SPREAD);
42+
pointX[i] = centreX + (OFFSET_X[i] * INK_SPREAD * factor);
43+
pointY[i] = centreY + (OFFSET_Y[i] * INK_SPREAD * factor);
4444
}
4545
}
4646

src/test/java/uk/org/okapibarcode/graphics/HexagonTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ public class HexagonTest {
3030
@Test
3131
public void testHexagon() {
3232

33-
Hexagon hex1 = new Hexagon(1, 2);
33+
Hexagon hex1 = new Hexagon(1, 2, 1);
3434
assertEquals(1, hex1.centreX, 0.001);
3535
assertEquals(2, hex1.centreY, 0.001);
3636
assertEquals("Hexagon[centreX=1.0, centreY=2.0]", hex1.toString());
3737

38-
Hexagon hex2 = new Hexagon(1, 2);
38+
Hexagon hex2 = new Hexagon(1, 2, 1);
3939
assertEqual(hex1, hex2);
4040

4141
Object obj = new Object();
4242
assertNotEquals(hex1, obj);
4343
assertNotEquals(obj, hex1);
4444

45-
assertNotEqual(hex1, new Hexagon(9, 2));
46-
assertNotEqual(hex1, new Hexagon(1, 9));
45+
assertNotEqual(hex1, new Hexagon(9, 2, 1));
46+
assertNotEqual(hex1, new Hexagon(1, 9, 1));
4747
}
4848

4949
private static void assertEqual(Hexagon hex1, Hexagon hex2) {
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
PROPERTIES
2+
3+
mode=4
4+
moduleWidth=2
5+
content=ABC
6+
7+
LOG
8+
9+
ECI Mode: 3
10+
ECI Charset: ISO-8859-1
11+
Mode: 4
12+
ECC Codewords: 40
13+
Codewords: 4 1 2 3 33 33 33 33 33 33 13 1 28 60 35 56 0 48 52 15 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 60 60 40 40 9 9 43 43 14 14 50 50 12 12 53 53 57 57 58 58 36 36 28 28 10 10 53 53 37 37 30 30 14 14 5 5 31 31 40 40
14+
15+
CODEWORDS
16+
17+
4 # mode 4
18+
1 # A
19+
2 # B
20+
3 # C
21+
33 # start padding
22+
33
23+
33
24+
33
25+
33
26+
33
27+
13 # start primary message error correction
28+
1
29+
28
30+
60
31+
35
32+
56
33+
0
34+
48
35+
52
36+
15 # end primary message error correction
37+
33 # start secondary message
38+
33
39+
33
40+
33
41+
33
42+
33
43+
33
44+
33
45+
33
46+
33
47+
33
48+
33
49+
33
50+
33
51+
33
52+
33
53+
33
54+
33
55+
33
56+
33
57+
33
58+
33
59+
33
60+
33
61+
33
62+
33
63+
33
64+
33
65+
33
66+
33
67+
33
68+
33
69+
33
70+
33
71+
33
72+
33
73+
33
74+
33
75+
33
76+
33
77+
33
78+
33
79+
33
80+
33
81+
33
82+
33
83+
33
84+
33
85+
33
86+
33
87+
33
88+
33
89+
33
90+
33
91+
33
92+
33
93+
33
94+
33
95+
33
96+
33
97+
33
98+
33
99+
33
100+
33
101+
33
102+
33
103+
33
104+
33
105+
33
106+
33
107+
33
108+
33
109+
33
110+
33
111+
33
112+
33
113+
33
114+
33
115+
33
116+
33
117+
33
118+
33
119+
33
120+
33
121+
60 # start secondary message error correction
122+
60
123+
40
124+
40
125+
9
126+
9
127+
43
128+
43
129+
14
130+
14
131+
50
132+
50
133+
12
134+
12
135+
53
136+
53
137+
57
138+
57
139+
58
140+
58
141+
36
142+
36
143+
28
144+
28
145+
10
146+
10
147+
53
148+
53
149+
37
150+
37
151+
30
152+
30
153+
14
154+
14
155+
5
156+
5
157+
31
158+
31
159+
40
160+
40 # end secondary message error correction

0 commit comments

Comments
 (0)