Skip to main content
Participant
August 4, 2011
Question

How to change setlinewidth on a given page?

  • August 4, 2011
  • 1 reply
  • 1403 views

We have our PostScript printer driver send a text file with some extra instructions. Among other things, this file establishes a custom "6 setlinewidth" mainly for fractional divider lines. The custom value is apparently reset to the default value of 1 with each new page, which is convenient. However, on some pages with such a line we also wish a character to be drawn. The strokes used in drawing the character on those pages are set at a width of 6, which is too black and too blurry for a character. The PS default setting of 1 would be appropriate, and we can see that it is so on pages that don't have horizontal lines. The wordprocessing program allows printer commands and files to be sent anywhere on the page. My approach to getting a drawn character of default thickness was to insert the command before the character and, if need be for further lines on the page, after it. But a printer command of "1 setlinewidth" (or any other value) results merely in a gap being left for the character. What PS code will tell the character to be printed in the space left for it?

What doesn't work is inserting 2 simple PS files in the file that is to be printed. I inserted a file with this content "gsave | 1 setlinewidth" immediately before the font that is to invoke the character to be drawn, and a file with "grestore" immediately after the code for the character. The resulting printout or the PDF always has an adequate space for the character but never prints it.
/Plantin-BoldR 450 _ff
end end save 1200 72 div dup scale
gsave
1 setlinewidth
restore wpdict begin wpdict2 begin
/TimesNRGreekMT-BoldInclinedR 450 _ff
3114 5216 _m
end end save 1200 72 div dup scale
grestore
restore wpdict begin wpdict2 begin
3164 5216 _m
/Plantin-BoldR 550 _ff
It's the same white gap if I simply send the command "1 setlinewidth" before the switch to TimesNRGreekMT-BoldInclinedR. What can be preventing the character to be drawn when setlinewidth is inserted? There are several setlinewidth commands in the file, but "6 setlinewidth" is left operable at this point.

This topic has been closed for replies.

1 reply

Lyulph1Author
Participant
August 5, 2011

The solution was simple but took hours to find. In our text file of extra PS instructions, inserted into the PS file, we have a definition for a line that needs to vary in length depending on the width of numerators and denominators:

/BRline {
6 setlinewidth
0 exch rmoveto
0 rlineto stroke
} bind def

To reset the default of 0 for setlinewidth, all that was required was

0 setlinewidth

inserted just before the last line. Apparently that allows the line to be drawn followed by a reset of setlinewidth.

Mr__Horton
Inspiring
August 9, 2011

You might consider using the following method instead of "hardcoding" a default value of 0 for "setlinewidth" just in case the default changes to something other than 0. This should be much less processing overhead than using gsave and grestore.:

/BRline {

%% First get the current/default linewidth and store it in PREVlinewidth  before making any changes with setlinewidth.

currentlinewidth /PREVlinewidth exch def

6 setlinewidth
0 exch rmoveto
0 rlineto stroke

%% Now change setlinewidth back to its previous/default value with PREVlinewidth, whatever it was before BRline was run.

PREVlinewidth setlinewidth

} def

Also, I noticed the use of restore's in your original post but their corresponding save's were not visible, but I would guess the issue you were having was being overridden by the restore's and the position relative to your instructions.

- Marvin

Lyulph1Author
Participant
August 10, 2011

Thank you, Marvin. I've tested and adopted your improvement. There are in fact quite a number of changes in setlinewidth in the file (program?), and this will protect them.

I didn't know what I was doing with gsave and grestore, and then found they weren't needed in restoring the default setlinewidth in the definition of BRline.