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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

right aligning(justifying) a string 1

Status
Not open for further replies.

Nahkis

Programmer
Apr 27, 2004
2
0
0
CH
I have a system where a localized string is inserted into a "tag" in a vanilla ps-file and run through a preprocessor. The output is captured and printed as a batch job later.

My problem is that most of the strings assigned are different lenght for different languages and I can only align the left side of the strings. When I align the right side of the strings they don't stay inside the bounding box box.

I have made the vanilla ps. template with a program and just replaced the texts inside with tags for the pre-processor.

I have tried to find a simple answer from PS cookbook and the net, but haven't found any simple enough answer to my limited brainpower.

here's a small snip of one template. the tag is {LBL1}

/_Helvetica 9 tfn
({LBL1}) 138.148 753.803 tpt
T
[1 0 0 1 333.3 -336.6] e
120.412 751.895 -6.78653 761.948 tbx
0 tal
10 tld

The text to be assigned to LBL1 should stop at position xxx and "expand" to left not right.

I really don't know PS at all, I can find a specific place inside a file, and can make some adjustements and thats all.

What I have gathered so far involves finding out the total lenght of the string, deducting that from the right most borders value and the adding that value to the leftmost borders value, move the cursor to that position and showing the string? But thats just the metacode...

I was hoping there would be a readymade way to make it happen, like clicking a button in wordprocessor :)

any assitance more than welcome.
 
Nope, there is no easy way. You have to do it the hard way. That's the number one gripe of PostScript newbies. But it allows for infinite flexibility, which is what hardcore programmers want.

You said:

What I have gathered so far involves finding out the total lenght of the string, deducting that from the right most borders value and the adding that value to the leftmost borders value, move the cursor to that position and showing the string?

Not quite. Almost.

1) Find the distance the string would move the currentpoint. (Call this the "width" of the string).

2) Determine where you want the string to "end".

3) Subtract the width from step 1 from the value of step 2.

4) That's where you start the string.

We're also assuming of course that you know the "y" value as well.

Here's a code snippet:

Code:
/rightMargin 576 def
/yPosition 400 def

/myString (Once upon a time) def

myString dup stringwidth pop   % width of string
rightMargin exch sub           % subtract from margin
yPosition moveto show          % position, show



Thomas D. Greer
Providing PostScript & PDF
Training, Development & Consulting
 
Thanks, in fact the code is simpler than I thought it would be. Now I'll try to convert it to a function :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top