Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Carlos 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> References: 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 [Peter Billam , 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 --