% This is a modified version of StarOffice's xprinter.prolog, produced by
% applying the changes from Michael Davis' staroffice.patch file.
% Please see staroffice.patch file enclosed with KFontinst's archive
% for details of this patch.
%
% The patch is copyright (c) 2000 Michael Davis - and distributed under
% the GNU General Public License.

% USER DEFINITIONS

% 100 defines the maximum no. of fonts in a document. Increase it
% if you need to print documents with more fonts. Remember that each
% font family typically requires four fonts for normal, bold, italic and
% bolditalic faces.
/FontEncodingDict 100 dict def

% Some fonts don't need to be reencoded. Add them to the dictionary here.
FontEncodingDict begin
   % MS FontPack fonts
   /Webdings /Webdings def

   % Win95 fonts
   /Symbol /Symbol def
   /Wingdings-Regular /Wingdings-Regular def

   % StarOffice fonts
   /StarBats /StarBats def
   /StarMath /StarMath def
   /Symbol /Symbol def
end

% END USER DEFINITIONS
% Don't modify anything below here unless you know what you are doing

/ff {
   FontEncodingDict begin
      dup where {
         % the font has a predefined encoding, get it
         pop load
      } {
         % no predefined encoding, reencode the font
         dup findfont begin
            /FontName load
         end
         dup length /TmpFontNameLen exch def
         TmpFontNameLen string cvs
         TmpFontNameLen 7 add string
         /TmpFontName exch def
         TmpFontName exch 0 exch putinterval
         TmpFontName TmpFontNameLen (WinAnsi) putinterval
         dup TmpFontName cvn def
         12 dict begin
            /SysFontDict exch findfont def
            /NewFontDict SysFontDict maxlength dict def
            SysFontDict {
               exch dup /FID eq { pop pop }
               {
                  dup /Encoding eq {
                     exch dup length array copy
                     NewFontDict 3 1 roll put
                  } {
                     exch NewFontDict 3 1 roll put
                  } ifelse
               } ifelse
            } forall

            % rename the font.
            NewFontDict /FontName TmpFontName put

            % reencode using changesvec
            changesvec dup length 2 div /noofchanges exch def aload pop
            1 1 noofchanges {
               pop
               NewFontDict /Encoding get 3 1 roll put
            } for

            % for some reason, some fonts use different glyph names for
            % single guillemots
            SysFontDict begin
               CharStrings /guilsingleft known not {
                  NewFontDict /Encoding get 16#8b /guilsinglleft put
                  NewFontDict /Encoding get 16#9b /guilsinglright put
               } if
            end

            % enroll font in FontDirectory
            TmpFontName NewFontDict definefont pop
         end

         TmpFontName
      } ifelse
   end
   findfont
} def

% The original xprinter.prolog follows. The following modifications
% were made:
%
% 1. The definition for /ff has been removed, as it is redefined above.
% 2. Spelling of some glyph names corrected (Euro, guilsingleft, Zcaron,
%    guilsingright).
/XPrinterDict dup 200 dict def load begin
/bdf{bind def}bind def
/ldf{load def}bdf
/m/rmoveto ldf
/l2/rlineto ldf
/gs/gsave ldf
/gr/grestore ldf
/np/newpath ldf
/sv/save ldf
/rs/restore ldf
/tl/translate ldf
/mt/matrix ldf
/l/length ldf
/z/dict ldf
/d/def ldf
/e/exch ldf
/a/array ldf
/ac/arc ldf
/an/arcn ldf
/b/begin ldf
/pi/putinterval ldf
/t/moveto ldf
/lo/lineto ldf
/st/stroke ldf
/p/add ldf
/s/sub ldf
/c/mul ldf
/v/div ldf
/cp/closepath ldf
/sl/scale ldf
/mf/makefont ldf
/sf/setfont ldf
/f/fill ldf
/sw/setlinewidth ldf
/sc/setlinecap ldf
/sj/setlinejoin ldf
/sg/setgray ldf
/ski/ISOLatin1Encoding where{pop true}{false}ifelse d
/fcd{ff dup l z b{1 index /FID ne{d}{pop pop}ifelse}forall /Encoding ISOLatin1Encoding d currentdict end}bdf
/fdf{e definefont pop}bdf
/sdt 22 z d
sdt b
/tpm mt d
/tpt mt d
/tps mt d
/cps
{/pr2 e cvlit d
/pr1 e cvlit d
/npc pr1 l pr2 l p a d
npc 0 pr1 pi
npc pr1 l pr2 pi
npc cvx
}bdf
/rmx mt d
/frs
{72 0 rmx defaultmatrix dtransform
/yres e d /xres e d
xres dup c yres dup c p sqrt
}bdf
end

/reencodesmalldict 12 dict def
/ReEncodeSmall { 
	reencodesmalldict begin
		/newcodesandnames exch def
		/newfontname exch def
		/basefontname exch def
		/basefontdict basefontname findfont def
		/newfont basefontdict maxlength dict def

		basefontdict
		{
			exch dup /FID ne
			{ 
				dup /Encoding eq
				{ 
					ski
					{
						exch pop
						ISOLatin1Encoding dup length array copy
					}{
					 	exch dup length array copy
					}
					ifelse
					newfont 3 1 roll put
				}{
					exch newfont 3 1 roll put
				}
				ifelse
			}{
				pop pop
			}
			ifelse
		} forall

		newfont /FontName newfontname put
		newcodesandnames aload pop
		newcodesandnames length 2 idiv
		{
			newfont /Encoding get 3 1 roll put
		} repeat

		newfontname newfont definefont pop
	end
} def

/changesvec [
	16#80 /Euro
	16#82 /quotesinglbase
	16#83 /florin
	16#84 /quotedblbase
	16#85 /ellipsis
	16#86 /dagger
	16#87 /daggerdbl
	16#88 /circumflex
	16#89 /perthousand
	16#8a /Scaron
	16#8b /guilsingleft
	16#8c /OE
	16#8e /Zcaron
	16#91 /quoteleft
	16#92 /quoteright
	16#93 /quotedblleft
	16#94 /quotedblright
	16#95 /bullet
	16#96 /endash
	16#97 /emdash
	16#98 /tilde
	16#99 /trademark
	16#9a /scaron
	16#9b /guilsingright
	16#9c /oe
	16#9e /zcaron
	16#9f /Ydieresis
] def


/sus 
{sdt b
/spf e d
/sag e d 
/ces e d
300 ces v sag /spf load
setscreen
end
}bdf
/spt 18 z d
spt b
/bts
{/ybit e d /xbit e d
/byv bstr ybit bwd c xbit 8 idiv
p get d
/mask 1 7 xbit 8 mod s bitshift d
byv mask and 0 ne
}bdf
end
/bsf
{spt b
/y e d /x e d
/xix x 1 p 2 v bpx c cvi d
/yix y 1 p 2 v bpy c cvi d
xix yix bts
{/onb onb 1 p d 1}
{/ofb ofb 1 p d 0}
ifelse
end
}bdf
/setpattern
{spt b
/csz e d
/agl e d
/bwd e d
/bpy e d
/bpx e d
/bstr e d
/onb 0 d /ofb 0 d
csz agl /bsf load
sus
{ }settransfer
ofb ofb onb p v setgray
end
}bdf
/picstr 500 string d
/inch{72 c}bdf
/DP{gs np 0 360 ac cp f gr}bdf
/DL{gs np t lo st gr}bdf
/RGB{setrgbcolor}bdf
/C{gs t show gr}bdf

/ren 12 z d
/REn
{ren b
/nwc e d
/nwf e d
/bft e d
/bfd bft ff d
/nf bfd maxlength z d
bfd
{e dup /FID ne 
{dup /Encoding eq
{e dup l a copy
nf 3 1 roll put}
{e nf 3 1 roll put}
ifelse
}
{pop pop}
ifelse
}forall
nf /FontName nwf put
nwc aload pop
nwc l 2 idiv
{nf /Encoding get 3 1 roll put}
repeat
nwf nf definefont pop
end
}d
/rots{gs t rotate show gr}bdf
