🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #5964

Re: Justifying strings, how??

#5964
From: Henry McGilton
Date: Thu, 17 Dec 1992 01:11
71 lines
2847 bytes
In article <MEYER.92Dec16131125@ibsen.geomatic.no>  writes:
    *  I want to be able to justify strings; left, right and middle. How can
    *  I do this when almost all PostScript fonts are non-fixed fonts? How do
    *  I calculate where to put the string???
    *  Anybody have a piece of code, or a general idea of how to do this?
These kinds of calculations are trivially easy for the trivially
easy cases.  Following is some PostScript code taken from Chapter
3 of ``PostScript by Example'' by Mary Campione and Henry McGilton,
published by Addison-Wesley.  More fun starts when the strings to be
justfified are in multiple fonts -- we also discuss this case.

	........  Henry

Here cometh the code:
%!PS

%	This example appears in section "Justification Operations"
%	in Chapter 3 - "Text".
%

/inch { 72 mul } def		%  define inch procedure
/Palatino-Roman findfont	%  obtain font
1 inch scalefont		%  scale font to required size
setfont				%  set into graphics state
0.5 inch 5.5 inch moveto	%  set current point
(Left Text) show		%  show the string
showpage			%  display page

%!PS
%	This example appears in section "Justification Operations"
%	in Chapter 3 - "Text".
%

/inch { 72 mul } def		%  define inch procedure

/center_show {			%  stack =  x  y  (string)
	dup			%  make copy of string
	stringwidth pop 2 div	%  compute half string width
	4 -1 roll exch sub	%  decrement x position
	3 -1 roll moveto	%  set current point
	show			%  image string
} def

/Palatino-Roman findfont	%  obtain font
1 inch scalefont		%  scale font to required size
setfont				%  set into graphics state
4.25 inch 5.5 inch		%  current point
(Centered Text) center_show	%  show in middle of page
showpage			%  display page
%!PS

%	This example appears in section "Justification Operations"
%	in Chapter 3 - "Text".
%

/inch { 72 mul } def		%  define inch procedure

/right_show {			%  stack = x  y  (string)
	dup			%  make copy of string
	stringwidth pop		%  compute string width
	4 -1 roll exch sub	%  decrement x position
	3 -1 roll moveto	%  set current point
	show			%  display the string
} def

/Palatino-Roman findfont	%  obtain font
1 inch scalefont		%  scale font to required size
setfont				%  set into graphics state
8 inch 5.5 inch			%  current point
(Right Text) right_show		%  show string at right of page
showpage			%  display page
Technical Details
Message-ID: <1992Dec17.011125.8658@trilithon.mpk.ca.us>
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!umn.edu!csus.edu!netcom.com!netcomsv!trilithon!henry
References: <MEYER.92Dec16131125@ibsen.geomatic.no>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.postscript
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!umn.edu!csus.edu!netcom.com!netcomsv!trilithon!henry
From: henry@trilithon.mpk.ca.us (Henry McGilton)
Subject: Re: Justifying strings, how??
Message-ID: <1992Dec17.011125.8658@trilithon.mpk.ca.us>
Sender: henry@trilithon.mpk.ca.us
Organization: Trilithon Software
References: <MEYER.92Dec16131125@ibsen.geomatic.no>
Date: Thu, 17 Dec 1992 01:11:25 GMT
Lines: 71