#!/usr/bin/perl
#
# Copyright (C) Koji Nakamaru
#
# Author: Koji Nakamaru (nakamaru at gmail.com)
# Modified: Apr 30 2005
#   * changed the contact information.
# Created: May 20 2002
# Keywords: postscript, fixeucfont
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Emacs; see the file COPYING.  If not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#

$isconverted = 0;
while (<>) {
    if (/^% fixeucfontaux begin/) {
	$isconverted = 1;
    }
    if (! $isconverted) {
	if (/^\/ishow {/) {
	    $_ = <<'EOF'
% fixeucfontaux begin
/tmpstr1 1 string def
/tmpstr2 2 string def
/tmpcnt 0 def
% fixeucfontaux end
/ishow {
EOF
	} elsif (/^0 vertoffset moveto show\n$/) {
	    $_ = <<'EOF'
% fixeucfontaux begin
%0 vertoffset moveto show
currentfont /FDepVector known {
  currentfont /FDepVector get 0 get printSize scalefont /efont exch def
  currentfont /FDepVector get 1 get /EUCFont get printSize scalefont /jfont exch def
}{
  currentfont /efont exch def
  /jfont null def
} ifelse
0 vertoffset moveto
{
  dup 16#80 lt jfont null eq or {
    tmpstr1 exch 0 exch put
    currentfont
    efont setfont
    tmpstr1 show
    setfont
  }{
    tmpcnt 0 eq {
      tmpstr2 exch 0 exch put
      /tmpcnt 1 def
    }{
      tmpstr2 exch 1 exch put
      /tmpcnt 0 def
      currentfont
      jfont setfont
      tmpstr2 show
      setfont
    } ifelse
  } ifelse
} forall
% fixeucfontaux end
EOF
	}
    }
    print;
}
