Skip to content

Commit d3b7125

Browse files
committed
renmatrix, renlinear: New (extra)textdirection options
1 parent f34d6d0 commit d3b7125

4 files changed

Lines changed: 282 additions & 104 deletions

File tree

src/gs1dldatamatrix.ps.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ begin
8181

8282
args (opt) options put
8383
args (alttext) hri put
84-
args (textyoffset) 1.0 put
84+
args (textyoffset) -1.0 put
8585
args (textfont) /Helvetica put
8686
args (textsize) 5 put
8787
args

src/gs1dlqrcode.ps.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ begin
8181

8282
args (opt) options put
8383
args (alttext) hri put
84-
args (textyoffset) 4.0 put
84+
args (textyoffset) -4.0 put
8585
args (textfont) /Helvetica put
8686
args (textsize) 5 put
8787
args

src/renlinear.ps.src

Lines changed: 140 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ begin
4949
/textcolor (unset) def
5050
/textxalign (unset) def
5151
/textyalign (unset) def
52+
/textdirection (forward) def
5253
/textfont (Courier) def
5354
/textsize 10.0 def
5455
/textxoffset 0.0 def
@@ -65,6 +66,7 @@ begin
6566
/extratextcolor (unset) def
6667
/extratextxalign (left) def
6768
/extratextyalign (above) def
69+
/extratextdirection (forward) def
6870
/extratextfont (Courier) def
6971
/extratextsize 10.0 def
7072
/extratextxoffset 0.0 def
@@ -231,9 +233,54 @@ begin
231233
fill
232234
grestore
233235

236+
/positions <<
237+
% direction
238+
% x-align y-align
239+
(forward) <<
240+
(offleft) { tw neg nudge sub } (below) { th neg nudge sub }
241+
(left) { 0 } (bottom) { 0 }
242+
(xcenter) { pixx tw sub 2 div } (ycenter) { pixy th sub 2 div }
243+
(right) { pixx tw sub } (top) { pixy th sub }
244+
(offright) { pixx nudge add } (above) { pixy nudge add }
245+
>>
246+
(backward) <<
247+
(offleft) { 0 nudge sub } (below) { 0 nudge sub }
248+
(left) { tw } (bottom) { th }
249+
(xcenter) { pixx tw add 2 div } (ycenter) { pixy th add 2 div }
250+
(right) { pixx } (top) { pixy }
251+
(offright) { pixx tw add nudge add } (above) { pixy th add nudge add }
252+
>>
253+
(upward) <<
254+
(offleft) { 0 nudge sub } (below) { tw neg nudge sub }
255+
(left) { th } (bottom) { 0 }
256+
(xcenter) { pixx th add 2 div } (ycenter) { pixy tw sub 2 div }
257+
(right) { pixx } (top) { pixy tw sub }
258+
(offright) { pixx th add nudge add } (above) { pixy nudge add }
259+
>>
260+
(downward) <<
261+
(offleft) { th neg nudge sub } (below) { 0 nudge sub }
262+
(left) { 0 } (bottom) { tw }
263+
(xcenter) { pixx th sub 2 div } (ycenter) { pixy tw add 2 div }
264+
(right) { pixx th sub } (top) { pixy }
265+
(offright) { pixx nudge add } (above) { pixy tw add nudge add }
266+
>>
267+
>> def
268+
269+
% x-align y-align direction text-width text-height
270+
/positiontext {
271+
/th exch def
272+
/tw exch def
273+
/nudge 1 def
274+
positions exch get dup
275+
4 -1 roll dup (center) eq {pop (xcenter)} if get exec exch
276+
3 -1 roll dup (center) eq {pop (ycenter)} if get exec
277+
} def
278+
234279
% Display the text for elements in the text array
235280
includetext {
281+
236282
textcolor (unset) ne { textcolor setanycolor } if
283+
237284
textxalign (unset) eq textyalign (unset) eq and alttext () eq and {
238285
/s 0 def /fn () def
239286
txt {
@@ -251,7 +298,7 @@ begin
251298
moveto show
252299
} forall
253300
} {
254-
textfont textsize selectfont
301+
255302
alttext () eq {
256303
/txt [ txt { 0 get {} forall } forall ] def
257304
/tstr txt length string def
@@ -267,6 +314,19 @@ begin
267314
} for
268315
} ifelse
269316

317+
alttext () ne alttextsplit () ne and {
318+
alttextsplit length 1 ne {
319+
/bwipp.alttextsplitBad (The alttextsplit option must be a single character) //raiseerror exec
320+
} if
321+
/textlines [
322+
tstr { alttextsplit search { exch pop exch } { exit } ifelse } loop
323+
] def
324+
} {
325+
/textlines [ tstr ] def
326+
} ifelse
327+
328+
textfont textsize selectfont
329+
270330
% Find true ascent of font
271331
tstr length 0 eq {
272332
0
@@ -285,41 +345,52 @@ begin
285345
} ifelse
286346
/textascent exch def
287347

288-
alttext () ne alttextsplit () ne and {
289-
alttextsplit length 1 ne {
290-
/bwipp.alttextsplitBad (The alttextsplit option must be a single character) //raiseerror exec
291-
} if
292-
/textlines [
293-
tstr { alttextsplit search { exch pop exch } { exit } ifelse } loop
294-
] def
295-
} {
296-
/textlines [ tstr ] def
297-
} ifelse
298-
299348
/textwidth 0 textlines { stringwidth pop 2 copy lt {exch} if pop } forall tstr length 1 sub textgaps mul add def
300349
/textheight textlines length dup textascent mul exch 1 sub textlinegaps mul add def
301350

302-
/textxpos textxoffset pixx textwidth sub 2 div add def % center
303-
textxalign (left) eq { /textxpos textxoffset def } if
304-
textxalign (right) eq { /textxpos pixx textxoffset sub textwidth sub def } if
305-
textxalign (offleft) eq { /textxpos textwidth textxoffset add neg def } if
306-
textxalign (offright) eq { /textxpos pixx textxoffset add def } if
307-
textxalign (justify) eq textwidth pixx lt and {
308-
/textxpos 0.0 def
309-
/textgaps pixx textwidth sub tstr length 1 sub div def
351+
textxalign (unset) eq { /textxalign (center) def } if
352+
textyalign (unset) eq { /textyalign (below) def } if
353+
354+
textxalign (justify) eq {
355+
textdirection (forward) ne textdirection (backward) ne and {
356+
/bwipp.textxjustify (textxalign=justify requires forward or backward text) //raiseerror exec
357+
} if
358+
textwidth pixx lt {
359+
/textgaps pixx textwidth sub tstr length 1 sub div def
360+
/textxalign textdirection (forward) eq { (left) } { (right) } ifelse def
361+
} {
362+
/textgaps 0.0 def
363+
/textxalign (center) def
364+
} ifelse
310365
} if
311-
/textypos textyoffset textheight add 1 add neg def % below
312-
textyalign (above) eq { /textypos textyoffset pixy add 1 add def } if
313-
textyalign (top) eq { /textypos textyoffset pixy add textheight sub def } if
314-
textyalign (center) eq { /textypos textyoffset pixy textheight sub 2 div add def } if
315-
textyalign (bottom) eq { /textypos textyoffset def } if
366+
367+
textyalign (justify) eq {
368+
textdirection (upward) ne textdirection (downward) ne and {
369+
/bwipp.textyjustify (textyalign=justify requires upward or downward text) //raiseerror exec
370+
} if
371+
textwidth pixy lt {
372+
/textgaps pixy textwidth sub tstr length 1 sub div def
373+
/textyalign textdirection (upward) eq { (bottom) } { (top) } ifelse def
374+
} {
375+
/textgaps 0.0 def
376+
/textyalign (center) def
377+
} ifelse
378+
} if
379+
380+
textxalign textyalign textdirection textwidth textheight positiontext moveto
381+
textxoffset textyoffset rmoveto
382+
gsave
383+
<< (forward) 0 (upward) 90 (backward) 180 (downward) 270 >> textdirection get rotate
384+
currentpoint translate
316385
0 1 textlines length 1 sub {
317386
/i exch def
318-
textxpos textypos textascent textlinegaps add i mul add moveto
387+
0 0 textascent textlinegaps add i mul add moveto
319388
textgaps 0 textlines dup length i sub 1 sub get ashow
320389
} for
390+
grestore
321391

322392
} ifelse
393+
323394
} if
324395

325396
% Display the guard elements
@@ -343,6 +414,7 @@ begin
343414

344415
% Render any extratext
345416
extratext () ne {
417+
346418
0 1 extratext length 1 sub {
347419
dup
348420
extratext exch 1 getinterval extratextsubspace exch search {
@@ -351,6 +423,17 @@ begin
351423
pop pop
352424
} for
353425

426+
extratextsplit () ne {
427+
extratextsplit length 1 ne {
428+
/bwipp.extratextsplitBad (The extratextsplit option must be a single character) //raiseerror exec
429+
} if
430+
/textlines [
431+
extratext { extratextsplit search { exch pop exch } { exit } ifelse } loop
432+
] def
433+
} {
434+
/textlines [ extratext ] def
435+
} ifelse
436+
354437
extratextcolor (unset) ne { extratextcolor setanycolor } if
355438
extratextfont extratextsize selectfont
356439

@@ -368,40 +451,46 @@ begin
368451
} if
369452
/textascent exch def
370453

371-
extratextsplit () ne {
372-
extratextsplit length 1 ne {
373-
/bwipp.extratextsplitBad (The extratextsplit option must be a single character) //raiseerror exec
374-
} if
375-
/textlines [
376-
extratext { extratextsplit search { exch pop exch } { exit } ifelse } loop
377-
] def
378-
} {
379-
/textlines [ extratext ] def
380-
} ifelse
381-
382454
/textwidth 0 textlines { stringwidth pop 2 copy lt {exch} if pop } forall extratext length 1 sub extratextgaps mul add def
383455
/textheight textlines length dup textascent mul exch 1 sub extratextlinegaps mul add def
384456

385-
/extratextxpos extratextxoffset pixx textwidth sub 2 div add def % center
386-
extratextxalign (left) eq { /textxpos extratextxoffset def } if
387-
extratextxalign (right) eq { /textxpos pixx extratextxoffset sub textwidth sub def } if
388-
extratextxalign (offleft) eq { /textxpos textwidth extratextxoffset add neg def } if
389-
extratextxalign (offright) eq { /textxpos pixx extratextxoffset add def } if
390-
extratextxalign (justify) eq textwidth pixx lt and {
391-
/textxpos 0.0 def
392-
/extratextgaps pixx textwidth sub extratext length 1 sub div def
457+
extratextxalign (justify) eq {
458+
extratextdirection (forward) ne extratextdirection (backward) ne and {
459+
/bwipp.extratextxjustify (extratextxalign=justify requires forward or backward text) //raiseerror exec
460+
} if
461+
textwidth pixx lt {
462+
/extratextgaps pixx textwidth sub extratext length 1 sub div def
463+
/extratextxalign extratextdirection (forward) eq { (left) } { (right) } ifelse def
464+
} {
465+
/extratextgaps 0.0 def
466+
/extratextxalign (center) def
467+
} ifelse
468+
} if
469+
470+
extratextyalign (justify) eq {
471+
extratextdirection (upward) ne extratextdirection (downward) ne and {
472+
/bwipp.extratextyjustify (extratextyalign=justify requires upward or downward text) //raiseerror exec
473+
} if
474+
textwidth pixy lt {
475+
/extratextgaps pixy textwidth sub extratext length 1 sub div def
476+
/extratextyalign extratextdirection (upward) eq { (bottom) } { (top) } ifelse def
477+
} {
478+
/extratextgaps 0.0 def
479+
/extratextyalign (center) def
480+
} ifelse
393481
} if
394-
/textypos extratextyoffset textheight add 1 add neg def % below
395-
extratextyalign (above) eq { /textypos extratextyoffset pixy add 1 add def } if
396-
extratextyalign (top) eq { /textypos extratextyoffset pixy add textheight sub def } if
397-
extratextyalign (center) eq { /textypos extratextyoffset pixy textheight sub 2 div add def } if
398-
extratextyalign (bottom) eq { /textypos extratextyoffset def } if
399482

483+
extratextxalign extratextyalign extratextdirection textwidth textheight positiontext moveto
484+
extratextxoffset extratextyoffset rmoveto
485+
gsave
486+
<< (forward) 0 (upward) 90 (backward) 180 (downward) 270 >> extratextdirection get rotate
487+
currentpoint translate
400488
0 1 textlines length 1 sub {
401489
/i exch def
402-
textxpos textypos textascent extratextlinegaps add i mul add moveto
490+
0 0 textascent extratextlinegaps add i mul add moveto
403491
extratextgaps 0 textlines dup length i sub 1 sub get ashow
404492
} for
493+
grestore
405494

406495
} if
407496

0 commit comments

Comments
 (0)