Skip to content

Commit 1e63e24

Browse files
committed
Additional helpers for renderers; text support for maximatrix
1 parent 2315c4a commit 1e63e24

8 files changed

Lines changed: 297 additions & 337 deletions

File tree

CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
XXXX-XX-XX
2+
3+
* Text group support was added to the MaxiCode symbology.
4+
5+
16
2026-03-31
27

38
* gridfit and griddpi options were added to the renderers to snap module boundaries to device pixel grid.

src/render.ps.src

Lines changed: 202 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@
3232
% IN THE SOFTWARE.
3333

3434
% --BEGIN RESOURCE render--
35-
% --REQUIRES preamble processoptions setanycolor--
35+
% --REQUIRES preamble raiseerror processoptions setanycolor--
3636
currentglobal
3737
true setglobal
3838
/setpacking where {pop currentpacking true setpacking} if
39-
32 dict
39+
48 dict
40+
dup /raiseerror dup /uk.co.terryburton.bwipp findresource put
4041
dup /processoptions dup /uk.co.terryburton.bwipp findresource put
4142
dup /setanycolor dup /uk.co.terryburton.bwipp findresource put
4243
begin
@@ -108,9 +109,9 @@ begin
108109
%
109110
% Validate a single text option dict
110111
%
111-
% grp textdict /validateoptions //render exec => bool [errorname errorstring |]
112+
% grp textdict /validatetextoptions //render exec => bool [errorname errorstring |]
112113
%
113-
/render.validateoptions {
114+
/render.validatetextoptions {
114115

115116
16 dict begin
116117

@@ -390,6 +391,35 @@ begin
390391

391392
} bind def
392393

394+
%
395+
% Render text groups 1-9
396+
%
397+
/render.textgroups {
398+
399+
4 dict begin
400+
401+
/pixy exch def
402+
/pixx exch def
403+
404+
/ok true def
405+
1 1 9 {
406+
/textgrp exch def
407+
textopts textgrp 1 sub get () get () ne % Has manual contents
408+
textgrp 1 eq txt length 0 gt and includetext and or % or text1 with encoder txt and includetext
409+
{
410+
textopts textgrp 1 sub get
411+
dup (txt) textgrp 1 eq { txt } { [] } ifelse put
412+
dup dup () get (content) exch put
413+
pixx pixy textgrp 4 -1 roll //render.rendertext exec
414+
not { /ok false def exit } if
415+
} if
416+
} for
417+
ok
418+
419+
end
420+
421+
} bind def
422+
393423
%
394424
% Snap module boundaries to device pixel grid
395425
%
@@ -455,14 +485,178 @@ begin
455485

456486
} bind def
457487

488+
%
489+
% Apply defaults from global context for properties common to all renderers
490+
%
491+
/render.global_defaults {
492+
493+
/uk.co.terryburton.bwipp.global_ctx dup where {
494+
exch get % ctx
495+
barcolor (unset) eq { dup /default_barcolor 2 copy known {get /barcolor exch def} {pop pop} ifelse } if
496+
backgroundcolor (unset) eq { dup /default_backgroundcolor 2 copy known {get /backgroundcolor exch def} {pop pop} ifelse } if
497+
bordercolor (unset) eq { dup /default_bordercolor 2 copy known {get /bordercolor exch def} {pop pop} ifelse } if
498+
inkspread null eq { dup /default_inkspread 2 copy known {get /inkspread exch def} {pop pop} ifelse } if
499+
griddpi 0 eq { dup /default_griddpi 2 copy known {get /griddpi exch def} {pop pop} ifelse } if
500+
gridfit false eq { dup /default_gridfit 2 copy known {get /gridfit exch def} {pop pop} ifelse } if
501+
pop
502+
} { pop } ifelse
503+
504+
} bind def
505+
506+
%
507+
% Validate common renderer options
508+
%
509+
/render.validate_common {
510+
511+
/textopts where {
512+
pop
513+
1 1 9 {
514+
textopts 1 index 1 sub get
515+
//render.validatetextoptions exec not { //raiseerror exec } if
516+
} for
517+
} if
518+
519+
inkspread -1 lt inkspread 1 gt or {
520+
/bwipp.renderBadInkspread (inkspread must be from -1 to 1) //raiseerror exec
521+
} if
522+
523+
borderleft -1 lt borderleft 50 gt or {
524+
/bwipp.renderBadBorderleft (borderleft must be from -1 to 50) //raiseerror exec
525+
} if
526+
527+
borderright -1 lt borderright 50 gt or {
528+
/bwipp.renderBadBorderright (borderright must be from -1 to 50) //raiseerror exec
529+
} if
530+
531+
bordertop -1 lt bordertop 50 gt or {
532+
/bwipp.renderBadBordertop (bordertop must be from -1 to 50) //raiseerror exec
533+
} if
534+
535+
borderbottom -1 lt borderbottom 50 gt or {
536+
/bwipp.renderBadBorderbottom (borderbottom must be from -1 to 50) //raiseerror exec
537+
} if
538+
539+
borderwidth 0 lt borderwidth 10 gt or {
540+
/bwipp.renderBadBorderwidth (borderwidth must be from 0 to 10) //raiseerror exec
541+
} if
542+
543+
griddpi 0 ne { griddpi 30 lt griddpi 9600 gt or {
544+
/bwipp.renderBadGriddpi (griddpi must be 0 or from 30 to 9600) //raiseerror exec
545+
} if } if
546+
547+
} bind def
548+
549+
%
550+
% Draw border, bearer bars, and background
551+
%
552+
/render.renderborder {
553+
554+
16 dict begin
555+
556+
/yspread exch def
557+
/xspread exch def
558+
/pixy exch def
559+
/pixx exch def
560+
561+
/showbearer /showbearer where { /showbearer get } { false } ifelse def
562+
563+
%
564+
% Corner geometry
565+
%
566+
showborder showbearer or {
567+
/tl [ borderleft borderwidth 2 div add neg pixy bordertop add borderwidth 2 div add ] def
568+
/tr [ pixx borderright add borderwidth 2 div add pixy bordertop add borderwidth 2 div add ] def
569+
/bl [ borderleft borderwidth 2 div add neg borderbottom borderwidth 2 div add neg ] def
570+
/br [ pixx borderright add borderwidth 2 div add borderbottom borderwidth 2 div add neg ] def
571+
} {
572+
/tl [ borderleft neg xspread add pixy bordertop add yspread sub ] def
573+
/tr [ pixx borderright add xspread sub pixy bordertop add yspread sub ] def
574+
/bl [ borderleft neg xspread add borderbottom neg yspread add ] def
575+
/br [ pixx borderright add xspread sub borderbottom neg yspread add ] def
576+
} ifelse
577+
578+
1 { % Common exit
579+
580+
%
581+
% Background fill
582+
%
583+
backgroundcolor (unset) ne {
584+
gsave
585+
newpath bl aload pop moveto [ br tr tl ] { aload pop lineto } forall closepath
586+
backgroundcolor //setanycolor exec not {
587+
grestore
588+
/bwipp.renderBadBackgroundColor (Invalid background color) false exit
589+
} if fill
590+
grestore
591+
} if
592+
593+
%
594+
% Bearer bars (horizontal rules at top and bottom)
595+
%
596+
showbearer {
597+
borderwidth inkspread gt {
598+
gsave
599+
newpath
600+
bl aload pop moveto br aload pop lineto
601+
tl aload pop moveto tr aload pop lineto
602+
bordercolor (unset) ne {
603+
bordercolor //setanycolor exec not {
604+
grestore
605+
/bwipp.renderBadBorderColor (Invalid border color) false exit
606+
} if
607+
} if
608+
borderwidth inkspread sub setlinewidth stroke
609+
grestore
610+
} if
611+
} if
612+
613+
%
614+
% Border (eofill rectangle frame)
615+
%
616+
showborder showbearer not and {
617+
/hw borderwidth inkspread sub 2 div def
618+
hw 0 gt {
619+
gsave
620+
bordercolor (unset) ne {
621+
bordercolor //setanycolor exec not {
622+
grestore
623+
/bwipp.renderBadBorderColor (Invalid border color) false exit
624+
} if
625+
} if
626+
newpath
627+
bl aload pop hw sub exch hw sub exch moveto
628+
br aload pop hw sub exch hw add exch lineto
629+
tr aload pop hw add exch hw add exch lineto
630+
tl aload pop hw add exch hw sub exch lineto closepath
631+
bl aload pop hw add exch hw add exch moveto
632+
tl aload pop hw sub exch hw add exch lineto
633+
tr aload pop hw sub exch hw sub exch lineto
634+
br aload pop hw add exch hw sub exch lineto closepath
635+
eofill
636+
grestore
637+
} if
638+
} if
639+
640+
true exit
641+
642+
} repeat
643+
644+
end
645+
646+
} bind def
647+
458648
%
459649
% Dispatcher table
460650
%
461651
/render.dispatch <<
462-
/groupoptions //render.groupoptions
463-
/rendertext //render.rendertext
464-
/validateoptions //render.validateoptions
465-
/gridfit //render.gridfit
652+
/groupoptions //render.groupoptions
653+
/textgroups //render.textgroups
654+
/rendertext //render.rendertext
655+
/validatetextoptions //render.validatetextoptions
656+
/gridfit //render.gridfit
657+
/global_defaults //render.global_defaults
658+
/validate_common //render.validate_common
659+
/renderborder //render.renderborder
466660
>> readonly def
467661

468662
/render {

0 commit comments

Comments
 (0)