1 % === BEGIN ps-print prologue 1
4 % Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
5 % Free Software Foundation, Inc.
7 % This file is part of GNU Emacs.
9 % GNU Emacs is free software: you can redistribute it and/or modify
10 % it under the terms of the GNU General Public License as published by
11 % the Free Software Foundation, either version 3 of the License, or
12 % (at your option) any later version.
14 % GNU Emacs is distributed in the hope that it will be useful,
15 % but WITHOUT ANY WARRANTY; without even the implied warranty of
16 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 % GNU General Public License for more details.
19 % You should have received a copy of the GNU General Public License
20 % along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 % As a special exception, the copyright holders of this module give
23 % you permission to include the module in a Postscript file generated
24 % by Emacs or other free software together with the result of
25 % converting text to be printed, regardless of the license terms of
26 % that text, and to use under terms of your choice the page images
27 % resulting from formatting said combination. If you modify this
28 % module, you may extend this exception to your version of the module
29 % but you are not obligated to do so. If you do not wish to do so,
30 % delete this exception statement from your version.
33 % ISOLatin1Encoding stolen from ps_init.ps in GhostScript 2.6.1.4:
34 /ISOLatin1Encoding where{pop}{
35 % -- The ISO Latin-1 encoding vector isn't known, so define it.
36 % -- The first half is the same as the standard encoding,
37 % -- except for minus instead of hyphen at code 055.
39 StandardEncoding 0 45 getinterval aload pop
41 StandardEncoding 46 82 getinterval aload pop
42 %*** NOTE: the following are missing in the Adobe documentation,
43 %*** but appear in the displayed table:
44 %*** macron at 0225, dieresis at 0230, cedilla at 0233, space at 0240.
46 /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
47 /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
48 /dotlessi/grave/acute/circumflex/tilde/macron/breve/dotaccent
49 /dieresis/.notdef/ring/cedilla/.notdef/hungarumlaut/ogonek/caron
51 /space/exclamdown/cent/sterling
52 /currency/yen/brokenbar/section
53 /dieresis/copyright/ordfeminine/guillemotleft
54 /logicalnot/hyphen/registered/macron
55 /degree/plusminus/twosuperior/threesuperior
56 /acute/mu/paragraph/periodcentered
57 /cedilla/onesuperior/ordmasculine/guillemotright
58 /onequarter/onehalf/threequarters/questiondown
60 /Agrave/Aacute/Acircumflex/Atilde
61 /Adieresis/Aring/AE/Ccedilla
62 /Egrave/Eacute/Ecircumflex/Edieresis
63 /Igrave/Iacute/Icircumflex/Idieresis
64 /Eth/Ntilde/Ograve/Oacute
65 /Ocircumflex/Otilde/Odieresis/multiply
66 /Oslash/Ugrave/Uacute/Ucircumflex
67 /Udieresis/Yacute/Thorn/germandbls
69 /agrave/aacute/acircumflex/atilde
70 /adieresis/aring/ae/ccedilla
71 /egrave/eacute/ecircumflex/edieresis
72 /igrave/iacute/icircumflex/idieresis
73 /eth/ntilde/ograve/oacute
74 /ocircumflex/otilde/odieresis/divide
75 /oslash/ugrave/uacute/ucircumflex
76 /udieresis/yacute/thorn/ydieresis
80 /reencodeFontISO{ %def
82 length 12 add dict % Make a new font (a new dict the same size
83 % as the old one) with room for our new symbols.
85 begin % Make the new font the current dictionary.
87 % Copy each of the symbols from the old dictionary
88 % to the new one except for the font ID.
89 {1 index/FID ne{def}{pop pop}ifelse}forall
91 % Override the encoding with the ISOLatin1 encoding.
92 currentdict/FontType get 0 ne{/Encoding ISOLatin1Encoding def}if
94 % Use the font's bounding box to determine the ascent, descent,
95 % and overall height; don't forget that these values have to be
96 % transformed using the font's matrix.
103 % | | | | Ascent (usually > 0)
105 % (0 0) -> +--+----+-------->
107 % | | v Descent (usually < 0)
108 % (x1 y1) --> +----+ - -
110 currentdict/FontType get 0 ne
111 {/FontBBox load aload pop % -- x1 y1 x2 y2
112 FontMatrix transform/Ascent exch def pop
113 FontMatrix transform/Descent exch def pop}
114 {/PrimaryFont FDepVector 0 get def
115 PrimaryFont/FontBBox get aload pop
116 PrimaryFont/FontMatrix get transform/Ascent exch def pop
117 PrimaryFont/FontMatrix get transform/Descent exch def pop}ifelse
119 /FontHeight Ascent Descent sub def % use `sub' because descent < 0
121 % Define these in case they're not in the FontInfo
122 % (also, here they're easier to get to).
123 /UnderlinePosition Descent 0.70 mul def
124 /OverlinePosition Descent UnderlinePosition sub Ascent add def
125 /StrikeoutPosition Ascent 0.30 mul def
126 /LineThickness FontHeight 0.05 mul def
127 /Xshadow FontHeight 0.08 mul def
128 /Yshadow FontHeight -0.09 mul def
129 /SpaceBackground Descent neg UnderlinePosition add def
130 /XBox Descent neg def
131 /YBox LineThickness 0.7 mul def
133 currentdict % Leave the new font on the stack
134 end % Stop using the font as the current dictionary.
135 definefont % Put the font into the font dictionary
136 pop % Discard the returned font.
140 /DefFont{findfont exch scalefont reencodeFontISO}def
145 dup/Ascent get/Ascent exch def
146 dup/Descent get/Descent exch def
147 dup/FontHeight get/FontHeight exch def
148 dup/UnderlinePosition get/UnderlinePosition exch def
149 dup/OverlinePosition get/OverlinePosition exch def
150 dup/StrikeoutPosition get/StrikeoutPosition exch def
151 dup/LineThickness get/LineThickness exch def
152 dup/Xshadow get/Xshadow exch def
153 dup/Yshadow get/Yshadow exch def
154 dup/SpaceBackground get/SpaceBackground exch def
155 dup/XBox get/XBox exch def
156 dup/YBox get/YBox exch def
160 /FG/setrgbcolor load def
173 % | Ascent (usually > 0)
175 % | Descent (usually < 0)
179 /dobackground{ % width --
180 currentpoint % -- width x y
186 0 Descent Ascent sub rlineto % D
193 /eolbg{ % dobackground until right margin
194 PrintWidth % -- x-eol
195 currentpoint pop % -- cur-x
196 sub % -- width until eol
200 /LineHS LineHeight LineSpacing add def
201 /ParagraphHS LineHeight ParagraphSpacing add def
202 /PSL{/h exch def bg{eolbg}if 0 currentpoint exch pop h sub moveto}def
203 /PLN{PrintLineNumber{doLineNumber}if}def
205 /SL{LineHS PSL isLineStep pop}def % Soft Linefeed
207 /PHL{ParagraphHS PSL PLN}def % Paragraph Hard Linefeed
208 /LHL{LineHS PSL PLN}def % Hard Linefeed
211 /dcp{currentpoint exch 40 string cvs print(, )print =}def
212 /dp{print 2 copy exch 40 string cvs print(, )print =}def
215 ( )stringwidth % Get the width of a space in the current font.
216 pop % Discard the Y component.
217 mul % Multiply the width of a space
218 % by the number of spaces to plot
219 bg{dup dobackground}if
224 /EffectUnderline false def
225 /EffectStrikeout false def
226 /EffectOverline false def
227 /EffectShadow false def
229 /EffectOutline false def
231 % effect: 1 - underline 2 - strikeout 4 - overline
232 % 8 - shadow 16 - box 32 - outline
235 /EffectUnderline Effect 1 and 0 ne def
236 /EffectStrikeout Effect 2 and 0 ne def
237 /EffectOverline Effect 4 and 0 ne def
238 /EffectShadow Effect 8 and 0 ne def
239 /EffectBox Effect 16 and 0 ne def
240 /EffectOutline Effect 32 and 0 ne def
243 % stack: string |- --
245 /xx currentpoint dup Descent add/yy exch def
246 Ascent add/YY exch def def
247 dup stringwidth pop xx add/XX exch def
249 /yy yy Yshadow add def
250 /XX XX Xshadow add def
255 {SpaceBackground doBox}
259 EffectBox {false 0 doBox}if % box
260 EffectShadow {dup doShadow}if % shadow
262 {true doOutline} % outline
265 EffectUnderline{UnderlinePosition Hline}if % underline
266 EffectStrikeout{StrikeoutPosition Hline}if % strikeout
267 EffectOverline {OverlinePosition Hline}if % overline
270 % stack: position |- --
272 currentpoint exch pop add dup
278 LineThickness setlinewidth stroke
282 % stack: fill-or-not delta |- --
285 xx XBox sub dd sub yy YBox sub dd sub
286 XX XBox add dd add YY YBox add dd add
290 % stack: fill-or-not lower-x lower-y upper-x upper-y |- --
303 % top of stack: fill-or-not
305 {LineThickness setlinewidth stroke}ifelse
309 % stack: string |- --
312 Xshadow Yshadow rmoveto
319 % stack: string fill-or-not |- --
322 /-ox- currentpoint/-oy- exch def def
324 LineThickness setlinewidth
327 -fillp- {gsave FillBgColor grestore}if
329 -oy- add/-oy- exch def
330 -ox- add/-ox- exch def
338 /FillBgColor{bgcolor aload pop setrgbcolor fill}bind def
340 % stack: -- |- boolean
343 {PLScounter 0 gt % or zebra
344 {/PLScounter PLScounter 1 sub def PLScounter 0 eq}
347 {/PrintLineStep PrintLineStep 1 sub def}
348 {/PrintLineStep ZebraHeight def
349 /PLScounter PrintLineStart def}ifelse}
350 {LineNumber PrintLineStart sub PrintLineStep mod 0 eq}ifelse % or line step
357 isLineStep % or line step
358 LineNumber Lines ge or % or last line
361 LineNumberColor SetColor
365 {LineNumber 6 string cvs( )strcat}ifelse
366 dup stringwidth pop neg 0 rmoveto
370 /LineNumber LineNumber 1 add def
374 % stack: color-specifier |- --
375 /SetColor{dup type/realtype eq{setgray}{aload pop setrgbcolor}ifelse}def
381 /double-zebra ZebraHeight ZebraHeight add def
382 /yiter double-zebra LineHS mul neg def
383 /xiter PrintWidth InterColumn add def
384 /zebra-line LinesPrinted def
385 NumberOfColumns{LinesPerColumn doColumnZebra xiter 0 rmoveto}repeat
389 % stack: lines-per-column |- --
393 ZebraFollow 1 and 0 ne{
394 /H ZebraHeight zebra-line ZebraHeight mod sub def
396 zebra-line double-zebra mod ZebraHeight lt
397 {H doZebra % "black" stripe followed by a "white" stripe
398 /lpc lpc ZebraHeight sub def
400 {H}ifelse % "white" stripe
401 LineHS mul neg 0 exch rmoveto
402 /zebra-line zebra-line LinesPerColumn add def
405 lpc dup double-zebra idiv{ZebraHeight doZebra 0 yiter rmoveto}repeat
406 double-zebra mod dup 0 le{pop}
409 {/zspacing LineSpacing def
410 ZebraFollow 2 and 0 ne{pop ZebraHeight}if}ifelse
415 % stack: zebra-height (in lines) |- --
417 /zh exch 0.05 sub LineHS mul zspacing sub def
419 0 LineHeight 0.65 mul rmoveto
422 PrintWidth neg 0 rlineto
430 /BackgroundColor where{
431 /LHg LineHeight 0.65 mul def
432 /PHg PrintHeight LHg add def
433 pop gsave BackgroundColor SetColor
439 PrintWidth neg 0 rlineto
443 PrintWidth InterColumn add 0 rmoveto
449 % tx ty rotation xscale yscale xpos ypos BeginBackImage
451 /-save-image- save def
459 /EndBackImage{-save-image- restore}def
461 % string fontsize fontname rotation gray xpos ypos ShowBackText
467 findfont exch dup/-offset- exch -0.25 mul def scalefont setfont
469 /-saveLineThickness- LineThickness def
472 /LineThickness -saveLineThickness- def
477 BMark/PageSize[PageWidth LandscapePageHeight LandscapeMode{exch}if]EMark setpagedevice
481 % ---- Remember space width of the normal text font `f0'.
482 /SpaceWidth/f0 findfont setfont( )stringwidth pop def
483 % ---- save the state of the document (useful for ghostscript!)
485 % ---- [andrewi] set PageSize based on chosen dimensions
487 WarnPaperSize{SetPageSize}{mark{SetPageSize}stopped cleartomark}ifelse
489 /ColumnWidth PrintWidth InterColumn add def
490 % ---- define where printing will start
491 /f0 F % this installs Ascent
492 /PrintStartY PrintHeight Ascent sub def
494 /N-Up-Counter N-Up-End 1 sub def
495 /PLScounter PrintLineStart def
499 % ---- restore the state of the document (useful for ghostscript!)
504 % ---- when 1st column, save the state of the page
505 ColumnIndex 1 eq{/pageState save def}if
506 % ---- save the state of the column
507 /columnState save def
510 /PrintHeaderWidth PrintOnlyOneHeader{PrintPageWidth}{PrintWidth}ifelse def
513 /LinesPrinted exch def
514 % ---- when 1st column, print all background effects
516 0 PrintStartY moveto % move to where printing will start
519 printGlobalBackground
522 PrintOnlyOneHeader{ColumnIndex 1 eq}{true}ifelse
524 PrintHeaderFrame{HeaderFrame}if
528 PrintFooterFrame{FooterFrame}if
531 0 PrintStartY moveto % move to where printing will start
535 {/H PageNumber 1 sub NumberOfColumns mul ColumnIndex 1 sub add
536 LinesPerColumn mul ZebraHeight mod def
537 /PLScounter H PrintLineStart ge{0}{PrintLineStart H sub}ifelse def
538 /PrintLineStep ZebraHeight H sub def}if}if
542 /EndPage{bg{eolbg}if}def
545 ColumnIndex NumberOfColumns eq{
546 % ---- restore the state of the page
552 {% ---- Next page on same row
553 /N-Up-Counter N-Up-Counter 1 sub def
554 N-Up-XColumn N-Up-YColumn}
555 {% ---- Next page on next line
556 /N-Up-Counter N-Up-End 1 sub def
557 N-Up-XLine N-Up-YLine}ifelse
561 % ---- restore the state of the current column
563 % ---- and translate to the next column
564 ColumnWidth 0 translate
565 /ColumnIndex ColumnIndex 1 add def
570 LeftMargin BottomMargin
573 FooterLines FooterLineHeight mul add
578 % stack: number-of-pages-per-sheet |- --
581 /pages-per-sheet exch def
583 % ---- translate to bottom-right corner of Portrait page
585 LandscapePageHeight 0 translate
588 % ---- [jack] Kludge: my ghostscript window is 21x27.7 instead of 21x29.7
589 /JackGhostscript where{pop 1 27.7 29.7 div scale}if
590 UpsideDown{PageWidth LandscapePageHeight translate 180 rotate}if
595 PageWidth 0 translate
598 N-Up-Margin dup translate
602 /WW LandscapePageHeight def
604 /HH LandscapePageHeight def
609 /ww WW WW mul N-Up-Lines HH mul div def
610 /cc HH N-Up-Columns N-Up-Missing add div def
611 ww cc gt{/xx WW def/WW cc ww div WW mul def/xx xx WW sub def}if
613 /hh HH N-Up-Columns N-Up-Missing add div def
614 /cc HH N-Up-Lines div def
615 hh cc gt{/xx WW def/WW cc hh div WW mul def/xx xx WW sub def}if
617 WW N-Up-Margin sub N-Up-Margin sub
620 {N-Up-Columns N-Up-Missing add div WW}ifelse
622 LandscapeMode{/yy 0 def}{/yy xx def/xx 0 def}ifelse
623 xx N-Up-Repeat 1 sub LandscapePageHeight mul yy add translate
624 % ---- go to start position in page matrix
625 N-Up-XStart N-Up-Missing 0.5 mul
627 {LandscapePageHeight mul N-Up-YStart add}
628 {PageWidth mul add N-Up-YStart}ifelse
631 % ---- translate to lower left corner of TEXT
635 N-Up 1 gt N-Up-Border and pages-per-sheet 0 gt and{
639 TextStart exch neg exch neg moveto
644 0 LandscapePageHeight rlineto
645 PageWidth neg 0 rlineto
648 /pages-per-sheet pages-per-sheet 1 sub def
649 pages-per-sheet 0 le{exit}if
650 N-Up-XColumn N-Up-YColumn rmoveto
652 pages-per-sheet 0 le{exit}if
653 N-Up-XLine N-Up-XColumn sub N-Up-YLine rmoveto
664 /SetHeaderLines{ % nb-lines --
665 /HeaderLines exch def
668 HeaderLines 1 sub HeaderLineHeight mul add
669 HeaderTitleLineHeight add
671 /HeaderHeight exch def
674 /SetFooterLines{ % nb-lines --
675 /FooterLines exch def
678 FooterLines FooterLineHeight mul add
680 /FooterHeight exch def
687 % |-+-------| <-- (x y)
695 % |-+-------| <-- (0 0)
700 /HeaderFrameStart{0 PrintHeight HeaderOffset add}def
701 /FooterFrameStart{0 FooterHeight FooterOffset add neg}def
705 PrintHeaderWidth 0 rlineto
707 PrintHeaderWidth neg 0 rlineto
711 /HeaderFramePath{HeaderHeight doFramePath}def
712 /FooterFramePath{FooterHeight doFramePath}def
714 % /path-fun /start-fun vector-property doFrame
717 /startFrame exch load def
718 /pathFrame exch load def
720 vecFrame 2 get setlinewidth % frame border width
721 % ---- do the shadow of the next rectangle
725 vecFrame 4 get SetColor fill % frame shadow color
726 % ---- do the next rectangle ...
729 gsave vecFrame 1 get SetColor fill grestore % frame background
730 gsave vecFrame 3 get SetColor stroke grestore % frame border color
734 /HeaderFrame{/HeaderFramePath /HeaderFrameStart HeaderFrameProperties doFrame}def
735 /FooterFrame{/FooterFramePath /FooterFrameStart FooterFrameProperties doFrame}def
739 exch HeaderPad add exch % horizontal pad
741 HeaderPad add % vertical pad
743 HeaderLineHeight HeaderLines 1 sub mul add
748 exch FooterPad add exch % horizontal pad
750 FooterPad add % vertical pad
752 FooterLineHeight FooterLines 1 sub mul add
755 /HeaderClip{HeaderFrameStart moveto HeaderFramePath clip}def
756 /FooterClip{FooterFrameStart moveto FooterFramePath clip}def
759 dup length 3 -1 roll dup length dup 4 -1 roll add string dup
760 0 5 -1 roll putinterval
761 dup 4 2 roll exch putinterval
765 PageNumber 32 string cvs
766 ShowNofN{(/)strcat PageCount 32 string cvs strcat}if
769 % lines is-right HeaderOrFooterTextLines
770 /HeaderOrFooterTextLines{
773 { % ---- process the lines
780 PrintHeaderWidth exch sub HFPad HFPad add sub 0 rmoveto
785 0 HFLineHeight neg rmoveto
789 % right-lines left-lines /start lineheight pad fore-color HeaderOrFooterText
793 /HFLineHeight exch def
794 /HFStart exch load def
796 % -- rightLines leftLines -- at stack
798 % ---- hack: `PN 1 and' == `PN 2 modulo'
799 % ---- if even page number and duplex, then exchange left and right
800 PageNumber 1 and 0 eq SwitchHeader and{exch}if
802 % ---- process the left lines
803 false HeaderOrFooterTextLines
805 % ---- process the right lines
806 true HeaderOrFooterTextLines
811 HeaderLinesRight HeaderLinesLeft
812 /HeaderStart HeaderLineHeight HeaderPad
813 HeaderFrameProperties 0 get
820 FooterLinesRight FooterLinesLeft
821 /FooterStart FooterLineHeight FooterPad
822 FooterFrameProperties 0 get
832 /sw( )stringwidth pop def
833 /aw(01234567890abcdefghijklmnopqrstuvwxyz)dup length exch
834 stringwidth pop exch div def
835 /t1 12/Helvetica-Oblique DefFont
838 (languagelevel = )show
839 languagelevel 32 string cvs show
841 0 FontHeight neg rmoveto
847 ( point, the line height is )show
848 lh 32 string cvs show
849 (, the space width is )show
850 sw 32 string cvs show
853 0 FontHeight neg rmoveto
855 (and a crude estimate of average character width is )show
856 aw 32 string cvs show
859 0 FontHeight neg rmoveto
863 /cm{72 mul 2.54 div}def
866 % key = font name value = font dictionary
867 FontDirectory{pop 10 exch ReportFontInfo}forall
870 % 3 cm 20 cm moveto 10/Courier ReportFontInfo showpage
871 % 3 cm 20 cm moveto ReportAllFontInfo showpage
873 % === END ps-print prologue 1