Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #2574

Re: wanted: kcharpath ...

Path csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Carlos <angus@quovadis.com.ar>
Newsgroups comp.lang.postscript
Subject Re: wanted: kcharpath ...
Date Wed, 18 May 2016 23:00:51 +0200
Organization A noiseless patient Spider
Lines 104
Message-ID <20160518230051.164da369@samara.DOMA> (permalink)
References <slrnnjfrfs.2bk.peter@box8.pjb.com.au>
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
Injection-Info mx02.eternal-september.org; posting-host="14ae01f255251c16afab023606f4d0b9"; logging-data="25437"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UCjDilptNOmfLxFIYRjv4ecutyT8BdKM="
X-Newsreader Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu)
Cancel-Lock sha1:Pa5v5xvLMP09JpeFf1RheNyEV8A=
Xref csiph.com comp.lang.postscript:2574

Show key headers only | View raw


[Peter Billam <peter@www.pjb.com.au>, 2016-05-15 03:33]
> Greetings.  OK; so we have show and kshow...
>   (a string) show
>   { -2 0 rmoveto } (a string) kshow
> 
> and we have charpath ...
>   gsave (a string) true charpath clip do_something_colourful grestore
> 
> but I haven't spotted its kerning equivalent :-(
>   gsave { -2 0 rmoveto } (a string) true kcharpath
>   clip do_something_colourful grestore
> 
> Is there another way to do this, like using cshow or something ?
> Should I write kcharpath myself, looping along the string with `get`
> and `charpath` and invoking proc ?  Has it been written already ?
> 
> Thanks, regards,
> Peter
> 
> P.S. hope I got the code right ...

This one uses cshow. It's certainly longer (and messier), but in case
you use composite fonts...

The proc gets the current and next character *names* (not codes) in the
stack. Also, currentfont returns the current char's font, and nextfont
the next char's.

% proc string bool --
/kcharpath {
    1 index length 0 gt {
        8 dict begin
            { bool str proc } { exch def } forall % nice!
            /oldfont currentfont def
            % accumulate char info: [ dx dy code name font ]
            /chars [ {
                3 -1 roll  dup  currentfont /Encoding get exch get  currentfont
                5 array astore
            } str cshow ] def
            /s 1 string def
            /curchar chars 0 get def
            curchar 4 get setfont  s 0 curchar 2 get put
            currentpoint
            s bool charpath
            moveto  curchar 0 get  curchar 1 get  rmoveto
            1 1 chars length 1 sub {
                dup  /curchar chars 3 -1 roll 1 sub get  def
                /nextchar chars 3 -1 roll get def
                % change 3's to 2's if you want the proc to get char *codes*:
                curchar 3 get  nextchar 3 get
                [
                    /nextfont nextchar 4 get /def cvx
                    /proc load /exec cvx
                    currentdict /begin cvx
                ] end cvx exec  % nicer!
                nextchar 4 get setfont  s 0 nextchar 2 get put
                currentpoint
                s bool charpath
                moveto  nextchar 0 get  nextchar 1 get  rmoveto
            } for
            oldfont setfont
        end
        currentdict /nextfont undef
    } { pop pop pop } ifelse
} def


(some good ideas stolen from luser--droog's solution)

Demo:

/ASCIISmallCaps <<
    /FontType 0
    /FontMatrix [ 1 0 0 1 0 0 ]
    /FMapType 6
    /SubsVector <00 61 1a>
    /Encoding [ 0 1 2 ]
    /FDepVector [
        /Times-Roman findfont
        /Times-SC /Times-Roman findfont dup length dict copy
          dup /FontName /Times-SC put
          dup /Encoding [ 65 1 90 {
                              1 string dup 0  4 -1 roll put  cvn
                          } for
                        ] put
          definefont 0.8 scalefont
        /Times-end /Times-Roman findfont dup length dict copy
          dup /FontName /Times-end put
          dup /Encoding [ /bracketleft /bar /bracketright
                          /tilde /.notdef ] put
          definefont
    ]
>> definefont pop

/ASCIISmallCaps 20 selectfont

100 400 moveto

{ pop pop 10 10 rmoveto } (Hello) true kcharpath stroke

showpage

-- 

Back to comp.lang.postscript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

wanted: kcharpath ... Peter Billam <peter@www.pjb.com.au> - 2016-05-15 03:33 +0000
  Re: wanted: kcharpath ... luser- -droog <mijoryx@yahoo.com> - 2016-05-15 14:16 -0700
    Re: wanted: kcharpath ... Peter Billam <peter@www.pjb.com.au> - 2016-05-16 06:51 +0000
      Re: wanted: kcharpath ... Peter Billam <peter@www.pjb.com.au> - 2016-05-18 02:01 +0000
        Re: wanted: kcharpath ... luser- -droog <mijoryx@yahoo.com> - 2016-05-17 20:41 -0700
          Re: wanted: kcharpath ... luser- -droog <mijoryx@yahoo.com> - 2016-05-17 20:44 -0700
            Re: wanted: kcharpath ... Peter Billam <peter@www.pjb.com.au> - 2016-05-18 06:59 +0000
      Re: wanted: kcharpath ... luser- -droog <mijoryx@yahoo.com> - 2016-05-18 22:29 -0700
  Re: wanted: kcharpath ... Carlos <angus@quovadis.com.ar> - 2016-05-18 23:00 +0200
    Re: wanted: kcharpath ... Peter Billam <peter@www.pjb.com.au> - 2016-05-21 02:09 +0000
      Re: wanted: kcharpath ... Peter Billam <peter@www.pjb.com.au> - 2016-05-21 03:13 +0000
      Re: wanted: kcharpath ... Carlos <angus@quovadis.com.ar> - 2016-05-22 14:20 +0200
        Re: wanted: kcharpath ... Peter Billam <peter@www.pjb.com.au> - 2016-05-29 06:24 +0000
          Re: wanted: kcharpath ... luser- -droog <mijoryx@yahoo.com> - 2016-05-28 23:43 -0700
          Re: wanted: kcharpath ... luser- -droog <mijoryx@yahoo.com> - 2016-05-29 01:10 -0700
            from image to imagemask Peter Billam <peter@www.pjb.com.au> - 2016-05-31 08:51 +0000
              Re: from image to imagemask luser- -droog <mijoryx@yahoo.com> - 2016-06-01 00:53 -0700
                Re: from image to imagemask luser- -droog <mijoryx@yahoo.com> - 2016-06-01 01:10 -0700
                Re: from image to imagemask Peter Billam <peter@www.pjb.com.au> - 2016-06-02 01:26 +0000
                Re: from image to imagemask Peter Billam <peter@www.pjb.com.au> - 2016-06-03 07:53 +0000
          Re: wanted: kcharpath ... Carlos <angus@quovadis.com.ar> - 2016-06-03 14:38 +0200
            Re: wanted: kcharpath ... Peter Billam <peter@www.pjb.com.au> - 2016-06-06 02:43 +0000
              Re: wanted: kcharpath ... Carlos <angus@quovadis.com.ar> - 2016-06-06 07:53 +0200

csiph-web