Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #3504 > unrolled thread
| Started by | news@zzo38computer.org.invalid |
|---|---|
| First post | 2020-04-14 16:17 -0700 |
| Last post | 2020-04-16 23:02 -0700 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.postscript
Some general purpose PostScript procedures - multiget scanpath straccum strfinish news@zzo38computer.org.invalid - 2020-04-14 16:17 -0700
Re: Some general purpose PostScript procedures - multiget scanpath straccum strfinish luser droog <luser.droog@gmail.com> - 2020-04-14 22:30 -0700
Re: Some general purpose PostScript procedures - multiget scanpath straccum strfinish luser droog <luser.droog@gmail.com> - 2020-04-16 23:02 -0700
| From | news@zzo38computer.org.invalid |
|---|---|
| Date | 2020-04-14 16:17 -0700 |
| Subject | Some general purpose PostScript procedures - multiget scanpath straccum strfinish |
| Message-ID | <1586905414.bystand@zzo38computer.org> |
As part of TeXnicard, I wrote many PostScript procedures. Many of them are
not usable outside of TeXnicard, but a few of them are. Maybe you might
find some of them useful; I don't know. But I found it useful.
The multiget procedure is used to retrieve multiple entries from a
dictionary, and put them into an array. It might be useful with
writeobject or with some other things too. (Unfortunately, this
implementation does not work with objects other than dictionaries, since
known is only compatible with dictionaries.)
/multiget { %( dict array -- array )
<< >> begin
exch /A exch def
/B 1 index length def
{
A 1 index known {
A exch get
} {
pop null
} ifelse
} forall
B array astore
end
} bind def
The straccum and strfinish procedures are used for string accumulation.
You can write data into the file to result a string with all of the data
that has been accumulated.
/_straccum [null] def
/straccum { %( -- file )
[<< /N 0 /T 0 >> {
begin {
dup length 0 eq {
pop
} {
/T 1 index length T add def
N exch def
/N N 1 add def
} ifelse
1024 string
} {
//_straccum 0 currentdict put
N exch def
()
} ifelse end
} //systemdict /exec get] cvx /NullEncode filter
} bind def
/strfinish { %( file -- string )
closefile //_straccum 0 get //_straccum 0 null put
begin
/S T N load length add string def 0
0 1 N {
load
S 2 index 2 index putinterval
length add
} for
pop S end
} bind def
currentdict /_straccum undef
The scanpath procedure is used to convert a monotone path into an array
to find the left and right boundary per scanline. Some algorithms may use
this for something, such as typesetting text into an area of some shape
that isn't rectangular.
/scanpath { %( -- array )
gsave [
matrix setmatrix initclip clip
pathbbox cvi exch pop exch cvi 3 -1 roll pop
dup 1 3 index {
clipsave
0 exch 65535 1 rectclip
clippath pathbbox pop exch pop
cvi exch cvi
cliprestore
} for
] grestore
} bind def
All of these codes are public domain.
You can also mention comment if you have a use for it, improvements of it,
complaints, questions, and/or other comments, please.
--
This signature intentionally left blank.
(But if it has these words, then actually it isn't blank, isn't it?)
[toc] | [next] | [standalone]
| From | luser droog <luser.droog@gmail.com> |
|---|---|
| Date | 2020-04-14 22:30 -0700 |
| Message-ID | <0d5b203a-884d-4752-95c3-9e5ce46197dd@googlegroups.com> |
| In reply to | #3504 |
On Tuesday, April 14, 2020 at 6:17:41 PM UTC-5, ne...@zzo38computer.org.invalid wrote:
> As part of TeXnicard, I wrote many PostScript procedures. Many of them are
> not usable outside of TeXnicard, but a few of them are. Maybe you might
> find some of them useful; I don't know. But I found it useful.
>
> The multiget procedure is used to retrieve multiple entries from a
> dictionary, and put them into an array. It might be useful with
> writeobject or with some other things too. (Unfortunately, this
> implementation does not work with objects other than dictionaries, since
> known is only compatible with dictionaries.)
>
> /multiget { %( dict array -- array )
> << >> begin
> exch /A exch def
> /B 1 index length def
> {
> A 1 index known {
> A exch get
> } {
> pop null
> } ifelse
> } forall
> B array astore
> end
> } bind def
>
Interesting stuff. I came up with a shorter version of this which doesn't
need a local dict. But it doesn't work with bind since it modifies the
internal proc.
/map { [ 3 1 roll forall ] } def
/mg {
{ DICT exch { get } stopped { pop pop null } if }
dup 0 5 -1 roll put map
} def
[toc] | [prev] | [next] | [standalone]
| From | luser droog <luser.droog@gmail.com> |
|---|---|
| Date | 2020-04-16 23:02 -0700 |
| Message-ID | <b6d38855-707a-422a-a1ce-c0795f4bc40c@googlegroups.com> |
| In reply to | #3505 |
On Wednesday, April 15, 2020 at 12:30:27 AM UTC-5, luser droog wrote:
> On Tuesday, April 14, 2020 at 6:17:41 PM UTC-5, ne...@zzo38computer.org.invalid wrote:
> > As part of TeXnicard, I wrote many PostScript procedures. Many of them are
> > not usable outside of TeXnicard, but a few of them are. Maybe you might
> > find some of them useful; I don't know. But I found it useful.
> >
> > The multiget procedure is used to retrieve multiple entries from a
> > dictionary, and put them into an array. It might be useful with
> > writeobject or with some other things too. (Unfortunately, this
> > implementation does not work with objects other than dictionaries, since
> > known is only compatible with dictionaries.)
> >
> > /multiget { %( dict array -- array )
> > << >> begin
> > exch /A exch def
> > /B 1 index length def
> > {
> > A 1 index known {
> > A exch get
> > } {
> > pop null
> > } ifelse
> > } forall
> > B array astore
> > end
> > } bind def
> >
>
> Interesting stuff. I came up with a shorter version of this which doesn't
> need a local dict. But it doesn't work with bind since it modifies the
> internal proc.
>
> /map { [ 3 1 roll forall ] } def
> /mg {
> { DICT exch { get } stopped { pop pop null } if }
> dup 0 5 -1 roll put map
> } def
I got it to work with bind. Gotta curry a new array instead of modifying.
/mg { % dict [keys] - [values]
exch
{ exch { get } stopped { pop pop null } if }
/exec cvx
3 array astore cvx
map
} bind def
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.postscript
csiph-web