Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8571145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:43:08+00:00 2026-06-11T18:43:08+00:00

Justifying a line in PostScript is possible by calculating the SpaceMod and using widthhow

  • 0

Justifying a line in PostScript is possible by calculating the SpaceMod and using widthhow:

/SpaceMod % calculated from line width and stringwidth
/h { 0 32 } def 

/Times-Roman findfont
14 scalefont setfont    
SpaceMod h (This line with single font is justified) widthshow

But how can we use this method for a line with different fonts? A simple example is to have a bold part in the line as

/Times-Roman findfont
14 scalefont setfont    
X h (How to) widthshow

/Times-Roman-Bold findfont
14 scalefont setfont    
X h justify this line) widthshow

/Times-Roman findfont
14 scalefont setfont    
X h (with multi fonts) widthshow

The problem is that we do not have a single string for the entire line to fetch stringwidth. Even if calculating it based on individual strings, how we can calculate/set SpaceMod?

Or we need to use another approach for justification of line with multi-fonts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:43:09+00:00Added an answer on June 11, 2026 at 6:43 pm

    Brute force..

    /justifyshow {
        /linerem exch def
        dup length 3 idiv /nsub exch def
        /instring exch def
        instring aload pop
        /spct 0 def
        /setf {3 2 roll findfont 3 2 roll scalefont setfont } def
        nsub {
            setf dup
            stringwidth pop linerem exch sub /linerem exch def
            {32 eq { spct 1 add /spct exch def} if } forall
             } repeat
        /addsp linerem spct div def
        instring aload pop
    %cleanup
        [ /spct /linerem /instring ] { userdict exch undef } forall
    % comment following three lines to reverse argument order
        /ct nsub def
        nsub 1 sub { ct 1 sub /ct exch def ct 1 add 3 mul  3 roll } repeat
        userdict /ct undef
    %
        nsub { setf addsp 0 32 4 -1 roll  widthshow } repeat
    } def
    % usage [ fontn sizen stringn ...  font1 size1 string1 ]
    % linewidth justifyshow
    
    100 100 moveto
    [
    /Helvetica 12 (hot to justify)
    /HelveticaBold 24 ( large bold)
    /Helvetica 12 ( in part of a line)
    ] 400 justifyshow
    

    No doubt this can be tightend up a bit..

    Edit, another take as I said tightend up a good bit.

    % count spaces in a string
    /stringspace {0 exch { 32 eq { 1 add } if}  forall} def
    % set font routine
    /setf {3 2 roll findfont 3 2 roll scalefont setfont } def
    /justifyshow {
    % def array length leave line length and array on stack
    exch dup length 3 idiv /nsub exch def
    aload pop
    % split input array into array of [ font size string ] arrays
    /incc nsub 3 mul 1 add def
    [ nsub { incc 1 roll [ 4 1 roll ] incc 3 sub /incc  exch def } repeat  ] /fstringlist exch def
    % reverse sort string order (can comment out this line if needed )
    [ nsub 1 sub -1 0 { fstringlist exch get} for ] /fstringlist exch def
    % count spaces
    0 fstringlist {aload pop 3 1 roll pop pop stringspace add } forall
    % count total line length
    0 fstringlist {aload pop setf stringwidth pop add } forall
    % at this point the target length, actuial length and space count are on the stack
    % calculate space to add
    3 -1 roll sub neg exch div /addsp exch def
    % show strings
    fstringlist { aload pop setf addsp 0 32 4 -1 roll  widthshow } forall } def
    
    100 100 moveto
    [
    /Helvetica 12 (how to justify)
    /HelveticaBold 24 ( large bold)
    /Helvetica 12 ( in part of a line)
    /Helvetica 50 ( !!!)
    ] 400
    justifyshow
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way of fully-justifying text in SQL Reporting Services? I've been searching
I would like to set a fixed width for an input textfield with an
Folks, Im considering using a microORM such as Dapper.net for the read access component
I've seen a question on justifying a 'print' right, but could I have text
I need to fire off an event, as early as possible in the dispatch
Although I have been discouraged from reading the OpenGL redbook, I am still doing
What is the best practice for right-justifying a numeric in TSQL? I have to
We know this is good to have, but I find myself justifying it to
I'm creating a Report using SQL Reporting Services and I need to justify the
I've written a Windows program in C++ which at times uses two threads: one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.