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
4141currentglobal
@@ -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
0 commit comments