• Some general purpose PostScript procedures - multiget scanpath straccum

    From news@zzo38computer.org.invalid@21:1/5 to All on Tue Apr 14 16:17:12 2020
    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?)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From luser droog@21:1/5 to ne...@zzo38computer.org.invalid on Tue Apr 14 22:30:26 2020
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From luser droog@21:1/5 to luser droog on Thu Apr 16 23:02:14 2020
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)