Postscript: combine two lines?

How to combine two lines in Postscript?

(foo) (bar) ??? -> (foobar) 
+4
source share
3 answers

PostScript does not have a built-in string concatenation operator. To do this, you need to write code. See http://en.wikibooks.org/wiki/PostScript_FAQ#How_to_concatenate_strings.3F , for example.

(mh update: copied here)

  /concatstrings % (a) (b) -> (ab) { exch dup length 2 index length add string dup dup 4 2 roll copy length 4 -1 roll putinterval } bind def 
+5
source

The same idea is generalized to any number of lines. In earlier versions, the acat helper function is acat , which takes an array of strings (for the convenience of counting and iteration). This version uses more complex loops and stack manipulations to avoid array allocation. This version also concatenates arrays by changing the string operator to array .

 % (s1) (s2) (s3) ... (sN) n ncat (s1s2s3...sN) /ncat { % s1 s2 s3 .. sN n % first sum the lengths dup 1 add % s1 s2 s3 .. sN n n+1 copy % s1 s2 s3 .. sN n s1 s2 s3 .. sN n 0 exch % s1 s2 s3 .. sN n s1 s2 s3 .. sN 0 n { exch length add } repeat % s1 s2 s3 .. sN n len % then allocate string string exch % s1 s2 s3 .. sN str n 0 exch % s1 s2 s3 .. sN str off n -1 1 { % s1 s2 s3 .. sN str off n % copy each string 2 add -1 roll % s2 s3 .. sN str off s1 % bottom to top 3 copy putinterval % s2 s3 .. sN str' off s1 length add % s2 s3 .. sN str' off+len(s1) % s2 s3 .. sN str' off' } for % str' off' pop % str' } def (abc) (def) (ghi) (jkl) 4 ncat == %(abcdefghijkl) 
+4
source

IN

There are useful routines.

http://www.jdawiseman.com/papers/placemat/placemat.ps

including Concatenate (accepting two strings) and ConcatenateToMark (tick string0 string1 ...).

+3
source

Source: https://habr.com/ru/post/1433674/


All Articles