Skip to content

Commit 6bbe5ae

Browse files
committed
Input validation for text options
1 parent efe5e31 commit 6bbe5ae

2 files changed

Lines changed: 74 additions & 6 deletions

File tree

src/renlinear.ps.src

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,51 @@ begin
9797
{def} forall
9898
opt currentdict /opt undef //processoptions exec pop
9999

100-
textsize 0 le {
101-
/bwipp.renlinearBadTextsize (The font size must be greater than zero) //raiseerror exec
102-
} if
103-
104100
/uk.co.terryburton.bwipp.global_ctx dup where {
105101
exch get /ctx exch def
106102
barcolor (unset) eq { ctx /default_barcolor 2 copy known {get /barcolor exch def} {pop pop} ifelse } if
107103
backgroundcolor (unset) eq { ctx /default_backgroundcolor 2 copy known {get /backgroundcolor exch def} {pop pop} ifelse } if
108104
bordercolor (unset) eq { ctx /default_bordercolor 2 copy known {get /bordercolor exch def} {pop pop} ifelse } if
109105
} { pop } ifelse
110106

107+
% Input validation
108+
109+
textxalign (unset) ne {
110+
<< /offleft dup /left dup /center dup /right dup /offright dup >> textxalign known not {
111+
/bwipp.renmatrixBadTextxalign (textxalign must be offleft, left, center, right or offright) //raiseerror exec
112+
} if
113+
} if
114+
115+
textyalign (unset) ne {
116+
<< /above dup /top dup /center dup /bottom dup /below dup >> textyalign known not {
117+
/bwipp.renmatrixBadTextyalign (textyalign must be above, top, center, bottom or below) //raiseerror exec
118+
} if
119+
} if
120+
121+
<< /forward dup /backward dup /upward dup /downward dup >> textdirection known not {
122+
/bwipp.renmatrixBadTextdirection (textdirection must be forward, backward, upward or downward) //raiseerror exec
123+
} if
124+
125+
textsize 0 le textsize 25 ge or {
126+
/bwipp.renmatrixBadTextsize (textsize must be greater than zero and less that 25) //raiseerror exec
127+
} if
128+
129+
<< /offleft dup /left dup /center dup /right dup /offright dup >> extratextxalign known not {
130+
/bwipp.renmatrixBadExtratextxalign (extratextxalign must be offleft, left, center, right or offright) //raiseerror exec
131+
} if
132+
133+
<< /above dup /top dup /center dup /bottom dup /below dup >> extratextyalign known not {
134+
/bwipp.renmatrixBadExtratextyalign (extratextyalign must be above, top, center, bottom or below) //raiseerror exec
135+
} if
136+
137+
<< /forward dup /backward dup /upward dup /downward dup >> extratextdirection known not {
138+
/bwipp.renmatrixBadExtratextdirection (extratextdirection must be forward, backward, upward or downward) //raiseerror exec
139+
} if
140+
141+
extratextsize 0 le extratextsize 25 ge or {
142+
/bwipp.renmatrixBadTextsize (extratextsize must be greater than zero and less that 25) //raiseerror exec
143+
} if
144+
111145
% Create bar elements and put them into the bars array
112146
/bars sbs length 1 add 2 idiv array def
113147
/pixx 0 def /pixy 0 def

src/renmatrix.ps.src

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,42 @@ begin
100100
bordercolor (unset) eq { ctx /default_bordercolor 2 copy known {get /bordercolor exch def} {pop pop} ifelse } if
101101
} { pop } ifelse
102102

103-
textsize 0 le {
104-
/bwipp.renmatrixBadTextsize (The font size must be greater than zero) //raiseerror exec
103+
% Input validation
104+
105+
textxalign (unset) ne {
106+
<< /offleft dup /left dup /center dup /right dup /offright dup >> textxalign known not {
107+
/bwipp.renmatrixBadTextxalign (textxalign must be offleft, left, center, right or offright) //raiseerror exec
108+
} if
109+
} if
110+
111+
textyalign (unset) ne {
112+
<< /above dup /top dup /center dup /bottom dup /below dup >> textyalign known not {
113+
/bwipp.renmatrixBadTextyalign (textyalign must be above, top, center, bottom or below) //raiseerror exec
114+
} if
115+
} if
116+
117+
<< /forward dup /backward dup /upward dup /downward dup >> textdirection known not {
118+
/bwipp.renmatrixBadTextdirection (textdirection must be forward, backward, upward or downward) //raiseerror exec
119+
} if
120+
121+
textsize 0 le textsize 25 ge or {
122+
/bwipp.renmatrixBadTextsize (textsize must be greater than zero and less that 25) //raiseerror exec
123+
} if
124+
125+
<< /offleft dup /left dup /center dup /right dup /offright dup >> extratextxalign known not {
126+
/bwipp.renmatrixBadExtratextxalign (extratextxalign must be offleft, left, center, right or offright) //raiseerror exec
127+
} if
128+
129+
<< /above dup /top dup /center dup /bottom dup /below dup >> extratextyalign known not {
130+
/bwipp.renmatrixBadExtratextyalign (extratextyalign must be above, top, center, bottom or below) //raiseerror exec
131+
} if
132+
133+
<< /forward dup /backward dup /upward dup /downward dup >> extratextdirection known not {
134+
/bwipp.renmatrixBadExtratextdirection (extratextdirection must be forward, backward, upward or downward) //raiseerror exec
135+
} if
136+
137+
extratextsize 0 le extratextsize 25 ge or {
138+
/bwipp.renmatrixBadTextsize (extratextsize must be greater than zero and less that 25) //raiseerror exec
105139
} if
106140

107141
/xyget { pixx mul add pixs exch get} def

0 commit comments

Comments
 (0)