Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm a newbie - help on carriage return

Status
Not open for further replies.

Wolfie7873

Technical User
Jan 15, 2004
94
US
Hi,
I read the earlier posts about wrapping unknown string lengths and I understand that's an undertaking in itself.
The postscript I'm trying to write doesn't need that capability; everything will be single line strings only. What I can't seem to find in the PLRM is the proper syntax for invoking the CR (carriage return) character. I'm trying to programmatically create a ps file from an open filestream in C++. Here's a snippet what I have:

/ms {moveto show} bind def
<</PageSize[612 792]/ImagingBBox null>>setpagedevice
/Times-Roman findfont 12 scalefont setfont
/topleft {72 700} def
(This is a string of text) topleft ms
showpage

The above code works great, what I would like to do is incorporate something like:
(This is a string \CR This is also a string) topleft ms

and get the output:
This is a string
This is also a string

And, if you can't answer that one, how much space is in the leading? so I can reposition the cursor.
 
PostScript treats the CR character as whitespace. So nothing about the CR character will &quot;force&quot; a linespace.

You would have to write a procedure that will search a string for the CR character, use that to break the string into substrings, position the first substring on the first line, adjust your position, and use the last substring as the see for the next loop interation.

Leading is whatever you want to make it.

I know this sounds like a lot of work, and it is, but that's why PostScript is so flexible.

Research the following PostScript operators:

currentpoint
moveto
show
search
string
loop
ifelse
eq


Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
Ok, here's another (simple) question for you. When I move the cursor to a point to show a line of text, how is the text vertically justified relative to that point? i.e. say i have:
/ms {moveto show} bind def
/fontname findfont
12 scalefont setfont
(string goes here) 200 700 ms

does the string sit &quot;on top&quot; of the horizontal line at 700?

Thanks

Eddie Rowe

 
Yes. That's known as the &quot;baseline&quot; in terms of fonts. Most characters will sit right on top of it. Characters like &quot;p&quot; will dangle their feet over the edge.

In terms of spacing between lines, a popular convention is to use 20% of the current point size.

So if you are setting type in a 12 point font, then you could separate your lines by 14.4 points.

Here's some code for you. I'd caution you about copying and pasting it from your browser, I've noticed the forum does funny things with whitespace. The &quot;CR&quot; definition below contains exactly one carriage return and that's all.

I'd be happy to provide detailed explanations if you have any questions about what's going on.

Code:
%!PS

/CR (
) def

/ptsize 12 def
/lead ptsize 1.2 mul def
/x 36 def
/yPos 700 lead add def
/y {yPos lead sub dup /yPos exch def} bind def

/setLines
{ /workstr exch def
  
  { workstr CR search
    { x y moveto show
      pop
      /workstr exch def
    }
    { x y moveto show exit
    } ifelse
  } loop
} bind def


/Courier ptsize selectfont

(This is line one.
This is line two.
This is line three.) setLines

showpage





Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top