Skip to content

Commit efaf2e4

Browse files
committed
d3aqr: Add hostratio option
1 parent 8791fc5 commit efaf2e4

2 files changed

Lines changed: 91 additions & 29 deletions

File tree

src/d3aqr.ps.src

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
% --REQUIRES preamble raiseerror setuphooks processoptions parseinput setanycolor fifocache rsecbinary render renmatrix qrcode--
3636
% --DESC: D3 AQR (beta)
3737
% --EXAM: HTTPS://ID.GS1.ORG/01/09521234543213/22/ABC%2D123?99=XYZ-987
38-
% --EXOP: category=2842
38+
% --EXOP: category=2842 hostratio=2
3939
% --RNDR: renmatrix
4040
% --FMLY: Two-dimensional symbols
4141
currentglobal
@@ -59,13 +59,23 @@ begin
5959
%
6060
/d3aqr.timingxs [ 19 23 27 31 ] readonly def
6161

62+
%
63+
% Accepted D3:host pitch ratios mapped to (halfx, hostmod) cell counts.
64+
%
65+
/d3aqr.hostratios <<
66+
2.0 << /halfx 1 /hostmod 1 >>
67+
2.5 << /halfx 5 /hostmod 4 >>
68+
3.0 << /halfx 3 /hostmod 2 >>
69+
>> readonly def
70+
6271
/d3aqr {
6372

6473
32 dict begin
6574
{
6675

6776
/dontdraw false def
6877
/category -1 def
78+
/hostratio 2.0 def
6979
/strictspec false def
7080
/propspec false def
7181
/loosespec false def
@@ -96,6 +106,17 @@ begin
96106
/bwipp.d3aqrCategoryOutOfRange (Category must be between 0 and 16383 inclusive) //raiseerror exec
97107
} if
98108

109+
%
110+
% Resolve halfx and hostmod from hostratio.
111+
%
112+
//d3aqr.hostratios hostratio 2 copy known not {
113+
pop pop
114+
/bwipp.d3aqrInvalidHostRatio (hostratio must be 2, 2.5 or 3) //raiseerror exec
115+
} if
116+
get
117+
dup /halfx get /halfx exch def
118+
/hostmod get /hostmod exch def
119+
99120
%
100121
% Apply AST spec overrides and resolve physical specification
101122
%
@@ -125,56 +146,63 @@ begin
125146
%
126147
% Extract metrics of host symbol
127148
%
128-
/qrpixs args /pixs get def
129-
/qrsize args /pixx get def
149+
/hostpixs args /pixs get def
150+
/hostsize args /pixx get def
130151

131152
%
132-
% Matrix sized to fit the full 9.5 D3-X arms and host symbol
153+
% Matrix sized to fit the full 9.5 D3-X arms and host symbol.
154+
% hostoffset is the top-left padding in cells; it grows beyond a
155+
% single 1 D3-X frame as necessary to fit the D3 component.
133156
%
134-
/qroffset 2 29 qrsize sub 2 copy lt {exch} if pop def
135-
/size qroffset qrsize add 6 add def
157+
/hostcells hostsize hostmod mul def
158+
/hostoffset 2 halfx mul 29 halfx mul hostcells sub 2 copy lt {exch} if pop def
159+
/size hostoffset hostcells add 6 halfx mul add def
136160

137161
%
138-
% 0-filled matrix. Each cell is half a D3-X (= 1 host QR module).
139-
% Matrix is host_size + 8 cells, growing as necessary to fit the
140-
% D3 component.
162+
% 0-filled matrix. Each cell is half a D3-X; each host module
163+
% occupies hostmod x hostmod cells.
141164
%
142165
/pixs size size mul array def
143166
0 1 size size mul 1 sub { pixs exch 0 put } for
144167

145168
%
146-
% Place the host at qroffset from top-left
169+
% Place the host: each input cell maps to a hostmod x hostmod output block.
147170
%
148-
0 1 qrsize 1 sub {
171+
0 1 hostcells 1 sub {
149172
/j exch def
150-
pixs j qroffset add size mul qroffset add
151-
qrpixs j qrsize mul qrsize getinterval
152-
putinterval
173+
/pixrow j hostoffset add size mul hostoffset add def
174+
/hostrow j hostmod idiv hostsize mul def
175+
0 1 hostcells 1 sub {
176+
/i exch def
177+
hostpixs hostrow i hostmod idiv add get 1 eq {
178+
pixs pixrow i add 1 put
179+
} if
180+
} for
153181
} for
154182

155183
%
156184
% Coordinate positions are measured in half-D3-X units (cells) from
157185
% the bottom-right corner of the matrix, with x and y increasing
158-
% leftward and upward respectively. paintcell paints a single cell
159-
% at (x, y); paintmod paints a 2 x 2 module whose bottom-right cell
160-
% sits at (x, y); paintmodsym paints a module at (x, y) and at the
161-
% diagonal mirror (y, x), used for fixtures shared between the
162-
% bottom and right arms by symmetry.
163-
%
164-
/paintcell { % paint a single cell at (x, y)
165-
size exch sub 1 sub size mul exch
166-
size exch sub 1 sub add
167-
pixs exch 1 put
186+
% leftward and upward respectively.
187+
%
188+
/paintcell { % paint a halfx x halfx cell block at half-D3-X (x,y)
189+
halfx mul size 1 sub exch sub /row0 exch def
190+
halfx mul size 1 sub exch sub /col0 exch def
191+
0 1 halfx 1 sub { /dy exch def
192+
0 1 halfx 1 sub { /dx exch def
193+
pixs row0 dy sub size mul col0 dx sub add 1 put
194+
} for
195+
} for
168196
} bind def
169197

170-
/paintmod { % 2x2 module with bottom-right cell at (x, y)
198+
/paintmod { % paint 2x2 module with bottom-right cell at (x, y)
171199
2 copy paintcell % x y
172200
2 copy 1 add paintcell % x y+1
173201
2 copy exch 1 add exch paintcell % x+1 y
174202
1 add exch 1 add exch paintcell % x+1 y+1
175203
} bind def
176204

177-
/paintmodsym {
205+
/paintmodsym { % paints a module at (x,y) and (y,x)
178206
2 copy paintmod % x y
179207
exch paintmod % y x
180208
} bind def
@@ -234,7 +262,7 @@ begin
234262
/xnom xnom
235263
/xmin xmin
236264
/xmax xmax
237-
/modunit 2
265+
/modunit halfx 2 mul
238266
/opt options
239267
>>
240268

tests/ps_tests/d3aqr.ps.test

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
exch isError
2323
} def
2424

25+
/sz_tmpl {
26+
3 1 roll { 0 0 d3aqr /pixx get }
27+
dup 3 -1 roll 1 exch put
28+
dup 3 -1 roll 0 exch put
29+
isEqual
30+
} def
31+
2532

2633
%
2734
% Examples are based on D3 AQR symbology specification Rev C draft
@@ -217,8 +224,35 @@
217224
] eq_tmpl
218225

219226

227+
%
228+
% Matrix size for each accepted hostratio across QR versions.
229+
%
230+
(HI) (category=2842 version=1 dontdraw) 35 sz_tmpl
231+
(HI) (category=2842 version=3 dontdraw) 37 sz_tmpl
232+
(HI) (category=2842 version=10 dontdraw) 65 sz_tmpl
233+
(HI) (category=2842 version=40 dontdraw) 185 sz_tmpl
234+
235+
(HI) (category=2842 version=1 hostratio=2.5 dontdraw) 175 sz_tmpl
236+
(HI) (category=2842 version=3 hostratio=2.5 dontdraw) 175 sz_tmpl
237+
(HI) (category=2842 version=10 hostratio=2.5 dontdraw) 268 sz_tmpl
238+
239+
(HI) (category=2842 version=1 hostratio=3 dontdraw) 105 sz_tmpl
240+
(HI) (category=2842 version=3 hostratio=3 dontdraw) 105 sz_tmpl
241+
(HI) (category=2842 version=10 hostratio=3 dontdraw) 138 sz_tmpl
242+
243+
220244
%
221245
% Errors
222246
%
223-
(HELLO) (dontdraw) /bwipp.d3aqrMissingCategory er_tmpl
224-
(HELLO) (category=16384 dontdraw) /bwipp.d3aqrCategoryOutOfRange er_tmpl
247+
(HELLO) (dontdraw) /bwipp.d3aqrMissingCategory er_tmpl
248+
(HELLO) (category=-1 dontdraw) /bwipp.d3aqrMissingCategory er_tmpl
249+
(HELLO) (category=-2 dontdraw) /bwipp.d3aqrCategoryOutOfRange er_tmpl
250+
(HELLO) (category=16384 dontdraw) /bwipp.d3aqrCategoryOutOfRange er_tmpl
251+
(HELLO) (category=99999 dontdraw) /bwipp.d3aqrCategoryOutOfRange er_tmpl
252+
(HELLO) (category=2842 hostratio=1 dontdraw) /bwipp.d3aqrInvalidHostRatio er_tmpl
253+
(HELLO) (category=2842 hostratio=1.5 dontdraw) /bwipp.d3aqrInvalidHostRatio er_tmpl
254+
(HELLO) (category=2842 hostratio=2.25 dontdraw) /bwipp.d3aqrInvalidHostRatio er_tmpl
255+
(HELLO) (category=2842 hostratio=2.75 dontdraw) /bwipp.d3aqrInvalidHostRatio er_tmpl
256+
(HELLO) (category=2842 hostratio=3.5 dontdraw) /bwipp.d3aqrInvalidHostRatio er_tmpl
257+
(HELLO) (category=2842 hostratio=4 dontdraw) /bwipp.d3aqrInvalidHostRatio er_tmpl
258+
(HELLO) (category=2842 hostratio=10 dontdraw) /bwipp.d3aqrInvalidHostRatio er_tmpl

0 commit comments

Comments
 (0)