Skip to content

Commit a89dc70

Browse files
committed
Convert EAN/UPC Composites to rowmult
1 parent f18d0b2 commit a89dc70

File tree

8 files changed

+184
-88
lines changed

8 files changed

+184
-88
lines changed

src/ean13composite.ps.src

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -135,36 +135,59 @@ begin
135135
/pixx ccpixx def
136136
} ifelse
137137

138-
/pixs [
139-
0 ccpixx ccpixs length 1 sub {
140-
/i exch def
141-
ccpixs i ccpixx getinterval aload pop ccrpad aload pop
142-
} for
143-
2 { linpad aload pop 0 1 93 {0} repeat 1 0 ccrpad aload pop } repeat
144-
2 { linpad aload pop 1 0 93 {0} repeat 0 1 ccrpad aload pop } repeat
145-
2 { linpad aload pop 0 1 93 {0} repeat 1 0 ccrpad aload pop } repeat
138+
/ccrows ccpixs length ccpixx idiv def
139+
140+
% Pre-compute bbs and bbs+bhs in row units to avoid repeated calculation
141+
/nbars sbs length 1 add 2 idiv def
142+
/bbsrow nbars array def
143+
/bhsrow nbars array def
144+
0 1 nbars 1 sub {
145+
/b exch def
146+
bbsrow b bbs b get 72 mul cvi put
147+
bhsrow b bbsrow b get bhs b get 72 mul add put
148+
} for
149+
150+
% Rasterize linear rows, deduplicating identical adjacent rows using a string buffer
151+
/rowbuf pixx string def
152+
/prevrow () def /linrowmult 72 array def /lri 0 def
153+
/linpixs [
146154
71 -1 0 {
147155
/y exch def
148-
linpad aload pop
149-
0
156+
/p 0 def
157+
linpad { rowbuf p 3 -1 roll put /p p 1 add def } forall
158+
rowbuf p 0 put /p p 1 add def
150159
0 1 sbs length 1 sub {
151160
/i exch def
152161
i 2 mod 0 eq {
153-
% Don't print when bbs > y || (bbs + bhs) < y (i.e. add-on or includetext offsets)
154-
bbs i 2 idiv get 72 mul cvi dup y gt exch bhs i 2 idiv get 72 mul add y lt or {
155-
sbs i get cvi {0} repeat
156-
} {
157-
sbs i get cvi {1} repeat
158-
} ifelse
159-
} {
160-
sbs i get cvi {0} repeat
161-
} ifelse
162+
bbsrow i 2 idiv get y gt bhsrow i 2 idiv get y lt or { 0 } { 1 } ifelse
163+
} { 0 } ifelse
164+
sbs i get cvi { rowbuf p 2 index put /p p 1 add def } repeat pop
162165
} for
163-
diff 0 lt {0} if % Allow for middle separator overhang on RHS if no add-on
166+
diff 0 lt { rowbuf p 0 put /p p 1 add def } if
167+
rowbuf prevrow eq {
168+
linrowmult lri 1 sub 2 copy get 1 add put % Bump multiplier
169+
} {
170+
prevrow length 0 gt { prevrow {} forall } if % Commit previous batch
171+
/prevrow rowbuf pixx string copy def
172+
linrowmult lri 1 put /lri lri 1 add def
173+
} ifelse
164174
} for
175+
prevrow {} forall % Commit final batch
165176
] def
177+
/linrowmult linrowmult 0 lri getinterval def
166178

167-
/pixy pixs length pixx idiv def
179+
/pixs [
180+
0 ccpixx ccpixs length 1 sub {
181+
/i exch def
182+
ccpixs i ccpixx getinterval aload pop ccrpad aload pop
183+
} for
184+
linpad aload pop 0 1 93 {0} repeat 1 0 ccrpad aload pop
185+
linpad aload pop 1 0 93 {0} repeat 0 1 ccrpad aload pop
186+
linpad aload pop 0 1 93 {0} repeat 1 0 ccrpad aload pop
187+
linpixs aload pop
188+
] def
189+
/rowmult [ ccrows { 1 } repeat 2 2 2 linrowmult aload pop ] def
190+
/pixy 0 rowmult {add} forall def
168191

169192
/borderleft
170193
linsym /borderleft 2 copy known { get } { pop pop 10 } ifelse linpad length 1 add sub
@@ -190,6 +213,7 @@ begin
190213
/pixs pixs
191214
/pixx pixx
192215
/pixy pixy
216+
/rowmult rowmult
193217
/height pixy 72 div
194218
/width pixx 72 div
195219
/borderleft borderleft

src/ean8composite.ps.src

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -145,36 +145,59 @@ begin
145145
/pixx ccpixx def
146146
} ifelse
147147

148-
/pixs [
149-
0 ccpixx ccpixs length 1 sub {
150-
/i exch def
151-
ccpixs i ccpixx getinterval aload pop ccrpad aload pop
152-
} for
153-
2 { linpad aload pop 0 1 65 {0} repeat 1 0 ccrpad aload pop } repeat
154-
2 { linpad aload pop 1 0 65 {0} repeat 0 1 ccrpad aload pop } repeat
155-
2 { linpad aload pop 0 1 65 {0} repeat 1 0 ccrpad aload pop } repeat
148+
/ccrows ccpixs length ccpixx idiv def
149+
150+
% Pre-compute bbs and bbs+bhs in row units to avoid repeated calculation
151+
/nbars sbs length 1 add 2 idiv def
152+
/bbsrow nbars array def
153+
/bhsrow nbars array def
154+
0 1 nbars 1 sub {
155+
/b exch def
156+
bbsrow b bbs b get 72 mul cvi put
157+
bhsrow b bbsrow b get bhs b get 72 mul add put
158+
} for
159+
160+
% Rasterize linear rows, deduplicating identical adjacent rows using a string buffer
161+
/rowbuf pixx string def
162+
/prevrow () def /linrowmult 72 array def /lri 0 def
163+
/linpixs [
156164
71 -1 0 {
157165
/y exch def
158-
linpad aload pop
159-
0
166+
/p 0 def
167+
linpad { rowbuf p 3 -1 roll put /p p 1 add def } forall
168+
rowbuf p 0 put /p p 1 add def
160169
0 1 sbs length 1 sub {
161170
/i exch def
162171
i 2 mod 0 eq {
163-
% Don't print when bbs > y || (bbs + bhs) < y (i.e. add-on or includetext offsets)
164-
bbs i 2 idiv get 72 mul cvi dup y gt exch bhs i 2 idiv get 72 mul add y lt or {
165-
sbs i get cvi {0} repeat
166-
} {
167-
sbs i get cvi {1} repeat
168-
} ifelse
169-
} {
170-
sbs i get cvi {0} repeat
171-
} ifelse
172+
bbsrow i 2 idiv get y gt bhsrow i 2 idiv get y lt or { 0 } { 1 } ifelse
173+
} { 0 } ifelse
174+
sbs i get cvi { rowbuf p 2 index put /p p 1 add def } repeat pop
172175
} for
173-
diff 0 lt {0} if % Allow for middle separator overhang on RHS if no add-on
176+
diff 0 lt { rowbuf p 0 put /p p 1 add def } if
177+
rowbuf prevrow eq {
178+
linrowmult lri 1 sub 2 copy get 1 add put % Bump multiplier
179+
} {
180+
prevrow length 0 gt { prevrow {} forall } if % Commit previous batch
181+
/prevrow rowbuf pixx string copy def
182+
linrowmult lri 1 put /lri lri 1 add def
183+
} ifelse
174184
} for
185+
prevrow {} forall % Commit final batch
175186
] def
187+
/linrowmult linrowmult 0 lri getinterval def
176188

177-
/pixy pixs length pixx idiv def
189+
/pixs [
190+
0 ccpixx ccpixs length 1 sub {
191+
/i exch def
192+
ccpixs i ccpixx getinterval aload pop ccrpad aload pop
193+
} for
194+
linpad aload pop 0 1 65 {0} repeat 1 0 ccrpad aload pop
195+
linpad aload pop 1 0 65 {0} repeat 0 1 ccrpad aload pop
196+
linpad aload pop 0 1 65 {0} repeat 1 0 ccrpad aload pop
197+
linpixs aload pop
198+
] def
199+
/rowmult [ ccrows { 1 } repeat 2 2 2 linrowmult aload pop ] def
200+
/pixy 0 rowmult {add} forall def
178201

179202
/borderleft
180203
linsym /borderleft 2 copy known { get } { pop pop 10 } ifelse linpad length 1 add sub
@@ -200,6 +223,7 @@ begin
200223
/pixs pixs
201224
/pixx pixx
202225
/pixy pixy
226+
/rowmult rowmult
203227
/height pixy 72 div
204228
/width pixx 72 div
205229
/borderleft borderleft

src/upcacomposite.ps.src

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -135,36 +135,59 @@ begin
135135
/pixx ccpixx def
136136
} ifelse
137137

138-
/pixs [
139-
0 ccpixx ccpixs length 1 sub {
140-
/i exch def
141-
ccpixs i ccpixx getinterval aload pop ccrpad aload pop
142-
} for
143-
2 { linpad aload pop 0 1 93 {0} repeat 1 0 ccrpad aload pop } repeat
144-
2 { linpad aload pop 1 0 93 {0} repeat 0 1 ccrpad aload pop } repeat
145-
2 { linpad aload pop 0 1 93 {0} repeat 1 0 ccrpad aload pop } repeat
138+
/ccrows ccpixs length ccpixx idiv def
139+
140+
% Pre-compute bbs and bbs+bhs in row units to avoid repeated calculation
141+
/nbars sbs length 1 add 2 idiv def
142+
/bbsrow nbars array def
143+
/bhsrow nbars array def
144+
0 1 nbars 1 sub {
145+
/b exch def
146+
bbsrow b bbs b get 72 mul cvi put
147+
bhsrow b bbsrow b get bhs b get 72 mul add put
148+
} for
149+
150+
% Rasterize linear rows, deduplicating identical adjacent rows using a string buffer
151+
/rowbuf pixx string def
152+
/prevrow () def /linrowmult 72 array def /lri 0 def
153+
/linpixs [
146154
71 -1 0 {
147155
/y exch def
148-
linpad aload pop
149-
0
156+
/p 0 def
157+
linpad { rowbuf p 3 -1 roll put /p p 1 add def } forall
158+
rowbuf p 0 put /p p 1 add def
150159
0 1 sbs length 1 sub {
151160
/i exch def
152161
i 2 mod 0 eq {
153-
% Don't print when bbs > y || (bbs + bhs) < y (i.e. add-on or includetext offsets)
154-
bbs i 2 idiv get 72 mul cvi dup y gt exch bhs i 2 idiv get 72 mul add y lt or {
155-
sbs i get cvi {0} repeat
156-
} {
157-
sbs i get cvi {1} repeat
158-
} ifelse
159-
} {
160-
sbs i get cvi {0} repeat
161-
} ifelse
162+
bbsrow i 2 idiv get y gt bhsrow i 2 idiv get y lt or { 0 } { 1 } ifelse
163+
} { 0 } ifelse
164+
sbs i get cvi { rowbuf p 2 index put /p p 1 add def } repeat pop
162165
} for
163-
diff 0 lt {0} if % Allow for middle separator overhang on RHS if no add-on
166+
diff 0 lt { rowbuf p 0 put /p p 1 add def } if
167+
rowbuf prevrow eq {
168+
linrowmult lri 1 sub 2 copy get 1 add put % Bump multiplier
169+
} {
170+
prevrow length 0 gt { prevrow {} forall } if % Commit previous batch
171+
/prevrow rowbuf pixx string copy def
172+
linrowmult lri 1 put /lri lri 1 add def
173+
} ifelse
164174
} for
175+
prevrow {} forall % Commit final batch
165176
] def
177+
/linrowmult linrowmult 0 lri getinterval def
166178

167-
/pixy pixs length pixx idiv def
179+
/pixs [
180+
0 ccpixx ccpixs length 1 sub {
181+
/i exch def
182+
ccpixs i ccpixx getinterval aload pop ccrpad aload pop
183+
} for
184+
linpad aload pop 0 1 93 {0} repeat 1 0 ccrpad aload pop
185+
linpad aload pop 1 0 93 {0} repeat 0 1 ccrpad aload pop
186+
linpad aload pop 0 1 93 {0} repeat 1 0 ccrpad aload pop
187+
linpixs aload pop
188+
] def
189+
/rowmult [ ccrows { 1 } repeat 2 2 2 linrowmult aload pop ] def
190+
/pixy 0 rowmult {add} forall def
168191

169192
/borderleft
170193
linsym /borderleft 2 copy known { get } { pop pop 10 } ifelse linpad length 1 add sub
@@ -190,6 +213,7 @@ begin
190213
/pixs pixs
191214
/pixx pixx
192215
/pixy pixy
216+
/rowmult rowmult
193217
/height pixy 72 div
194218
/width pixx 72 div
195219
/borderleft borderleft

src/upcecomposite.ps.src

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -142,36 +142,59 @@ begin
142142
/pixx ccpixx def
143143
} ifelse
144144

145-
/pixs [
146-
0 ccpixx ccpixs length 1 sub {
147-
/i exch def
148-
ccpixs i ccpixx getinterval aload pop ccrpad aload pop
149-
} for
150-
2 { linpad aload pop 0 1 49 {0} repeat 1 0 ccrpad aload pop } repeat
151-
2 { linpad aload pop 1 0 49 {0} repeat 0 1 ccrpad aload pop } repeat
152-
2 { linpad aload pop 0 1 49 {0} repeat 1 0 ccrpad aload pop } repeat
145+
/ccrows ccpixs length ccpixx idiv def
146+
147+
% Pre-compute bbs and bbs+bhs in row units to avoid repeated calculation
148+
/nbars sbs length 1 add 2 idiv def
149+
/bbsrow nbars array def
150+
/bhsrow nbars array def
151+
0 1 nbars 1 sub {
152+
/b exch def
153+
bbsrow b bbs b get 72 mul cvi put
154+
bhsrow b bbsrow b get bhs b get 72 mul add put
155+
} for
156+
157+
% Rasterize linear rows, deduplicating identical adjacent rows using a string buffer
158+
/rowbuf pixx string def
159+
/prevrow () def /linrowmult 72 array def /lri 0 def
160+
/linpixs [
153161
71 -1 0 {
154162
/y exch def
155-
linpad aload pop
156-
0
163+
/p 0 def
164+
linpad { rowbuf p 3 -1 roll put /p p 1 add def } forall
165+
rowbuf p 0 put /p p 1 add def
157166
0 1 sbs length 1 sub {
158167
/i exch def
159168
i 2 mod 0 eq {
160-
% Don't print when bbs > y || (bbs + bhs) < y (i.e. add-on or includetext offsets)
161-
bbs i 2 idiv get 72 mul cvi dup y gt exch bhs i 2 idiv get 72 mul add y lt or {
162-
sbs i get cvi {0} repeat
163-
} {
164-
sbs i get cvi {1} repeat
165-
} ifelse
166-
} {
167-
sbs i get cvi {0} repeat
168-
} ifelse
169+
bbsrow i 2 idiv get y gt bhsrow i 2 idiv get y lt or { 0 } { 1 } ifelse
170+
} { 0 } ifelse
171+
sbs i get cvi { rowbuf p 2 index put /p p 1 add def } repeat pop
169172
} for
170-
diff 0 lt {0} if % Allow for middle separator overhang on RHS if no add-on
173+
diff 0 lt { rowbuf p 0 put /p p 1 add def } if
174+
rowbuf prevrow eq {
175+
linrowmult lri 1 sub 2 copy get 1 add put % Bump multiplier
176+
} {
177+
prevrow length 0 gt { prevrow {} forall } if % Commit previous batch
178+
/prevrow rowbuf pixx string copy def
179+
linrowmult lri 1 put /lri lri 1 add def
180+
} ifelse
171181
} for
182+
prevrow {} forall % Commit final batch
172183
] def
184+
/linrowmult linrowmult 0 lri getinterval def
173185

174-
/pixy pixs length pixx idiv def
186+
/pixs [
187+
0 ccpixx ccpixs length 1 sub {
188+
/i exch def
189+
ccpixs i ccpixx getinterval aload pop ccrpad aload pop
190+
} for
191+
linpad aload pop 0 1 49 {0} repeat 1 0 ccrpad aload pop
192+
linpad aload pop 1 0 49 {0} repeat 0 1 ccrpad aload pop
193+
linpad aload pop 0 1 49 {0} repeat 1 0 ccrpad aload pop
194+
linpixs aload pop
195+
] def
196+
/rowmult [ ccrows { 1 } repeat 2 2 2 linrowmult aload pop ] def
197+
/pixy 0 rowmult {add} forall def
175198

176199
/borderleft
177200
linsym /borderleft 2 copy known { get } { pop pop 10 } ifelse linpad length 1 add sub
@@ -197,6 +220,7 @@ begin
197220
/pixs pixs
198221
/pixx pixx
199222
/pixy pixy
223+
/rowmult rowmult
200224
/height pixy 72 div
201225
/width pixx 72 div
202226
/borderleft borderleft

tests/ps_tests/ean13composite.ps.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/ean13composite dup /uk.co.terryburton.bwipp findresource cvx def
1313

1414
/eq_tmpl {
15-
3 1 roll { 0 0 ean13composite /pixs get }
15+
3 1 roll { 0 0 ean13composite expandpixs }
1616
dup 3 -1 roll 1 exch put
1717
dup 3 -1 roll 0 exch put
1818
isEqual

tests/ps_tests/ean8composite.ps.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/ean8composite dup /uk.co.terryburton.bwipp findresource cvx def
1313

1414
/eq_tmpl {
15-
3 1 roll { 0 0 ean8composite /pixs get }
15+
3 1 roll { 0 0 ean8composite expandpixs }
1616
dup 3 -1 roll 1 exch put
1717
dup 3 -1 roll 0 exch put
1818
isEqual

tests/ps_tests/upcacomposite.ps.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/upcacomposite dup /uk.co.terryburton.bwipp findresource cvx def
1313

1414
/eq_tmpl {
15-
3 1 roll { 0 0 upcacomposite /pixs get }
15+
3 1 roll { 0 0 upcacomposite expandpixs }
1616
dup 3 -1 roll 1 exch put
1717
dup 3 -1 roll 0 exch put
1818
isEqual

tests/ps_tests/upcecomposite.ps.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/upcecomposite dup /uk.co.terryburton.bwipp findresource cvx def
1313

1414
/eq_tmpl {
15-
3 1 roll { 0 0 upcecomposite /pixs get }
15+
3 1 roll { 0 0 upcecomposite expandpixs }
1616
dup 3 -1 roll 1 exch put
1717
dup 3 -1 roll 0 exch put
1818
isEqual

0 commit comments

Comments
 (0)