[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hebrew printing



Eli Marmor wrote:
> Meanwhile, if Dov Grobgeld (I hope I don't mispell his name) reads
> these lines, he may help you. I think he has a Perl script which
> trying to do a similar thing.

Indeed I do. I'm inclosing it below. This script takes a postscript
output by netscape, guesses which strings are in Hebrew, and changes
the font into Hebrew. It also justifies the position of the strings 
in order to try to keep the right margin straight. Finally it
ouputs a new postscript file. You have to configure your font
directory at the top of the script. 

#!/usr/local/bin/perl

######################################################################
#  nsps2heb
#
#  A Hebrew beautification script for netscape postscript output.
#
#  Dov Grobgeld
#  dov@orbotech.co.il
#  Version 1.0
#  19 Jan 1997
#
#  TODO:
#    * Support use of different fonts for bold, italics, etc.
# 
#  Licence:
#    * This program is distributed under the GNU licence.
######################################################################

##############################
# <Configuration section>
##############################
$font_dir = "/home/dov/lib/X11fonts/Type1/";  # Directory of Hebrew fonts
@fonts = ("wehad.pfa",                     # Proportional font
          "wehm.pfa",	  		   # Fixed font
	 );
	 
@font_names = ("WebHebrewAD",		   # PostScript prop font name
	       "WebHebrewMonospace");	   # PostScript fixed font name 

##############################
# </configuration section>
##############################
$do_ins_page = 1;
$in_prologue = 1;

while(<>) {
    if ($in_prologue && /^%%EndComments/) {
	print "%% Hebrew beautified by nsps2heb, a program by Dov Grobgeld\n";
    }
    
    if ($in_prologue) {
	# Get rid of high characters in the title
	s/[\200-\377]/sprintf("\\%03o", unpack("C",$&))/ge;
    }
	
    if ($in_prologue && !/^%/) {
	insert_fonts();
	declare_hshow();
	$in_prologue = 0;
    }
    if (!$done_font && m|^/F0|) {
	$in_font_section++;
    }
    if ($in_font_section && m|^/rhc|) {
	$in_font_section=0;
	process_font_section(@font_section);
	$done_font++;
    }
    if ($in_font_section) {
	push(@font_section, $_);
	next;
    }
    if (/^(\d+) ([fF]\d)/) {
	$last_font_size = $1;
	$last_font_num = $2;
    }
    if ($do_ins_page && /^showpage/) {
        $page++;
        print 595/2, " 40 moveto\n";
	print "/TimesRoman findfont 12 scalefont setfont\n";
	print "($page) dup stringwidth exch -2 div exch rmoveto show\n";
    }

    # If the string looks like Hebrew right justify it by comparing
    # the width of the Times roman font with the hebrew font and doing
    # a rmoveto in the xdirection of the delta.
    if (/^(\(.*?\\3\d\d.*?\)) show/) {
	print "$1 dup $last_font_size t$last_font_num " .
	  "stringwidth rmoveto " .
	  "dup $last_font_size $last_font_num " .
	  "stringwidth exch neg exch rmoveto " .
	  "show\n";
	next;
    }
    print;
}

sub insert_fonts {
    for $fn (@fonts) {
	open(FONT, $font_dir . "/". $fn) || die "Can't open fontfile $fn!\n";
	print <FONT>;
    }
    close(FONT);
}

# hshow is not used at the moment
sub declare_hshow {
    print "/hshow { show } def\n";
}

sub process_font_section {
    my(@font_section) = @_;

    # First change f* declarations to tf*
    foreach(@font_section) {
	my $line = $_;   # Make a copy so that we don't change @font_section
        $line=~ s:/F(\d):/TF$1:g;
        $line=~ s:/f(\d):/tf$1:g;
	print $line;
    }

    # Now change the fonts for the f declarations
    foreach(@font_section) {
	s/Times-(\S+)/$font_names[0]/g;
	s/Courier-(\S+)/$font_names[1]/g;
	print;
    }
}

--
                                                                    ___
Dov Grobgeld                        | Email: dov@orbotech.co.il    /+  \  PCB
Algorithms Department, Orbotech     | Phone: +972-8-9423882        \  +/  AOI
POB 215, Yavne 81102, Israel	    | Fax:   +972-8-9423775       __| |
               Disclaimer: All views above are mine alone.        ____|