[Top][All Lists]

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

[Groff] Implementing a full right-to-left integration to groff

From: Bereshit
Subject: [Groff] Implementing a full right-to-left integration to groff
Date: Mon, 18 Dec 2006 16:57:20 +0100 (CET)

Hi, I looked around in order to see what is available for typesetting
hebrew, and found really nothing like what I want. Thus I decided to
implement it by myself, and being a groffer for many years, I chose to
do it with groff.

I found very easy to implement a RTL support for the PostScript output,
in order to use all low and high level abilities of groff:
  justification, alignment, indentation, etc.
except kerning. Anyway, hebrew shapes are such that good fonts don't
need kerning.

The idea is quite simple: install an hebrew font to your system
(groff/devps and probably ghostscript fonts). Create a macro file
for overriding this font by a "mirror font" for the PostScript
interpreter (let groff think it is the "normal font"...): same
size for each character, same writing-direction for successive
letters, but each character being mirrored.

Then create macros for encapsulating your block of hebrew text
by an appropriate translate/scale combination in the PostScript
output, and it's done!

You can mix several RTL fonts, in the same paragraph, but
of course no LTR and RTL. You can still with good macros
make a tiny LTR numbering system at the beginning of each
of your RTL paragraphs.

Here is the beginning of my file; more remarks follow.

\X'ps: def /mirrorfont { dup 10 dict dup begin exch /BaseFont exch'\c
\X'ps: def findfont def /FontName 2 index def /FontType'\c
\X'ps: def 3 def /FontMatrix [-1 0 0 1 0 0] def /FontBBox'\c
\X'ps: def [0 0 0 0] def /Encoding BaseFont /Encoding get def'\c
\X'ps: def /OneChar 1 string def'\c
\X'ps: def /BuildChar'\c
\X'ps: def {'\c
\X'ps: def    exch begin OneChar exch 0 exch put BaseFont setfont'\c
\X'ps: def    OneChar stringwidth exch neg exch 2 copy'\c
\X'ps: def    2 copy moveto OneChar true charpath pathbbox'\c
\X'ps: def    setcachedevice moveto OneChar show end'\c
\X'ps: def } def'\c
\X'ps: def end definefont pop} def'\c
.\" Print something empty in order to make groff change the font
.\" though nothing has been printed yet, then extract the
.\" internal PostScript FontName of the font.
.ft \\$1
\z\N'32'\X'ps: exec currentfont begin FontName end mirrorfont'\c

The MFONT request creates a "mirror font" with the name of its
argument: .MFONT HEB    will make the font HEB be mirrored.
Until... next page. But a good macro system should provide
a macro being called at the beginning of each page; it's OK to
make it call the MFONT request for all your hebrew fonts, thus
you won't have to think about it. For instance, the -me macro
system provides macros to be redefined where you can put this

The block for mirroring the section where your hebrew text is
depends on your macro system, so I only wrote hacks for the
moment, but I may later write something more sophisticated,
for 1 or 2 columns, and handling the 'end of page' which needs
some attention.


Thomas Baruchel

reply via email to

[Prev in Thread] Current Thread [Next in Thread]