Path: csiph.com!aioe.org!.POSTED.iSqskUzK2KPWtZfZ6bkvfw.user.gioia.aioe.org!not-for-mail From: news@zzo38computer.org.invalid Newsgroups: comp.lang.postscript Subject: Some general purpose PostScript procedures - multiget scanpath straccum strfinish Date: Tue, 14 Apr 2020 16:17:12 -0700 Organization: Aioe.org NNTP Server Lines: 91 Message-ID: <1586905414.bystand@zzo38computer.org> NNTP-Posting-Host: iSqskUzK2KPWtZfZ6bkvfw.user.gioia.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: bystand/1.1.1 X-Notice: Filtered by postfilter v. 0.9.2 Xref: csiph.com comp.lang.postscript:3504 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?)