Skip to content

Commit da3b128

Browse files
committed
Move alias table and handing into processoption.apply
1 parent 833c71d commit da3b128

7 files changed

Lines changed: 76 additions & 246 deletions

File tree

CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2026-03-30
2+
3+
* Alias option handling was simplified and improved.
4+
5+
16
2026-03-29
27

38
* The text rendering system was generalised to support up to 9 independent text groups. The existing text and extratext options are retained as aliases.

src/processoptions.ps.src

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,36 @@ begin
5454
/integertype { dup cvr dup cvi ne {dup not} if cvi } bind % Force type error when precision is lost or boolean is given
5555
>> readonly def
5656

57+
% Alias maps: old option names => canonical names
58+
/processoptions.aliases <<
59+
(alttext) /text1
60+
(alttextsubspace) /text1subspace
61+
(alttextsplit) /text1split
62+
(textlinegaps) /text1linegaps
63+
(textcolor) /text1color
64+
(textxalign) /text1xalign
65+
(textyalign) /text1yalign
66+
(textdirection) /text1direction
67+
(textfont) /text1font
68+
(textsize) /text1size
69+
(textxoffset) /text1xoffset
70+
(textyoffset) /text1yoffset
71+
(textgaps) /text1gaps
72+
(extratext) /text2
73+
(extratextsubspace) /text2subspace
74+
(extratextsplit) /text2split
75+
(extratextlinegaps) /text2linegaps
76+
(extratextcolor) /text2color
77+
(extratextxalign) /text2xalign
78+
(extratextyalign) /text2yalign
79+
(extratextdirection) /text2direction
80+
(extratextfont) /text2font
81+
(extratextsize) /text2size
82+
(extratextxoffset) /text2xoffset
83+
(extratextyoffset) /text2yoffset
84+
(extratextgaps) /text2gaps
85+
>> readonly def
86+
5787
/processoptions.apply {
5888

5989
%
@@ -71,11 +101,20 @@ begin
71101
} if
72102

73103
%
74-
% Apply options that exist in currentdict, converting values to existing types
104+
% Apply options that exist in currentdict, converting values to existing types.
105+
% Unknown options are checked against the alias map and applied to the canonical name.
75106
%
76107
mark exch dup
77108
{
78-
exch dup currentdict exch known {
109+
exch dup currentdict exch known not { % Not known, but we might have been given an alias
110+
//processoptions.aliases 1 index 2 copy known {
111+
get dup 4 index exch known not { exch } if % Replace alias key with canonical, if no clash
112+
pop
113+
} {
114+
pop pop
115+
} ifelse
116+
} if
117+
dup currentdict exch known {
79118
dup load type 3 -1 roll exch
80119
//processoptions.typemap exch get stopped {
81120
pop pop
@@ -198,34 +237,13 @@ begin
198237

199238
} bind def
200239

201-
%
202-
% Resolve alias options: for each alias in the table, if the user set
203-
% the alias in their options dict, copy the value to the primary name.
204-
% User-set primary always wins.
205-
%
206-
/processoptions.resolve { % optionsdict aliastable --
207-
{ % optdict alias-key primary-name
208-
2 index 1 index known { % user set primary? => primary wins
209-
pop pop
210-
} {
211-
2 index 2 index known { % user set alias in options?
212-
exch load def % copy alias value to primary
213-
} {
214-
pop pop
215-
} ifelse
216-
} ifelse
217-
} forall
218-
pop % optdict
219-
} bind def
220-
221240
%
222241
% Dispatcher table
223242
%
224243
/processoptions.dispatch <<
225244
/apply //processoptions.apply
226245
/generategroup //processoptions.generate
227246
/collectgroup //processoptions.collect
228-
/resolve //processoptions.resolve
229247
>> readonly def
230248

231249
/processoptions {

src/rendertext.ps.src

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -92,40 +92,6 @@ begin
9292
(gaps) 0.0
9393
>> readonly def
9494

95-
% Alias mapping: old text1 option names => new primary names
96-
/rendertext.text1aliases <<
97-
(alttext) /text1
98-
(alttextsubspace) /text1subspace
99-
(alttextsplit) /text1split
100-
(textlinegaps) /text1linegaps
101-
(textcolor) /text1color
102-
(textxalign) /text1xalign
103-
(textyalign) /text1yalign
104-
(textdirection) /text1direction
105-
(textfont) /text1font
106-
(textsize) /text1size
107-
(textxoffset) /text1xoffset
108-
(textyoffset) /text1yoffset
109-
(textgaps) /text1gaps
110-
>> readonly def
111-
112-
% Alias mapping: old text2/extratext names => new primary names
113-
/rendertext.text2aliases <<
114-
(extratext) /text2
115-
(extratextsubspace) /text2subspace
116-
(extratextsplit) /text2split
117-
(extratextlinegaps) /text2linegaps
118-
(extratextcolor) /text2color
119-
(extratextxalign) /text2xalign
120-
(extratextyalign) /text2yalign
121-
(extratextdirection) /text2direction
122-
(extratextfont) /text2font
123-
(extratextsize) /text2size
124-
(extratextxoffset) /text2xoffset
125-
(extratextyoffset) /text2yoffset
126-
(extratextgaps) /text2gaps
127-
>> readonly def
128-
12995
% Validation dicts
13096
/rendertext.xalignopts <<
13197
/offleft dup /left dup /center dup /right dup /offright dup /justify dup
@@ -139,14 +105,6 @@ begin
139105
/forward dup /backward dup /upward dup /downward dup
140106
>> readonly def
141107

142-
%
143-
% Resolve text1 and text2 aliases after processoptions
144-
%
145-
/rendertext.resolvealiases { % optionsdict --
146-
dup //rendertext.text1aliases /resolve //processoptions exec
147-
//rendertext.text2aliases /resolve //processoptions exec
148-
} bind def
149-
150108
%
151109
% Validate a single text option dict
152110
%
@@ -448,7 +406,6 @@ begin
448406
/groupoptions //rendertext.groupoptions
449407
/render //rendertext.render
450408
/validateoptions //rendertext.validateoptions
451-
/resolvealiases //rendertext.resolvealiases
452409
>> readonly def
453410

454411
/rendertext {

src/renlinear.ps.src

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -64,35 +64,6 @@ begin
6464
/text1xalign (unset) def
6565
/text1yalign (unset) def
6666

67-
% text1 aliases
68-
/textcolor (unset) def
69-
/textxalign (unset) def
70-
/textyalign (unset) def
71-
/textdirection (forward) def
72-
/textfont (Courier) def
73-
/textsize 10.0 def
74-
/textxoffset 0.0 def
75-
/textyoffset 0.0 def
76-
/textgaps 0.0 def
77-
/textlinegaps 1.2 def
78-
/alttext () def
79-
/alttextsubspace () def % Misnomer
80-
/alttextsplit () def % Misnomer
81-
82-
% text2 aliases
83-
/extratext () def
84-
/extratextcolor (unset) def
85-
/extratextxalign (left) def
86-
/extratextyalign (above) def
87-
/extratextdirection (forward) def
88-
/extratextfont (Courier) def
89-
/extratextsize 10.0 def
90-
/extratextxoffset 0.0 def
91-
/extratextyoffset 0.0 def
92-
/extratextgaps 0.0 def
93-
/extratextlinegaps 1.2 def
94-
/extratextsubspace () def
95-
/extratextsplit () def
9667

9768
/includetext false def
9869
/barcolor (unset) def
@@ -121,7 +92,6 @@ begin
12192
opt currentdict /opt undef /apply //processoptions exec /options exch def
12293

12394
% Resolve text aliases: alttext=>text1, extratext=>text2
124-
options /resolvealiases //rendertext exec
12595

12696
% Collect into an text options array
12797
/textopts (text) 9 /groupoptions //rendertext exec /collectgroup //processoptions exec def

src/renmatrix.ps.src

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -158,36 +158,6 @@ begin
158158
/text1xalign (unset) def
159159
/text1yalign (unset) def
160160

161-
% text1 aliases
162-
/textcolor (unset) def
163-
/textxalign (unset) def
164-
/textyalign (unset) def
165-
/textdirection (forward) def
166-
/textfont (Courier) def
167-
/textsize 10.0 def
168-
/textxoffset 0.0 def
169-
/textyoffset 0.0 def
170-
/textgaps 0.0 def
171-
/textlinegaps 1.2 def
172-
/alttext () def
173-
/alttextsubspace () def % Misnomer
174-
/alttextsplit () def % Misnomer
175-
176-
% text2 aliases
177-
/extratext () def
178-
/extratextcolor (unset) def
179-
/extratextxalign (left) def
180-
/extratextyalign (above) def
181-
/extratextdirection (forward) def
182-
/extratextfont (Courier) def
183-
/extratextsize 10.0 def
184-
/extratextxoffset 0.0 def
185-
/extratextyoffset 0.0 def
186-
/extratextgaps 0.0 def
187-
/extratextlinegaps 1.2 def
188-
/extratextsubspace () def
189-
/extratextsplit () def
190-
191161
/includetext false def
192162
/showborder false def
193163
/borderleft 0.0 def
@@ -200,7 +170,6 @@ begin
200170
opt currentdict /opt undef /apply //processoptions exec /options exch def
201171

202172
% Resolve text aliases: alttext=>text1, extratext=>text2
203-
options /resolvealiases //rendertext exec
204173

205174
inkspread null eq {
206175
/uk.co.terryburton.bwipp.global_ctx dup where {

tests/ps_tests/processoptions.ps.test

Lines changed: 21 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@
1818
/boolopt false def
1919
/intopt 0 def
2020
/realopt 0.0 def
21+
/text1 () def
22+
/text1font (Courier) def
23+
/text1size 10.0 def
24+
/text1xoffset 0.0 def
25+
/text1yoffset 0.0 def
26+
/text1xalign (left) def
27+
/text2 () def
28+
/text2font (Courier) def
2129
} def
2230

2331
/ok_apply {
24-
{ 10 dict begin setup 0 exec end }
32+
{ 50 dict begin setup 0 exec end }
2533
dup 3 -1 roll 4 exch put
2634
true isEqual
2735
} def
@@ -260,110 +268,36 @@
260268

261269

262270
%
263-
% resolve: alias copied to primary when only alias set
271+
% apply: alias resolved to canonical name
264272
%
265-
{
266-
50 dict begin
267-
/primary () def
268-
/alias (value) def
269-
<< (alias) (value) >> << /alias /primary >> /resolve processoptions
270-
primary
271-
end
272-
} (value) isEqual
273+
{ (textfont=Helvetica) /apply processoptions pop text1font (Helvetica) eq } ok_apply
273274

274275

275276
%
276-
% resolve: primary wins when both set
277+
% apply: canonical name wins over alias
277278
%
278-
{
279-
50 dict begin
280-
/primary (winner) def
281-
/alias (loser) def
282-
<< (alias) (loser) (primary) (winner) >> << /alias /primary >> /resolve processoptions
283-
primary
284-
end
285-
} (winner) isEqual
279+
{ (text1font=Courier textfont=Helvetica) /apply processoptions pop text1font (Courier) eq } ok_apply
286280

287281

288282
%
289-
% resolve: no-op when alias not set
283+
% apply: alias not applied when canonical not in currentdict
290284
%
291-
{
292-
50 dict begin
293-
/primary (original) def
294-
/alias () def
295-
<< >> << /alias /primary >> /resolve processoptions
296-
primary
297-
end
298-
} (original) isEqual
285+
{ (textfont=Helvetica) /apply processoptions pop true } ok_apply
299286

300287

301288
%
302-
% resolve: no-op when neither changed (same defaults)
289+
% apply: text1 alias for alttext
303290
%
304-
{
305-
50 dict begin
306-
/primary (default) def
307-
/alias (default) def
308-
<< >> << /alias /primary >> /resolve processoptions
309-
primary
310-
end
311-
} (default) isEqual
291+
{ (alttext=HELLO) /apply processoptions pop text1 (HELLO) eq } ok_apply
312292

313293

314294
%
315-
% resolve: multiple aliases in one table
295+
% apply: text2 alias for extratext
316296
%
317-
{
318-
50 dict begin
319-
/p1 () def /p2 (Courier) def /p3 0.0 def
320-
/a1 (hello) def /a2 (Helvetica) def /a3 5.0 def
321-
<< (a1) (hello) (a2) (Helvetica) (a3) 5.0 >>
322-
<< /a1 /p1 /a2 /p2 /a3 /p3 >> /resolve processoptions
323-
p1 p2 p3
324-
3 array astore
325-
end
326-
} [(hello) (Helvetica) 5.0] isEqual
297+
{ (extratext=WORLD) /apply processoptions pop text2 (WORLD) eq } ok_apply
327298

328299

329300
%
330-
% resolve: real-valued alias
301+
% apply: real-typed alias
331302
%
332-
{
333-
50 dict begin
334-
/textsize 10.0 def
335-
/text1size 10.0 def
336-
/textsize 14.0 def
337-
<< (textsize) 14.0 >> << /textsize /text1size >> /resolve processoptions
338-
text1size
339-
end
340-
} 14.0 isEqual
341-
342-
343-
%
344-
% resolve: sequential tables (text1 then text2 pattern)
345-
%
346-
{
347-
50 dict begin
348-
/text1 () def /text2 () def
349-
/alttext (HELLO) def /extratext (WORLD) def
350-
<< (alttext) (HELLO) (extratext) (WORLD) >>
351-
dup << /alttext /text1 >> /resolve processoptions
352-
<< /extratext /text2 >> /resolve processoptions
353-
text1 text2
354-
2 array astore
355-
end
356-
} [(HELLO) (WORLD)] isEqual
357-
358-
359-
%
360-
% resolve: alias with name-typed value
361-
%
362-
{
363-
50 dict begin
364-
/text1xalign (left) def
365-
/textxalign /center def
366-
<< (textxalign) /center >> << /textxalign /text1xalign >> /resolve processoptions
367-
text1xalign
368-
end
369-
} /center isEqual
303+
{ (textyoffset=-5) /apply processoptions pop text1yoffset -5.0 eq } ok_apply

0 commit comments

Comments
 (0)